10b57cec5SDimitry Andric //===- ASTReader.h - AST File Reader ----------------------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file defines the ASTReader class, which reads AST files. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric #ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H 140b57cec5SDimitry Andric #define LLVM_CLANG_SERIALIZATION_ASTREADER_H 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric #include "clang/AST/Type.h" 170b57cec5SDimitry Andric #include "clang/Basic/Diagnostic.h" 180b57cec5SDimitry Andric #include "clang/Basic/DiagnosticOptions.h" 190b57cec5SDimitry Andric #include "clang/Basic/IdentifierTable.h" 200b57cec5SDimitry Andric #include "clang/Basic/OpenCLOptions.h" 210b57cec5SDimitry Andric #include "clang/Basic/SourceLocation.h" 220b57cec5SDimitry Andric #include "clang/Basic/Version.h" 230b57cec5SDimitry Andric #include "clang/Lex/ExternalPreprocessorSource.h" 240b57cec5SDimitry Andric #include "clang/Lex/HeaderSearch.h" 250b57cec5SDimitry Andric #include "clang/Lex/PreprocessingRecord.h" 26e8d8bef9SDimitry Andric #include "clang/Lex/PreprocessorOptions.h" 270b57cec5SDimitry Andric #include "clang/Sema/ExternalSemaSource.h" 280b57cec5SDimitry Andric #include "clang/Sema/IdentifierResolver.h" 29e8d8bef9SDimitry Andric #include "clang/Sema/Sema.h" 300b57cec5SDimitry Andric #include "clang/Serialization/ASTBitCodes.h" 310b57cec5SDimitry Andric #include "clang/Serialization/ContinuousRangeMap.h" 32480093f4SDimitry Andric #include "clang/Serialization/ModuleFile.h" 330b57cec5SDimitry Andric #include "clang/Serialization/ModuleFileExtension.h" 340b57cec5SDimitry Andric #include "clang/Serialization/ModuleManager.h" 3581ad6265SDimitry Andric #include "clang/Serialization/SourceLocationEncoding.h" 360b57cec5SDimitry Andric #include "llvm/ADT/ArrayRef.h" 370b57cec5SDimitry Andric #include "llvm/ADT/DenseMap.h" 380b57cec5SDimitry Andric #include "llvm/ADT/DenseSet.h" 390b57cec5SDimitry Andric #include "llvm/ADT/IntrusiveRefCntPtr.h" 400b57cec5SDimitry Andric #include "llvm/ADT/MapVector.h" 415f757f3fSDimitry Andric #include "llvm/ADT/PagedVector.h" 420b57cec5SDimitry Andric #include "llvm/ADT/STLExtras.h" 430b57cec5SDimitry Andric #include "llvm/ADT/SetVector.h" 440b57cec5SDimitry Andric #include "llvm/ADT/SmallPtrSet.h" 450b57cec5SDimitry Andric #include "llvm/ADT/SmallVector.h" 460b57cec5SDimitry Andric #include "llvm/ADT/StringMap.h" 470b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h" 480b57cec5SDimitry Andric #include "llvm/ADT/iterator.h" 490b57cec5SDimitry Andric #include "llvm/ADT/iterator_range.h" 500b57cec5SDimitry Andric #include "llvm/Bitstream/BitstreamReader.h" 510b57cec5SDimitry Andric #include "llvm/Support/MemoryBuffer.h" 520b57cec5SDimitry Andric #include "llvm/Support/Timer.h" 530b57cec5SDimitry Andric #include "llvm/Support/VersionTuple.h" 540b57cec5SDimitry Andric #include <cassert> 550b57cec5SDimitry Andric #include <cstddef> 560b57cec5SDimitry Andric #include <cstdint> 570b57cec5SDimitry Andric #include <ctime> 580b57cec5SDimitry Andric #include <deque> 590b57cec5SDimitry Andric #include <memory> 60bdd1243dSDimitry Andric #include <optional> 610b57cec5SDimitry Andric #include <set> 620b57cec5SDimitry Andric #include <string> 630b57cec5SDimitry Andric #include <utility> 640b57cec5SDimitry Andric #include <vector> 650b57cec5SDimitry Andric 660b57cec5SDimitry Andric namespace clang { 670b57cec5SDimitry Andric 680b57cec5SDimitry Andric class ASTConsumer; 690b57cec5SDimitry Andric class ASTContext; 700b57cec5SDimitry Andric class ASTDeserializationListener; 710b57cec5SDimitry Andric class ASTReader; 720b57cec5SDimitry Andric class ASTRecordReader; 730b57cec5SDimitry Andric class CXXTemporary; 740b57cec5SDimitry Andric class Decl; 75480093f4SDimitry Andric class DeclarationName; 760b57cec5SDimitry Andric class DeclaratorDecl; 770b57cec5SDimitry Andric class DeclContext; 780b57cec5SDimitry Andric class EnumDecl; 790b57cec5SDimitry Andric class Expr; 800b57cec5SDimitry Andric class FieldDecl; 810b57cec5SDimitry Andric class FileEntry; 820b57cec5SDimitry Andric class FileManager; 830b57cec5SDimitry Andric class FileSystemOptions; 840b57cec5SDimitry Andric class FunctionDecl; 850b57cec5SDimitry Andric class GlobalModuleIndex; 860b57cec5SDimitry Andric struct HeaderFileInfo; 870b57cec5SDimitry Andric class HeaderSearchOptions; 880b57cec5SDimitry Andric class LangOptions; 890b57cec5SDimitry Andric class MacroInfo; 900b57cec5SDimitry Andric class InMemoryModuleCache; 910b57cec5SDimitry Andric class NamedDecl; 920b57cec5SDimitry Andric class NamespaceDecl; 930b57cec5SDimitry Andric class ObjCCategoryDecl; 940b57cec5SDimitry Andric class ObjCInterfaceDecl; 950b57cec5SDimitry Andric class PCHContainerReader; 960b57cec5SDimitry Andric class Preprocessor; 970b57cec5SDimitry Andric class PreprocessorOptions; 980b57cec5SDimitry Andric class Sema; 990b57cec5SDimitry Andric class SourceManager; 1000b57cec5SDimitry Andric class Stmt; 1010b57cec5SDimitry Andric class SwitchCase; 1020b57cec5SDimitry Andric class TargetOptions; 103480093f4SDimitry Andric class Token; 1040b57cec5SDimitry Andric class TypedefNameDecl; 1050b57cec5SDimitry Andric class ValueDecl; 1060b57cec5SDimitry Andric class VarDecl; 1070b57cec5SDimitry Andric 1080b57cec5SDimitry Andric /// Abstract interface for callback invocations by the ASTReader. 1090b57cec5SDimitry Andric /// 1100b57cec5SDimitry Andric /// While reading an AST file, the ASTReader will call the methods of the 1110b57cec5SDimitry Andric /// listener to pass on specific information. Some of the listener methods can 1120b57cec5SDimitry Andric /// return true to indicate to the ASTReader that the information (and 1130b57cec5SDimitry Andric /// consequently the AST file) is invalid. 1140b57cec5SDimitry Andric class ASTReaderListener { 1150b57cec5SDimitry Andric public: 1160b57cec5SDimitry Andric virtual ~ASTReaderListener(); 1170b57cec5SDimitry Andric 1180b57cec5SDimitry Andric /// Receives the full Clang version information. 1190b57cec5SDimitry Andric /// 1200b57cec5SDimitry Andric /// \returns true to indicate that the version is invalid. Subclasses should 1210b57cec5SDimitry Andric /// generally defer to this implementation. ReadFullVersionInformation(StringRef FullVersion)1220b57cec5SDimitry Andric virtual bool ReadFullVersionInformation(StringRef FullVersion) { 1230b57cec5SDimitry Andric return FullVersion != getClangFullRepositoryVersion(); 1240b57cec5SDimitry Andric } 1250b57cec5SDimitry Andric ReadModuleName(StringRef ModuleName)1260b57cec5SDimitry Andric virtual void ReadModuleName(StringRef ModuleName) {} ReadModuleMapFile(StringRef ModuleMapPath)1270b57cec5SDimitry Andric virtual void ReadModuleMapFile(StringRef ModuleMapPath) {} 1280b57cec5SDimitry Andric 1290b57cec5SDimitry Andric /// Receives the language options. 1300b57cec5SDimitry Andric /// 1310b57cec5SDimitry Andric /// \returns true to indicate the options are invalid or false otherwise. ReadLanguageOptions(const LangOptions & LangOpts,bool Complain,bool AllowCompatibleDifferences)1320b57cec5SDimitry Andric virtual bool ReadLanguageOptions(const LangOptions &LangOpts, 1330b57cec5SDimitry Andric bool Complain, 1340b57cec5SDimitry Andric bool AllowCompatibleDifferences) { 1350b57cec5SDimitry Andric return false; 1360b57cec5SDimitry Andric } 1370b57cec5SDimitry Andric 1380b57cec5SDimitry Andric /// Receives the target options. 1390b57cec5SDimitry Andric /// 1400b57cec5SDimitry Andric /// \returns true to indicate the target options are invalid, or false 1410b57cec5SDimitry Andric /// otherwise. ReadTargetOptions(const TargetOptions & TargetOpts,bool Complain,bool AllowCompatibleDifferences)1420b57cec5SDimitry Andric virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, 1430b57cec5SDimitry Andric bool AllowCompatibleDifferences) { 1440b57cec5SDimitry Andric return false; 1450b57cec5SDimitry Andric } 1460b57cec5SDimitry Andric 1470b57cec5SDimitry Andric /// Receives the diagnostic options. 1480b57cec5SDimitry Andric /// 1490b57cec5SDimitry Andric /// \returns true to indicate the diagnostic options are invalid, or false 1500b57cec5SDimitry Andric /// otherwise. 1510b57cec5SDimitry Andric virtual bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,bool Complain)1520b57cec5SDimitry Andric ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, 1530b57cec5SDimitry Andric bool Complain) { 1540b57cec5SDimitry Andric return false; 1550b57cec5SDimitry Andric } 1560b57cec5SDimitry Andric 1570b57cec5SDimitry Andric /// Receives the file system options. 1580b57cec5SDimitry Andric /// 1590b57cec5SDimitry Andric /// \returns true to indicate the file system options are invalid, or false 1600b57cec5SDimitry Andric /// otherwise. ReadFileSystemOptions(const FileSystemOptions & FSOpts,bool Complain)1610b57cec5SDimitry Andric virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, 1620b57cec5SDimitry Andric bool Complain) { 1630b57cec5SDimitry Andric return false; 1640b57cec5SDimitry Andric } 1650b57cec5SDimitry Andric 1660b57cec5SDimitry Andric /// Receives the header search options. 1670b57cec5SDimitry Andric /// 168bdd1243dSDimitry Andric /// \param HSOpts The read header search options. The following fields are 169bdd1243dSDimitry Andric /// missing and are reported in ReadHeaderSearchPaths(): 170bdd1243dSDimitry Andric /// UserEntries, SystemHeaderPrefixes, VFSOverlayFiles. 171bdd1243dSDimitry Andric /// 1720b57cec5SDimitry Andric /// \returns true to indicate the header search options are invalid, or false 1730b57cec5SDimitry Andric /// otherwise. ReadHeaderSearchOptions(const HeaderSearchOptions & HSOpts,StringRef SpecificModuleCachePath,bool Complain)1740b57cec5SDimitry Andric virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, 1750b57cec5SDimitry Andric StringRef SpecificModuleCachePath, 1760b57cec5SDimitry Andric bool Complain) { 1770b57cec5SDimitry Andric return false; 1780b57cec5SDimitry Andric } 1790b57cec5SDimitry Andric 180bdd1243dSDimitry Andric /// Receives the header search paths. 181bdd1243dSDimitry Andric /// 182bdd1243dSDimitry Andric /// \param HSOpts The read header search paths. Only the following fields are 183bdd1243dSDimitry Andric /// initialized: UserEntries, SystemHeaderPrefixes, 184bdd1243dSDimitry Andric /// VFSOverlayFiles. The rest is reported in 185bdd1243dSDimitry Andric /// ReadHeaderSearchOptions(). 186bdd1243dSDimitry Andric /// 187bdd1243dSDimitry Andric /// \returns true to indicate the header search paths are invalid, or false 188bdd1243dSDimitry Andric /// otherwise. ReadHeaderSearchPaths(const HeaderSearchOptions & HSOpts,bool Complain)189bdd1243dSDimitry Andric virtual bool ReadHeaderSearchPaths(const HeaderSearchOptions &HSOpts, 190bdd1243dSDimitry Andric bool Complain) { 191bdd1243dSDimitry Andric return false; 192bdd1243dSDimitry Andric } 193bdd1243dSDimitry Andric 1940b57cec5SDimitry Andric /// Receives the preprocessor options. 1950b57cec5SDimitry Andric /// 1960b57cec5SDimitry Andric /// \param SuggestedPredefines Can be filled in with the set of predefines 1970b57cec5SDimitry Andric /// that are suggested by the preprocessor options. Typically only used when 1980b57cec5SDimitry Andric /// loading a precompiled header. 1990b57cec5SDimitry Andric /// 2000b57cec5SDimitry Andric /// \returns true to indicate the preprocessor options are invalid, or false 2010b57cec5SDimitry Andric /// otherwise. ReadPreprocessorOptions(const PreprocessorOptions & PPOpts,bool ReadMacros,bool Complain,std::string & SuggestedPredefines)2020b57cec5SDimitry Andric virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, 2035f757f3fSDimitry Andric bool ReadMacros, bool Complain, 2040b57cec5SDimitry Andric std::string &SuggestedPredefines) { 2050b57cec5SDimitry Andric return false; 2060b57cec5SDimitry Andric } 2070b57cec5SDimitry Andric 2080b57cec5SDimitry Andric /// Receives __COUNTER__ value. ReadCounter(const serialization::ModuleFile & M,unsigned Value)2090b57cec5SDimitry Andric virtual void ReadCounter(const serialization::ModuleFile &M, 2100b57cec5SDimitry Andric unsigned Value) {} 2110b57cec5SDimitry Andric 2120b57cec5SDimitry Andric /// This is called for each AST file loaded. visitModuleFile(StringRef Filename,serialization::ModuleKind Kind)2130b57cec5SDimitry Andric virtual void visitModuleFile(StringRef Filename, 2140b57cec5SDimitry Andric serialization::ModuleKind Kind) {} 2150b57cec5SDimitry Andric 2160b57cec5SDimitry Andric /// Returns true if this \c ASTReaderListener wants to receive the 2170b57cec5SDimitry Andric /// input files of the AST file via \c visitInputFile, false otherwise. needsInputFileVisitation()2180b57cec5SDimitry Andric virtual bool needsInputFileVisitation() { return false; } 2190b57cec5SDimitry Andric 2200b57cec5SDimitry Andric /// Returns true if this \c ASTReaderListener wants to receive the 2210b57cec5SDimitry Andric /// system input files of the AST file via \c visitInputFile, false otherwise. needsSystemInputFileVisitation()2220b57cec5SDimitry Andric virtual bool needsSystemInputFileVisitation() { return false; } 2230b57cec5SDimitry Andric 2240b57cec5SDimitry Andric /// if \c needsInputFileVisitation returns true, this is called for 2250b57cec5SDimitry Andric /// each non-system input file of the AST File. If 2260b57cec5SDimitry Andric /// \c needsSystemInputFileVisitation is true, then it is called for all 2270b57cec5SDimitry Andric /// system input files as well. 2280b57cec5SDimitry Andric /// 2290b57cec5SDimitry Andric /// \returns true to continue receiving the next input file, false to stop. visitInputFile(StringRef Filename,bool isSystem,bool isOverridden,bool isExplicitModule)2300b57cec5SDimitry Andric virtual bool visitInputFile(StringRef Filename, bool isSystem, 2310b57cec5SDimitry Andric bool isOverridden, bool isExplicitModule) { 2320b57cec5SDimitry Andric return true; 2330b57cec5SDimitry Andric } 2340b57cec5SDimitry Andric 2350b57cec5SDimitry Andric /// Returns true if this \c ASTReaderListener wants to receive the 2360b57cec5SDimitry Andric /// imports of the AST file via \c visitImport, false otherwise. needsImportVisitation()2370b57cec5SDimitry Andric virtual bool needsImportVisitation() const { return false; } 2380b57cec5SDimitry Andric 2390b57cec5SDimitry Andric /// If needsImportVisitation returns \c true, this is called for each 2400b57cec5SDimitry Andric /// AST file imported by this AST file. visitImport(StringRef ModuleName,StringRef Filename)2410b57cec5SDimitry Andric virtual void visitImport(StringRef ModuleName, StringRef Filename) {} 2420b57cec5SDimitry Andric 2430b57cec5SDimitry Andric /// Indicates that a particular module file extension has been read. readModuleFileExtension(const ModuleFileExtensionMetadata & Metadata)2440b57cec5SDimitry Andric virtual void readModuleFileExtension( 2450b57cec5SDimitry Andric const ModuleFileExtensionMetadata &Metadata) {} 2460b57cec5SDimitry Andric }; 2470b57cec5SDimitry Andric 2480b57cec5SDimitry Andric /// Simple wrapper class for chaining listeners. 2490b57cec5SDimitry Andric class ChainedASTReaderListener : public ASTReaderListener { 2500b57cec5SDimitry Andric std::unique_ptr<ASTReaderListener> First; 2510b57cec5SDimitry Andric std::unique_ptr<ASTReaderListener> Second; 2520b57cec5SDimitry Andric 2530b57cec5SDimitry Andric public: 2540b57cec5SDimitry Andric /// Takes ownership of \p First and \p Second. ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First,std::unique_ptr<ASTReaderListener> Second)2550b57cec5SDimitry Andric ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First, 2560b57cec5SDimitry Andric std::unique_ptr<ASTReaderListener> Second) 2570b57cec5SDimitry Andric : First(std::move(First)), Second(std::move(Second)) {} 2580b57cec5SDimitry Andric takeFirst()2590b57cec5SDimitry Andric std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); } takeSecond()2600b57cec5SDimitry Andric std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); } 2610b57cec5SDimitry Andric 2620b57cec5SDimitry Andric bool ReadFullVersionInformation(StringRef FullVersion) override; 2630b57cec5SDimitry Andric void ReadModuleName(StringRef ModuleName) override; 2640b57cec5SDimitry Andric void ReadModuleMapFile(StringRef ModuleMapPath) override; 2650b57cec5SDimitry Andric bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, 2660b57cec5SDimitry Andric bool AllowCompatibleDifferences) override; 2670b57cec5SDimitry Andric bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, 2680b57cec5SDimitry Andric bool AllowCompatibleDifferences) override; 2690b57cec5SDimitry Andric bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, 2700b57cec5SDimitry Andric bool Complain) override; 2710b57cec5SDimitry Andric bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, 2720b57cec5SDimitry Andric bool Complain) override; 2730b57cec5SDimitry Andric 2740b57cec5SDimitry Andric bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, 2750b57cec5SDimitry Andric StringRef SpecificModuleCachePath, 2760b57cec5SDimitry Andric bool Complain) override; 2770b57cec5SDimitry Andric bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, 2785f757f3fSDimitry Andric bool ReadMacros, bool Complain, 2790b57cec5SDimitry Andric std::string &SuggestedPredefines) override; 2800b57cec5SDimitry Andric 2810b57cec5SDimitry Andric void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override; 2820b57cec5SDimitry Andric bool needsInputFileVisitation() override; 2830b57cec5SDimitry Andric bool needsSystemInputFileVisitation() override; 2840b57cec5SDimitry Andric void visitModuleFile(StringRef Filename, 2850b57cec5SDimitry Andric serialization::ModuleKind Kind) override; 2860b57cec5SDimitry Andric bool visitInputFile(StringRef Filename, bool isSystem, 2870b57cec5SDimitry Andric bool isOverridden, bool isExplicitModule) override; 2880b57cec5SDimitry Andric void readModuleFileExtension( 2890b57cec5SDimitry Andric const ModuleFileExtensionMetadata &Metadata) override; 2900b57cec5SDimitry Andric }; 2910b57cec5SDimitry Andric 2920b57cec5SDimitry Andric /// ASTReaderListener implementation to validate the information of 2930b57cec5SDimitry Andric /// the PCH file against an initialized Preprocessor. 2940b57cec5SDimitry Andric class PCHValidator : public ASTReaderListener { 2950b57cec5SDimitry Andric Preprocessor &PP; 2960b57cec5SDimitry Andric ASTReader &Reader; 2970b57cec5SDimitry Andric 2980b57cec5SDimitry Andric public: PCHValidator(Preprocessor & PP,ASTReader & Reader)2990b57cec5SDimitry Andric PCHValidator(Preprocessor &PP, ASTReader &Reader) 3000b57cec5SDimitry Andric : PP(PP), Reader(Reader) {} 3010b57cec5SDimitry Andric 3020b57cec5SDimitry Andric bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, 3030b57cec5SDimitry Andric bool AllowCompatibleDifferences) override; 3040b57cec5SDimitry Andric bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, 3050b57cec5SDimitry Andric bool AllowCompatibleDifferences) override; 3060b57cec5SDimitry Andric bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, 3070b57cec5SDimitry Andric bool Complain) override; 3085f757f3fSDimitry Andric bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, 3095f757f3fSDimitry Andric bool ReadMacros, bool Complain, 3100b57cec5SDimitry Andric std::string &SuggestedPredefines) override; 3110b57cec5SDimitry Andric bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, 3120b57cec5SDimitry Andric StringRef SpecificModuleCachePath, 3130b57cec5SDimitry Andric bool Complain) override; 3140b57cec5SDimitry Andric void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override; 3150b57cec5SDimitry Andric }; 3160b57cec5SDimitry Andric 3170b57cec5SDimitry Andric /// ASTReaderListenter implementation to set SuggestedPredefines of 3180b57cec5SDimitry Andric /// ASTReader which is required to use a pch file. This is the replacement 3190b57cec5SDimitry Andric /// of PCHValidator or SimplePCHValidator when using a pch file without 3200b57cec5SDimitry Andric /// validating it. 3210b57cec5SDimitry Andric class SimpleASTReaderListener : public ASTReaderListener { 3220b57cec5SDimitry Andric Preprocessor &PP; 3230b57cec5SDimitry Andric 3240b57cec5SDimitry Andric public: SimpleASTReaderListener(Preprocessor & PP)3250b57cec5SDimitry Andric SimpleASTReaderListener(Preprocessor &PP) : PP(PP) {} 3260b57cec5SDimitry Andric 3275f757f3fSDimitry Andric bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, 3285f757f3fSDimitry Andric bool ReadMacros, bool Complain, 3290b57cec5SDimitry Andric std::string &SuggestedPredefines) override; 3300b57cec5SDimitry Andric }; 3310b57cec5SDimitry Andric 3320b57cec5SDimitry Andric namespace serialization { 3330b57cec5SDimitry Andric 3340b57cec5SDimitry Andric class ReadMethodPoolVisitor; 3350b57cec5SDimitry Andric 3360b57cec5SDimitry Andric namespace reader { 3370b57cec5SDimitry Andric 3380b57cec5SDimitry Andric class ASTIdentifierLookupTrait; 3390b57cec5SDimitry Andric 3400b57cec5SDimitry Andric /// The on-disk hash table(s) used for DeclContext name lookup. 3410b57cec5SDimitry Andric struct DeclContextLookupTable; 3420b57cec5SDimitry Andric 3430b57cec5SDimitry Andric } // namespace reader 3440b57cec5SDimitry Andric 3450b57cec5SDimitry Andric } // namespace serialization 3460b57cec5SDimitry Andric 3470b57cec5SDimitry Andric /// Reads an AST files chain containing the contents of a translation 3480b57cec5SDimitry Andric /// unit. 3490b57cec5SDimitry Andric /// 3500b57cec5SDimitry Andric /// The ASTReader class reads bitstreams (produced by the ASTWriter 3510b57cec5SDimitry Andric /// class) containing the serialized representation of a given 3520b57cec5SDimitry Andric /// abstract syntax tree and its supporting data structures. An 3530b57cec5SDimitry Andric /// instance of the ASTReader can be attached to an ASTContext object, 3540b57cec5SDimitry Andric /// which will provide access to the contents of the AST files. 3550b57cec5SDimitry Andric /// 3560b57cec5SDimitry Andric /// The AST reader provides lazy de-serialization of declarations, as 3570b57cec5SDimitry Andric /// required when traversing the AST. Only those AST nodes that are 3580b57cec5SDimitry Andric /// actually required will be de-serialized. 3590b57cec5SDimitry Andric class ASTReader 3600b57cec5SDimitry Andric : public ExternalPreprocessorSource, 3610b57cec5SDimitry Andric public ExternalPreprocessingRecordSource, 3620b57cec5SDimitry Andric public ExternalHeaderFileInfoSource, 3630b57cec5SDimitry Andric public ExternalSemaSource, 3640b57cec5SDimitry Andric public IdentifierInfoLookup, 3650b57cec5SDimitry Andric public ExternalSLocEntrySource 3660b57cec5SDimitry Andric { 3670b57cec5SDimitry Andric public: 3680b57cec5SDimitry Andric /// Types of AST files. 3690b57cec5SDimitry Andric friend class ASTDeclReader; 3700b57cec5SDimitry Andric friend class ASTIdentifierIterator; 3710b57cec5SDimitry Andric friend class ASTRecordReader; 3720b57cec5SDimitry Andric friend class ASTUnit; // ASTUnit needs to remap source locations. 3730b57cec5SDimitry Andric friend class ASTWriter; 3740b57cec5SDimitry Andric friend class PCHValidator; 3750b57cec5SDimitry Andric friend class serialization::reader::ASTIdentifierLookupTrait; 3760b57cec5SDimitry Andric friend class serialization::ReadMethodPoolVisitor; 3770b57cec5SDimitry Andric friend class TypeLocReader; 3780b57cec5SDimitry Andric 3790b57cec5SDimitry Andric using RecordData = SmallVector<uint64_t, 64>; 3800b57cec5SDimitry Andric using RecordDataImpl = SmallVectorImpl<uint64_t>; 3810b57cec5SDimitry Andric 3820b57cec5SDimitry Andric /// The result of reading the control block of an AST file, which 3830b57cec5SDimitry Andric /// can fail for various reasons. 3840b57cec5SDimitry Andric enum ASTReadResult { 3850b57cec5SDimitry Andric /// The control block was read successfully. Aside from failures, 3860b57cec5SDimitry Andric /// the AST file is safe to read into the current context. 3870b57cec5SDimitry Andric Success, 3880b57cec5SDimitry Andric 3890b57cec5SDimitry Andric /// The AST file itself appears corrupted. 3900b57cec5SDimitry Andric Failure, 3910b57cec5SDimitry Andric 3920b57cec5SDimitry Andric /// The AST file was missing. 3930b57cec5SDimitry Andric Missing, 3940b57cec5SDimitry Andric 3950b57cec5SDimitry Andric /// The AST file is out-of-date relative to its input files, 3960b57cec5SDimitry Andric /// and needs to be regenerated. 3970b57cec5SDimitry Andric OutOfDate, 3980b57cec5SDimitry Andric 3990b57cec5SDimitry Andric /// The AST file was written by a different version of Clang. 4000b57cec5SDimitry Andric VersionMismatch, 4010b57cec5SDimitry Andric 402bdd1243dSDimitry Andric /// The AST file was written with a different language/target 4030b57cec5SDimitry Andric /// configuration. 4040b57cec5SDimitry Andric ConfigurationMismatch, 4050b57cec5SDimitry Andric 4060b57cec5SDimitry Andric /// The AST file has errors. 4070b57cec5SDimitry Andric HadErrors 4080b57cec5SDimitry Andric }; 4090b57cec5SDimitry Andric 4100b57cec5SDimitry Andric using ModuleFile = serialization::ModuleFile; 4110b57cec5SDimitry Andric using ModuleKind = serialization::ModuleKind; 4120b57cec5SDimitry Andric using ModuleManager = serialization::ModuleManager; 4130b57cec5SDimitry Andric using ModuleIterator = ModuleManager::ModuleIterator; 4140b57cec5SDimitry Andric using ModuleConstIterator = ModuleManager::ModuleConstIterator; 4150b57cec5SDimitry Andric using ModuleReverseIterator = ModuleManager::ModuleReverseIterator; 4160b57cec5SDimitry Andric 4170b57cec5SDimitry Andric private: 41881ad6265SDimitry Andric using LocSeq = SourceLocationSequence; 41981ad6265SDimitry Andric 4200b57cec5SDimitry Andric /// The receiver of some callbacks invoked by ASTReader. 4210b57cec5SDimitry Andric std::unique_ptr<ASTReaderListener> Listener; 4220b57cec5SDimitry Andric 4230b57cec5SDimitry Andric /// The receiver of deserialization events. 4240b57cec5SDimitry Andric ASTDeserializationListener *DeserializationListener = nullptr; 4250b57cec5SDimitry Andric 4260b57cec5SDimitry Andric bool OwnsDeserializationListener = false; 4270b57cec5SDimitry Andric 4280b57cec5SDimitry Andric SourceManager &SourceMgr; 4290b57cec5SDimitry Andric FileManager &FileMgr; 4300b57cec5SDimitry Andric const PCHContainerReader &PCHContainerRdr; 4310b57cec5SDimitry Andric DiagnosticsEngine &Diags; 4320b57cec5SDimitry Andric 4330b57cec5SDimitry Andric /// The semantic analysis object that will be processing the 4340b57cec5SDimitry Andric /// AST files and the translation unit that uses it. 4350b57cec5SDimitry Andric Sema *SemaObj = nullptr; 4360b57cec5SDimitry Andric 4370b57cec5SDimitry Andric /// The preprocessor that will be loading the source file. 4380b57cec5SDimitry Andric Preprocessor &PP; 4390b57cec5SDimitry Andric 4400b57cec5SDimitry Andric /// The AST context into which we'll read the AST files. 4410b57cec5SDimitry Andric ASTContext *ContextObj = nullptr; 4420b57cec5SDimitry Andric 4430b57cec5SDimitry Andric /// The AST consumer. 4440b57cec5SDimitry Andric ASTConsumer *Consumer = nullptr; 4450b57cec5SDimitry Andric 4460b57cec5SDimitry Andric /// The module manager which manages modules and their dependencies 4470b57cec5SDimitry Andric ModuleManager ModuleMgr; 4480b57cec5SDimitry Andric 4490b57cec5SDimitry Andric /// A dummy identifier resolver used to merge TU-scope declarations in 4500b57cec5SDimitry Andric /// C, for the cases where we don't have a Sema object to provide a real 4510b57cec5SDimitry Andric /// identifier resolver. 4520b57cec5SDimitry Andric IdentifierResolver DummyIdResolver; 4530b57cec5SDimitry Andric 4540b57cec5SDimitry Andric /// A mapping from extension block names to module file extensions. 4550b57cec5SDimitry Andric llvm::StringMap<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions; 4560b57cec5SDimitry Andric 4570b57cec5SDimitry Andric /// A timer used to track the time spent deserializing. 4580b57cec5SDimitry Andric std::unique_ptr<llvm::Timer> ReadTimer; 4590b57cec5SDimitry Andric 4600b57cec5SDimitry Andric /// The location where the module file will be considered as 4610b57cec5SDimitry Andric /// imported from. For non-module AST types it should be invalid. 4620b57cec5SDimitry Andric SourceLocation CurrentImportLoc; 4630b57cec5SDimitry Andric 464e8d8bef9SDimitry Andric /// The module kind that is currently deserializing. 465bdd1243dSDimitry Andric std::optional<ModuleKind> CurrentDeserializingModuleKind; 466e8d8bef9SDimitry Andric 4670b57cec5SDimitry Andric /// The global module index, if loaded. 4680b57cec5SDimitry Andric std::unique_ptr<GlobalModuleIndex> GlobalIndex; 4690b57cec5SDimitry Andric 4700b57cec5SDimitry Andric /// A map of global bit offsets to the module that stores entities 4710b57cec5SDimitry Andric /// at those bit offsets. 4720b57cec5SDimitry Andric ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap; 4730b57cec5SDimitry Andric 4740b57cec5SDimitry Andric /// A map of negated SLocEntryIDs to the modules containing them. 4750b57cec5SDimitry Andric ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap; 4760b57cec5SDimitry Andric 4770b57cec5SDimitry Andric using GlobalSLocOffsetMapType = 4780b57cec5SDimitry Andric ContinuousRangeMap<unsigned, ModuleFile *, 64>; 4790b57cec5SDimitry Andric 4800b57cec5SDimitry Andric /// A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset) 4810b57cec5SDimitry Andric /// SourceLocation offsets to the modules containing them. 4820b57cec5SDimitry Andric GlobalSLocOffsetMapType GlobalSLocOffsetMap; 4830b57cec5SDimitry Andric 4840b57cec5SDimitry Andric /// Types that have already been loaded from the chain. 4850b57cec5SDimitry Andric /// 4860b57cec5SDimitry Andric /// When the pointer at index I is non-NULL, the type with 4870b57cec5SDimitry Andric /// ID = (I + 1) << FastQual::Width has already been loaded 4885f757f3fSDimitry Andric llvm::PagedVector<QualType> TypesLoaded; 4890b57cec5SDimitry Andric 4900b57cec5SDimitry Andric using GlobalTypeMapType = 4910b57cec5SDimitry Andric ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>; 4920b57cec5SDimitry Andric 4930b57cec5SDimitry Andric /// Mapping from global type IDs to the module in which the 4940b57cec5SDimitry Andric /// type resides along with the offset that should be added to the 4950b57cec5SDimitry Andric /// global type ID to produce a local ID. 4960b57cec5SDimitry Andric GlobalTypeMapType GlobalTypeMap; 4970b57cec5SDimitry Andric 4980b57cec5SDimitry Andric /// Declarations that have already been loaded from the chain. 4990b57cec5SDimitry Andric /// 5000b57cec5SDimitry Andric /// When the pointer at index I is non-NULL, the declaration with ID 5010b57cec5SDimitry Andric /// = I + 1 has already been loaded. 5025f757f3fSDimitry Andric llvm::PagedVector<Decl *> DeclsLoaded; 5030b57cec5SDimitry Andric 5040b57cec5SDimitry Andric using GlobalDeclMapType = 5050b57cec5SDimitry Andric ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>; 5060b57cec5SDimitry Andric 5070b57cec5SDimitry Andric /// Mapping from global declaration IDs to the module in which the 5080b57cec5SDimitry Andric /// declaration resides. 5090b57cec5SDimitry Andric GlobalDeclMapType GlobalDeclMap; 5100b57cec5SDimitry Andric 5110b57cec5SDimitry Andric using FileOffset = std::pair<ModuleFile *, uint64_t>; 5120b57cec5SDimitry Andric using FileOffsetsTy = SmallVector<FileOffset, 2>; 5130b57cec5SDimitry Andric using DeclUpdateOffsetsMap = 5140b57cec5SDimitry Andric llvm::DenseMap<serialization::DeclID, FileOffsetsTy>; 5150b57cec5SDimitry Andric 5160b57cec5SDimitry Andric /// Declarations that have modifications residing in a later file 5170b57cec5SDimitry Andric /// in the chain. 5180b57cec5SDimitry Andric DeclUpdateOffsetsMap DeclUpdateOffsets; 5190b57cec5SDimitry Andric 5200b57cec5SDimitry Andric struct PendingUpdateRecord { 5210b57cec5SDimitry Andric Decl *D; 5220b57cec5SDimitry Andric serialization::GlobalDeclID ID; 5230b57cec5SDimitry Andric 5240b57cec5SDimitry Andric // Whether the declaration was just deserialized. 5250b57cec5SDimitry Andric bool JustLoaded; 5260b57cec5SDimitry Andric PendingUpdateRecordPendingUpdateRecord5270b57cec5SDimitry Andric PendingUpdateRecord(serialization::GlobalDeclID ID, Decl *D, 5280b57cec5SDimitry Andric bool JustLoaded) 5290b57cec5SDimitry Andric : D(D), ID(ID), JustLoaded(JustLoaded) {} 5300b57cec5SDimitry Andric }; 5310b57cec5SDimitry Andric 5320b57cec5SDimitry Andric /// Declaration updates for already-loaded declarations that we need 5330b57cec5SDimitry Andric /// to apply once we finish processing an import. 5340b57cec5SDimitry Andric llvm::SmallVector<PendingUpdateRecord, 16> PendingUpdateRecords; 5350b57cec5SDimitry Andric 5360b57cec5SDimitry Andric enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded }; 5370b57cec5SDimitry Andric 5380b57cec5SDimitry Andric /// The DefinitionData pointers that we faked up for class definitions 5390b57cec5SDimitry Andric /// that we needed but hadn't loaded yet. 5400b57cec5SDimitry Andric llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData; 5410b57cec5SDimitry Andric 5420b57cec5SDimitry Andric /// Exception specification updates that have been loaded but not yet 5430b57cec5SDimitry Andric /// propagated across the relevant redeclaration chain. The map key is the 5440b57cec5SDimitry Andric /// canonical declaration (used only for deduplication) and the value is a 5450b57cec5SDimitry Andric /// declaration that has an exception specification. 5460b57cec5SDimitry Andric llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates; 5470b57cec5SDimitry Andric 5480b57cec5SDimitry Andric /// Deduced return type updates that have been loaded but not yet propagated 5490b57cec5SDimitry Andric /// across the relevant redeclaration chain. The map key is the canonical 5500b57cec5SDimitry Andric /// declaration and the value is the deduced return type. 5510b57cec5SDimitry Andric llvm::SmallMapVector<FunctionDecl *, QualType, 4> PendingDeducedTypeUpdates; 5520b57cec5SDimitry Andric 5537a6dacacSDimitry Andric /// Functions has undededuced return type and we wish we can find the deduced 5547a6dacacSDimitry Andric /// return type by iterating the redecls in other modules. 5557a6dacacSDimitry Andric llvm::SmallVector<FunctionDecl *, 4> PendingUndeducedFunctionDecls; 5567a6dacacSDimitry Andric 5570b57cec5SDimitry Andric /// Declarations that have been imported and have typedef names for 5580b57cec5SDimitry Andric /// linkage purposes. 5590b57cec5SDimitry Andric llvm::DenseMap<std::pair<DeclContext *, IdentifierInfo *>, NamedDecl *> 5600b57cec5SDimitry Andric ImportedTypedefNamesForLinkage; 5610b57cec5SDimitry Andric 5620b57cec5SDimitry Andric /// Mergeable declaration contexts that have anonymous declarations 5630b57cec5SDimitry Andric /// within them, and those anonymous declarations. 5640b57cec5SDimitry Andric llvm::DenseMap<Decl*, llvm::SmallVector<NamedDecl*, 2>> 5650b57cec5SDimitry Andric AnonymousDeclarationsForMerging; 5660b57cec5SDimitry Andric 56706c3fb27SDimitry Andric /// Map from numbering information for lambdas to the corresponding lambdas. 56806c3fb27SDimitry Andric llvm::DenseMap<std::pair<const Decl *, unsigned>, NamedDecl *> 56906c3fb27SDimitry Andric LambdaDeclarationsForMerging; 57006c3fb27SDimitry Andric 571480093f4SDimitry Andric /// Key used to identify LifetimeExtendedTemporaryDecl for merging, 572480093f4SDimitry Andric /// containing the lifetime-extending declaration and the mangling number. 573480093f4SDimitry Andric using LETemporaryKey = std::pair<Decl *, unsigned>; 574480093f4SDimitry Andric 575480093f4SDimitry Andric /// Map of already deserialiazed temporaries. 576480093f4SDimitry Andric llvm::DenseMap<LETemporaryKey, LifetimeExtendedTemporaryDecl *> 577480093f4SDimitry Andric LETemporaryForMerging; 578480093f4SDimitry Andric 5790b57cec5SDimitry Andric struct FileDeclsInfo { 5800b57cec5SDimitry Andric ModuleFile *Mod = nullptr; 5810b57cec5SDimitry Andric ArrayRef<serialization::LocalDeclID> Decls; 5820b57cec5SDimitry Andric 5830b57cec5SDimitry Andric FileDeclsInfo() = default; FileDeclsInfoFileDeclsInfo5840b57cec5SDimitry Andric FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls) 5850b57cec5SDimitry Andric : Mod(Mod), Decls(Decls) {} 5860b57cec5SDimitry Andric }; 5870b57cec5SDimitry Andric 5880b57cec5SDimitry Andric /// Map from a FileID to the file-level declarations that it contains. 5890b57cec5SDimitry Andric llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs; 5900b57cec5SDimitry Andric 5910b57cec5SDimitry Andric /// An array of lexical contents of a declaration context, as a sequence of 5920b57cec5SDimitry Andric /// Decl::Kind, DeclID pairs. 5930b57cec5SDimitry Andric using LexicalContents = ArrayRef<llvm::support::unaligned_uint32_t>; 5940b57cec5SDimitry Andric 5950b57cec5SDimitry Andric /// Map from a DeclContext to its lexical contents. 5960b57cec5SDimitry Andric llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>> 5970b57cec5SDimitry Andric LexicalDecls; 5980b57cec5SDimitry Andric 5990b57cec5SDimitry Andric /// Map from the TU to its lexical contents from each module file. 6000b57cec5SDimitry Andric std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls; 6010b57cec5SDimitry Andric 6020b57cec5SDimitry Andric /// Map from a DeclContext to its lookup tables. 6030b57cec5SDimitry Andric llvm::DenseMap<const DeclContext *, 6040b57cec5SDimitry Andric serialization::reader::DeclContextLookupTable> Lookups; 6050b57cec5SDimitry Andric 6060b57cec5SDimitry Andric // Updates for visible decls can occur for other contexts than just the 6070b57cec5SDimitry Andric // TU, and when we read those update records, the actual context may not 6080b57cec5SDimitry Andric // be available yet, so have this pending map using the ID as a key. It 6090b57cec5SDimitry Andric // will be realized when the context is actually loaded. 6100b57cec5SDimitry Andric struct PendingVisibleUpdate { 6110b57cec5SDimitry Andric ModuleFile *Mod; 6120b57cec5SDimitry Andric const unsigned char *Data; 6130b57cec5SDimitry Andric }; 6140b57cec5SDimitry Andric using DeclContextVisibleUpdates = SmallVector<PendingVisibleUpdate, 1>; 6150b57cec5SDimitry Andric 6160b57cec5SDimitry Andric /// Updates to the visible declarations of declaration contexts that 6170b57cec5SDimitry Andric /// haven't been loaded yet. 6180b57cec5SDimitry Andric llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates> 6190b57cec5SDimitry Andric PendingVisibleUpdates; 6200b57cec5SDimitry Andric 6210b57cec5SDimitry Andric /// The set of C++ or Objective-C classes that have forward 6220b57cec5SDimitry Andric /// declarations that have not yet been linked to their definitions. 6230b57cec5SDimitry Andric llvm::SmallPtrSet<Decl *, 4> PendingDefinitions; 6240b57cec5SDimitry Andric 6250b57cec5SDimitry Andric using PendingBodiesMap = 6260b57cec5SDimitry Andric llvm::MapVector<Decl *, uint64_t, 6270b57cec5SDimitry Andric llvm::SmallDenseMap<Decl *, unsigned, 4>, 6280b57cec5SDimitry Andric SmallVector<std::pair<Decl *, uint64_t>, 4>>; 6290b57cec5SDimitry Andric 6300b57cec5SDimitry Andric /// Functions or methods that have bodies that will be attached. 6310b57cec5SDimitry Andric PendingBodiesMap PendingBodies; 6320b57cec5SDimitry Andric 6330b57cec5SDimitry Andric /// Definitions for which we have added merged definitions but not yet 6340b57cec5SDimitry Andric /// performed deduplication. 6350b57cec5SDimitry Andric llvm::SetVector<NamedDecl *> PendingMergedDefinitionsToDeduplicate; 6360b57cec5SDimitry Andric 6370b57cec5SDimitry Andric /// Read the record that describes the lexical contents of a DC. 6380b57cec5SDimitry Andric bool ReadLexicalDeclContextStorage(ModuleFile &M, 6390b57cec5SDimitry Andric llvm::BitstreamCursor &Cursor, 6400b57cec5SDimitry Andric uint64_t Offset, DeclContext *DC); 6410b57cec5SDimitry Andric 6420b57cec5SDimitry Andric /// Read the record that describes the visible contents of a DC. 6430b57cec5SDimitry Andric bool ReadVisibleDeclContextStorage(ModuleFile &M, 6440b57cec5SDimitry Andric llvm::BitstreamCursor &Cursor, 6450b57cec5SDimitry Andric uint64_t Offset, serialization::DeclID ID); 6460b57cec5SDimitry Andric 6470b57cec5SDimitry Andric /// A vector containing identifiers that have already been 6480b57cec5SDimitry Andric /// loaded. 6490b57cec5SDimitry Andric /// 6500b57cec5SDimitry Andric /// If the pointer at index I is non-NULL, then it refers to the 6510b57cec5SDimitry Andric /// IdentifierInfo for the identifier with ID=I+1 that has already 6520b57cec5SDimitry Andric /// been loaded. 6530b57cec5SDimitry Andric std::vector<IdentifierInfo *> IdentifiersLoaded; 6540b57cec5SDimitry Andric 6550b57cec5SDimitry Andric using GlobalIdentifierMapType = 6560b57cec5SDimitry Andric ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>; 6570b57cec5SDimitry Andric 6580b57cec5SDimitry Andric /// Mapping from global identifier IDs to the module in which the 6590b57cec5SDimitry Andric /// identifier resides along with the offset that should be added to the 6600b57cec5SDimitry Andric /// global identifier ID to produce a local ID. 6610b57cec5SDimitry Andric GlobalIdentifierMapType GlobalIdentifierMap; 6620b57cec5SDimitry Andric 6630b57cec5SDimitry Andric /// A vector containing macros that have already been 6640b57cec5SDimitry Andric /// loaded. 6650b57cec5SDimitry Andric /// 6660b57cec5SDimitry Andric /// If the pointer at index I is non-NULL, then it refers to the 6670b57cec5SDimitry Andric /// MacroInfo for the identifier with ID=I+1 that has already 6680b57cec5SDimitry Andric /// been loaded. 6690b57cec5SDimitry Andric std::vector<MacroInfo *> MacrosLoaded; 6700b57cec5SDimitry Andric 6710b57cec5SDimitry Andric using LoadedMacroInfo = 6720b57cec5SDimitry Andric std::pair<IdentifierInfo *, serialization::SubmoduleID>; 6730b57cec5SDimitry Andric 6740b57cec5SDimitry Andric /// A set of #undef directives that we have loaded; used to 6750b57cec5SDimitry Andric /// deduplicate the same #undef information coming from multiple module 6760b57cec5SDimitry Andric /// files. 6770b57cec5SDimitry Andric llvm::DenseSet<LoadedMacroInfo> LoadedUndefs; 6780b57cec5SDimitry Andric 6790b57cec5SDimitry Andric using GlobalMacroMapType = 6800b57cec5SDimitry Andric ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>; 6810b57cec5SDimitry Andric 6820b57cec5SDimitry Andric /// Mapping from global macro IDs to the module in which the 6830b57cec5SDimitry Andric /// macro resides along with the offset that should be added to the 6840b57cec5SDimitry Andric /// global macro ID to produce a local ID. 6850b57cec5SDimitry Andric GlobalMacroMapType GlobalMacroMap; 6860b57cec5SDimitry Andric 6870b57cec5SDimitry Andric /// A vector containing submodules that have already been loaded. 6880b57cec5SDimitry Andric /// 6890b57cec5SDimitry Andric /// This vector is indexed by the Submodule ID (-1). NULL submodule entries 6900b57cec5SDimitry Andric /// indicate that the particular submodule ID has not yet been loaded. 6910b57cec5SDimitry Andric SmallVector<Module *, 2> SubmodulesLoaded; 6920b57cec5SDimitry Andric 6930b57cec5SDimitry Andric using GlobalSubmoduleMapType = 6940b57cec5SDimitry Andric ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>; 6950b57cec5SDimitry Andric 6960b57cec5SDimitry Andric /// Mapping from global submodule IDs to the module file in which the 6970b57cec5SDimitry Andric /// submodule resides along with the offset that should be added to the 6980b57cec5SDimitry Andric /// global submodule ID to produce a local ID. 6990b57cec5SDimitry Andric GlobalSubmoduleMapType GlobalSubmoduleMap; 7000b57cec5SDimitry Andric 7010b57cec5SDimitry Andric /// A set of hidden declarations. 7020b57cec5SDimitry Andric using HiddenNames = SmallVector<Decl *, 2>; 7030b57cec5SDimitry Andric using HiddenNamesMapType = llvm::DenseMap<Module *, HiddenNames>; 7040b57cec5SDimitry Andric 7050b57cec5SDimitry Andric /// A mapping from each of the hidden submodules to the deserialized 7060b57cec5SDimitry Andric /// declarations in that submodule that could be made visible. 7070b57cec5SDimitry Andric HiddenNamesMapType HiddenNamesMap; 7080b57cec5SDimitry Andric 7090b57cec5SDimitry Andric /// A module import, export, or conflict that hasn't yet been resolved. 7100b57cec5SDimitry Andric struct UnresolvedModuleRef { 7110b57cec5SDimitry Andric /// The file in which this module resides. 7120b57cec5SDimitry Andric ModuleFile *File; 7130b57cec5SDimitry Andric 7140b57cec5SDimitry Andric /// The module that is importing or exporting. 7150b57cec5SDimitry Andric Module *Mod; 7160b57cec5SDimitry Andric 7170b57cec5SDimitry Andric /// The kind of module reference. 718bdd1243dSDimitry Andric enum { Import, Export, Conflict, Affecting } Kind; 7190b57cec5SDimitry Andric 7200b57cec5SDimitry Andric /// The local ID of the module that is being exported. 7210b57cec5SDimitry Andric unsigned ID; 7220b57cec5SDimitry Andric 7230b57cec5SDimitry Andric /// Whether this is a wildcard export. 7240b57cec5SDimitry Andric unsigned IsWildcard : 1; 7250b57cec5SDimitry Andric 7260b57cec5SDimitry Andric /// String data. 7270b57cec5SDimitry Andric StringRef String; 7280b57cec5SDimitry Andric }; 7290b57cec5SDimitry Andric 7300b57cec5SDimitry Andric /// The set of module imports and exports that still need to be 7310b57cec5SDimitry Andric /// resolved. 7320b57cec5SDimitry Andric SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs; 7330b57cec5SDimitry Andric 7340b57cec5SDimitry Andric /// A vector containing selectors that have already been loaded. 7350b57cec5SDimitry Andric /// 7360b57cec5SDimitry Andric /// This vector is indexed by the Selector ID (-1). NULL selector 7370b57cec5SDimitry Andric /// entries indicate that the particular selector ID has not yet 7380b57cec5SDimitry Andric /// been loaded. 7390b57cec5SDimitry Andric SmallVector<Selector, 16> SelectorsLoaded; 7400b57cec5SDimitry Andric 7410b57cec5SDimitry Andric using GlobalSelectorMapType = 7420b57cec5SDimitry Andric ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>; 7430b57cec5SDimitry Andric 7440b57cec5SDimitry Andric /// Mapping from global selector IDs to the module in which the 7450b57cec5SDimitry Andric /// global selector ID to produce a local ID. 7460b57cec5SDimitry Andric GlobalSelectorMapType GlobalSelectorMap; 7470b57cec5SDimitry Andric 7480b57cec5SDimitry Andric /// The generation number of the last time we loaded data from the 7490b57cec5SDimitry Andric /// global method pool for this selector. 7500b57cec5SDimitry Andric llvm::DenseMap<Selector, unsigned> SelectorGeneration; 7510b57cec5SDimitry Andric 7520b57cec5SDimitry Andric /// Whether a selector is out of date. We mark a selector as out of date 7530b57cec5SDimitry Andric /// if we load another module after the method pool entry was pulled in. 7540b57cec5SDimitry Andric llvm::DenseMap<Selector, bool> SelectorOutOfDate; 7550b57cec5SDimitry Andric 7560b57cec5SDimitry Andric struct PendingMacroInfo { 7570b57cec5SDimitry Andric ModuleFile *M; 7585ffd83dbSDimitry Andric /// Offset relative to ModuleFile::MacroOffsetsBase. 7595ffd83dbSDimitry Andric uint32_t MacroDirectivesOffset; 7600b57cec5SDimitry Andric PendingMacroInfoPendingMacroInfo7615ffd83dbSDimitry Andric PendingMacroInfo(ModuleFile *M, uint32_t MacroDirectivesOffset) 7620b57cec5SDimitry Andric : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {} 7630b57cec5SDimitry Andric }; 7640b57cec5SDimitry Andric 7650b57cec5SDimitry Andric using PendingMacroIDsMap = 7660b57cec5SDimitry Andric llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2>>; 7670b57cec5SDimitry Andric 7680b57cec5SDimitry Andric /// Mapping from identifiers that have a macro history to the global 7690b57cec5SDimitry Andric /// IDs have not yet been deserialized to the global IDs of those macros. 7700b57cec5SDimitry Andric PendingMacroIDsMap PendingMacroIDs; 7710b57cec5SDimitry Andric 7720b57cec5SDimitry Andric using GlobalPreprocessedEntityMapType = 7730b57cec5SDimitry Andric ContinuousRangeMap<unsigned, ModuleFile *, 4>; 7740b57cec5SDimitry Andric 7750b57cec5SDimitry Andric /// Mapping from global preprocessing entity IDs to the module in 7760b57cec5SDimitry Andric /// which the preprocessed entity resides along with the offset that should be 7770b57cec5SDimitry Andric /// added to the global preprocessing entity ID to produce a local ID. 7780b57cec5SDimitry Andric GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap; 7790b57cec5SDimitry Andric 7800b57cec5SDimitry Andric using GlobalSkippedRangeMapType = 7810b57cec5SDimitry Andric ContinuousRangeMap<unsigned, ModuleFile *, 4>; 7820b57cec5SDimitry Andric 7830b57cec5SDimitry Andric /// Mapping from global skipped range base IDs to the module in which 7840b57cec5SDimitry Andric /// the skipped ranges reside. 7850b57cec5SDimitry Andric GlobalSkippedRangeMapType GlobalSkippedRangeMap; 7860b57cec5SDimitry Andric 7870b57cec5SDimitry Andric /// \name CodeGen-relevant special data 7880b57cec5SDimitry Andric /// Fields containing data that is relevant to CodeGen. 7890b57cec5SDimitry Andric //@{ 7900b57cec5SDimitry Andric 7910b57cec5SDimitry Andric /// The IDs of all declarations that fulfill the criteria of 7920b57cec5SDimitry Andric /// "interesting" decls. 7930b57cec5SDimitry Andric /// 7940b57cec5SDimitry Andric /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks 7950b57cec5SDimitry Andric /// in the chain. The referenced declarations are deserialized and passed to 7960b57cec5SDimitry Andric /// the consumer eagerly. 797fe6060f1SDimitry Andric SmallVector<serialization::DeclID, 16> EagerlyDeserializedDecls; 7980b57cec5SDimitry Andric 7990b57cec5SDimitry Andric /// The IDs of all tentative definitions stored in the chain. 8000b57cec5SDimitry Andric /// 8010b57cec5SDimitry Andric /// Sema keeps track of all tentative definitions in a TU because it has to 8020b57cec5SDimitry Andric /// complete them and pass them on to CodeGen. Thus, tentative definitions in 8030b57cec5SDimitry Andric /// the PCH chain must be eagerly deserialized. 804fe6060f1SDimitry Andric SmallVector<serialization::DeclID, 16> TentativeDefinitions; 8050b57cec5SDimitry Andric 8060b57cec5SDimitry Andric /// The IDs of all CXXRecordDecls stored in the chain whose VTables are 8070b57cec5SDimitry Andric /// used. 8080b57cec5SDimitry Andric /// 8090b57cec5SDimitry Andric /// CodeGen has to emit VTables for these records, so they have to be eagerly 8100b57cec5SDimitry Andric /// deserialized. 811fe6060f1SDimitry Andric SmallVector<serialization::DeclID, 64> VTableUses; 8120b57cec5SDimitry Andric 8130b57cec5SDimitry Andric /// A snapshot of the pending instantiations in the chain. 8140b57cec5SDimitry Andric /// 8150b57cec5SDimitry Andric /// This record tracks the instantiations that Sema has to perform at the 8160b57cec5SDimitry Andric /// end of the TU. It consists of a pair of values for every pending 8170b57cec5SDimitry Andric /// instantiation where the first value is the ID of the decl and the second 8180b57cec5SDimitry Andric /// is the instantiation location. 819fe6060f1SDimitry Andric SmallVector<serialization::DeclID, 64> PendingInstantiations; 8200b57cec5SDimitry Andric 8210b57cec5SDimitry Andric //@} 8220b57cec5SDimitry Andric 8230b57cec5SDimitry Andric /// \name DiagnosticsEngine-relevant special data 8240b57cec5SDimitry Andric /// Fields containing data that is used for generating diagnostics 8250b57cec5SDimitry Andric //@{ 8260b57cec5SDimitry Andric 8270b57cec5SDimitry Andric /// A snapshot of Sema's unused file-scoped variable tracking, for 8280b57cec5SDimitry Andric /// generating warnings. 829fe6060f1SDimitry Andric SmallVector<serialization::DeclID, 16> UnusedFileScopedDecls; 8300b57cec5SDimitry Andric 8310b57cec5SDimitry Andric /// A list of all the delegating constructors we've seen, to diagnose 8320b57cec5SDimitry Andric /// cycles. 833fe6060f1SDimitry Andric SmallVector<serialization::DeclID, 4> DelegatingCtorDecls; 8340b57cec5SDimitry Andric 8350b57cec5SDimitry Andric /// Method selectors used in a @selector expression. Used for 8360b57cec5SDimitry Andric /// implementation of -Wselector. 837fe6060f1SDimitry Andric SmallVector<serialization::SelectorID, 64> ReferencedSelectorsData; 8380b57cec5SDimitry Andric 8390b57cec5SDimitry Andric /// A snapshot of Sema's weak undeclared identifier tracking, for 8400b57cec5SDimitry Andric /// generating warnings. 841fe6060f1SDimitry Andric SmallVector<serialization::IdentifierID, 64> WeakUndeclaredIdentifiers; 8420b57cec5SDimitry Andric 8430b57cec5SDimitry Andric /// The IDs of type aliases for ext_vectors that exist in the chain. 8440b57cec5SDimitry Andric /// 8450b57cec5SDimitry Andric /// Used by Sema for finding sugared names for ext_vectors in diagnostics. 846fe6060f1SDimitry Andric SmallVector<serialization::DeclID, 4> ExtVectorDecls; 8470b57cec5SDimitry Andric 8480b57cec5SDimitry Andric //@} 8490b57cec5SDimitry Andric 8500b57cec5SDimitry Andric /// \name Sema-relevant special data 8510b57cec5SDimitry Andric /// Fields containing data that is used for semantic analysis 8520b57cec5SDimitry Andric //@{ 8530b57cec5SDimitry Andric 8540b57cec5SDimitry Andric /// The IDs of all potentially unused typedef names in the chain. 8550b57cec5SDimitry Andric /// 8560b57cec5SDimitry Andric /// Sema tracks these to emit warnings. 857fe6060f1SDimitry Andric SmallVector<serialization::DeclID, 16> UnusedLocalTypedefNameCandidates; 8580b57cec5SDimitry Andric 8590b57cec5SDimitry Andric /// Our current depth in #pragma cuda force_host_device begin/end 8600b57cec5SDimitry Andric /// macros. 8610b57cec5SDimitry Andric unsigned ForceCUDAHostDeviceDepth = 0; 8620b57cec5SDimitry Andric 8630b57cec5SDimitry Andric /// The IDs of the declarations Sema stores directly. 8640b57cec5SDimitry Andric /// 8650b57cec5SDimitry Andric /// Sema tracks a few important decls, such as namespace std, directly. 866fe6060f1SDimitry Andric SmallVector<serialization::DeclID, 4> SemaDeclRefs; 8670b57cec5SDimitry Andric 8680b57cec5SDimitry Andric /// The IDs of the types ASTContext stores directly. 8690b57cec5SDimitry Andric /// 8700b57cec5SDimitry Andric /// The AST context tracks a few important types, such as va_list, directly. 871fe6060f1SDimitry Andric SmallVector<serialization::TypeID, 16> SpecialTypes; 8720b57cec5SDimitry Andric 8730b57cec5SDimitry Andric /// The IDs of CUDA-specific declarations ASTContext stores directly. 8740b57cec5SDimitry Andric /// 8750b57cec5SDimitry Andric /// The AST context tracks a few important decls, currently cudaConfigureCall, 8760b57cec5SDimitry Andric /// directly. 877fe6060f1SDimitry Andric SmallVector<serialization::DeclID, 2> CUDASpecialDeclRefs; 8780b57cec5SDimitry Andric 8790b57cec5SDimitry Andric /// The floating point pragma option settings. 8800b57cec5SDimitry Andric SmallVector<uint64_t, 1> FPPragmaOptions; 8810b57cec5SDimitry Andric 8820b57cec5SDimitry Andric /// The pragma clang optimize location (if the pragma state is "off"). 8830b57cec5SDimitry Andric SourceLocation OptimizeOffPragmaLocation; 8840b57cec5SDimitry Andric 8850b57cec5SDimitry Andric /// The PragmaMSStructKind pragma ms_struct state if set, or -1. 8860b57cec5SDimitry Andric int PragmaMSStructState = -1; 8870b57cec5SDimitry Andric 8880b57cec5SDimitry Andric /// The PragmaMSPointersToMembersKind pragma pointers_to_members state. 8890b57cec5SDimitry Andric int PragmaMSPointersToMembersState = -1; 8900b57cec5SDimitry Andric SourceLocation PointersToMembersPragmaLocation; 8910b57cec5SDimitry Andric 8925ffd83dbSDimitry Andric /// The pragma float_control state. 893bdd1243dSDimitry Andric std::optional<FPOptionsOverride> FpPragmaCurrentValue; 8945ffd83dbSDimitry Andric SourceLocation FpPragmaCurrentLocation; 8955ffd83dbSDimitry Andric struct FpPragmaStackEntry { 896e8d8bef9SDimitry Andric FPOptionsOverride Value; 8975ffd83dbSDimitry Andric SourceLocation Location; 8985ffd83dbSDimitry Andric SourceLocation PushLocation; 8995ffd83dbSDimitry Andric StringRef SlotLabel; 9005ffd83dbSDimitry Andric }; 9015ffd83dbSDimitry Andric llvm::SmallVector<FpPragmaStackEntry, 2> FpPragmaStack; 9025ffd83dbSDimitry Andric llvm::SmallVector<std::string, 2> FpPragmaStrings; 9035ffd83dbSDimitry Andric 904e8d8bef9SDimitry Andric /// The pragma align/pack state. 905bdd1243dSDimitry Andric std::optional<Sema::AlignPackInfo> PragmaAlignPackCurrentValue; 906e8d8bef9SDimitry Andric SourceLocation PragmaAlignPackCurrentLocation; 907e8d8bef9SDimitry Andric struct PragmaAlignPackStackEntry { 908e8d8bef9SDimitry Andric Sema::AlignPackInfo Value; 9090b57cec5SDimitry Andric SourceLocation Location; 9100b57cec5SDimitry Andric SourceLocation PushLocation; 9110b57cec5SDimitry Andric StringRef SlotLabel; 9120b57cec5SDimitry Andric }; 913e8d8bef9SDimitry Andric llvm::SmallVector<PragmaAlignPackStackEntry, 2> PragmaAlignPackStack; 914e8d8bef9SDimitry Andric llvm::SmallVector<std::string, 2> PragmaAlignPackStrings; 9150b57cec5SDimitry Andric 9160b57cec5SDimitry Andric /// The OpenCL extension settings. 9170b57cec5SDimitry Andric OpenCLOptions OpenCLExtensions; 9180b57cec5SDimitry Andric 9190b57cec5SDimitry Andric /// Extensions required by an OpenCL type. 9200b57cec5SDimitry Andric llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap; 9210b57cec5SDimitry Andric 9220b57cec5SDimitry Andric /// Extensions required by an OpenCL declaration. 9230b57cec5SDimitry Andric llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap; 9240b57cec5SDimitry Andric 9250b57cec5SDimitry Andric /// A list of the namespaces we've seen. 926fe6060f1SDimitry Andric SmallVector<serialization::DeclID, 4> KnownNamespaces; 9270b57cec5SDimitry Andric 9280b57cec5SDimitry Andric /// A list of undefined decls with internal linkage followed by the 9290b57cec5SDimitry Andric /// SourceLocation of a matching ODR-use. 930fe6060f1SDimitry Andric SmallVector<serialization::DeclID, 8> UndefinedButUsed; 9310b57cec5SDimitry Andric 9320b57cec5SDimitry Andric /// Delete expressions to analyze at the end of translation unit. 9330b57cec5SDimitry Andric SmallVector<uint64_t, 8> DelayedDeleteExprs; 9340b57cec5SDimitry Andric 935e8d8bef9SDimitry Andric // A list of late parsed template function data with their module files. 936e8d8bef9SDimitry Andric SmallVector<std::pair<ModuleFile *, SmallVector<uint64_t, 1>>, 4> 937e8d8bef9SDimitry Andric LateParsedTemplates; 9380b57cec5SDimitry Andric 9395ffd83dbSDimitry Andric /// The IDs of all decls to be checked for deferred diags. 9405ffd83dbSDimitry Andric /// 9415ffd83dbSDimitry Andric /// Sema tracks these to emit deferred diags. 942fe6060f1SDimitry Andric llvm::SmallSetVector<serialization::DeclID, 4> DeclsToCheckForDeferredDiags; 9435ffd83dbSDimitry Andric 9445f757f3fSDimitry Andric private: 9450b57cec5SDimitry Andric struct ImportedSubmodule { 9460b57cec5SDimitry Andric serialization::SubmoduleID ID; 9470b57cec5SDimitry Andric SourceLocation ImportLoc; 9480b57cec5SDimitry Andric ImportedSubmoduleImportedSubmodule9490b57cec5SDimitry Andric ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc) 9500b57cec5SDimitry Andric : ID(ID), ImportLoc(ImportLoc) {} 9510b57cec5SDimitry Andric }; 9520b57cec5SDimitry Andric 9530b57cec5SDimitry Andric /// A list of modules that were imported by precompiled headers or 95406c3fb27SDimitry Andric /// any other non-module AST file and have not yet been made visible. If a 95506c3fb27SDimitry Andric /// module is made visible in the ASTReader, it will be transfered to 95606c3fb27SDimitry Andric /// \c PendingImportedModulesSema. 95706c3fb27SDimitry Andric SmallVector<ImportedSubmodule, 2> PendingImportedModules; 95806c3fb27SDimitry Andric 95906c3fb27SDimitry Andric /// A list of modules that were imported by precompiled headers or 96006c3fb27SDimitry Andric /// any other non-module AST file and have not yet been made visible for Sema. 96106c3fb27SDimitry Andric SmallVector<ImportedSubmodule, 2> PendingImportedModulesSema; 9620b57cec5SDimitry Andric //@} 9630b57cec5SDimitry Andric 9640b57cec5SDimitry Andric /// The system include root to be used when loading the 9650b57cec5SDimitry Andric /// precompiled header. 9660b57cec5SDimitry Andric std::string isysroot; 9670b57cec5SDimitry Andric 9680b57cec5SDimitry Andric /// Whether to disable the normal validation performed on precompiled 969e8d8bef9SDimitry Andric /// headers and module files when they are loaded. 970e8d8bef9SDimitry Andric DisableValidationForModuleKind DisableValidationKind; 9710b57cec5SDimitry Andric 9720b57cec5SDimitry Andric /// Whether to accept an AST file with compiler errors. 9730b57cec5SDimitry Andric bool AllowASTWithCompilerErrors; 9740b57cec5SDimitry Andric 9750b57cec5SDimitry Andric /// Whether to accept an AST file that has a different configuration 9760b57cec5SDimitry Andric /// from the current compiler instance. 9770b57cec5SDimitry Andric bool AllowConfigurationMismatch; 9780b57cec5SDimitry Andric 9790b57cec5SDimitry Andric /// Whether validate system input files. 9800b57cec5SDimitry Andric bool ValidateSystemInputs; 9810b57cec5SDimitry Andric 982a7dea167SDimitry Andric /// Whether validate headers and module maps using hash based on contents. 983a7dea167SDimitry Andric bool ValidateASTInputFilesContent; 984a7dea167SDimitry Andric 9850b57cec5SDimitry Andric /// Whether we are allowed to use the global module index. 9860b57cec5SDimitry Andric bool UseGlobalIndex; 9870b57cec5SDimitry Andric 9880b57cec5SDimitry Andric /// Whether we have tried loading the global module index yet. 9890b57cec5SDimitry Andric bool TriedLoadingGlobalIndex = false; 9900b57cec5SDimitry Andric 9910b57cec5SDimitry Andric ///Whether we are currently processing update records. 9920b57cec5SDimitry Andric bool ProcessingUpdateRecords = false; 9930b57cec5SDimitry Andric 9940b57cec5SDimitry Andric using SwitchCaseMapTy = llvm::DenseMap<unsigned, SwitchCase *>; 9950b57cec5SDimitry Andric 9960b57cec5SDimitry Andric /// Mapping from switch-case IDs in the chain to switch-case statements 9970b57cec5SDimitry Andric /// 9980b57cec5SDimitry Andric /// Statements usually don't have IDs, but switch cases need them, so that the 9990b57cec5SDimitry Andric /// switch statement can refer to them. 10000b57cec5SDimitry Andric SwitchCaseMapTy SwitchCaseStmts; 10010b57cec5SDimitry Andric 10020b57cec5SDimitry Andric SwitchCaseMapTy *CurrSwitchCaseStmts; 10030b57cec5SDimitry Andric 10040b57cec5SDimitry Andric /// The number of source location entries de-serialized from 10050b57cec5SDimitry Andric /// the PCH file. 10060b57cec5SDimitry Andric unsigned NumSLocEntriesRead = 0; 10070b57cec5SDimitry Andric 10080b57cec5SDimitry Andric /// The number of source location entries in the chain. 10090b57cec5SDimitry Andric unsigned TotalNumSLocEntries = 0; 10100b57cec5SDimitry Andric 10110b57cec5SDimitry Andric /// The number of statements (and expressions) de-serialized 10120b57cec5SDimitry Andric /// from the chain. 10130b57cec5SDimitry Andric unsigned NumStatementsRead = 0; 10140b57cec5SDimitry Andric 10150b57cec5SDimitry Andric /// The total number of statements (and expressions) stored 10160b57cec5SDimitry Andric /// in the chain. 10170b57cec5SDimitry Andric unsigned TotalNumStatements = 0; 10180b57cec5SDimitry Andric 10190b57cec5SDimitry Andric /// The number of macros de-serialized from the chain. 10200b57cec5SDimitry Andric unsigned NumMacrosRead = 0; 10210b57cec5SDimitry Andric 10220b57cec5SDimitry Andric /// The total number of macros stored in the chain. 10230b57cec5SDimitry Andric unsigned TotalNumMacros = 0; 10240b57cec5SDimitry Andric 10250b57cec5SDimitry Andric /// The number of lookups into identifier tables. 10260b57cec5SDimitry Andric unsigned NumIdentifierLookups = 0; 10270b57cec5SDimitry Andric 10280b57cec5SDimitry Andric /// The number of lookups into identifier tables that succeed. 10290b57cec5SDimitry Andric unsigned NumIdentifierLookupHits = 0; 10300b57cec5SDimitry Andric 10310b57cec5SDimitry Andric /// The number of selectors that have been read. 10320b57cec5SDimitry Andric unsigned NumSelectorsRead = 0; 10330b57cec5SDimitry Andric 10340b57cec5SDimitry Andric /// The number of method pool entries that have been read. 10350b57cec5SDimitry Andric unsigned NumMethodPoolEntriesRead = 0; 10360b57cec5SDimitry Andric 10370b57cec5SDimitry Andric /// The number of times we have looked up a selector in the method 10380b57cec5SDimitry Andric /// pool. 10390b57cec5SDimitry Andric unsigned NumMethodPoolLookups = 0; 10400b57cec5SDimitry Andric 10410b57cec5SDimitry Andric /// The number of times we have looked up a selector in the method 10420b57cec5SDimitry Andric /// pool and found something. 10430b57cec5SDimitry Andric unsigned NumMethodPoolHits = 0; 10440b57cec5SDimitry Andric 10450b57cec5SDimitry Andric /// The number of times we have looked up a selector in the method 10460b57cec5SDimitry Andric /// pool within a specific module. 10470b57cec5SDimitry Andric unsigned NumMethodPoolTableLookups = 0; 10480b57cec5SDimitry Andric 10490b57cec5SDimitry Andric /// The number of times we have looked up a selector in the method 10500b57cec5SDimitry Andric /// pool within a specific module and found something. 10510b57cec5SDimitry Andric unsigned NumMethodPoolTableHits = 0; 10520b57cec5SDimitry Andric 10530b57cec5SDimitry Andric /// The total number of method pool entries in the selector table. 10540b57cec5SDimitry Andric unsigned TotalNumMethodPoolEntries = 0; 10550b57cec5SDimitry Andric 10560b57cec5SDimitry Andric /// Number of lexical decl contexts read/total. 10570b57cec5SDimitry Andric unsigned NumLexicalDeclContextsRead = 0, TotalLexicalDeclContexts = 0; 10580b57cec5SDimitry Andric 10590b57cec5SDimitry Andric /// Number of visible decl contexts read/total. 10600b57cec5SDimitry Andric unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0; 10610b57cec5SDimitry Andric 10620b57cec5SDimitry Andric /// Total size of modules, in bits, currently loaded 10630b57cec5SDimitry Andric uint64_t TotalModulesSizeInBits = 0; 10640b57cec5SDimitry Andric 10650b57cec5SDimitry Andric /// Number of Decl/types that are currently deserializing. 10660b57cec5SDimitry Andric unsigned NumCurrentElementsDeserializing = 0; 10670b57cec5SDimitry Andric 10680b57cec5SDimitry Andric /// Set true while we are in the process of passing deserialized 10690b57cec5SDimitry Andric /// "interesting" decls to consumer inside FinishedDeserializing(). 10700b57cec5SDimitry Andric /// This is used as a guard to avoid recursively repeating the process of 10710b57cec5SDimitry Andric /// passing decls to consumer. 10720b57cec5SDimitry Andric bool PassingDeclsToConsumer = false; 10730b57cec5SDimitry Andric 10740b57cec5SDimitry Andric /// The set of identifiers that were read while the AST reader was 10750b57cec5SDimitry Andric /// (recursively) loading declarations. 10760b57cec5SDimitry Andric /// 10770b57cec5SDimitry Andric /// The declarations on the identifier chain for these identifiers will be 10780b57cec5SDimitry Andric /// loaded once the recursive loading has completed. 10790b57cec5SDimitry Andric llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4>> 10800b57cec5SDimitry Andric PendingIdentifierInfos; 10810b57cec5SDimitry Andric 10820b57cec5SDimitry Andric /// The set of lookup results that we have faked in order to support 10830b57cec5SDimitry Andric /// merging of partially deserialized decls but that we have not yet removed. 10840b57cec5SDimitry Andric llvm::SmallMapVector<IdentifierInfo *, SmallVector<NamedDecl*, 2>, 16> 10850b57cec5SDimitry Andric PendingFakeLookupResults; 10860b57cec5SDimitry Andric 10870b57cec5SDimitry Andric /// The generation number of each identifier, which keeps track of 10880b57cec5SDimitry Andric /// the last time we loaded information about this identifier. 10890b57cec5SDimitry Andric llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration; 10900b57cec5SDimitry Andric 10910b57cec5SDimitry Andric class InterestingDecl { 10920b57cec5SDimitry Andric Decl *D; 10930b57cec5SDimitry Andric bool DeclHasPendingBody; 10940b57cec5SDimitry Andric 10950b57cec5SDimitry Andric public: InterestingDecl(Decl * D,bool HasBody)10960b57cec5SDimitry Andric InterestingDecl(Decl *D, bool HasBody) 10970b57cec5SDimitry Andric : D(D), DeclHasPendingBody(HasBody) {} 10980b57cec5SDimitry Andric getDecl()10990b57cec5SDimitry Andric Decl *getDecl() { return D; } 11000b57cec5SDimitry Andric 11010b57cec5SDimitry Andric /// Whether the declaration has a pending body. hasPendingBody()11020b57cec5SDimitry Andric bool hasPendingBody() { return DeclHasPendingBody; } 11030b57cec5SDimitry Andric }; 11040b57cec5SDimitry Andric 11050b57cec5SDimitry Andric /// Contains declarations and definitions that could be 11060b57cec5SDimitry Andric /// "interesting" to the ASTConsumer, when we get that AST consumer. 11070b57cec5SDimitry Andric /// 11080b57cec5SDimitry Andric /// "Interesting" declarations are those that have data that may 11090b57cec5SDimitry Andric /// need to be emitted, such as inline function definitions or 11100b57cec5SDimitry Andric /// Objective-C protocols. 11110b57cec5SDimitry Andric std::deque<InterestingDecl> PotentiallyInterestingDecls; 11120b57cec5SDimitry Andric 11130b57cec5SDimitry Andric /// The list of deduced function types that we have not yet read, because 11140b57cec5SDimitry Andric /// they might contain a deduced return type that refers to a local type 11150b57cec5SDimitry Andric /// declared within the function. 11160b57cec5SDimitry Andric SmallVector<std::pair<FunctionDecl *, serialization::TypeID>, 16> 111706c3fb27SDimitry Andric PendingDeducedFunctionTypes; 111806c3fb27SDimitry Andric 111906c3fb27SDimitry Andric /// The list of deduced variable types that we have not yet read, because 112006c3fb27SDimitry Andric /// they might contain a deduced type that refers to a local type declared 112106c3fb27SDimitry Andric /// within the variable. 112206c3fb27SDimitry Andric SmallVector<std::pair<VarDecl *, serialization::TypeID>, 16> 112306c3fb27SDimitry Andric PendingDeducedVarTypes; 11240b57cec5SDimitry Andric 11250b57cec5SDimitry Andric /// The list of redeclaration chains that still need to be 11260b57cec5SDimitry Andric /// reconstructed, and the local offset to the corresponding list 11270b57cec5SDimitry Andric /// of redeclarations. 11280b57cec5SDimitry Andric SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains; 11290b57cec5SDimitry Andric 11300b57cec5SDimitry Andric /// The list of canonical declarations whose redeclaration chains 11310b57cec5SDimitry Andric /// need to be marked as incomplete once we're done deserializing things. 11320b57cec5SDimitry Andric SmallVector<Decl *, 16> PendingIncompleteDeclChains; 11330b57cec5SDimitry Andric 11340b57cec5SDimitry Andric /// The Decl IDs for the Sema/Lexical DeclContext of a Decl that has 11350b57cec5SDimitry Andric /// been loaded but its DeclContext was not set yet. 11360b57cec5SDimitry Andric struct PendingDeclContextInfo { 11370b57cec5SDimitry Andric Decl *D; 11380b57cec5SDimitry Andric serialization::GlobalDeclID SemaDC; 11390b57cec5SDimitry Andric serialization::GlobalDeclID LexicalDC; 11400b57cec5SDimitry Andric }; 11410b57cec5SDimitry Andric 11420b57cec5SDimitry Andric /// The set of Decls that have been loaded but their DeclContexts are 11430b57cec5SDimitry Andric /// not set yet. 11440b57cec5SDimitry Andric /// 11450b57cec5SDimitry Andric /// The DeclContexts for these Decls will be set once recursive loading has 11460b57cec5SDimitry Andric /// been completed. 11470b57cec5SDimitry Andric std::deque<PendingDeclContextInfo> PendingDeclContextInfos; 11480b57cec5SDimitry Andric 114981ad6265SDimitry Andric template <typename DeclTy> 115081ad6265SDimitry Andric using DuplicateObjCDecls = std::pair<DeclTy *, DeclTy *>; 115181ad6265SDimitry Andric 115281ad6265SDimitry Andric /// When resolving duplicate ivars from Objective-C extensions we don't error 115381ad6265SDimitry Andric /// out immediately but check if can merge identical extensions. Not checking 115481ad6265SDimitry Andric /// extensions for equality immediately because ivar deserialization isn't 115581ad6265SDimitry Andric /// over yet at that point. 115681ad6265SDimitry Andric llvm::SmallMapVector<DuplicateObjCDecls<ObjCCategoryDecl>, 115781ad6265SDimitry Andric llvm::SmallVector<DuplicateObjCDecls<ObjCIvarDecl>, 4>, 115881ad6265SDimitry Andric 2> 115981ad6265SDimitry Andric PendingObjCExtensionIvarRedeclarations; 116081ad6265SDimitry Andric 116106c3fb27SDimitry Andric /// Members that have been added to classes, for which the class has not yet 116206c3fb27SDimitry Andric /// been notified. CXXRecordDecl::addedMember will be called for each of 116306c3fb27SDimitry Andric /// these once recursive deserialization is complete. 116406c3fb27SDimitry Andric SmallVector<std::pair<CXXRecordDecl*, Decl*>, 4> PendingAddedClassMembers; 116506c3fb27SDimitry Andric 11660b57cec5SDimitry Andric /// The set of NamedDecls that have been loaded, but are members of a 11670b57cec5SDimitry Andric /// context that has been merged into another context where the corresponding 11680b57cec5SDimitry Andric /// declaration is either missing or has not yet been loaded. 11690b57cec5SDimitry Andric /// 11700b57cec5SDimitry Andric /// We will check whether the corresponding declaration is in fact missing 11710b57cec5SDimitry Andric /// once recursing loading has been completed. 11720b57cec5SDimitry Andric llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks; 11730b57cec5SDimitry Andric 11740b57cec5SDimitry Andric using DataPointers = 11750b57cec5SDimitry Andric std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>; 1176bdd1243dSDimitry Andric using ObjCInterfaceDataPointers = 1177bdd1243dSDimitry Andric std::pair<ObjCInterfaceDecl *, 1178bdd1243dSDimitry Andric struct ObjCInterfaceDecl::DefinitionData *>; 1179bdd1243dSDimitry Andric using ObjCProtocolDataPointers = 1180bdd1243dSDimitry Andric std::pair<ObjCProtocolDecl *, struct ObjCProtocolDecl::DefinitionData *>; 11810b57cec5SDimitry Andric 11820b57cec5SDimitry Andric /// Record definitions in which we found an ODR violation. 11830b57cec5SDimitry Andric llvm::SmallDenseMap<CXXRecordDecl *, llvm::SmallVector<DataPointers, 2>, 2> 11840b57cec5SDimitry Andric PendingOdrMergeFailures; 11850b57cec5SDimitry Andric 1186bdd1243dSDimitry Andric /// C/ObjC record definitions in which we found an ODR violation. 1187bdd1243dSDimitry Andric llvm::SmallDenseMap<RecordDecl *, llvm::SmallVector<RecordDecl *, 2>, 2> 1188bdd1243dSDimitry Andric PendingRecordOdrMergeFailures; 1189bdd1243dSDimitry Andric 11900b57cec5SDimitry Andric /// Function definitions in which we found an ODR violation. 11910b57cec5SDimitry Andric llvm::SmallDenseMap<FunctionDecl *, llvm::SmallVector<FunctionDecl *, 2>, 2> 11920b57cec5SDimitry Andric PendingFunctionOdrMergeFailures; 11930b57cec5SDimitry Andric 11940b57cec5SDimitry Andric /// Enum definitions in which we found an ODR violation. 11950b57cec5SDimitry Andric llvm::SmallDenseMap<EnumDecl *, llvm::SmallVector<EnumDecl *, 2>, 2> 11960b57cec5SDimitry Andric PendingEnumOdrMergeFailures; 11970b57cec5SDimitry Andric 1198bdd1243dSDimitry Andric /// ObjCInterfaceDecl in which we found an ODR violation. 1199bdd1243dSDimitry Andric llvm::SmallDenseMap<ObjCInterfaceDecl *, 1200bdd1243dSDimitry Andric llvm::SmallVector<ObjCInterfaceDataPointers, 2>, 2> 1201bdd1243dSDimitry Andric PendingObjCInterfaceOdrMergeFailures; 1202bdd1243dSDimitry Andric 1203bdd1243dSDimitry Andric /// ObjCProtocolDecl in which we found an ODR violation. 1204bdd1243dSDimitry Andric llvm::SmallDenseMap<ObjCProtocolDecl *, 1205bdd1243dSDimitry Andric llvm::SmallVector<ObjCProtocolDataPointers, 2>, 2> 1206bdd1243dSDimitry Andric PendingObjCProtocolOdrMergeFailures; 1207bdd1243dSDimitry Andric 12080b57cec5SDimitry Andric /// DeclContexts in which we have diagnosed an ODR violation. 12090b57cec5SDimitry Andric llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures; 12100b57cec5SDimitry Andric 12110b57cec5SDimitry Andric /// The set of Objective-C categories that have been deserialized 12120b57cec5SDimitry Andric /// since the last time the declaration chains were linked. 12130b57cec5SDimitry Andric llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized; 12140b57cec5SDimitry Andric 12150b57cec5SDimitry Andric /// The set of Objective-C class definitions that have already been 12160b57cec5SDimitry Andric /// loaded, for which we will need to check for categories whenever a new 12170b57cec5SDimitry Andric /// module is loaded. 12180b57cec5SDimitry Andric SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded; 12190b57cec5SDimitry Andric 12200b57cec5SDimitry Andric using KeyDeclsMap = 12210b57cec5SDimitry Andric llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2>>; 12220b57cec5SDimitry Andric 12230b57cec5SDimitry Andric /// A mapping from canonical declarations to the set of global 12240b57cec5SDimitry Andric /// declaration IDs for key declaration that have been merged with that 12250b57cec5SDimitry Andric /// canonical declaration. A key declaration is a formerly-canonical 12260b57cec5SDimitry Andric /// declaration whose module did not import any other key declaration for that 12270b57cec5SDimitry Andric /// entity. These are the IDs that we use as keys when finding redecl chains. 12280b57cec5SDimitry Andric KeyDeclsMap KeyDecls; 12290b57cec5SDimitry Andric 12300b57cec5SDimitry Andric /// A mapping from DeclContexts to the semantic DeclContext that we 12310b57cec5SDimitry Andric /// are treating as the definition of the entity. This is used, for instance, 12320b57cec5SDimitry Andric /// when merging implicit instantiations of class templates across modules. 12330b57cec5SDimitry Andric llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts; 12340b57cec5SDimitry Andric 12350b57cec5SDimitry Andric /// A mapping from canonical declarations of enums to their canonical 12360b57cec5SDimitry Andric /// definitions. Only populated when using modules in C++. 12370b57cec5SDimitry Andric llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions; 12380b57cec5SDimitry Andric 1239349cc55cSDimitry Andric /// A mapping from canonical declarations of records to their canonical 1240349cc55cSDimitry Andric /// definitions. Doesn't cover CXXRecordDecl. 1241349cc55cSDimitry Andric llvm::DenseMap<RecordDecl *, RecordDecl *> RecordDefinitions; 1242349cc55cSDimitry Andric 12430b57cec5SDimitry Andric /// When reading a Stmt tree, Stmt operands are placed in this stack. 12440b57cec5SDimitry Andric SmallVector<Stmt *, 16> StmtStack; 12450b57cec5SDimitry Andric 12460b57cec5SDimitry Andric /// What kind of records we are reading. 12470b57cec5SDimitry Andric enum ReadingKind { 12480b57cec5SDimitry Andric Read_None, Read_Decl, Read_Type, Read_Stmt 12490b57cec5SDimitry Andric }; 12500b57cec5SDimitry Andric 12510b57cec5SDimitry Andric /// What kind of records we are reading. 12520b57cec5SDimitry Andric ReadingKind ReadingKind = Read_None; 12530b57cec5SDimitry Andric 12540b57cec5SDimitry Andric /// RAII object to change the reading kind. 12550b57cec5SDimitry Andric class ReadingKindTracker { 12560b57cec5SDimitry Andric ASTReader &Reader; 12570b57cec5SDimitry Andric enum ReadingKind PrevKind; 12580b57cec5SDimitry Andric 12590b57cec5SDimitry Andric public: ReadingKindTracker(enum ReadingKind newKind,ASTReader & reader)12600b57cec5SDimitry Andric ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader) 12610b57cec5SDimitry Andric : Reader(reader), PrevKind(Reader.ReadingKind) { 12620b57cec5SDimitry Andric Reader.ReadingKind = newKind; 12630b57cec5SDimitry Andric } 12640b57cec5SDimitry Andric 12650b57cec5SDimitry Andric ReadingKindTracker(const ReadingKindTracker &) = delete; 12660b57cec5SDimitry Andric ReadingKindTracker &operator=(const ReadingKindTracker &) = delete; ~ReadingKindTracker()12670b57cec5SDimitry Andric ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; } 12680b57cec5SDimitry Andric }; 12690b57cec5SDimitry Andric 12700b57cec5SDimitry Andric /// RAII object to mark the start of processing updates. 12710b57cec5SDimitry Andric class ProcessingUpdatesRAIIObj { 12720b57cec5SDimitry Andric ASTReader &Reader; 12730b57cec5SDimitry Andric bool PrevState; 12740b57cec5SDimitry Andric 12750b57cec5SDimitry Andric public: ProcessingUpdatesRAIIObj(ASTReader & reader)12760b57cec5SDimitry Andric ProcessingUpdatesRAIIObj(ASTReader &reader) 12770b57cec5SDimitry Andric : Reader(reader), PrevState(Reader.ProcessingUpdateRecords) { 12780b57cec5SDimitry Andric Reader.ProcessingUpdateRecords = true; 12790b57cec5SDimitry Andric } 12800b57cec5SDimitry Andric 12810b57cec5SDimitry Andric ProcessingUpdatesRAIIObj(const ProcessingUpdatesRAIIObj &) = delete; 12820b57cec5SDimitry Andric ProcessingUpdatesRAIIObj & 12830b57cec5SDimitry Andric operator=(const ProcessingUpdatesRAIIObj &) = delete; ~ProcessingUpdatesRAIIObj()12840b57cec5SDimitry Andric ~ProcessingUpdatesRAIIObj() { Reader.ProcessingUpdateRecords = PrevState; } 12850b57cec5SDimitry Andric }; 12860b57cec5SDimitry Andric 12870b57cec5SDimitry Andric /// Suggested contents of the predefines buffer, after this 12880b57cec5SDimitry Andric /// PCH file has been processed. 12890b57cec5SDimitry Andric /// 12900b57cec5SDimitry Andric /// In most cases, this string will be empty, because the predefines 12910b57cec5SDimitry Andric /// buffer computed to build the PCH file will be identical to the 12920b57cec5SDimitry Andric /// predefines buffer computed from the command line. However, when 12930b57cec5SDimitry Andric /// there are differences that the PCH reader can work around, this 12940b57cec5SDimitry Andric /// predefines buffer may contain additional definitions. 12950b57cec5SDimitry Andric std::string SuggestedPredefines; 12960b57cec5SDimitry Andric 12970b57cec5SDimitry Andric llvm::DenseMap<const Decl *, bool> DefinitionSource; 12980b57cec5SDimitry Andric 1299e8d8bef9SDimitry Andric bool shouldDisableValidationForFile(const serialization::ModuleFile &M) const; 1300e8d8bef9SDimitry Andric 13010b57cec5SDimitry Andric /// Reads a statement from the specified cursor. 13020b57cec5SDimitry Andric Stmt *ReadStmtFromStream(ModuleFile &F); 13030b57cec5SDimitry Andric 1304bdd1243dSDimitry Andric /// Retrieve the stored information about an input file. 1305bdd1243dSDimitry Andric serialization::InputFileInfo getInputFileInfo(ModuleFile &F, unsigned ID); 13060b57cec5SDimitry Andric 13070b57cec5SDimitry Andric /// Retrieve the file entry and 'overridden' bit for an input 13080b57cec5SDimitry Andric /// file in the given module file. 13090b57cec5SDimitry Andric serialization::InputFile getInputFile(ModuleFile &F, unsigned ID, 13100b57cec5SDimitry Andric bool Complain = true); 13110b57cec5SDimitry Andric 13120b57cec5SDimitry Andric public: 13130b57cec5SDimitry Andric void ResolveImportedPath(ModuleFile &M, std::string &Filename); 13140b57cec5SDimitry Andric static void ResolveImportedPath(std::string &Filename, StringRef Prefix); 13150b57cec5SDimitry Andric 13160b57cec5SDimitry Andric /// Returns the first key declaration for the given declaration. This 13170b57cec5SDimitry Andric /// is one that is formerly-canonical (or still canonical) and whose module 13180b57cec5SDimitry Andric /// did not import any other key declaration of the entity. getKeyDeclaration(Decl * D)13190b57cec5SDimitry Andric Decl *getKeyDeclaration(Decl *D) { 13200b57cec5SDimitry Andric D = D->getCanonicalDecl(); 13210b57cec5SDimitry Andric if (D->isFromASTFile()) 13220b57cec5SDimitry Andric return D; 13230b57cec5SDimitry Andric 13240b57cec5SDimitry Andric auto I = KeyDecls.find(D); 13250b57cec5SDimitry Andric if (I == KeyDecls.end() || I->second.empty()) 13260b57cec5SDimitry Andric return D; 13270b57cec5SDimitry Andric return GetExistingDecl(I->second[0]); 13280b57cec5SDimitry Andric } getKeyDeclaration(const Decl * D)13290b57cec5SDimitry Andric const Decl *getKeyDeclaration(const Decl *D) { 13300b57cec5SDimitry Andric return getKeyDeclaration(const_cast<Decl*>(D)); 13310b57cec5SDimitry Andric } 13320b57cec5SDimitry Andric 13330b57cec5SDimitry Andric /// Run a callback on each imported key declaration of \p D. 13340b57cec5SDimitry Andric template <typename Fn> forEachImportedKeyDecl(const Decl * D,Fn Visit)13350b57cec5SDimitry Andric void forEachImportedKeyDecl(const Decl *D, Fn Visit) { 13360b57cec5SDimitry Andric D = D->getCanonicalDecl(); 13370b57cec5SDimitry Andric if (D->isFromASTFile()) 13380b57cec5SDimitry Andric Visit(D); 13390b57cec5SDimitry Andric 13400b57cec5SDimitry Andric auto It = KeyDecls.find(const_cast<Decl*>(D)); 13410b57cec5SDimitry Andric if (It != KeyDecls.end()) 13420b57cec5SDimitry Andric for (auto ID : It->second) 13430b57cec5SDimitry Andric Visit(GetExistingDecl(ID)); 13440b57cec5SDimitry Andric } 13450b57cec5SDimitry Andric 13460b57cec5SDimitry Andric /// Get the loaded lookup tables for \p Primary, if any. 13470b57cec5SDimitry Andric const serialization::reader::DeclContextLookupTable * 13480b57cec5SDimitry Andric getLoadedLookupTables(DeclContext *Primary) const; 13490b57cec5SDimitry Andric 13500b57cec5SDimitry Andric private: 13510b57cec5SDimitry Andric struct ImportedModule { 13520b57cec5SDimitry Andric ModuleFile *Mod; 13530b57cec5SDimitry Andric ModuleFile *ImportedBy; 13540b57cec5SDimitry Andric SourceLocation ImportLoc; 13550b57cec5SDimitry Andric ImportedModuleImportedModule13560b57cec5SDimitry Andric ImportedModule(ModuleFile *Mod, 13570b57cec5SDimitry Andric ModuleFile *ImportedBy, 13580b57cec5SDimitry Andric SourceLocation ImportLoc) 13590b57cec5SDimitry Andric : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) {} 13600b57cec5SDimitry Andric }; 13610b57cec5SDimitry Andric 13620b57cec5SDimitry Andric ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type, 13630b57cec5SDimitry Andric SourceLocation ImportLoc, ModuleFile *ImportedBy, 13640b57cec5SDimitry Andric SmallVectorImpl<ImportedModule> &Loaded, 13650b57cec5SDimitry Andric off_t ExpectedSize, time_t ExpectedModTime, 13660b57cec5SDimitry Andric ASTFileSignature ExpectedSignature, 13670b57cec5SDimitry Andric unsigned ClientLoadCapabilities); 13680b57cec5SDimitry Andric ASTReadResult ReadControlBlock(ModuleFile &F, 13690b57cec5SDimitry Andric SmallVectorImpl<ImportedModule> &Loaded, 13700b57cec5SDimitry Andric const ModuleFile *ImportedBy, 13710b57cec5SDimitry Andric unsigned ClientLoadCapabilities); 13720b57cec5SDimitry Andric static ASTReadResult ReadOptionsBlock( 13730b57cec5SDimitry Andric llvm::BitstreamCursor &Stream, unsigned ClientLoadCapabilities, 13740b57cec5SDimitry Andric bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener, 13750b57cec5SDimitry Andric std::string &SuggestedPredefines); 13760b57cec5SDimitry Andric 13770b57cec5SDimitry Andric /// Read the unhashed control block. 13780b57cec5SDimitry Andric /// 13790b57cec5SDimitry Andric /// This has no effect on \c F.Stream, instead creating a fresh cursor from 13800b57cec5SDimitry Andric /// \c F.Data and reading ahead. 13810b57cec5SDimitry Andric ASTReadResult readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy, 13820b57cec5SDimitry Andric unsigned ClientLoadCapabilities); 13830b57cec5SDimitry Andric 13840b57cec5SDimitry Andric static ASTReadResult 13850b57cec5SDimitry Andric readUnhashedControlBlockImpl(ModuleFile *F, llvm::StringRef StreamData, 13860b57cec5SDimitry Andric unsigned ClientLoadCapabilities, 13870b57cec5SDimitry Andric bool AllowCompatibleConfigurationMismatch, 13880b57cec5SDimitry Andric ASTReaderListener *Listener, 13890b57cec5SDimitry Andric bool ValidateDiagnosticOptions); 13900b57cec5SDimitry Andric 1391349cc55cSDimitry Andric llvm::Error ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities); 1392349cc55cSDimitry Andric llvm::Error ReadExtensionBlock(ModuleFile &F); 13930b57cec5SDimitry Andric void ReadModuleOffsetMap(ModuleFile &F) const; 1394349cc55cSDimitry Andric void ParseLineTable(ModuleFile &F, const RecordData &Record); 1395349cc55cSDimitry Andric llvm::Error ReadSourceManagerBlock(ModuleFile &F); 13960b57cec5SDimitry Andric SourceLocation getImportLocation(ModuleFile *F); 13970b57cec5SDimitry Andric ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, 13980b57cec5SDimitry Andric const ModuleFile *ImportedBy, 13990b57cec5SDimitry Andric unsigned ClientLoadCapabilities); 1400349cc55cSDimitry Andric llvm::Error ReadSubmoduleBlock(ModuleFile &F, 14010b57cec5SDimitry Andric unsigned ClientLoadCapabilities); 14020b57cec5SDimitry Andric static bool ParseLanguageOptions(const RecordData &Record, bool Complain, 14030b57cec5SDimitry Andric ASTReaderListener &Listener, 14040b57cec5SDimitry Andric bool AllowCompatibleDifferences); 14050b57cec5SDimitry Andric static bool ParseTargetOptions(const RecordData &Record, bool Complain, 14060b57cec5SDimitry Andric ASTReaderListener &Listener, 14070b57cec5SDimitry Andric bool AllowCompatibleDifferences); 14080b57cec5SDimitry Andric static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain, 14090b57cec5SDimitry Andric ASTReaderListener &Listener); 14100b57cec5SDimitry Andric static bool ParseFileSystemOptions(const RecordData &Record, bool Complain, 14110b57cec5SDimitry Andric ASTReaderListener &Listener); 14120b57cec5SDimitry Andric static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain, 14130b57cec5SDimitry Andric ASTReaderListener &Listener); 1414bdd1243dSDimitry Andric static bool ParseHeaderSearchPaths(const RecordData &Record, bool Complain, 1415bdd1243dSDimitry Andric ASTReaderListener &Listener); 14160b57cec5SDimitry Andric static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain, 14170b57cec5SDimitry Andric ASTReaderListener &Listener, 14180b57cec5SDimitry Andric std::string &SuggestedPredefines); 14190b57cec5SDimitry Andric 14200b57cec5SDimitry Andric struct RecordLocation { 14210b57cec5SDimitry Andric ModuleFile *F; 14220b57cec5SDimitry Andric uint64_t Offset; 14230b57cec5SDimitry Andric RecordLocationRecordLocation14240b57cec5SDimitry Andric RecordLocation(ModuleFile *M, uint64_t O) : F(M), Offset(O) {} 14250b57cec5SDimitry Andric }; 14260b57cec5SDimitry Andric 14270b57cec5SDimitry Andric QualType readTypeRecord(unsigned Index); 14280b57cec5SDimitry Andric RecordLocation TypeCursorForIndex(unsigned Index); 14290b57cec5SDimitry Andric void LoadedDecl(unsigned Index, Decl *D); 14300b57cec5SDimitry Andric Decl *ReadDeclRecord(serialization::DeclID ID); 14315f757f3fSDimitry Andric void markIncompleteDeclChain(Decl *D); 14320b57cec5SDimitry Andric 14330b57cec5SDimitry Andric /// Returns the most recent declaration of a declaration (which must be 14340b57cec5SDimitry Andric /// of a redeclarable kind) that is either local or has already been loaded 14350b57cec5SDimitry Andric /// merged into its redecl chain. 14360b57cec5SDimitry Andric Decl *getMostRecentExistingDecl(Decl *D); 14370b57cec5SDimitry Andric 14380b57cec5SDimitry Andric RecordLocation DeclCursorForID(serialization::DeclID ID, 14390b57cec5SDimitry Andric SourceLocation &Location); 14400b57cec5SDimitry Andric void loadDeclUpdateRecords(PendingUpdateRecord &Record); 14410b57cec5SDimitry Andric void loadPendingDeclChain(Decl *D, uint64_t LocalOffset); 14420b57cec5SDimitry Andric void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D, 14430b57cec5SDimitry Andric unsigned PreviousGeneration = 0); 14440b57cec5SDimitry Andric 14450b57cec5SDimitry Andric RecordLocation getLocalBitOffset(uint64_t GlobalOffset); 14465ffd83dbSDimitry Andric uint64_t getGlobalBitOffset(ModuleFile &M, uint64_t LocalOffset); 14470b57cec5SDimitry Andric 14480b57cec5SDimitry Andric /// Returns the first preprocessed entity ID that begins or ends after 14490b57cec5SDimitry Andric /// \arg Loc. 14500b57cec5SDimitry Andric serialization::PreprocessedEntityID 14510b57cec5SDimitry Andric findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const; 14520b57cec5SDimitry Andric 14530b57cec5SDimitry Andric /// Find the next module that contains entities and return the ID 14540b57cec5SDimitry Andric /// of the first entry. 14550b57cec5SDimitry Andric /// 14560b57cec5SDimitry Andric /// \param SLocMapI points at a chunk of a module that contains no 14570b57cec5SDimitry Andric /// preprocessed entities or the entities it contains are not the 14580b57cec5SDimitry Andric /// ones we are looking for. 14590b57cec5SDimitry Andric serialization::PreprocessedEntityID 14600b57cec5SDimitry Andric findNextPreprocessedEntity( 14610b57cec5SDimitry Andric GlobalSLocOffsetMapType::const_iterator SLocMapI) const; 14620b57cec5SDimitry Andric 14630b57cec5SDimitry Andric /// Returns (ModuleFile, Local index) pair for \p GlobalIndex of a 14640b57cec5SDimitry Andric /// preprocessed entity. 14650b57cec5SDimitry Andric std::pair<ModuleFile *, unsigned> 14660b57cec5SDimitry Andric getModulePreprocessedEntity(unsigned GlobalIndex); 14670b57cec5SDimitry Andric 14680b57cec5SDimitry Andric /// Returns (begin, end) pair for the preprocessed entities of a 14690b57cec5SDimitry Andric /// particular module. 14700b57cec5SDimitry Andric llvm::iterator_range<PreprocessingRecord::iterator> 14710b57cec5SDimitry Andric getModulePreprocessedEntities(ModuleFile &Mod) const; 14720b57cec5SDimitry Andric 1473fe6060f1SDimitry Andric bool canRecoverFromOutOfDate(StringRef ModuleFileName, 1474fe6060f1SDimitry Andric unsigned ClientLoadCapabilities); 1475fe6060f1SDimitry Andric 14760b57cec5SDimitry Andric public: 14770b57cec5SDimitry Andric class ModuleDeclIterator 14780b57cec5SDimitry Andric : public llvm::iterator_adaptor_base< 14790b57cec5SDimitry Andric ModuleDeclIterator, const serialization::LocalDeclID *, 14800b57cec5SDimitry Andric std::random_access_iterator_tag, const Decl *, ptrdiff_t, 14810b57cec5SDimitry Andric const Decl *, const Decl *> { 14820b57cec5SDimitry Andric ASTReader *Reader = nullptr; 14830b57cec5SDimitry Andric ModuleFile *Mod = nullptr; 14840b57cec5SDimitry Andric 14850b57cec5SDimitry Andric public: ModuleDeclIterator()14860b57cec5SDimitry Andric ModuleDeclIterator() : iterator_adaptor_base(nullptr) {} 14870b57cec5SDimitry Andric ModuleDeclIterator(ASTReader * Reader,ModuleFile * Mod,const serialization::LocalDeclID * Pos)14880b57cec5SDimitry Andric ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod, 14890b57cec5SDimitry Andric const serialization::LocalDeclID *Pos) 14900b57cec5SDimitry Andric : iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {} 14910b57cec5SDimitry Andric 14920b57cec5SDimitry Andric value_type operator*() const { 14930b57cec5SDimitry Andric return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *I)); 14940b57cec5SDimitry Andric } 14950b57cec5SDimitry Andric 14960b57cec5SDimitry Andric value_type operator->() const { return **this; } 14970b57cec5SDimitry Andric 14980b57cec5SDimitry Andric bool operator==(const ModuleDeclIterator &RHS) const { 14990b57cec5SDimitry Andric assert(Reader == RHS.Reader && Mod == RHS.Mod); 15000b57cec5SDimitry Andric return I == RHS.I; 15010b57cec5SDimitry Andric } 15020b57cec5SDimitry Andric }; 15030b57cec5SDimitry Andric 15040b57cec5SDimitry Andric llvm::iterator_range<ModuleDeclIterator> 15050b57cec5SDimitry Andric getModuleFileLevelDecls(ModuleFile &Mod); 15060b57cec5SDimitry Andric 15070b57cec5SDimitry Andric private: 15080b57cec5SDimitry Andric void PassInterestingDeclsToConsumer(); 15090b57cec5SDimitry Andric void PassInterestingDeclToConsumer(Decl *D); 15100b57cec5SDimitry Andric 15110b57cec5SDimitry Andric void finishPendingActions(); 15120b57cec5SDimitry Andric void diagnoseOdrViolations(); 15130b57cec5SDimitry Andric 15140b57cec5SDimitry Andric void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name); 15150b57cec5SDimitry Andric addPendingDeclContextInfo(Decl * D,serialization::GlobalDeclID SemaDC,serialization::GlobalDeclID LexicalDC)15160b57cec5SDimitry Andric void addPendingDeclContextInfo(Decl *D, 15170b57cec5SDimitry Andric serialization::GlobalDeclID SemaDC, 15180b57cec5SDimitry Andric serialization::GlobalDeclID LexicalDC) { 15190b57cec5SDimitry Andric assert(D); 15200b57cec5SDimitry Andric PendingDeclContextInfo Info = { D, SemaDC, LexicalDC }; 15210b57cec5SDimitry Andric PendingDeclContextInfos.push_back(Info); 15220b57cec5SDimitry Andric } 15230b57cec5SDimitry Andric 15240b57cec5SDimitry Andric /// Produce an error diagnostic and return true. 15250b57cec5SDimitry Andric /// 15260b57cec5SDimitry Andric /// This routine should only be used for fatal errors that have to 15270b57cec5SDimitry Andric /// do with non-routine failures (e.g., corrupted AST file). 15280b57cec5SDimitry Andric void Error(StringRef Msg) const; 15290b57cec5SDimitry Andric void Error(unsigned DiagID, StringRef Arg1 = StringRef(), 1530480093f4SDimitry Andric StringRef Arg2 = StringRef(), StringRef Arg3 = StringRef()) const; 15310b57cec5SDimitry Andric void Error(llvm::Error &&Err) const; 15320b57cec5SDimitry Andric 15330b57cec5SDimitry Andric public: 15340b57cec5SDimitry Andric /// Load the AST file and validate its contents against the given 15350b57cec5SDimitry Andric /// Preprocessor. 15360b57cec5SDimitry Andric /// 15370b57cec5SDimitry Andric /// \param PP the preprocessor associated with the context in which this 15380b57cec5SDimitry Andric /// precompiled header will be loaded. 15390b57cec5SDimitry Andric /// 15400b57cec5SDimitry Andric /// \param Context the AST context that this precompiled header will be 15410b57cec5SDimitry Andric /// loaded into, if any. 15420b57cec5SDimitry Andric /// 15430b57cec5SDimitry Andric /// \param PCHContainerRdr the PCHContainerOperations to use for loading and 15440b57cec5SDimitry Andric /// creating modules. 15450b57cec5SDimitry Andric /// 15460b57cec5SDimitry Andric /// \param Extensions the list of module file extensions that can be loaded 15470b57cec5SDimitry Andric /// from the AST files. 15480b57cec5SDimitry Andric /// 15490b57cec5SDimitry Andric /// \param isysroot If non-NULL, the system include path specified by the 15500b57cec5SDimitry Andric /// user. This is only used with relocatable PCH files. If non-NULL, 15510b57cec5SDimitry Andric /// a relocatable PCH file will use the default path "/". 15520b57cec5SDimitry Andric /// 1553e8d8bef9SDimitry Andric /// \param DisableValidationKind If set, the AST reader will suppress most 15540b57cec5SDimitry Andric /// of its regular consistency checking, allowing the use of precompiled 1555e8d8bef9SDimitry Andric /// headers and module files that cannot be determined to be compatible. 15560b57cec5SDimitry Andric /// 15570b57cec5SDimitry Andric /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an 15580b57cec5SDimitry Andric /// AST file the was created out of an AST with compiler errors, 15590b57cec5SDimitry Andric /// otherwise it will reject it. 15600b57cec5SDimitry Andric /// 15610b57cec5SDimitry Andric /// \param AllowConfigurationMismatch If true, the AST reader will not check 15620b57cec5SDimitry Andric /// for configuration differences between the AST file and the invocation. 15630b57cec5SDimitry Andric /// 15640b57cec5SDimitry Andric /// \param ValidateSystemInputs If true, the AST reader will validate 15650b57cec5SDimitry Andric /// system input files in addition to user input files. This is only 15660b57cec5SDimitry Andric /// meaningful if \p DisableValidation is false. 15670b57cec5SDimitry Andric /// 15680b57cec5SDimitry Andric /// \param UseGlobalIndex If true, the AST reader will try to load and use 15690b57cec5SDimitry Andric /// the global module index. 15700b57cec5SDimitry Andric /// 15710b57cec5SDimitry Andric /// \param ReadTimer If non-null, a timer used to track the time spent 15720b57cec5SDimitry Andric /// deserializing. 15730b57cec5SDimitry Andric ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache, 15740b57cec5SDimitry Andric ASTContext *Context, const PCHContainerReader &PCHContainerRdr, 15750b57cec5SDimitry Andric ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, 1576e8d8bef9SDimitry Andric StringRef isysroot = "", 1577e8d8bef9SDimitry Andric DisableValidationForModuleKind DisableValidationKind = 1578e8d8bef9SDimitry Andric DisableValidationForModuleKind::None, 15790b57cec5SDimitry Andric bool AllowASTWithCompilerErrors = false, 15800b57cec5SDimitry Andric bool AllowConfigurationMismatch = false, 1581a7dea167SDimitry Andric bool ValidateSystemInputs = false, 1582a7dea167SDimitry Andric bool ValidateASTInputFilesContent = false, 1583a7dea167SDimitry Andric bool UseGlobalIndex = true, 15840b57cec5SDimitry Andric std::unique_ptr<llvm::Timer> ReadTimer = {}); 15850b57cec5SDimitry Andric ASTReader(const ASTReader &) = delete; 15860b57cec5SDimitry Andric ASTReader &operator=(const ASTReader &) = delete; 15870b57cec5SDimitry Andric ~ASTReader() override; 15880b57cec5SDimitry Andric getSourceManager()15890b57cec5SDimitry Andric SourceManager &getSourceManager() const { return SourceMgr; } getFileManager()15900b57cec5SDimitry Andric FileManager &getFileManager() const { return FileMgr; } getDiags()15910b57cec5SDimitry Andric DiagnosticsEngine &getDiags() const { return Diags; } 15920b57cec5SDimitry Andric 15930b57cec5SDimitry Andric /// Flags that indicate what kind of AST loading failures the client 15940b57cec5SDimitry Andric /// of the AST reader can directly handle. 15950b57cec5SDimitry Andric /// 15960b57cec5SDimitry Andric /// When a client states that it can handle a particular kind of failure, 15970b57cec5SDimitry Andric /// the AST reader will not emit errors when producing that kind of failure. 15980b57cec5SDimitry Andric enum LoadFailureCapabilities { 15990b57cec5SDimitry Andric /// The client can't handle any AST loading failures. 16000b57cec5SDimitry Andric ARR_None = 0, 16010b57cec5SDimitry Andric 16020b57cec5SDimitry Andric /// The client can handle an AST file that cannot load because it 16030b57cec5SDimitry Andric /// is missing. 16040b57cec5SDimitry Andric ARR_Missing = 0x1, 16050b57cec5SDimitry Andric 16060b57cec5SDimitry Andric /// The client can handle an AST file that cannot load because it 16070b57cec5SDimitry Andric /// is out-of-date relative to its input files. 16080b57cec5SDimitry Andric ARR_OutOfDate = 0x2, 16090b57cec5SDimitry Andric 16100b57cec5SDimitry Andric /// The client can handle an AST file that cannot load because it 16110b57cec5SDimitry Andric /// was built with a different version of Clang. 16120b57cec5SDimitry Andric ARR_VersionMismatch = 0x4, 16130b57cec5SDimitry Andric 16140b57cec5SDimitry Andric /// The client can handle an AST file that cannot load because it's 16150b57cec5SDimitry Andric /// compiled configuration doesn't match that of the context it was 16160b57cec5SDimitry Andric /// loaded into. 1617fe6060f1SDimitry Andric ARR_ConfigurationMismatch = 0x8, 1618fe6060f1SDimitry Andric 1619fe6060f1SDimitry Andric /// If a module file is marked with errors treat it as out-of-date so the 1620fe6060f1SDimitry Andric /// caller can rebuild it. 1621fe6060f1SDimitry Andric ARR_TreatModuleWithErrorsAsOutOfDate = 0x10 16220b57cec5SDimitry Andric }; 16230b57cec5SDimitry Andric 16240b57cec5SDimitry Andric /// Load the AST file designated by the given file name. 16250b57cec5SDimitry Andric /// 16260b57cec5SDimitry Andric /// \param FileName The name of the AST file to load. 16270b57cec5SDimitry Andric /// 16280b57cec5SDimitry Andric /// \param Type The kind of AST being loaded, e.g., PCH, module, main file, 16290b57cec5SDimitry Andric /// or preamble. 16300b57cec5SDimitry Andric /// 16310b57cec5SDimitry Andric /// \param ImportLoc the location where the module file will be considered as 16320b57cec5SDimitry Andric /// imported from. For non-module AST types it should be invalid. 16330b57cec5SDimitry Andric /// 16340b57cec5SDimitry Andric /// \param ClientLoadCapabilities The set of client load-failure 16350b57cec5SDimitry Andric /// capabilities, represented as a bitset of the enumerators of 16360b57cec5SDimitry Andric /// LoadFailureCapabilities. 16370b57cec5SDimitry Andric /// 16385f757f3fSDimitry Andric /// \param LoadedModuleFile The optional out-parameter refers to the new 16395f757f3fSDimitry Andric /// loaded modules. In case the module specified by FileName is already 16405f757f3fSDimitry Andric /// loaded, the module file pointer referred by NewLoadedModuleFile wouldn't 16415f757f3fSDimitry Andric /// change. Otherwise if the AST file get loaded successfully, 16425f757f3fSDimitry Andric /// NewLoadedModuleFile would refer to the address of the new loaded top level 16435f757f3fSDimitry Andric /// module. The state of NewLoadedModuleFile is unspecified if the AST file 16445f757f3fSDimitry Andric /// isn't loaded successfully. 16450b57cec5SDimitry Andric ASTReadResult ReadAST(StringRef FileName, ModuleKind Type, 16460b57cec5SDimitry Andric SourceLocation ImportLoc, 16470b57cec5SDimitry Andric unsigned ClientLoadCapabilities, 16485f757f3fSDimitry Andric ModuleFile **NewLoadedModuleFile = nullptr); 16490b57cec5SDimitry Andric 16500b57cec5SDimitry Andric /// Make the entities in the given module and any of its (non-explicit) 16510b57cec5SDimitry Andric /// submodules visible to name lookup. 16520b57cec5SDimitry Andric /// 16530b57cec5SDimitry Andric /// \param Mod The module whose names should be made visible. 16540b57cec5SDimitry Andric /// 16550b57cec5SDimitry Andric /// \param NameVisibility The level of visibility to give the names in the 16560b57cec5SDimitry Andric /// module. Visibility can only be increased over time. 16570b57cec5SDimitry Andric /// 16580b57cec5SDimitry Andric /// \param ImportLoc The location at which the import occurs. 16590b57cec5SDimitry Andric void makeModuleVisible(Module *Mod, 16600b57cec5SDimitry Andric Module::NameVisibilityKind NameVisibility, 16610b57cec5SDimitry Andric SourceLocation ImportLoc); 16620b57cec5SDimitry Andric 16630b57cec5SDimitry Andric /// Make the names within this set of hidden names visible. 16640b57cec5SDimitry Andric void makeNamesVisible(const HiddenNames &Names, Module *Owner); 16650b57cec5SDimitry Andric 16660b57cec5SDimitry Andric /// Note that MergedDef is a redefinition of the canonical definition 16670b57cec5SDimitry Andric /// Def, so Def should be visible whenever MergedDef is. 16680b57cec5SDimitry Andric void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef); 16690b57cec5SDimitry Andric 16700b57cec5SDimitry Andric /// Take the AST callbacks listener. takeListener()16710b57cec5SDimitry Andric std::unique_ptr<ASTReaderListener> takeListener() { 16720b57cec5SDimitry Andric return std::move(Listener); 16730b57cec5SDimitry Andric } 16740b57cec5SDimitry Andric 16750b57cec5SDimitry Andric /// Set the AST callbacks listener. setListener(std::unique_ptr<ASTReaderListener> Listener)16760b57cec5SDimitry Andric void setListener(std::unique_ptr<ASTReaderListener> Listener) { 16770b57cec5SDimitry Andric this->Listener = std::move(Listener); 16780b57cec5SDimitry Andric } 16790b57cec5SDimitry Andric 16800b57cec5SDimitry Andric /// Add an AST callback listener. 16810b57cec5SDimitry Andric /// 16820b57cec5SDimitry Andric /// Takes ownership of \p L. addListener(std::unique_ptr<ASTReaderListener> L)16830b57cec5SDimitry Andric void addListener(std::unique_ptr<ASTReaderListener> L) { 16840b57cec5SDimitry Andric if (Listener) 1685a7dea167SDimitry Andric L = std::make_unique<ChainedASTReaderListener>(std::move(L), 16860b57cec5SDimitry Andric std::move(Listener)); 16870b57cec5SDimitry Andric Listener = std::move(L); 16880b57cec5SDimitry Andric } 16890b57cec5SDimitry Andric 16900b57cec5SDimitry Andric /// RAII object to temporarily add an AST callback listener. 16910b57cec5SDimitry Andric class ListenerScope { 16920b57cec5SDimitry Andric ASTReader &Reader; 16930b57cec5SDimitry Andric bool Chained = false; 16940b57cec5SDimitry Andric 16950b57cec5SDimitry Andric public: ListenerScope(ASTReader & Reader,std::unique_ptr<ASTReaderListener> L)16960b57cec5SDimitry Andric ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L) 16970b57cec5SDimitry Andric : Reader(Reader) { 16980b57cec5SDimitry Andric auto Old = Reader.takeListener(); 16990b57cec5SDimitry Andric if (Old) { 17000b57cec5SDimitry Andric Chained = true; 1701a7dea167SDimitry Andric L = std::make_unique<ChainedASTReaderListener>(std::move(L), 17020b57cec5SDimitry Andric std::move(Old)); 17030b57cec5SDimitry Andric } 17040b57cec5SDimitry Andric Reader.setListener(std::move(L)); 17050b57cec5SDimitry Andric } 17060b57cec5SDimitry Andric ~ListenerScope()17070b57cec5SDimitry Andric ~ListenerScope() { 17080b57cec5SDimitry Andric auto New = Reader.takeListener(); 17090b57cec5SDimitry Andric if (Chained) 17100b57cec5SDimitry Andric Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get()) 17110b57cec5SDimitry Andric ->takeSecond()); 17120b57cec5SDimitry Andric } 17130b57cec5SDimitry Andric }; 17140b57cec5SDimitry Andric 17150b57cec5SDimitry Andric /// Set the AST deserialization listener. 17160b57cec5SDimitry Andric void setDeserializationListener(ASTDeserializationListener *Listener, 17170b57cec5SDimitry Andric bool TakeOwnership = false); 17180b57cec5SDimitry Andric 17190b57cec5SDimitry Andric /// Get the AST deserialization listener. getDeserializationListener()17200b57cec5SDimitry Andric ASTDeserializationListener *getDeserializationListener() { 17210b57cec5SDimitry Andric return DeserializationListener; 17220b57cec5SDimitry Andric } 17230b57cec5SDimitry Andric 17240b57cec5SDimitry Andric /// Determine whether this AST reader has a global index. hasGlobalIndex()17250b57cec5SDimitry Andric bool hasGlobalIndex() const { return (bool)GlobalIndex; } 17260b57cec5SDimitry Andric 17270b57cec5SDimitry Andric /// Return global module index. getGlobalIndex()17280b57cec5SDimitry Andric GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); } 17290b57cec5SDimitry Andric 17300b57cec5SDimitry Andric /// Reset reader for a reload try. resetForReload()17310b57cec5SDimitry Andric void resetForReload() { TriedLoadingGlobalIndex = false; } 17320b57cec5SDimitry Andric 17330b57cec5SDimitry Andric /// Attempts to load the global index. 17340b57cec5SDimitry Andric /// 17350b57cec5SDimitry Andric /// \returns true if loading the global index has failed for any reason. 17360b57cec5SDimitry Andric bool loadGlobalIndex(); 17370b57cec5SDimitry Andric 17380b57cec5SDimitry Andric /// Determine whether we tried to load the global index, but failed, 17390b57cec5SDimitry Andric /// e.g., because it is out-of-date or does not exist. 17400b57cec5SDimitry Andric bool isGlobalIndexUnavailable() const; 17410b57cec5SDimitry Andric 17420b57cec5SDimitry Andric /// Initializes the ASTContext 17430b57cec5SDimitry Andric void InitializeContext(); 17440b57cec5SDimitry Andric 17450b57cec5SDimitry Andric /// Update the state of Sema after loading some additional modules. 17460b57cec5SDimitry Andric void UpdateSema(); 17470b57cec5SDimitry Andric 17480b57cec5SDimitry Andric /// Add in-memory (virtual file) buffer. addInMemoryBuffer(StringRef & FileName,std::unique_ptr<llvm::MemoryBuffer> Buffer)17490b57cec5SDimitry Andric void addInMemoryBuffer(StringRef &FileName, 17500b57cec5SDimitry Andric std::unique_ptr<llvm::MemoryBuffer> Buffer) { 17510b57cec5SDimitry Andric ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer)); 17520b57cec5SDimitry Andric } 17530b57cec5SDimitry Andric 17540b57cec5SDimitry Andric /// Finalizes the AST reader's state before writing an AST file to 17550b57cec5SDimitry Andric /// disk. 17560b57cec5SDimitry Andric /// 17570b57cec5SDimitry Andric /// This operation may undo temporary state in the AST that should not be 17580b57cec5SDimitry Andric /// emitted. 17590b57cec5SDimitry Andric void finalizeForWriting(); 17600b57cec5SDimitry Andric 17610b57cec5SDimitry Andric /// Retrieve the module manager. getModuleManager()17620b57cec5SDimitry Andric ModuleManager &getModuleManager() { return ModuleMgr; } 17630b57cec5SDimitry Andric 17640b57cec5SDimitry Andric /// Retrieve the preprocessor. getPreprocessor()17650b57cec5SDimitry Andric Preprocessor &getPreprocessor() const { return PP; } 17660b57cec5SDimitry Andric 17670b57cec5SDimitry Andric /// Retrieve the name of the original source file name for the primary 17680b57cec5SDimitry Andric /// module file. getOriginalSourceFile()17690b57cec5SDimitry Andric StringRef getOriginalSourceFile() { 17700b57cec5SDimitry Andric return ModuleMgr.getPrimaryModule().OriginalSourceFileName; 17710b57cec5SDimitry Andric } 17720b57cec5SDimitry Andric 17730b57cec5SDimitry Andric /// Retrieve the name of the original source file name directly from 17740b57cec5SDimitry Andric /// the AST file, without actually loading the AST file. 17750b57cec5SDimitry Andric static std::string 17760b57cec5SDimitry Andric getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr, 17770b57cec5SDimitry Andric const PCHContainerReader &PCHContainerRdr, 17780b57cec5SDimitry Andric DiagnosticsEngine &Diags); 17790b57cec5SDimitry Andric 17800b57cec5SDimitry Andric /// Read the control block for the named AST file. 17810b57cec5SDimitry Andric /// 17820b57cec5SDimitry Andric /// \returns true if an error occurred, false otherwise. 1783bdd1243dSDimitry Andric static bool readASTFileControlBlock(StringRef Filename, FileManager &FileMgr, 1784bdd1243dSDimitry Andric const InMemoryModuleCache &ModuleCache, 17850b57cec5SDimitry Andric const PCHContainerReader &PCHContainerRdr, 17860b57cec5SDimitry Andric bool FindModuleFileExtensions, 17870b57cec5SDimitry Andric ASTReaderListener &Listener, 17880b57cec5SDimitry Andric bool ValidateDiagnosticOptions); 17890b57cec5SDimitry Andric 17900b57cec5SDimitry Andric /// Determine whether the given AST file is acceptable to load into a 17910b57cec5SDimitry Andric /// translation unit with the given language and target options. 17920b57cec5SDimitry Andric static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, 1793bdd1243dSDimitry Andric const InMemoryModuleCache &ModuleCache, 17940b57cec5SDimitry Andric const PCHContainerReader &PCHContainerRdr, 17950b57cec5SDimitry Andric const LangOptions &LangOpts, 17960b57cec5SDimitry Andric const TargetOptions &TargetOpts, 17970b57cec5SDimitry Andric const PreprocessorOptions &PPOpts, 179861cfbce3SDimitry Andric StringRef ExistingModuleCachePath, 179961cfbce3SDimitry Andric bool RequireStrictOptionMatches = false); 18000b57cec5SDimitry Andric 18010b57cec5SDimitry Andric /// Returns the suggested contents of the predefines buffer, 18020b57cec5SDimitry Andric /// which contains a (typically-empty) subset of the predefines 18030b57cec5SDimitry Andric /// build prior to including the precompiled header. getSuggestedPredefines()18040b57cec5SDimitry Andric const std::string &getSuggestedPredefines() { return SuggestedPredefines; } 18050b57cec5SDimitry Andric 18060b57cec5SDimitry Andric /// Read a preallocated preprocessed entity from the external source. 18070b57cec5SDimitry Andric /// 18080b57cec5SDimitry Andric /// \returns null if an error occurred that prevented the preprocessed 18090b57cec5SDimitry Andric /// entity from being loaded. 18100b57cec5SDimitry Andric PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override; 18110b57cec5SDimitry Andric 18120b57cec5SDimitry Andric /// Returns a pair of [Begin, End) indices of preallocated 18130b57cec5SDimitry Andric /// preprocessed entities that \p Range encompasses. 18140b57cec5SDimitry Andric std::pair<unsigned, unsigned> 18150b57cec5SDimitry Andric findPreprocessedEntitiesInRange(SourceRange Range) override; 18160b57cec5SDimitry Andric 18170b57cec5SDimitry Andric /// Optionally returns true or false if the preallocated preprocessed 18180b57cec5SDimitry Andric /// entity with index \p Index came from file \p FID. 1819bdd1243dSDimitry Andric std::optional<bool> isPreprocessedEntityInFileID(unsigned Index, 18200b57cec5SDimitry Andric FileID FID) override; 18210b57cec5SDimitry Andric 18220b57cec5SDimitry Andric /// Read a preallocated skipped range from the external source. 18230b57cec5SDimitry Andric SourceRange ReadSkippedRange(unsigned Index) override; 18240b57cec5SDimitry Andric 18250b57cec5SDimitry Andric /// Read the header file information for the given file entry. 18265f757f3fSDimitry Andric HeaderFileInfo GetHeaderFileInfo(FileEntryRef FE) override; 18270b57cec5SDimitry Andric 18280b57cec5SDimitry Andric void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag); 18290b57cec5SDimitry Andric 18300b57cec5SDimitry Andric /// Returns the number of source locations found in the chain. getTotalNumSLocs()18310b57cec5SDimitry Andric unsigned getTotalNumSLocs() const { 18320b57cec5SDimitry Andric return TotalNumSLocEntries; 18330b57cec5SDimitry Andric } 18340b57cec5SDimitry Andric 18350b57cec5SDimitry Andric /// Returns the number of identifiers found in the chain. getTotalNumIdentifiers()18360b57cec5SDimitry Andric unsigned getTotalNumIdentifiers() const { 18370b57cec5SDimitry Andric return static_cast<unsigned>(IdentifiersLoaded.size()); 18380b57cec5SDimitry Andric } 18390b57cec5SDimitry Andric 18400b57cec5SDimitry Andric /// Returns the number of macros found in the chain. getTotalNumMacros()18410b57cec5SDimitry Andric unsigned getTotalNumMacros() const { 18420b57cec5SDimitry Andric return static_cast<unsigned>(MacrosLoaded.size()); 18430b57cec5SDimitry Andric } 18440b57cec5SDimitry Andric 18450b57cec5SDimitry Andric /// Returns the number of types found in the chain. getTotalNumTypes()18460b57cec5SDimitry Andric unsigned getTotalNumTypes() const { 18470b57cec5SDimitry Andric return static_cast<unsigned>(TypesLoaded.size()); 18480b57cec5SDimitry Andric } 18490b57cec5SDimitry Andric 18500b57cec5SDimitry Andric /// Returns the number of declarations found in the chain. getTotalNumDecls()18510b57cec5SDimitry Andric unsigned getTotalNumDecls() const { 18520b57cec5SDimitry Andric return static_cast<unsigned>(DeclsLoaded.size()); 18530b57cec5SDimitry Andric } 18540b57cec5SDimitry Andric 18550b57cec5SDimitry Andric /// Returns the number of submodules known. getTotalNumSubmodules()18560b57cec5SDimitry Andric unsigned getTotalNumSubmodules() const { 18570b57cec5SDimitry Andric return static_cast<unsigned>(SubmodulesLoaded.size()); 18580b57cec5SDimitry Andric } 18590b57cec5SDimitry Andric 18600b57cec5SDimitry Andric /// Returns the number of selectors found in the chain. getTotalNumSelectors()18610b57cec5SDimitry Andric unsigned getTotalNumSelectors() const { 18620b57cec5SDimitry Andric return static_cast<unsigned>(SelectorsLoaded.size()); 18630b57cec5SDimitry Andric } 18640b57cec5SDimitry Andric 18650b57cec5SDimitry Andric /// Returns the number of preprocessed entities known to the AST 18660b57cec5SDimitry Andric /// reader. getTotalNumPreprocessedEntities()18670b57cec5SDimitry Andric unsigned getTotalNumPreprocessedEntities() const { 18680b57cec5SDimitry Andric unsigned Result = 0; 18690b57cec5SDimitry Andric for (const auto &M : ModuleMgr) 18700b57cec5SDimitry Andric Result += M.NumPreprocessedEntities; 18710b57cec5SDimitry Andric return Result; 18720b57cec5SDimitry Andric } 18730b57cec5SDimitry Andric 18740b57cec5SDimitry Andric /// Resolve a type ID into a type, potentially building a new 18750b57cec5SDimitry Andric /// type. 18760b57cec5SDimitry Andric QualType GetType(serialization::TypeID ID); 18770b57cec5SDimitry Andric 18780b57cec5SDimitry Andric /// Resolve a local type ID within a given AST file into a type. 18790b57cec5SDimitry Andric QualType getLocalType(ModuleFile &F, unsigned LocalID); 18800b57cec5SDimitry Andric 18810b57cec5SDimitry Andric /// Map a local type ID within a given AST file into a global type ID. 18820b57cec5SDimitry Andric serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const; 18830b57cec5SDimitry Andric 18840b57cec5SDimitry Andric /// Read a type from the current position in the given record, which 18850b57cec5SDimitry Andric /// was read from the given AST file. readType(ModuleFile & F,const RecordData & Record,unsigned & Idx)18860b57cec5SDimitry Andric QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) { 18870b57cec5SDimitry Andric if (Idx >= Record.size()) 18880b57cec5SDimitry Andric return {}; 18890b57cec5SDimitry Andric 18900b57cec5SDimitry Andric return getLocalType(F, Record[Idx++]); 18910b57cec5SDimitry Andric } 18920b57cec5SDimitry Andric 18930b57cec5SDimitry Andric /// Map from a local declaration ID within a given module to a 18940b57cec5SDimitry Andric /// global declaration ID. 18950b57cec5SDimitry Andric serialization::DeclID getGlobalDeclID(ModuleFile &F, 18960b57cec5SDimitry Andric serialization::LocalDeclID LocalID) const; 18970b57cec5SDimitry Andric 18980b57cec5SDimitry Andric /// Returns true if global DeclID \p ID originated from module \p M. 18990b57cec5SDimitry Andric bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const; 19000b57cec5SDimitry Andric 19010b57cec5SDimitry Andric /// Retrieve the module file that owns the given declaration, or NULL 19020b57cec5SDimitry Andric /// if the declaration is not from a module file. 19030b57cec5SDimitry Andric ModuleFile *getOwningModuleFile(const Decl *D); 19040b57cec5SDimitry Andric 19050b57cec5SDimitry Andric /// Returns the source location for the decl \p ID. 19060b57cec5SDimitry Andric SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID); 19070b57cec5SDimitry Andric 19080b57cec5SDimitry Andric /// Resolve a declaration ID into a declaration, potentially 19090b57cec5SDimitry Andric /// building a new declaration. 19100b57cec5SDimitry Andric Decl *GetDecl(serialization::DeclID ID); 19110b57cec5SDimitry Andric Decl *GetExternalDecl(uint32_t ID) override; 19120b57cec5SDimitry Andric 19130b57cec5SDimitry Andric /// Resolve a declaration ID into a declaration. Return 0 if it's not 19140b57cec5SDimitry Andric /// been loaded yet. 19150b57cec5SDimitry Andric Decl *GetExistingDecl(serialization::DeclID ID); 19160b57cec5SDimitry Andric 19170b57cec5SDimitry Andric /// Reads a declaration with the given local ID in the given module. GetLocalDecl(ModuleFile & F,uint32_t LocalID)19180b57cec5SDimitry Andric Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) { 19190b57cec5SDimitry Andric return GetDecl(getGlobalDeclID(F, LocalID)); 19200b57cec5SDimitry Andric } 19210b57cec5SDimitry Andric 19220b57cec5SDimitry Andric /// Reads a declaration with the given local ID in the given module. 19230b57cec5SDimitry Andric /// 19240b57cec5SDimitry Andric /// \returns The requested declaration, casted to the given return type. 19250b57cec5SDimitry Andric template<typename T> GetLocalDeclAs(ModuleFile & F,uint32_t LocalID)19260b57cec5SDimitry Andric T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) { 19270b57cec5SDimitry Andric return cast_or_null<T>(GetLocalDecl(F, LocalID)); 19280b57cec5SDimitry Andric } 19290b57cec5SDimitry Andric 19300b57cec5SDimitry Andric /// Map a global declaration ID into the declaration ID used to 19310b57cec5SDimitry Andric /// refer to this declaration within the given module fule. 19320b57cec5SDimitry Andric /// 19330b57cec5SDimitry Andric /// \returns the global ID of the given declaration as known in the given 19340b57cec5SDimitry Andric /// module file. 19350b57cec5SDimitry Andric serialization::DeclID 19360b57cec5SDimitry Andric mapGlobalIDToModuleFileGlobalID(ModuleFile &M, 19370b57cec5SDimitry Andric serialization::DeclID GlobalID); 19380b57cec5SDimitry Andric 19390b57cec5SDimitry Andric /// Reads a declaration ID from the given position in a record in the 19400b57cec5SDimitry Andric /// given module. 19410b57cec5SDimitry Andric /// 19420b57cec5SDimitry Andric /// \returns The declaration ID read from the record, adjusted to a global ID. 19430b57cec5SDimitry Andric serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record, 19440b57cec5SDimitry Andric unsigned &Idx); 19450b57cec5SDimitry Andric 19460b57cec5SDimitry Andric /// Reads a declaration from the given position in a record in the 19470b57cec5SDimitry Andric /// given module. ReadDecl(ModuleFile & F,const RecordData & R,unsigned & I)19480b57cec5SDimitry Andric Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) { 19490b57cec5SDimitry Andric return GetDecl(ReadDeclID(F, R, I)); 19500b57cec5SDimitry Andric } 19510b57cec5SDimitry Andric 19520b57cec5SDimitry Andric /// Reads a declaration from the given position in a record in the 19530b57cec5SDimitry Andric /// given module. 19540b57cec5SDimitry Andric /// 19550b57cec5SDimitry Andric /// \returns The declaration read from this location, casted to the given 19560b57cec5SDimitry Andric /// result type. 19570b57cec5SDimitry Andric template<typename T> ReadDeclAs(ModuleFile & F,const RecordData & R,unsigned & I)19580b57cec5SDimitry Andric T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) { 19590b57cec5SDimitry Andric return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I))); 19600b57cec5SDimitry Andric } 19610b57cec5SDimitry Andric 19620b57cec5SDimitry Andric /// If any redeclarations of \p D have been imported since it was 19630b57cec5SDimitry Andric /// last checked, this digs out those redeclarations and adds them to the 19640b57cec5SDimitry Andric /// redeclaration chain for \p D. 19650b57cec5SDimitry Andric void CompleteRedeclChain(const Decl *D) override; 19660b57cec5SDimitry Andric 19670b57cec5SDimitry Andric CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override; 19680b57cec5SDimitry Andric 19690b57cec5SDimitry Andric /// Resolve the offset of a statement into a statement. 19700b57cec5SDimitry Andric /// 19710b57cec5SDimitry Andric /// This operation will read a new statement from the external 19720b57cec5SDimitry Andric /// source each time it is called, and is meant to be used via a 19730b57cec5SDimitry Andric /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). 19740b57cec5SDimitry Andric Stmt *GetExternalDeclStmt(uint64_t Offset) override; 19750b57cec5SDimitry Andric 19760b57cec5SDimitry Andric /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the 19770b57cec5SDimitry Andric /// specified cursor. Read the abbreviations that are at the top of the block 19780b57cec5SDimitry Andric /// and then leave the cursor pointing into the block. 1979349cc55cSDimitry Andric static llvm::Error ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, 1980349cc55cSDimitry Andric unsigned BlockID, 19815ffd83dbSDimitry Andric uint64_t *StartOfBlockOffset = nullptr); 19820b57cec5SDimitry Andric 19830b57cec5SDimitry Andric /// Finds all the visible declarations with a given name. 19840b57cec5SDimitry Andric /// The current implementation of this method just loads the entire 19850b57cec5SDimitry Andric /// lookup table as unmaterialized references. 19860b57cec5SDimitry Andric bool FindExternalVisibleDeclsByName(const DeclContext *DC, 19870b57cec5SDimitry Andric DeclarationName Name) override; 19880b57cec5SDimitry Andric 19890b57cec5SDimitry Andric /// Read all of the declarations lexically stored in a 19900b57cec5SDimitry Andric /// declaration context. 19910b57cec5SDimitry Andric /// 19920b57cec5SDimitry Andric /// \param DC The declaration context whose declarations will be 19930b57cec5SDimitry Andric /// read. 19940b57cec5SDimitry Andric /// 19950b57cec5SDimitry Andric /// \param IsKindWeWant A predicate indicating which declaration kinds 19960b57cec5SDimitry Andric /// we are interested in. 19970b57cec5SDimitry Andric /// 19980b57cec5SDimitry Andric /// \param Decls Vector that will contain the declarations loaded 19990b57cec5SDimitry Andric /// from the external source. The caller is responsible for merging 20000b57cec5SDimitry Andric /// these declarations with any declarations already stored in the 20010b57cec5SDimitry Andric /// declaration context. 20020b57cec5SDimitry Andric void 20030b57cec5SDimitry Andric FindExternalLexicalDecls(const DeclContext *DC, 20040b57cec5SDimitry Andric llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, 20050b57cec5SDimitry Andric SmallVectorImpl<Decl *> &Decls) override; 20060b57cec5SDimitry Andric 20070b57cec5SDimitry Andric /// Get the decls that are contained in a file in the Offset/Length 20080b57cec5SDimitry Andric /// range. \p Length can be 0 to indicate a point at \p Offset instead of 20090b57cec5SDimitry Andric /// a range. 20100b57cec5SDimitry Andric void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length, 20110b57cec5SDimitry Andric SmallVectorImpl<Decl *> &Decls) override; 20120b57cec5SDimitry Andric 20130b57cec5SDimitry Andric /// Notify ASTReader that we started deserialization of 20140b57cec5SDimitry Andric /// a decl or type so until FinishedDeserializing is called there may be 20150b57cec5SDimitry Andric /// decls that are initializing. Must be paired with FinishedDeserializing. 20160b57cec5SDimitry Andric void StartedDeserializing() override; 20170b57cec5SDimitry Andric 20180b57cec5SDimitry Andric /// Notify ASTReader that we finished the deserialization of 20190b57cec5SDimitry Andric /// a decl or type. Must be paired with StartedDeserializing. 20200b57cec5SDimitry Andric void FinishedDeserializing() override; 20210b57cec5SDimitry Andric 20220b57cec5SDimitry Andric /// Function that will be invoked when we begin parsing a new 20230b57cec5SDimitry Andric /// translation unit involving this external AST source. 20240b57cec5SDimitry Andric /// 20250b57cec5SDimitry Andric /// This function will provide all of the external definitions to 20260b57cec5SDimitry Andric /// the ASTConsumer. 20270b57cec5SDimitry Andric void StartTranslationUnit(ASTConsumer *Consumer) override; 20280b57cec5SDimitry Andric 20290b57cec5SDimitry Andric /// Print some statistics about AST usage. 20300b57cec5SDimitry Andric void PrintStats() override; 20310b57cec5SDimitry Andric 20320b57cec5SDimitry Andric /// Dump information about the AST reader to standard error. 20330b57cec5SDimitry Andric void dump(); 20340b57cec5SDimitry Andric 20350b57cec5SDimitry Andric /// Return the amount of memory used by memory buffers, breaking down 20360b57cec5SDimitry Andric /// by heap-backed versus mmap'ed memory. 20370b57cec5SDimitry Andric void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override; 20380b57cec5SDimitry Andric 20390b57cec5SDimitry Andric /// Initialize the semantic source with the Sema instance 20400b57cec5SDimitry Andric /// being used to perform semantic analysis on the abstract syntax 20410b57cec5SDimitry Andric /// tree. 20420b57cec5SDimitry Andric void InitializeSema(Sema &S) override; 20430b57cec5SDimitry Andric 20440b57cec5SDimitry Andric /// Inform the semantic consumer that Sema is no longer available. ForgetSema()20450b57cec5SDimitry Andric void ForgetSema() override { SemaObj = nullptr; } 20460b57cec5SDimitry Andric 20470b57cec5SDimitry Andric /// Retrieve the IdentifierInfo for the named identifier. 20480b57cec5SDimitry Andric /// 20490b57cec5SDimitry Andric /// This routine builds a new IdentifierInfo for the given identifier. If any 20500b57cec5SDimitry Andric /// declarations with this name are visible from translation unit scope, their 20510b57cec5SDimitry Andric /// declarations will be deserialized and introduced into the declaration 20520b57cec5SDimitry Andric /// chain of the identifier. 20530b57cec5SDimitry Andric IdentifierInfo *get(StringRef Name) override; 20540b57cec5SDimitry Andric 20550b57cec5SDimitry Andric /// Retrieve an iterator into the set of all identifiers 20560b57cec5SDimitry Andric /// in all loaded AST files. 20570b57cec5SDimitry Andric IdentifierIterator *getIdentifiers() override; 20580b57cec5SDimitry Andric 20590b57cec5SDimitry Andric /// Load the contents of the global method pool for a given 20600b57cec5SDimitry Andric /// selector. 20610b57cec5SDimitry Andric void ReadMethodPool(Selector Sel) override; 20620b57cec5SDimitry Andric 20630b57cec5SDimitry Andric /// Load the contents of the global method pool for a given 20640b57cec5SDimitry Andric /// selector if necessary. 20650b57cec5SDimitry Andric void updateOutOfDateSelector(Selector Sel) override; 20660b57cec5SDimitry Andric 20670b57cec5SDimitry Andric /// Load the set of namespaces that are known to the external source, 20680b57cec5SDimitry Andric /// which will be used during typo correction. 20690b57cec5SDimitry Andric void ReadKnownNamespaces( 20700b57cec5SDimitry Andric SmallVectorImpl<NamespaceDecl *> &Namespaces) override; 20710b57cec5SDimitry Andric 20720b57cec5SDimitry Andric void ReadUndefinedButUsed( 20730b57cec5SDimitry Andric llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override; 20740b57cec5SDimitry Andric 20750b57cec5SDimitry Andric void ReadMismatchingDeleteExpressions(llvm::MapVector< 20760b57cec5SDimitry Andric FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & 20770b57cec5SDimitry Andric Exprs) override; 20780b57cec5SDimitry Andric 20790b57cec5SDimitry Andric void ReadTentativeDefinitions( 20800b57cec5SDimitry Andric SmallVectorImpl<VarDecl *> &TentativeDefs) override; 20810b57cec5SDimitry Andric 20820b57cec5SDimitry Andric void ReadUnusedFileScopedDecls( 20830b57cec5SDimitry Andric SmallVectorImpl<const DeclaratorDecl *> &Decls) override; 20840b57cec5SDimitry Andric 20850b57cec5SDimitry Andric void ReadDelegatingConstructors( 20860b57cec5SDimitry Andric SmallVectorImpl<CXXConstructorDecl *> &Decls) override; 20870b57cec5SDimitry Andric 20880b57cec5SDimitry Andric void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override; 20890b57cec5SDimitry Andric 20900b57cec5SDimitry Andric void ReadUnusedLocalTypedefNameCandidates( 20910b57cec5SDimitry Andric llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override; 20920b57cec5SDimitry Andric 20935ffd83dbSDimitry Andric void ReadDeclsToCheckForDeferredDiags( 2094fe6060f1SDimitry Andric llvm::SmallSetVector<Decl *, 4> &Decls) override; 20955ffd83dbSDimitry Andric 20960b57cec5SDimitry Andric void ReadReferencedSelectors( 20970b57cec5SDimitry Andric SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) override; 20980b57cec5SDimitry Andric 20990b57cec5SDimitry Andric void ReadWeakUndeclaredIdentifiers( 21005f757f3fSDimitry Andric SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WeakIDs) override; 21010b57cec5SDimitry Andric 21020b57cec5SDimitry Andric void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override; 21030b57cec5SDimitry Andric 21040b57cec5SDimitry Andric void ReadPendingInstantiations( 21050b57cec5SDimitry Andric SmallVectorImpl<std::pair<ValueDecl *, 21060b57cec5SDimitry Andric SourceLocation>> &Pending) override; 21070b57cec5SDimitry Andric 21080b57cec5SDimitry Andric void ReadLateParsedTemplates( 21090b57cec5SDimitry Andric llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> 21100b57cec5SDimitry Andric &LPTMap) override; 21110b57cec5SDimitry Andric 211206c3fb27SDimitry Andric void AssignedLambdaNumbering(const CXXRecordDecl *Lambda) override; 211306c3fb27SDimitry Andric 21140b57cec5SDimitry Andric /// Load a selector from disk, registering its ID if it exists. 21150b57cec5SDimitry Andric void LoadSelector(Selector Sel); 21160b57cec5SDimitry Andric 21170b57cec5SDimitry Andric void SetIdentifierInfo(unsigned ID, IdentifierInfo *II); 21180b57cec5SDimitry Andric void SetGloballyVisibleDecls(IdentifierInfo *II, 21190b57cec5SDimitry Andric const SmallVectorImpl<uint32_t> &DeclIDs, 21200b57cec5SDimitry Andric SmallVectorImpl<Decl *> *Decls = nullptr); 21210b57cec5SDimitry Andric 21220b57cec5SDimitry Andric /// Report a diagnostic. 21230b57cec5SDimitry Andric DiagnosticBuilder Diag(unsigned DiagID) const; 21240b57cec5SDimitry Andric 21250b57cec5SDimitry Andric /// Report a diagnostic. 21260b57cec5SDimitry Andric DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const; 21270b57cec5SDimitry Andric 21280b57cec5SDimitry Andric IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID); 21290b57cec5SDimitry Andric readIdentifier(ModuleFile & M,const RecordData & Record,unsigned & Idx)2130480093f4SDimitry Andric IdentifierInfo *readIdentifier(ModuleFile &M, const RecordData &Record, 21310b57cec5SDimitry Andric unsigned &Idx) { 21320b57cec5SDimitry Andric return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++])); 21330b57cec5SDimitry Andric } 21340b57cec5SDimitry Andric GetIdentifier(serialization::IdentifierID ID)21350b57cec5SDimitry Andric IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) override { 21360b57cec5SDimitry Andric // Note that we are loading an identifier. 21370b57cec5SDimitry Andric Deserializing AnIdentifier(this); 21380b57cec5SDimitry Andric 21390b57cec5SDimitry Andric return DecodeIdentifierInfo(ID); 21400b57cec5SDimitry Andric } 21410b57cec5SDimitry Andric 21420b57cec5SDimitry Andric IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID); 21430b57cec5SDimitry Andric 21440b57cec5SDimitry Andric serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M, 21450b57cec5SDimitry Andric unsigned LocalID); 21460b57cec5SDimitry Andric 21470b57cec5SDimitry Andric void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo); 21480b57cec5SDimitry Andric 21490b57cec5SDimitry Andric /// Retrieve the macro with the given ID. 21500b57cec5SDimitry Andric MacroInfo *getMacro(serialization::MacroID ID); 21510b57cec5SDimitry Andric 21520b57cec5SDimitry Andric /// Retrieve the global macro ID corresponding to the given local 21530b57cec5SDimitry Andric /// ID within the given module file. 21540b57cec5SDimitry Andric serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID); 21550b57cec5SDimitry Andric 21560b57cec5SDimitry Andric /// Read the source location entry with index ID. 21570b57cec5SDimitry Andric bool ReadSLocEntry(int ID) override; 21585f757f3fSDimitry Andric /// Get the index ID for the loaded SourceLocation offset. 21595f757f3fSDimitry Andric int getSLocEntryID(SourceLocation::UIntTy SLocOffset) override; 21605f757f3fSDimitry Andric /// Try to read the offset of the SLocEntry at the given index in the given 21615f757f3fSDimitry Andric /// module file. 21625f757f3fSDimitry Andric llvm::Expected<SourceLocation::UIntTy> readSLocOffset(ModuleFile *F, 21635f757f3fSDimitry Andric unsigned Index); 21640b57cec5SDimitry Andric 21650b57cec5SDimitry Andric /// Retrieve the module import location and module name for the 21660b57cec5SDimitry Andric /// given source manager entry ID. 21670b57cec5SDimitry Andric std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override; 21680b57cec5SDimitry Andric 21690b57cec5SDimitry Andric /// Retrieve the global submodule ID given a module and its local ID 21700b57cec5SDimitry Andric /// number. 21710b57cec5SDimitry Andric serialization::SubmoduleID 21720b57cec5SDimitry Andric getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID); 21730b57cec5SDimitry Andric 21740b57cec5SDimitry Andric /// Retrieve the submodule that corresponds to a global submodule ID. 21750b57cec5SDimitry Andric /// 21760b57cec5SDimitry Andric Module *getSubmodule(serialization::SubmoduleID GlobalID); 21770b57cec5SDimitry Andric 21780b57cec5SDimitry Andric /// Retrieve the module that corresponds to the given module ID. 21790b57cec5SDimitry Andric /// 21800b57cec5SDimitry Andric /// Note: overrides method in ExternalASTSource 21810b57cec5SDimitry Andric Module *getModule(unsigned ID) override; 21820b57cec5SDimitry Andric 21830b57cec5SDimitry Andric /// Retrieve the module file with a given local ID within the specified 21840b57cec5SDimitry Andric /// ModuleFile. 21850b57cec5SDimitry Andric ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID); 21860b57cec5SDimitry Andric 21870b57cec5SDimitry Andric /// Get an ID for the given module file. 21880b57cec5SDimitry Andric unsigned getModuleFileID(ModuleFile *M); 21890b57cec5SDimitry Andric 21900b57cec5SDimitry Andric /// Return a descriptor for the corresponding module. 2191bdd1243dSDimitry Andric std::optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override; 21920b57cec5SDimitry Andric 21930b57cec5SDimitry Andric ExtKind hasExternalDefinitions(const Decl *D) override; 21940b57cec5SDimitry Andric 21950b57cec5SDimitry Andric /// Retrieve a selector from the given module with its local ID 21960b57cec5SDimitry Andric /// number. 21970b57cec5SDimitry Andric Selector getLocalSelector(ModuleFile &M, unsigned LocalID); 21980b57cec5SDimitry Andric 21990b57cec5SDimitry Andric Selector DecodeSelector(serialization::SelectorID Idx); 22000b57cec5SDimitry Andric 22010b57cec5SDimitry Andric Selector GetExternalSelector(serialization::SelectorID ID) override; 22020b57cec5SDimitry Andric uint32_t GetNumExternalSelectors() override; 22030b57cec5SDimitry Andric ReadSelector(ModuleFile & M,const RecordData & Record,unsigned & Idx)22040b57cec5SDimitry Andric Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) { 22050b57cec5SDimitry Andric return getLocalSelector(M, Record[Idx++]); 22060b57cec5SDimitry Andric } 22070b57cec5SDimitry Andric 22080b57cec5SDimitry Andric /// Retrieve the global selector ID that corresponds to this 22090b57cec5SDimitry Andric /// the local selector ID in a given module. 22105f757f3fSDimitry Andric serialization::SelectorID getGlobalSelectorID(ModuleFile &M, 22110b57cec5SDimitry Andric unsigned LocalID) const; 22120b57cec5SDimitry Andric 22130b57cec5SDimitry Andric /// Read the contents of a CXXCtorInitializer array. 22140b57cec5SDimitry Andric CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override; 22150b57cec5SDimitry Andric 2216e8d8bef9SDimitry Andric /// Read a AlignPackInfo from raw form. ReadAlignPackInfo(uint32_t Raw)2217e8d8bef9SDimitry Andric Sema::AlignPackInfo ReadAlignPackInfo(uint32_t Raw) const { 2218e8d8bef9SDimitry Andric return Sema::AlignPackInfo::getFromRawEncoding(Raw); 2219e8d8bef9SDimitry Andric } 2220e8d8bef9SDimitry Andric 22210b57cec5SDimitry Andric /// Read a source location from raw form and return it in its 22220b57cec5SDimitry Andric /// originating module file's source location space. 222381ad6265SDimitry Andric SourceLocation ReadUntranslatedSourceLocation(SourceLocation::UIntTy Raw, 222481ad6265SDimitry Andric LocSeq *Seq = nullptr) const { 222581ad6265SDimitry Andric return SourceLocationEncoding::decode(Raw, Seq); 22260b57cec5SDimitry Andric } 22270b57cec5SDimitry Andric 22280b57cec5SDimitry Andric /// Read a source location from raw form. 2229fe6060f1SDimitry Andric SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, 223081ad6265SDimitry Andric SourceLocation::UIntTy Raw, 223181ad6265SDimitry Andric LocSeq *Seq = nullptr) const { 223281ad6265SDimitry Andric SourceLocation Loc = ReadUntranslatedSourceLocation(Raw, Seq); 22330b57cec5SDimitry Andric return TranslateSourceLocation(ModuleFile, Loc); 22340b57cec5SDimitry Andric } 22350b57cec5SDimitry Andric 22360b57cec5SDimitry Andric /// Translate a source location from another module file's source 22370b57cec5SDimitry Andric /// location space into ours. TranslateSourceLocation(ModuleFile & ModuleFile,SourceLocation Loc)22380b57cec5SDimitry Andric SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile, 22390b57cec5SDimitry Andric SourceLocation Loc) const { 22400b57cec5SDimitry Andric if (!ModuleFile.ModuleOffsetMap.empty()) 22410b57cec5SDimitry Andric ReadModuleOffsetMap(ModuleFile); 22420b57cec5SDimitry Andric assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != 22430b57cec5SDimitry Andric ModuleFile.SLocRemap.end() && 22440b57cec5SDimitry Andric "Cannot find offset to remap."); 2245fe6060f1SDimitry Andric SourceLocation::IntTy Remap = 2246fe6060f1SDimitry Andric ModuleFile.SLocRemap.find(Loc.getOffset())->second; 22470b57cec5SDimitry Andric return Loc.getLocWithOffset(Remap); 22480b57cec5SDimitry Andric } 22490b57cec5SDimitry Andric 22500b57cec5SDimitry Andric /// Read a source location. 22510b57cec5SDimitry Andric SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, 225281ad6265SDimitry Andric const RecordDataImpl &Record, unsigned &Idx, 225381ad6265SDimitry Andric LocSeq *Seq = nullptr) { 225481ad6265SDimitry Andric return ReadSourceLocation(ModuleFile, Record[Idx++], Seq); 22550b57cec5SDimitry Andric } 22560b57cec5SDimitry Andric 2257bdd1243dSDimitry Andric /// Read a FileID. ReadFileID(ModuleFile & F,const RecordDataImpl & Record,unsigned & Idx)2258bdd1243dSDimitry Andric FileID ReadFileID(ModuleFile &F, const RecordDataImpl &Record, 2259bdd1243dSDimitry Andric unsigned &Idx) const { 2260bdd1243dSDimitry Andric return TranslateFileID(F, FileID::get(Record[Idx++])); 2261bdd1243dSDimitry Andric } 2262bdd1243dSDimitry Andric 2263bdd1243dSDimitry Andric /// Translate a FileID from another module file's FileID space into ours. TranslateFileID(ModuleFile & F,FileID FID)2264bdd1243dSDimitry Andric FileID TranslateFileID(ModuleFile &F, FileID FID) const { 2265bdd1243dSDimitry Andric assert(FID.ID >= 0 && "Reading non-local FileID."); 2266bdd1243dSDimitry Andric return FileID::get(F.SLocEntryBaseID + FID.ID - 1); 2267bdd1243dSDimitry Andric } 2268bdd1243dSDimitry Andric 22690b57cec5SDimitry Andric /// Read a source range. 227081ad6265SDimitry Andric SourceRange ReadSourceRange(ModuleFile &F, const RecordData &Record, 227181ad6265SDimitry Andric unsigned &Idx, LocSeq *Seq = nullptr); 22720b57cec5SDimitry Andric 22730b57cec5SDimitry Andric // Read a string 227406c3fb27SDimitry Andric static std::string ReadString(const RecordDataImpl &Record, unsigned &Idx); 22750b57cec5SDimitry Andric 22760b57cec5SDimitry Andric // Skip a string SkipString(const RecordData & Record,unsigned & Idx)22770b57cec5SDimitry Andric static void SkipString(const RecordData &Record, unsigned &Idx) { 22780b57cec5SDimitry Andric Idx += Record[Idx] + 1; 22790b57cec5SDimitry Andric } 22800b57cec5SDimitry Andric 22810b57cec5SDimitry Andric // Read a path 22820b57cec5SDimitry Andric std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx); 22830b57cec5SDimitry Andric 22840b57cec5SDimitry Andric // Read a path 22850b57cec5SDimitry Andric std::string ReadPath(StringRef BaseDirectory, const RecordData &Record, 22860b57cec5SDimitry Andric unsigned &Idx); 22870b57cec5SDimitry Andric 22880b57cec5SDimitry Andric // Skip a path SkipPath(const RecordData & Record,unsigned & Idx)22890b57cec5SDimitry Andric static void SkipPath(const RecordData &Record, unsigned &Idx) { 22900b57cec5SDimitry Andric SkipString(Record, Idx); 22910b57cec5SDimitry Andric } 22920b57cec5SDimitry Andric 22930b57cec5SDimitry Andric /// Read a version tuple. 22940b57cec5SDimitry Andric static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx); 22950b57cec5SDimitry Andric 22960b57cec5SDimitry Andric CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record, 22970b57cec5SDimitry Andric unsigned &Idx); 22980b57cec5SDimitry Andric 22990b57cec5SDimitry Andric /// Reads a statement. 23000b57cec5SDimitry Andric Stmt *ReadStmt(ModuleFile &F); 23010b57cec5SDimitry Andric 23020b57cec5SDimitry Andric /// Reads an expression. 23030b57cec5SDimitry Andric Expr *ReadExpr(ModuleFile &F); 23040b57cec5SDimitry Andric 23050b57cec5SDimitry Andric /// Reads a sub-statement operand during statement reading. ReadSubStmt()23060b57cec5SDimitry Andric Stmt *ReadSubStmt() { 23070b57cec5SDimitry Andric assert(ReadingKind == Read_Stmt && 23080b57cec5SDimitry Andric "Should be called only during statement reading!"); 23090b57cec5SDimitry Andric // Subexpressions are stored from last to first, so the next Stmt we need 23100b57cec5SDimitry Andric // is at the back of the stack. 23110b57cec5SDimitry Andric assert(!StmtStack.empty() && "Read too many sub-statements!"); 23120b57cec5SDimitry Andric return StmtStack.pop_back_val(); 23130b57cec5SDimitry Andric } 23140b57cec5SDimitry Andric 23150b57cec5SDimitry Andric /// Reads a sub-expression operand during statement reading. 23160b57cec5SDimitry Andric Expr *ReadSubExpr(); 23170b57cec5SDimitry Andric 23180b57cec5SDimitry Andric /// Reads a token out of a record. 23190b57cec5SDimitry Andric Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx); 23200b57cec5SDimitry Andric 23210b57cec5SDimitry Andric /// Reads the macro record located at the given offset. 23220b57cec5SDimitry Andric MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset); 23230b57cec5SDimitry Andric 23240b57cec5SDimitry Andric /// Determine the global preprocessed entity ID that corresponds to 23250b57cec5SDimitry Andric /// the given local ID within the given module. 23260b57cec5SDimitry Andric serialization::PreprocessedEntityID 23270b57cec5SDimitry Andric getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const; 23280b57cec5SDimitry Andric 23290b57cec5SDimitry Andric /// Add a macro to deserialize its macro directive history. 23300b57cec5SDimitry Andric /// 23310b57cec5SDimitry Andric /// \param II The name of the macro. 23320b57cec5SDimitry Andric /// \param M The module file. 23330b57cec5SDimitry Andric /// \param MacroDirectivesOffset Offset of the serialized macro directive 23340b57cec5SDimitry Andric /// history. 23350b57cec5SDimitry Andric void addPendingMacro(IdentifierInfo *II, ModuleFile *M, 23365ffd83dbSDimitry Andric uint32_t MacroDirectivesOffset); 23370b57cec5SDimitry Andric 23380b57cec5SDimitry Andric /// Read the set of macros defined by this external macro source. 23390b57cec5SDimitry Andric void ReadDefinedMacros() override; 23400b57cec5SDimitry Andric 23410b57cec5SDimitry Andric /// Update an out-of-date identifier. 23420b57cec5SDimitry Andric void updateOutOfDateIdentifier(IdentifierInfo &II) override; 23430b57cec5SDimitry Andric 23440b57cec5SDimitry Andric /// Note that this identifier is up-to-date. 23450b57cec5SDimitry Andric void markIdentifierUpToDate(IdentifierInfo *II); 23460b57cec5SDimitry Andric 23470b57cec5SDimitry Andric /// Load all external visible decls in the given DeclContext. 23480b57cec5SDimitry Andric void completeVisibleDeclsMap(const DeclContext *DC) override; 23490b57cec5SDimitry Andric 23500b57cec5SDimitry Andric /// Retrieve the AST context that this AST reader supplements. getContext()23510b57cec5SDimitry Andric ASTContext &getContext() { 23520b57cec5SDimitry Andric assert(ContextObj && "requested AST context when not loading AST"); 23530b57cec5SDimitry Andric return *ContextObj; 23540b57cec5SDimitry Andric } 23550b57cec5SDimitry Andric 23560b57cec5SDimitry Andric // Contains the IDs for declarations that were requested before we have 23570b57cec5SDimitry Andric // access to a Sema object. 23580b57cec5SDimitry Andric SmallVector<uint64_t, 16> PreloadedDeclIDs; 23590b57cec5SDimitry Andric 23600b57cec5SDimitry Andric /// Retrieve the semantic analysis object used to analyze the 23610b57cec5SDimitry Andric /// translation unit in which the precompiled header is being 23620b57cec5SDimitry Andric /// imported. getSema()23630b57cec5SDimitry Andric Sema *getSema() { return SemaObj; } 23640b57cec5SDimitry Andric 23650b57cec5SDimitry Andric /// Get the identifier resolver used for name lookup / updates 23660b57cec5SDimitry Andric /// in the translation unit scope. We have one of these even if we don't 23670b57cec5SDimitry Andric /// have a Sema object. 23680b57cec5SDimitry Andric IdentifierResolver &getIdResolver(); 23690b57cec5SDimitry Andric 23700b57cec5SDimitry Andric /// Retrieve the identifier table associated with the 23710b57cec5SDimitry Andric /// preprocessor. 23720b57cec5SDimitry Andric IdentifierTable &getIdentifierTable(); 23730b57cec5SDimitry Andric 23740b57cec5SDimitry Andric /// Record that the given ID maps to the given switch-case 23750b57cec5SDimitry Andric /// statement. 23760b57cec5SDimitry Andric void RecordSwitchCaseID(SwitchCase *SC, unsigned ID); 23770b57cec5SDimitry Andric 23780b57cec5SDimitry Andric /// Retrieve the switch-case statement with the given ID. 23790b57cec5SDimitry Andric SwitchCase *getSwitchCaseWithID(unsigned ID); 23800b57cec5SDimitry Andric 23810b57cec5SDimitry Andric void ClearSwitchCaseIDs(); 23820b57cec5SDimitry Andric 23830b57cec5SDimitry Andric /// Cursors for comments blocks. 23840b57cec5SDimitry Andric SmallVector<std::pair<llvm::BitstreamCursor, 23850b57cec5SDimitry Andric serialization::ModuleFile *>, 8> CommentsCursors; 23860b57cec5SDimitry Andric 23870b57cec5SDimitry Andric /// Loads comments ranges. 23880b57cec5SDimitry Andric void ReadComments() override; 23890b57cec5SDimitry Andric 23905f757f3fSDimitry Andric /// Visit all the input file infos of the given module file. 23915f757f3fSDimitry Andric void visitInputFileInfos( 23925f757f3fSDimitry Andric serialization::ModuleFile &MF, bool IncludeSystem, 23935f757f3fSDimitry Andric llvm::function_ref<void(const serialization::InputFileInfo &IFI, 23945f757f3fSDimitry Andric bool IsSystem)> 23955f757f3fSDimitry Andric Visitor); 23965f757f3fSDimitry Andric 23970b57cec5SDimitry Andric /// Visit all the input files of the given module file. 23980b57cec5SDimitry Andric void visitInputFiles(serialization::ModuleFile &MF, 23990b57cec5SDimitry Andric bool IncludeSystem, bool Complain, 24000b57cec5SDimitry Andric llvm::function_ref<void(const serialization::InputFile &IF, 24010b57cec5SDimitry Andric bool isSystem)> Visitor); 24020b57cec5SDimitry Andric 24030b57cec5SDimitry Andric /// Visit all the top-level module maps loaded when building the given module 24040b57cec5SDimitry Andric /// file. 24050b57cec5SDimitry Andric void visitTopLevelModuleMaps(serialization::ModuleFile &MF, 2406bdd1243dSDimitry Andric llvm::function_ref<void(FileEntryRef)> Visitor); 24070b57cec5SDimitry Andric isProcessingUpdateRecords()24080b57cec5SDimitry Andric bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; } 24090b57cec5SDimitry Andric }; 24100b57cec5SDimitry Andric 24115f757f3fSDimitry Andric /// A simple helper class to unpack an integer to bits and consuming 24125f757f3fSDimitry Andric /// the bits in order. 24135f757f3fSDimitry Andric class BitsUnpacker { 24145f757f3fSDimitry Andric constexpr static uint32_t BitsIndexUpbound = 32; 24155f757f3fSDimitry Andric 24165f757f3fSDimitry Andric public: BitsUnpacker(uint32_t V)24175f757f3fSDimitry Andric BitsUnpacker(uint32_t V) { updateValue(V); } 24185f757f3fSDimitry Andric BitsUnpacker(const BitsUnpacker &) = delete; 24195f757f3fSDimitry Andric BitsUnpacker(BitsUnpacker &&) = delete; 24205f757f3fSDimitry Andric BitsUnpacker operator=(const BitsUnpacker &) = delete; 24215f757f3fSDimitry Andric BitsUnpacker operator=(BitsUnpacker &&) = delete; 24225f757f3fSDimitry Andric ~BitsUnpacker() = default; 24235f757f3fSDimitry Andric updateValue(uint32_t V)24245f757f3fSDimitry Andric void updateValue(uint32_t V) { 24255f757f3fSDimitry Andric Value = V; 24265f757f3fSDimitry Andric CurrentBitsIndex = 0; 24275f757f3fSDimitry Andric } 24285f757f3fSDimitry Andric advance(uint32_t BitsWidth)2429cb14a3feSDimitry Andric void advance(uint32_t BitsWidth) { CurrentBitsIndex += BitsWidth; } 2430cb14a3feSDimitry Andric getNextBit()24315f757f3fSDimitry Andric bool getNextBit() { 24325f757f3fSDimitry Andric assert(isValid()); 24335f757f3fSDimitry Andric return Value & (1 << CurrentBitsIndex++); 24345f757f3fSDimitry Andric } 24355f757f3fSDimitry Andric getNextBits(uint32_t Width)24365f757f3fSDimitry Andric uint32_t getNextBits(uint32_t Width) { 24375f757f3fSDimitry Andric assert(isValid()); 24385f757f3fSDimitry Andric assert(Width < BitsIndexUpbound); 24395f757f3fSDimitry Andric uint32_t Ret = (Value >> CurrentBitsIndex) & ((1 << Width) - 1); 24405f757f3fSDimitry Andric CurrentBitsIndex += Width; 24415f757f3fSDimitry Andric return Ret; 24425f757f3fSDimitry Andric } 24435f757f3fSDimitry Andric canGetNextNBits(uint32_t Width)24445f757f3fSDimitry Andric bool canGetNextNBits(uint32_t Width) const { 24455f757f3fSDimitry Andric return CurrentBitsIndex + Width < BitsIndexUpbound; 24465f757f3fSDimitry Andric } 24475f757f3fSDimitry Andric 24485f757f3fSDimitry Andric private: isValid()24495f757f3fSDimitry Andric bool isValid() const { return CurrentBitsIndex < BitsIndexUpbound; } 24505f757f3fSDimitry Andric 24515f757f3fSDimitry Andric uint32_t Value; 24525f757f3fSDimitry Andric uint32_t CurrentBitsIndex = ~0; 24535f757f3fSDimitry Andric }; 24540b57cec5SDimitry Andric } // namespace clang 24550b57cec5SDimitry Andric 24560b57cec5SDimitry Andric #endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H 2457