Go to the documentation of this file.
14 #ifndef LLVM_CLANG_AST_EXTERNALASTSOURCE_H
15 #define LLVM_CLANG_AST_EXTERNALASTSOURCE_H
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/IntrusiveRefCntPtr.h"
23 #include "llvm/ADT/Optional.h"
24 #include "llvm/ADT/PointerUnion.h"
25 #include "llvm/ADT/STLExtras.h"
26 #include "llvm/ADT/SmallVector.h"
27 #include "llvm/ADT/iterator.h"
28 #include "llvm/Support/PointerLikeTypeTraits.h"
39 class ASTSourceDescriptor;
40 class CXXBaseSpecifier;
41 class CXXCtorInitializer;
43 class DeclarationName;
47 class ObjCInterfaceDecl;
65 uint32_t CurrentGeneration = 0;
178 llvm::function_ref<
bool(
Decl::Kind)> IsKindWeWant,
270 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
271 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
272 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets);
298 virtual bool isA(
const void *ClassID)
const {
return ClassID == &ID; }
322 template<
typename T,
typename OffsT, T* (ExternalASTSource::*Get)(OffsT Offset)>
336 assert((
Offset << 1 >> 1) ==
Offset &&
"Offsets must require < 63 bits");
347 assert((
Offset << 1 >> 1) ==
Offset &&
"Offsets must require < 63 bits");
359 explicit operator bool()
const {
return Ptr != 0; }
377 "Cannot deserialize a lazy pointer without an AST source");
380 return reinterpret_cast<T*
>(
Ptr);
387 template<
typename Owner,
typename T,
void (ExternalASTSource::*Update)(Owner)>
421 Value.template get<LazyData *>()->LastGeneration = 0;
426 if (
auto *LazyVal =
Value.template dyn_cast<LazyData *>()) {
427 LazyVal->LastValue = NewValue;
438 if (
auto *LazyVal =
Value.template dyn_cast<LazyData *>()) {
439 if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) {
440 LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration();
441 (LazyVal->ExternalSource->*
Update)(O);
443 return LazyVal->LastValue;
445 return Value.template get<T>();
450 if (
auto *LazyVal =
Value.template dyn_cast<LazyData *>())
451 return LazyVal->LastValue;
452 return Value.template get<T>();
467 template<
typename Owner,
typename T,
476 static constexpr
int NumLowBitsAvailable =
490 template<
typename T,
typename Source,
491 void (Source::*Loader)(SmallVectorImpl<T>&),
492 unsigned LoadedStorage = 2,
unsigned LocalStorage = 4>
515 :
public llvm::iterator_adaptor_base<
516 iterator,
int, std::random_access_iterator_tag, T,
int, T *, T &> {
522 :
iterator::iterator_adaptor_base(Position), Self(Self) {}
524 bool isLoaded()
const {
return this->I < 0; }
531 return Self->Loaded.end()[this->I];
532 return Self->Local.begin()[this->I];
536 iterator
begin(Source *source,
bool LocalOnly =
false) {
538 return iterator(
this, 0);
541 (source->*Loader)(Loaded);
542 return iterator(
this, -(
int)Loaded.size());
546 return iterator(
this, Local.size());
550 Local.push_back(LocalValue);
553 void erase(iterator From, iterator To) {
554 if (From.isLoaded() && To.isLoaded()) {
555 Loaded.erase(&*From, &*To);
559 if (From.isLoaded()) {
560 Loaded.erase(&*From, Loaded.end());
561 From = begin(
nullptr,
true);
564 Local.erase(&*From, &*To);
579 &ExternalASTSource::GetExternalCXXCtorInitializers>;
584 &ExternalASTSource::GetExternalCXXBaseSpecifiers>;
588 #endif // LLVM_CLANG_AST_EXTERNALASTSOURCE_H
Represents an ObjC class declaration.
LazyGenerationalUpdatePtr(const ASTContext &Ctx, T Value=T())
YAML serialization mapping.
Iteration over the elements in the vector.
NotUpdatedTag
Create a pointer that is not potentially updated by later generations of the external AST source.
virtual void ReadComments()
Loads comment ranges.
LazyGenerationalUpdatePtr(ValueType V)
virtual void StartTranslationUnit(ASTConsumer *Consumer)
Function that will be invoked when we begin parsing a new translation unit involving this external AS...
ExternalASTSource()=default
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
void erase(iterator From, iterator To)
virtual void CompleteRedeclChain(const Decl *D)
Gives the external AST source an opportunity to complete the redeclaration chain for a declaration.
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...
Deserializing(ExternalASTSource *source)
uint32_t getGeneration() const
Get the current generation of this AST source.
A cache of the value of this pointer, in the most recent generation in which we queried it.
virtual void FinishedDeserializing()
Notify ExternalASTSource that we finished the deserialization of a decl or type.
virtual llvm::Optional< ASTSourceDescriptor > getSourceDescriptor(unsigned ID)
Return a descriptor for the corresponding module, if one exists.
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.
void FindExternalLexicalDecls(const DeclContext *DC, SmallVectorImpl< Decl * > &Result)
Finds all declarations lexically contained within the given DeclContext.
void setNotUpdated(T NewValue)
Set the value of this pointer, for this and all future generations.
MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)
virtual Selector GetExternalSelector(uint32_t ID)
Resolve a selector ID into a selector.
The name of a declaration.
virtual Module * getModule(unsigned ID)
Retrieve the module that corresponds to the given module ID.
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 f...
A lazy pointer to an AST node (of base type T) that resides within an external AST source.
Kind
Lists the kind of concrete classes of Decl.
Describes a module or submodule.
virtual Stmt * GetExternalDeclStmt(uint64_t Offset)
Resolve the offset of a statement in the decl stream into a statement.
LazyOffsetPtr< Stmt, uint64_t, &ExternalASTSource::GetExternalDeclStmt > LazyDeclStmtPtr
A lazy pointer to a statement.
iterator::reference operator*() const
LazyOffsetPtr & operator=(uint64_t Offset)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
uint64_t Ptr
Either a pointer to an AST node or the offset within the external AST source where the AST node can b...
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
A lazy value (of type T) that is within an AST node of type Owner, where the value might change in la...
An abstract interface that should be implemented by external AST sources that also provide informatio...
void push_back(const T &LocalValue)
static bool classof(const ExternalASTSource *S)
Represents the declaration of a struct/union/class/enum.
T getNotUpdated() const
Get the most recently computed value of this pointer without updating it.
virtual bool isA(const void *ClassID) const
LLVM-style RTTI.
virtual void PrintStats()
Print any statistics that have been gathered regarding the external AST source.
ExternalASTSource * ExternalSource
static ValueType makeValue(const ASTContext &Ctx, T Value)
Create the representation of a LazyGenerationalUpdatePtr.
virtual ~ExternalASTSource()
bool isValid() const
Whether this pointer is non-NULL.
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.
void markIncomplete()
Forcibly set this pointer (which must be lazy) as needing updates.
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...
bool isOffset() const
Whether this pointer is currently stored as an offset.
void set(T NewValue)
Set the value of this pointer, in the current generation.
LazyGenerationalUpdatePtr(NotUpdatedTag, T Value=T())
virtual ExtKind hasExternalDefinitions(const Decl *D)
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
uint32_t incrementGeneration(ASTContext &C)
Increment the current generation.
Decl - This represents one declaration (or definition), e.g.
Represents a lazily-loaded vector of data.
iterator begin(Source *source, bool LocalOnly=false)
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...
One of these records is kept for each identifier that is lexed.
llvm::PointerUnion< T, LazyData * > ValueType
LazyData(ExternalASTSource *Source, T Value)
T get(Owner O)
Get the value of this pointer, updating its owner if necessary.
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer points to.
static void * getAsVoidPointer(Ptr P)
LazyOffsetPtr(uint64_t Offset)
static DeclContextLookupResult SetNoExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name)
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 uint32_t GetNumExternalSelectors()
Returns the number of selectors known to the external AST source.
Smart pointer class that efficiently represents Objective-C method names.
static LazyGenerationalUpdatePtr getFromOpaqueValue(void *Ptr)
Stmt - This represents one statement.
virtual void completeVisibleDeclsMap(const DeclContext *DC)
Ensures that the table of all visible declarations inside this context is up to date.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
static Ptr getFromVoidPointer(void *P)
Represents a base class of a C++ class.
The results of name lookup within a DeclContext.
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
LazyOffsetPtr & operator=(T *Ptr)
virtual void StartedDeserializing()
Notify ExternalASTSource that we started deserialization of a decl or type so until FinishedDeseriali...
virtual Decl * GetExternalDecl(uint32_t ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
Represents a C++ base or member initializer.
Abstract interface for external sources of AST nodes.
Represents a struct/union/class.
static DeclContextLookupResult SetExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name, ArrayRef< NamedDecl * > Decls)