class ExternalASTMerger

Declaration

class ExternalASTMerger : public ExternalASTSource { /* full declaration omitted */ };

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.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:48

Inherits from: ExternalASTSource

Member Variables

private clang::ExternalASTMerger::ImporterVector Importers
One importer exists for each source.
private clang::ExternalASTMerger::OriginMap Origins
Overrides in case name lookup would return nothing or would return the wrong thing.
private llvm::raw_ostream* LogStream
The installed log stream.
private clang::ExternalASTMerger::ImporterTarget Target
The target for this ExternalASTMerger.
private std::shared_ptr<ASTImporterSharedState> SharedState
ExternalASTMerger has multiple ASTImporters that import into the same TU. This is the shared state for all ASTImporters of this ExternalASTMerger. See also the CrossTranslationUnitContext that has a similar setup.

Method Overview

  • public void AddSources(llvm::ArrayRef<ImporterSource> Sources)
  • public bool CanComplete(clang::DeclContext * DC)
  • public void CompleteType(clang::TagDecl * Tag)
  • public void CompleteType(clang::ObjCInterfaceDecl * Interface)
  • public ExternalASTMerger(const clang::ExternalASTMerger::ImporterTarget & Target, llvm::ArrayRef<ImporterSource> Sources)
  • public void FindExternalLexicalDecls(const clang::DeclContext * DC, llvm::function_ref<bool (Decl::Kind)> IsKindWeWant, SmallVectorImpl<clang::Decl *> & Result)
  • public bool FindExternalVisibleDeclsByName(const clang::DeclContext * DC, clang::DeclarationName Name)
  • public clang::Decl * FindOriginalDecl(clang::Decl * D)
  • private template <typename CallbackType>void ForEachMatchingDC(const clang::DeclContext * DC, CallbackType Callback)
  • public void ForceRecordOrigin(const clang::DeclContext * ToDC, clang::ExternalASTMerger::DCOrigin Origin)
  • public const clang::ExternalASTMerger::OriginMap & GetOrigins()
  • public bool HasImporterForOrigin(clang::ASTContext & OriginContext)
  • public clang::ASTImporter & ImporterForOrigin(clang::ASTContext & OriginContext)
  • public bool LoggingEnabled()
  • public void MaybeRecordOrigin(const clang::DeclContext * ToDC, clang::ExternalASTMerger::DCOrigin Origin)
  • private void RecordOriginImpl(const clang::DeclContext * ToDC, clang::ExternalASTMerger::DCOrigin Origin, clang::ASTImporter & importer)
  • public void RemoveSources(llvm::ArrayRef<ImporterSource> Sources)
  • public void SetLogStream(llvm::raw_string_ostream & Stream)
  • public llvm::raw_ostream & logs()

Inherited from ExternalASTSource:

Methods

void AddSources(
    llvm::ArrayRef<ImporterSource> Sources)

Description

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.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:131

Parameters

llvm::ArrayRef<ImporterSource> Sources

bool CanComplete(clang::DeclContext* DC)

Description

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

Declared at: clang/include/clang/AST/ExternalASTMerger.h:159

Parameters

clang::DeclContext* DC

void CompleteType(clang::TagDecl* Tag)

Description

Implementation of the ExternalASTSource API.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:153

Parameters

clang::TagDecl* Tag

void CompleteType(
    clang::ObjCInterfaceDecl* Interface)

Description

Implementation of the ExternalASTSource API.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:156

Parameters

clang::ObjCInterfaceDecl* Interface

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

Declared at: clang/include/clang/AST/ExternalASTMerger.h:115

Parameters

const clang::ExternalASTMerger::ImporterTarget& Target
llvm::ArrayRef<ImporterSource> Sources

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

Description

Implementation of the ExternalASTSource API.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:148

Parameters

const clang::DeclContext* DC
llvm::function_ref<bool(Decl::Kind)> IsKindWeWant
SmallVectorImpl<clang::Decl*>& Result

bool FindExternalVisibleDeclsByName(
    const clang::DeclContext* DC,
    clang::DeclarationName Name)

Description

Implementation of the ExternalASTSource API.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:143

Parameters

const clang::DeclContext* DC
clang::DeclarationName Name

clang::Decl* FindOriginalDecl(clang::Decl* D)

Description

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 import D.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:122

Parameters

clang::Decl* D

template <typename CallbackType>
void ForEachMatchingDC(
    const clang::DeclContext* DC,
    CallbackType Callback)

Description

Performs an action for every DeclContext that is identified as corresponding (either by forced origin or by name lookup) to DC.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:191

Templates

CallbackType

Parameters

const clang::DeclContext* DC
CallbackType Callback

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

Description

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

Declared at: clang/include/clang/AST/ExternalASTMerger.h:166

Parameters

const clang::DeclContext* ToDC
clang::ExternalASTMerger::DCOrigin Origin

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

Description

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

Declared at: clang/include/clang/AST/ExternalASTMerger.h:170

bool HasImporterForOrigin(
    clang::ASTContext& OriginContext)

Description

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

Declared at: clang/include/clang/AST/ExternalASTMerger.h:174

Parameters

clang::ASTContext& OriginContext

clang::ASTImporter& ImporterForOrigin(
    clang::ASTContext& OriginContext)

Description

Returns a reference to the ASTImporter from Importers whose origin is OriginContext. This allows manual import of ASTs while preserving the OriginMap correctly.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:179

Parameters

clang::ASTContext& OriginContext

bool LoggingEnabled()

Description

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

Declared at: clang/include/clang/AST/ExternalASTMerger.h:198

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

Description

Records an origin in Origins only if name lookup would find something different or nothing at all.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:163

Parameters

const clang::DeclContext* ToDC
clang::ExternalASTMerger::DCOrigin Origin

void RecordOriginImpl(
    const clang::DeclContext* ToDC,
    clang::ExternalASTMerger::DCOrigin Origin,
    clang::ASTImporter& importer)

Description

Records and origin in Origins.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:185

Parameters

const clang::DeclContext* ToDC
clang::ExternalASTMerger::DCOrigin Origin
clang::ASTImporter& importer

void RemoveSources(
    llvm::ArrayRef<ImporterSource> Sources)

Description

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.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:140

Parameters

llvm::ArrayRef<ImporterSource> Sources

void SetLogStream(
    llvm::raw_string_ostream& Stream)

Description

Sets the current log stream.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:182

Parameters

llvm::raw_string_ostream& Stream

llvm::raw_ostream& logs()

Description

Log something if there is a logging callback installed.

Declared at: clang/include/clang/AST/ExternalASTMerger.h:195