clang 22.0.0git
clang::ExternalASTMerger Class Reference

ExternalASTSource implementation that merges information from several ASTContexts. More...

#include "clang/AST/ExternalASTMerger.h"

Inheritance diagram for clang::ExternalASTMerger:
[legend]

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 *, DCOriginOriginMap
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, ArrayRef< ImporterSource > Sources)
DeclFindOriginalDecl (Decl *D)
 Asks all connected ASTImporters if any of them imported the given declaration.
void AddSources (ArrayRef< ImporterSource > Sources)
 Add a set of ASTContexts as possible origins.
void RemoveSources (ArrayRef< ImporterSource > Sources)
 Remove a set of ASTContexts as possible origins.
bool FindExternalVisibleDeclsByName (const DeclContext *DC, DeclarationName Name, const DeclContext *OriginalDC) 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 OriginMapGetOrigins ()
 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.
ASTImporterImporterForOrigin (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 DeclGetExternalDecl (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 StmtGetExternalDeclStmt (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 CXXBaseSpecifierGetExternalCXXBaseSpecifiers (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 LoadExternalSpecializations (const Decl *D, bool OnlyPartial)
 Load all the external specializations for the Decl.
virtual bool LoadExternalSpecializations (const Decl *D, ArrayRef< TemplateArgument > TemplateArgs)
 Load all the specializations for the Decl.
virtual void completeVisibleDeclsMap (const DeclContext *DC)
 Ensures that the table of all visible declarations inside this context is up to date.
virtual ModulegetModule (unsigned ID)
 Retrieve the module that corresponds to the given module ID.
virtual std::optional< ASTSourceDescriptorgetSourceDescriptor (unsigned ID)
 Return a descriptor for the corresponding module, if one exists.
virtual ExtKind hasExternalDefinitions (const Decl *D)
virtual bool wasThisDeclarationADefinition (const FunctionDecl *FD)
 True if this function declaration was a definition before in its own module.
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 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 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)

Detailed Description

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:

  • The DeclContext of origin can be found by simple name lookup. In this case, no additional state is required.
  • The DeclContext of origin is different from what would be found by name lookup. In this case, Origins contains an entry overriding lookup and specifying the correct pair of DeclContext/ASTContext.
  • The DeclContext of origin was determined by another ExternalASTMerger. (This is possible when the source ASTContext for one of the Importers has its own ExternalASTMerger). The origin must be properly forwarded in this case.

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.

Member Typedef Documentation

◆ ImporterVector

typedef std::vector<std::unique_ptr<ASTImporter> > clang::ExternalASTMerger::ImporterVector

Definition at line 58 of file ExternalASTMerger.h.

◆ OriginMap

Definition at line 57 of file ExternalASTMerger.h.

Constructor & Destructor Documentation

◆ ExternalASTMerger()

ExternalASTMerger::ExternalASTMerger ( const ImporterTarget & Target,
ArrayRef< ImporterSource > Sources )

Member Function Documentation

◆ AddSources()

void ExternalASTMerger::AddSources ( 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 408 of file ExternalASTMerger.cpp.

Referenced by ExternalASTMerger().

◆ CanComplete()

bool ExternalASTMerger::CanComplete ( DeclContext * DC)

Returns true if DC can be found in any source AST context.

Definition at line 339 of file ExternalASTMerger.cpp.

References clang::Interface.

◆ CompleteType() [1/2]

void ExternalASTMerger::CompleteType ( ObjCInterfaceDecl * Interface)
overridevirtual

◆ CompleteType() [2/2]

void ExternalASTMerger::CompleteType ( TagDecl * Tag)
overridevirtual

◆ FindExternalLexicalDecls()

void ExternalASTMerger::FindExternalLexicalDecls ( const DeclContext * DC,
llvm::function_ref< bool(Decl::Kind)> IsKindWeWant,
SmallVectorImpl< Decl * > & Result )
overridevirtual

Implementation of the ExternalASTSource API.

Reimplemented from clang::ExternalASTSource.

Definition at line 523 of file ExternalASTMerger.cpp.

References clang::Result.

◆ FindExternalVisibleDeclsByName()

bool ExternalASTMerger::FindExternalVisibleDeclsByName ( const DeclContext * DC,
DeclarationName Name,
const DeclContext * OriginalDC )
overridevirtual

◆ FindOriginalDecl()

Decl * ExternalASTMerger::FindOriginalDecl ( Decl * D)

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 400 of file ExternalASTMerger.cpp.

References clang::Decl::getASTContext(), and clang::Result.

◆ ForceRecordOrigin()

void ExternalASTMerger::ForceRecordOrigin ( const DeclContext * ToDC,
DCOrigin Origin )

Regardless of any checks, override the Origin for a DeclContext.

Definition at line 381 of file ExternalASTMerger.cpp.

References clang::ExternalASTMerger::DCOrigin::AST, and ImporterForOrigin().

◆ GetOrigins()

const OriginMap & clang::ExternalASTMerger::GetOrigins ( )
inline

Get a read-only view of the Origins map, for use in constructing an ImporterSource for another ExternalASTMerger.

Definition at line 171 of file ExternalASTMerger.h.

◆ HasImporterForOrigin()

bool ExternalASTMerger::HasImporterForOrigin ( ASTContext & OriginContext)

Returns true if Importers contains an ASTImporter whose source is OriginContext.

Definition at line 267 of file ExternalASTMerger.cpp.

◆ ImporterForOrigin()

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 252 of file ExternalASTMerger.cpp.

Referenced by ForceRecordOrigin().

◆ LoggingEnabled()

bool clang::ExternalASTMerger::LoggingEnabled ( )
inline

True if the log stream is not llvm::nulls();.

Definition at line 199 of file ExternalASTMerger.h.

Referenced by MaybeRecordOrigin(), and RemoveSources().

◆ logs()

llvm::raw_ostream & clang::ExternalASTMerger::logs ( )
inline

Log something if there is a logging callback installed.

Definition at line 196 of file ExternalASTMerger.h.

Referenced by MaybeRecordOrigin(), and RemoveSources().

◆ MaybeRecordOrigin()

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 364 of file ExternalASTMerger.cpp.

References clang::ExternalASTMerger::DCOrigin::AST, clang::ExternalASTMerger::DCOrigin::DC, clang::ASTContext::getTranslationUnitDecl(), LoggingEnabled(), and logs().

◆ RemoveSources()

void ExternalASTMerger::RemoveSources ( 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 418 of file ExternalASTMerger.cpp.

References LoggingEnabled(), and logs().

◆ SetLogStream()

void clang::ExternalASTMerger::SetLogStream ( llvm::raw_string_ostream & Stream)
inline

Sets the current log stream.

Definition at line 183 of file ExternalASTMerger.h.


The documentation for this class was generated from the following files: