14 #ifndef LLVM_CLANG_AST_EXTERNALASTSOURCE_H
15 #define LLVM_CLANG_AST_EXTERNALASTSOURCE_H
19 #include "llvm/ADT/DenseMap.h"
24 class CXXBaseSpecifier;
25 class CXXCtorInitializer;
26 class DeclarationName;
27 class ExternalSemaSource;
60 uint32_t CurrentGeneration;
196 template <
typename DeclTy>
284 const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
285 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
286 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
287 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets);
298 : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
331 template<
typename T,
typename OffsT, T* (ExternalASTSource::*Get)(OffsT Offset)>
345 assert((Offset << 1 >> 1) == Offset &&
"Offsets must require < 63 bits");
351 this->Ptr =
reinterpret_cast<uint64_t
>(
Ptr);
356 assert((Offset << 1 >> 1) == Offset &&
"Offsets must require < 63 bits");
360 Ptr = (Offset << 1) | 0x01;
368 explicit operator bool()
const {
return Ptr != 0; }
386 "Cannot deserialize a lazy pointer without an AST source");
387 Ptr =
reinterpret_cast<uint64_t
>((Source->*Get)(
Ptr >> 1));
389 return reinterpret_cast<T*
>(
Ptr);
396 template<
typename Owner,
typename T,
void (ExternalASTSource::*Update)(Owner)>
429 Value.template get<LazyData *>()->LastGeneration = 0;
434 if (
LazyData *LazyVal =
Value.template dyn_cast<LazyData*>()) {
435 LazyVal->LastValue = NewValue;
446 if (
LazyData *LazyVal =
Value.template dyn_cast<LazyData*>()) {
447 if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) {
448 LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration();
449 (LazyVal->ExternalSource->*Update)(O);
451 return LazyVal->LastValue;
453 return Value.template get<T>();
458 if (
LazyData *LazyVal =
Value.template dyn_cast<LazyData*>())
459 return LazyVal->LastValue;
460 return Value.template get<T>();
473 template<
typename Owner,
typename T,
493 template<
typename T,
typename Source,
494 void (Source::*Loader)(SmallVectorImpl<T>&),
495 unsigned LoadedStorage = 2,
unsigned LocalStorage = 4>
517 class iterator :
public llvm::iterator_adaptor_base<
518 iterator, int, std::random_access_iterator_tag, T,
int> {
522 : iterator::iterator_adaptor_base(Position), Self(Self) {}
524 bool isLoaded()
const {
return this->I < 0; }
532 return Self->Loaded.end()[this->I];
533 return Self->Local.begin()[this->I];
537 iterator
begin(Source *source,
bool LocalOnly =
false) {
539 return iterator(
this, 0);
542 (source->*Loader)(Loaded);
543 return iterator(
this, -(
int)Loaded.size());
547 return iterator(
this, Local.size());
551 Local.push_back(LocalValue);
554 void erase(iterator From, iterator To) {
555 if (From.isLoaded() && To.isLoaded()) {
556 Loaded.erase(&*From, &*To);
560 if (From.isLoaded()) {
561 Loaded.erase(&*From, Loaded.end());
562 From = begin(
nullptr,
true);
565 Local.erase(&*From, &*To);
570 typedef LazyOffsetPtr<Stmt, uint64_t, &ExternalASTSource::GetExternalDeclStmt>
579 &ExternalASTSource::GetExternalCXXCtorInitializers>
584 &ExternalASTSource::GetExternalCXXBaseSpecifiers>
uint64_t Ptr
Either a pointer to an AST node or the offset within the external AST source where the AST node can b...
Smart pointer class that efficiently represents Objective-C method names.
virtual Decl * GetExternalDecl(uint32_t ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
Represents a lazily-loaded vector of data.
void setNotUpdated(T NewValue)
Set the value of this pointer, for this and all future generations.
LazyData(ExternalASTSource *Source, T Value)
bool isOffset() const
Whether this pointer is currently stored as an offset.
virtual uint32_t GetNumExternalSelectors()
Returns the number of selectors known to the external AST source.
static DeclContextLookupResult SetExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name, ArrayRef< NamedDecl * > Decls)
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.
LazyOffsetPtr< CXXCtorInitializer *, uint64_t,&ExternalASTSource::GetExternalCXXCtorInitializers > LazyCXXCtorInitializersPtr
A lazy pointer to a set of CXXCtorInitializers.
LazyOffsetPtr & operator=(uint64_t Offset)
virtual void PrintStats()
Print any statistics that have been gathered regarding the external AST source.
Deserializing(ExternalASTSource *source)
virtual void CompleteRedeclChain(const Decl *D)
Gives the external AST source an opportunity to complete the redeclaration chain for a declaration...
virtual Selector GetExternalSelector(uint32_t ID)
Resolve a selector ID into a selector.
virtual void StartedDeserializing()
Notify ExternalASTSource that we started deserialization of a decl or type so until FinishedDeseriali...
iterator begin(Source *source, bool LocalOnly=false)
MemoryBufferSizes getMemoryBufferSizes() const
LazyOffsetPtr< Stmt, uint64_t,&ExternalASTSource::GetExternalDeclStmt > LazyDeclStmtPtr
A lazy pointer to a statement.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
The results of name lookup within a DeclContext. This is either a single result (with no stable stora...
void erase(iterator From, iterator To)
iterator::reference operator*() const
uint32_t incrementGeneration(ASTContext &C)
Increment the current generation.
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...
Describes a module or submodule.
virtual void updateOutOfDateIdentifier(IdentifierInfo &II)
Update an out-of-date identifier.
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. Length can be 0 to indicate a ...
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 callin...
ExternalLoadResult FindExternalLexicalDeclsBy(const DeclContext *DC, SmallVectorImpl< Decl * > &Result)
virtual void FinishedDeserializing()
Notify ExternalASTSource that we finished the deserialization of a decl or type. Must be paired with ...
static DeclContextLookupResult SetNoExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name)
virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC, bool(*isKindWeWant)(Decl::Kind), SmallVectorImpl< Decl * > &Result)
Finds all declarations lexically contained within the given DeclContext, after applying an optional f...
LazyGenerationalUpdatePtr(ValueType V)
ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC, SmallVectorImpl< Decl * > &Result)
Finds all declarations lexically contained within the given DeclContext.
Represents an ObjC class declaration.
virtual void completeVisibleDeclsMap(const DeclContext *DC)
Ensures that the table of all visible declarations inside this context is up to date.
ID
Defines the set of possible language-specific address spaces.
ExternalLoadResult
Enumeration describing the result of loading information from an external source. ...
Loading the external information has succeeded.
The external information has already been loaded, and therefore no additional processing is required...
static ValueType makeValue(const ASTContext &Ctx, T Value)
Create the representation of a LazyGenerationalUpdatePtr.
The result type of a method or function.
static void * getAsVoidPointer(Ptr P)
An abstract interface that should be implemented by external AST sources that also provide informatio...
Abstract interface for external sources of AST nodes.
virtual Stmt * GetExternalDeclStmt(uint64_t Offset)
Resolve the offset of a statement in the decl stream into a statement.
TagDecl - Represents the declaration of a struct/union/class/enum.
LazyOffsetPtr< CXXBaseSpecifier, uint64_t,&ExternalASTSource::GetExternalCXXBaseSpecifiers > LazyCXXBaseSpecifiersPtr
A lazy pointer to a set of CXXBaseSpecifiers.
static LazyGenerationalUpdatePtr getFromOpaqueValue(void *Ptr)
void push_back(const T &LocalValue)
LazyOffsetPtr< Decl, uint32_t,&ExternalASTSource::GetExternalDecl > LazyDeclPtr
A lazy pointer to a declaration.
ExternalASTSource * ExternalSource
MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
clang::LazyGenerationalUpdatePtr< Owner, T, Update > Ptr
virtual Module * getModule(unsigned ID)
Retrieve the module that corresponds to the given module ID.
bool isValid() const
Whether this pointer is non-NULL.
void markIncomplete()
Forcibly set this pointer (which must be lazy) as needing updates.
virtual void StartTranslationUnit(ASTConsumer *Consumer)
Function that will be invoked when we begin parsing a new translation unit involving this external AS...
virtual void ReadComments()
Loads comment ranges.
LazyOffsetPtr & operator=(T *Ptr)
A lazy pointer to an AST node (of base type T) that resides within an external AST source...
virtual CXXCtorInitializer ** GetExternalCXXCtorInitializers(uint64_t Offset)
Resolve the offset of a set of C++ constructor initializers in the decl stream into an array of initi...
void set(T NewValue)
Set the value of this pointer, in the current generation.
T getNotUpdated() const
Get the most recently computed value of this pointer without updating it.
virtual ~ExternalASTSource()
uint32_t getGeneration() const
Get the current generation of this AST source. This number is incremented each time the AST source la...
LazyGenerationalUpdatePtr(NotUpdatedTag, T Value=T())
Represents a C++ base or member initializer.
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
Represents a base class of a C++ class.
virtual llvm::Optional< ASTSourceDescriptor > getSourceDescriptor(unsigned ID)
Return a descriptor for the corresponding module, if one exists.
LazyGenerationalUpdatePtr(const ASTContext &Ctx, T Value=T())
Kind
Lists the kind of concrete classes of Decl.
Loading the external information has failed.
A lazy value (of type T) that is within an AST node of type Owner, where the value might change in la...
llvm::PointerUnion< T, LazyData * > ValueType
LazyOffsetPtr(uint64_t Offset)
static Ptr getFromVoidPointer(void *P)
Holds everything needed to generate debug info for an imported module or precompiled header file...