clang  6.0.0svn
Classes | Public Types | Public Member Functions | List of all members
clang::ExternalASTMerger Class Reference

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

#include "clang/AST/ExternalASTMerger.h"

Inheritance diagram for clang::ExternalASTMerger:
Inheritance graph
[legend]
Collaboration diagram for clang::ExternalASTMerger:
Collaboration graph
[legend]

Classes

struct  DCOrigin
 A single origin for a DeclContext. More...
 
struct  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, llvm::ArrayRef< ImporterSource > Sources)
 
void AddSources (llvm::ArrayRef< ImporterSource > Sources)
 Add a set of ASTContexts as possible origins. More...
 
void RemoveSources (llvm::ArrayRef< ImporterSource > Sources)
 Remove a set of ASTContexts as possible origins. More...
 
bool FindExternalVisibleDeclsByName (const DeclContext *DC, DeclarationName Name) override
 Implementation of the ExternalASTSource API. More...
 
void FindExternalLexicalDecls (const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl *> &Result) override
 Implementation of the ExternalASTSource API. More...
 
void CompleteType (TagDecl *Tag) override
 Implementation of the ExternalASTSource API. More...
 
void CompleteType (ObjCInterfaceDecl *Interface) override
 Implementation of the ExternalASTSource API. More...
 
bool CanComplete (DeclContext *DC)
 Returns true if DC can be found in any source AST context. More...
 
void MaybeRecordOrigin (const DeclContext *ToDC, DCOrigin Origin)
 Records an origin in Origins only if name lookup would find something different or nothing at all. More...
 
void ForceRecordOrigin (const DeclContext *ToDC, DCOrigin Origin)
 Regardless of any checks, override the Origin for a DeclContext. More...
 
const OriginMapGetOrigins ()
 Get a read-only view of the Origins map, for use in constructing an ImporterSource for another ExternalASTMerger. More...
 
bool HasImporterForOrigin (ASTContext &OriginContext)
 Returns true if Importers contains an ASTImporter whose source is OriginContext. More...
 
ASTImporterImporterForOrigin (ASTContext &OriginContext)
 Returns a reference to the ASTRImporter from Importers whose origin is OriginContext. More...
 
void SetLogStream (llvm::raw_string_ostream &Stream)
 Sets the current log stream. More...
 
llvm::raw_ostream & logs ()
 Log something if there is a logging callback installed. More...
 
bool LoggingEnabled ()
 True if the log stream is not llvm::nulls();. More...
 
- Public Member Functions inherited from clang::ExternalASTSource
 ExternalASTSource ()=default
 
virtual ~ExternalASTSource ()
 
uint32_t getGeneration () const
 Get the current generation of this AST source. More...
 
virtual DeclGetExternalDecl (uint32_t ID)
 Resolve a declaration ID into a declaration, potentially building a new declaration. More...
 
virtual Selector GetExternalSelector (uint32_t ID)
 Resolve a selector ID into a selector. More...
 
virtual uint32_t GetNumExternalSelectors ()
 Returns the number of selectors known to the external AST source. More...
 
virtual StmtGetExternalDeclStmt (uint64_t Offset)
 Resolve the offset of a statement in the decl stream into a statement. More...
 
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. More...
 
virtual CXXBaseSpecifierGetExternalCXXBaseSpecifiers (uint64_t Offset)
 Resolve the offset of a set of C++ base specifiers in the decl stream into an array of specifiers. More...
 
virtual void updateOutOfDateIdentifier (IdentifierInfo &II)
 Update an out-of-date identifier. More...
 
virtual void completeVisibleDeclsMap (const DeclContext *DC)
 Ensures that the table of all visible declarations inside this context is up to date. More...
 
virtual ModulegetModule (unsigned ID)
 Retrieve the module that corresponds to the given module ID. More...
 
virtual llvm::Optional< ASTSourceDescriptorgetSourceDescriptor (unsigned ID)
 Return a descriptor for the corresponding module, if one exists. More...
 
virtual ExtKind hasExternalDefinitions (const Decl *D)
 
void FindExternalLexicalDecls (const DeclContext *DC, SmallVectorImpl< Decl *> &Result)
 Finds all declarations lexically contained within the given DeclContext. More...
 
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. More...
 
virtual void CompleteRedeclChain (const Decl *D)
 Gives the external AST source an opportunity to complete the redeclaration chain for a declaration. More...
 
virtual void ReadComments ()
 Loads comment ranges. More...
 
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. More...
 
virtual void FinishedDeserializing ()
 Notify ExternalASTSource that we finished the deserialization of a decl or type. More...
 
virtual void StartTranslationUnit (ASTConsumer *Consumer)
 Function that will be invoked when we begin parsing a new translation unit involving this external AST source. More...
 
virtual void PrintStats ()
 Print any statistics that have been gathered regarding the external AST source. More...
 
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. More...
 
MemoryBufferSizes getMemoryBufferSizes () const
 Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memory. More...
 
virtual void getMemoryBufferSizes (MemoryBufferSizes &sizes) const
 

Additional Inherited Members

- Protected Member Functions inherited from clang::ExternalASTSource
uint32_t incrementGeneration (ASTContext &C)
 Increment the current generation. More...
 
- 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.

ExtermalASTMerger 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.

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,
llvm::ArrayRef< ImporterSource Sources 
)

Definition at line 309 of file ExternalASTMerger.cpp.

References AddSources().

Member Function Documentation

◆ 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 neeed 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 314 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 256 of file ExternalASTMerger.cpp.

References clang::DeclContext::hasExternalLexicalStorage(), and clang::DeclContext::hasExternalVisibleStorage().

◆ CompleteType() [1/2]

void ExternalASTMerger::CompleteType ( TagDecl Tag)
overridevirtual

◆ CompleteType() [2/2]

void ExternalASTMerger::CompleteType ( ObjCInterfaceDecl Interface)
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 387 of file ExternalASTMerger.cpp.

References clang::Decl::getDeclContext(), and clang::ASTImporter::Import().

◆ FindExternalVisibleDeclsByName()

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

◆ ForceRecordOrigin()

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

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

Definition at line 298 of file ExternalASTMerger.cpp.

References clang::ExternalASTMerger::DCOrigin::AST, and clang::ExternalASTMerger::DCOrigin::DC.

◆ 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 143 of file ExternalASTMerger.h.

References HasImporterForOrigin(), and ImporterForOrigin().

◆ HasImporterForOrigin()

bool ExternalASTMerger::HasImporterForOrigin ( ASTContext OriginContext)

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

Definition at line 186 of file ExternalASTMerger.cpp.

Referenced by GetOrigins().

◆ ImporterForOrigin()

ASTImporter & ExternalASTMerger::ImporterForOrigin ( ASTContext OriginContext)

Returns a reference to the ASTRImporter from Importers whose origin is OriginContext.

This allows manual import of ASTs while preserving the OriginMap correctly.

Definition at line 171 of file ExternalASTMerger.cpp.

Referenced by GetOrigins().

◆ LoggingEnabled()

bool clang::ExternalASTMerger::LoggingEnabled ( )
inline

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

Definition at line 171 of file ExternalASTMerger.h.

Referenced by RemoveSources().

◆ logs()

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

Log something if there is a logging callback installed.

Definition at line 168 of file ExternalASTMerger.h.

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

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

◆ RemoveSources()

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

References LoggingEnabled().

◆ SetLogStream()

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

Sets the current log stream.

Definition at line 155 of file ExternalASTMerger.h.


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