clang 20.0.0git
|
ExternalASTSource implementation that merges information from several ASTContexts. More...
#include "clang/AST/ExternalASTMerger.h"
Classes | |
struct | DCOrigin |
A single origin for a DeclContext. More... | |
class | ImporterSource |
A source for an ExternalASTMerger. More... | |
struct | ImporterTarget |
The target for an ExternalASTMerger. More... | |
Public Types | |
typedef std::map< const DeclContext *, DCOrigin > | OriginMap |
typedef std::vector< std::unique_ptr< ASTImporter > > | ImporterVector |
Public Types inherited from clang::ExternalASTSource | |
enum | ExtKind { EK_Always , EK_Never , EK_ReplyHazy } |
Public Member Functions | |
ExternalASTMerger (const ImporterTarget &Target, llvm::ArrayRef< ImporterSource > Sources) | |
Decl * | FindOriginalDecl (Decl *D) |
Asks all connected ASTImporters if any of them imported the given declaration. | |
void | AddSources (llvm::ArrayRef< ImporterSource > Sources) |
Add a set of ASTContexts as possible origins. | |
void | RemoveSources (llvm::ArrayRef< ImporterSource > Sources) |
Remove a set of ASTContexts as possible origins. | |
bool | FindExternalVisibleDeclsByName (const DeclContext *DC, DeclarationName Name) override |
Implementation of the ExternalASTSource API. | |
void | FindExternalLexicalDecls (const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl * > &Result) override |
Implementation of the ExternalASTSource API. | |
void | CompleteType (TagDecl *Tag) override |
Implementation of the ExternalASTSource API. | |
void | CompleteType (ObjCInterfaceDecl *Interface) override |
Implementation of the ExternalASTSource API. | |
bool | CanComplete (DeclContext *DC) |
Returns true if DC can be found in any source AST context. | |
void | MaybeRecordOrigin (const DeclContext *ToDC, DCOrigin Origin) |
Records an origin in Origins only if name lookup would find something different or nothing at all. | |
void | ForceRecordOrigin (const DeclContext *ToDC, DCOrigin Origin) |
Regardless of any checks, override the Origin for a DeclContext. | |
const OriginMap & | GetOrigins () |
Get a read-only view of the Origins map, for use in constructing an ImporterSource for another ExternalASTMerger. | |
bool | HasImporterForOrigin (ASTContext &OriginContext) |
Returns true if Importers contains an ASTImporter whose source is OriginContext. | |
ASTImporter & | ImporterForOrigin (ASTContext &OriginContext) |
Returns a reference to the ASTImporter from Importers whose origin is OriginContext. | |
void | SetLogStream (llvm::raw_string_ostream &Stream) |
Sets the current log stream. | |
llvm::raw_ostream & | logs () |
Log something if there is a logging callback installed. | |
bool | LoggingEnabled () |
True if the log stream is not llvm::nulls();. | |
Public Member Functions inherited from clang::ExternalASTSource | |
ExternalASTSource ()=default | |
virtual | ~ExternalASTSource () |
uint32_t | getGeneration () const |
Get the current generation of this AST source. | |
virtual Decl * | GetExternalDecl (GlobalDeclID ID) |
Resolve a declaration ID into a declaration, potentially building a new declaration. | |
virtual Selector | GetExternalSelector (uint32_t ID) |
Resolve a selector ID into a selector. | |
virtual uint32_t | GetNumExternalSelectors () |
Returns the number of selectors known to the external AST source. | |
virtual Stmt * | GetExternalDeclStmt (uint64_t Offset) |
Resolve the offset of a statement in the decl stream into a statement. | |
virtual CXXCtorInitializer ** | GetExternalCXXCtorInitializers (uint64_t Offset) |
Resolve the offset of a set of C++ constructor initializers in the decl stream into an array of initializers. | |
virtual CXXBaseSpecifier * | GetExternalCXXBaseSpecifiers (uint64_t Offset) |
Resolve the offset of a set of C++ base specifiers in the decl stream into an array of specifiers. | |
virtual void | updateOutOfDateIdentifier (const IdentifierInfo &II) |
Update an out-of-date identifier. | |
virtual bool | FindExternalVisibleDeclsByName (const DeclContext *DC, DeclarationName Name) |
Find all declarations with the given name in the given context, and add them to the context by calling SetExternalVisibleDeclsForName or SetNoExternalVisibleDeclsForName. | |
virtual void | completeVisibleDeclsMap (const DeclContext *DC) |
Ensures that the table of all visible declarations inside this context is up to date. | |
virtual Module * | getModule (unsigned ID) |
Retrieve the module that corresponds to the given module ID. | |
virtual std::optional< ASTSourceDescriptor > | getSourceDescriptor (unsigned ID) |
Return a descriptor for the corresponding module, if one exists. | |
virtual ExtKind | hasExternalDefinitions (const Decl *D) |
virtual void | FindExternalLexicalDecls (const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl * > &Result) |
Finds all declarations lexically contained within the given DeclContext, after applying an optional filter predicate. | |
void | FindExternalLexicalDecls (const DeclContext *DC, SmallVectorImpl< Decl * > &Result) |
Finds all declarations lexically contained within the given DeclContext. | |
virtual void | FindFileRegionDecls (FileID File, unsigned Offset, unsigned Length, SmallVectorImpl< Decl * > &Decls) |
Get the decls that are contained in a file in the Offset/Length range. | |
virtual void | CompleteRedeclChain (const Decl *D) |
Gives the external AST source an opportunity to complete the redeclaration chain for a declaration. | |
virtual void | CompleteType (TagDecl *Tag) |
Gives the external AST source an opportunity to complete an incomplete type. | |
virtual void | CompleteType (ObjCInterfaceDecl *Class) |
Gives the external AST source an opportunity to complete an incomplete Objective-C class. | |
virtual void | ReadComments () |
Loads comment ranges. | |
virtual void | StartedDeserializing () |
Notify ExternalASTSource that we started deserialization of a decl or type so until FinishedDeserializing is called there may be decls that are initializing. | |
virtual void | FinishedDeserializing () |
Notify ExternalASTSource that we finished the deserialization of a decl or type. | |
virtual void | StartTranslationUnit (ASTConsumer *Consumer) |
Function that will be invoked when we begin parsing a new translation unit involving this external AST source. | |
virtual void | PrintStats () |
Print any statistics that have been gathered regarding the external AST source. | |
virtual bool | layoutRecordType (const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, llvm::DenseMap< const FieldDecl *, uint64_t > &FieldOffsets, llvm::DenseMap< const CXXRecordDecl *, CharUnits > &BaseOffsets, llvm::DenseMap< const CXXRecordDecl *, CharUnits > &VirtualBaseOffsets) |
Perform layout on the given record. | |
MemoryBufferSizes | getMemoryBufferSizes () const |
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memory. | |
virtual void | getMemoryBufferSizes (MemoryBufferSizes &sizes) const |
virtual bool | isA (const void *ClassID) const |
LLVM-style RTTI. | |
Additional Inherited Members | |
Static Public Member Functions inherited from clang::ExternalASTSource | |
static bool | classof (const ExternalASTSource *S) |
Protected Member Functions inherited from clang::ExternalASTSource | |
uint32_t | incrementGeneration (ASTContext &C) |
Increment the current generation. | |
Static Protected Member Functions inherited from clang::ExternalASTSource | |
static DeclContextLookupResult | SetExternalVisibleDeclsForName (const DeclContext *DC, DeclarationName Name, ArrayRef< NamedDecl * > Decls) |
static DeclContextLookupResult | SetNoExternalVisibleDeclsForName (const DeclContext *DC, DeclarationName Name) |
ExternalASTSource implementation that merges information from several ASTContexts.
ExternalASTMerger maintains a vector of ASTImporters that it uses to import (potentially incomplete) Decls and DeclContexts from the source ASTContexts in response to ExternalASTSource API calls.
When lookup occurs in the resulting imported DeclContexts, the original DeclContexts need to be queried. Roughly, there are three cases here:
ExternalASTMerger's job is to maintain the data structures necessary to allow this. The data structures themselves can be extracted (read-only) and copied for re-use.
Definition at line 48 of file ExternalASTMerger.h.
typedef std::vector<std::unique_ptr<ASTImporter> > clang::ExternalASTMerger::ImporterVector |
Definition at line 58 of file ExternalASTMerger.h.
typedef std::map<const DeclContext *, DCOrigin> clang::ExternalASTMerger::OriginMap |
Definition at line 57 of file ExternalASTMerger.h.
ExternalASTMerger::ExternalASTMerger | ( | const ImporterTarget & | Target, |
llvm::ArrayRef< ImporterSource > | Sources | ||
) |
Definition at line 394 of file ExternalASTMerger.cpp.
References AddSources().
void ExternalASTMerger::AddSources | ( | llvm::ArrayRef< ImporterSource > | Sources | ) |
Add a set of ASTContexts as possible origins.
Usually the set will be initialized in the constructor, but long-lived ExternalASTMergers may need to import from new sources (for example, newly-parsed source files).
Ensures that Importers does not gain duplicate entries as a result.
Definition at line 409 of file ExternalASTMerger.cpp.
References clang::Sema::getASTContext().
Referenced by ExternalASTMerger().
bool ExternalASTMerger::CanComplete | ( | DeclContext * | DC | ) |
Returns true if DC can be found in any source AST context.
Definition at line 341 of file ExternalASTMerger.cpp.
References clang::Interface.
|
overridevirtual |
Implementation of the ExternalASTSource API.
Reimplemented from clang::ExternalASTSource.
Definition at line 322 of file ExternalASTMerger.cpp.
References clang::ExternalASTSource::CompleteType(), clang::Decl::getASTContext(), clang::ASTContext::getExternalSource(), clang::ASTImporter::ImportDefinition(), clang::Interface, and clang::ASTImporter::MapImported().
|
overridevirtual |
Implementation of the ExternalASTSource API.
Reimplemented from clang::ExternalASTSource.
Definition at line 305 of file ExternalASTMerger.cpp.
References clang::ExternalASTSource::CompleteType(), clang::Decl::getASTContext(), clang::ASTContext::getExternalSource(), clang::ASTImporter::ImportDefinition(), and clang::ASTImporter::MapImported().
|
overridevirtual |
Implementation of the ExternalASTSource API.
Reimplemented from clang::ExternalASTSource.
Definition at line 523 of file ExternalASTMerger.cpp.
|
overridevirtual |
Implementation of the ExternalASTSource API.
Reimplemented from clang::ExternalASTSource.
Definition at line 474 of file ExternalASTMerger.cpp.
References clang::C, clang::ASTImporter::Import(), importSpecializationsIfNeeded(), clang::Result, and clang::ExternalASTSource::SetExternalVisibleDeclsForName().
Asks all connected ASTImporters if any of them imported the given declaration.
If any ASTImporter did import the given declaration, then this function returns the declaration that D was imported from. Returns nullptr if no ASTImporter did import D.
Definition at line 401 of file ExternalASTMerger.cpp.
References D, clang::Decl::getASTContext(), and clang::Result.
void ExternalASTMerger::ForceRecordOrigin | ( | const DeclContext * | ToDC, |
DCOrigin | Origin | ||
) |
Regardless of any checks, override the Origin for a DeclContext.
Definition at line 383 of file ExternalASTMerger.cpp.
References clang::ExternalASTMerger::DCOrigin::AST, and ImporterForOrigin().
|
inline |
Get a read-only view of the Origins map, for use in constructing an ImporterSource for another ExternalASTMerger.
Definition at line 170 of file ExternalASTMerger.h.
bool ExternalASTMerger::HasImporterForOrigin | ( | ASTContext & | OriginContext | ) |
Returns true if Importers contains an ASTImporter whose source is OriginContext.
Definition at line 269 of file ExternalASTMerger.cpp.
ASTImporter & ExternalASTMerger::ImporterForOrigin | ( | ASTContext & | OriginContext | ) |
Returns a reference to the ASTImporter from Importers whose origin is OriginContext.
This allows manual import of ASTs while preserving the OriginMap correctly.
Definition at line 254 of file ExternalASTMerger.cpp.
Referenced by ForceRecordOrigin().
|
inline |
True if the log stream is not llvm::nulls();.
Definition at line 198 of file ExternalASTMerger.h.
Referenced by MaybeRecordOrigin(), and RemoveSources().
|
inline |
Log something if there is a logging callback installed.
Definition at line 195 of file ExternalASTMerger.h.
Referenced by MaybeRecordOrigin(), and RemoveSources().
void ExternalASTMerger::MaybeRecordOrigin | ( | const DeclContext * | ToDC, |
DCOrigin | Origin | ||
) |
Records an origin in Origins only if name lookup would find something different or nothing at all.
Definition at line 366 of file ExternalASTMerger.cpp.
References clang::ExternalASTMerger::DCOrigin::AST, clang::ExternalASTMerger::DCOrigin::DC, clang::ASTContext::getTranslationUnitDecl(), LoggingEnabled(), and logs().
void ExternalASTMerger::RemoveSources | ( | llvm::ArrayRef< ImporterSource > | Sources | ) |
Remove a set of ASTContexts as possible origins.
Sometimes an origin goes away (for example, if a source file gets superseded by a newer version).
The caller is responsible for ensuring that this doesn't leave DeclContexts that can't be completed.
Definition at line 419 of file ExternalASTMerger.cpp.
References clang::Sema::getASTContext(), LoggingEnabled(), and logs().
|
inline |
Sets the current log stream.
Definition at line 182 of file ExternalASTMerger.h.