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/PointerUnion.h"
24#include "llvm/ADT/STLExtras.h"
25#include "llvm/ADT/SmallVector.h"
26#include "llvm/ADT/iterator.h"
27#include "llvm/Support/PointerLikeTypeTraits.h"
39class ASTSourceDescriptor;
40class CXXBaseSpecifier;
41class CXXCtorInitializer;
47class 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; }
322template<
typename T,
typename OffsT, T* (ExternalASTSource::*Get)(OffsT Offset)>
336 assert((Offset << 1 >> 1) == Offset &&
"Offsets must require < 63 bits");
342 this->Ptr =
reinterpret_cast<uint64_t
>(
Ptr);
347 assert((Offset << 1 >> 1) == Offset &&
"Offsets must require < 63 bits");
351 Ptr = (Offset << 1) | 0x01;
359 explicit operator bool()
const {
return Ptr != 0; }
377 "Cannot deserialize a lazy pointer without an AST source");
378 Ptr =
reinterpret_cast<uint64_t
>((Source->*Get)(OffsT(
Ptr >> 1)));
380 return reinterpret_cast<T*
>(
Ptr);
388 return reinterpret_cast<T**
>(&
Ptr);
395template<
typename Owner,
typename T,
void (ExternalASTSource::*Update)(Owner)>
429 Value.template get<LazyData *>()->LastGeneration = 0;
434 if (
auto *LazyVal =
Value.template dyn_cast<LazyData *>()) {
435 LazyVal->LastValue = NewValue;
446 if (
auto *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 (
auto *LazyVal =
Value.template dyn_cast<LazyData *>())
459 return LazyVal->LastValue;
460 return Value.template get<T>();
475template<
typename Owner,
typename T,
484 static constexpr int NumLowBitsAvailable =
498template<
typename T,
typename Source,
499 void (Source::*Loader)(SmallVectorImpl<T>&),
500 unsigned LoadedStorage = 2,
unsigned LocalStorage = 4>
523 :
public llvm::iterator_adaptor_base<
530 :
iterator::iterator_adaptor_base(Position), Self(Self) {}
532 bool isLoaded()
const {
return this->I < 0; }
539 return Self->Loaded.end()[this->I];
540 return Self->Local.begin()[this->I];
549 (source->*Loader)(Loaded);
550 return iterator(
this, -(
int)Loaded.size());
554 return iterator(
this, Local.size());
558 Local.push_back(LocalValue);
562 if (From.isLoaded() && To.isLoaded()) {
563 Loaded.erase(&*From, &*To);
567 if (From.isLoaded()) {
568 Loaded.erase(&*From, Loaded.end());
569 From = begin(
nullptr,
true);
572 Local.erase(&*From, &*To);
587 &ExternalASTSource::GetExternalCXXCtorInitializers>;
592 &ExternalASTSource::GetExternalCXXBaseSpecifiers>;
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
llvm::MachO::Record Record
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a base class of a C++ class.
Represents a C++ base or member initializer.
The results of name lookup within a DeclContext.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
Kind
Lists the kind of concrete classes of Decl.
The name of a declaration.
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
Deserializing(ExternalASTSource *source)
Abstract interface for external sources of AST nodes.
static bool classof(const ExternalASTSource *S)
virtual ExtKind hasExternalDefinitions(const Decl *D)
virtual void StartTranslationUnit(ASTConsumer *Consumer)
Function that will be invoked when we begin parsing a new translation unit involving this external AS...
virtual std::optional< ASTSourceDescriptor > getSourceDescriptor(unsigned ID)
Return a descriptor for the corresponding module, if one exists.
static DeclContextLookupResult SetExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name, ArrayRef< NamedDecl * > Decls)
virtual bool isA(const void *ClassID) const
LLVM-style RTTI.
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...
uint32_t incrementGeneration(ASTContext &C)
Increment the current generation.
static DeclContextLookupResult SetNoExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name)
virtual Module * getModule(unsigned ID)
Retrieve the module that corresponds to the given module ID.
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...
virtual void FinishedDeserializing()
Notify ExternalASTSource that we finished the deserialization of a decl or type.
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.
void FindExternalLexicalDecls(const DeclContext *DC, SmallVectorImpl< Decl * > &Result)
Finds all declarations lexically contained within the given DeclContext.
virtual ~ExternalASTSource()
virtual void ReadComments()
Loads comment ranges.
virtual void CompleteRedeclChain(const Decl *D)
Gives the external AST source an opportunity to complete the redeclaration chain for a declaration.
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 Decl * GetExternalDecl(GlobalDeclID ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
virtual void PrintStats()
Print any statistics that have been gathered regarding the external AST source.
virtual Stmt * GetExternalDeclStmt(uint64_t Offset)
Resolve the offset of a statement in the decl stream into a statement.
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...
virtual void StartedDeserializing()
Notify ExternalASTSource that we started deserialization of a decl or type so until FinishedDeseriali...
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.
uint32_t getGeneration() const
Get the current generation of this 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.
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
virtual void completeVisibleDeclsMap(const DeclContext *DC)
Ensures that the table of all visible declarations inside this context is up to date.
virtual void updateOutOfDateIdentifier(const IdentifierInfo &II)
Update an out-of-date identifier.
ExternalASTSource()=default
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...
An abstract interface that should be implemented by external AST sources that also provide informatio...
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
One of these records is kept for each identifier that is lexed.
Iteration over the elements in the vector.
iterator::reference operator*() const
Represents a lazily-loaded vector of data.
void push_back(const T &LocalValue)
void erase(iterator From, iterator To)
iterator begin(Source *source, bool LocalOnly=false)
Describes a module or submodule.
Represents an ObjC class declaration.
Represents a struct/union/class.
Smart pointer class that efficiently represents Objective-C method names.
Stmt - This represents one statement.
Represents the declaration of a struct/union/class/enum.
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Diagnostic wrappers for TextAPI types for error reporting.
MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)
A cache of the value of this pointer, in the most recent generation in which we queried it.
LazyData(ExternalASTSource *Source, T Value)
ExternalASTSource * ExternalSource
A lazy value (of type T) that is within an AST node of type Owner, where the value might change in la...
static ValueType makeValue(const ASTContext &Ctx, T Value)
Create the representation of a LazyGenerationalUpdatePtr.
T getNotUpdated() const
Get the most recently computed value of this pointer without updating it.
void set(T NewValue)
Set the value of this pointer, in the current generation.
LazyGenerationalUpdatePtr(ValueType V)
LazyGenerationalUpdatePtr(const ASTContext &Ctx, T Value=T())
NotUpdatedTag
Create a pointer that is not potentially updated by later generations of the external AST source.
void setNotUpdated(T NewValue)
Set the value of this pointer, for this and all future generations.
T get(Owner O)
Get the value of this pointer, updating its owner if necessary.
void markIncomplete()
Forcibly set this pointer (which must be lazy) as needing updates.
static LazyGenerationalUpdatePtr getFromOpaqueValue(void *Ptr)
llvm::PointerUnion< T, LazyData * > ValueType
LazyGenerationalUpdatePtr(NotUpdatedTag, T Value=T())
A lazy pointer to an AST node (of base type T) that resides within an external AST source.
bool isValid() const
Whether this pointer is non-NULL.
LazyOffsetPtr(uint64_t Offset)
bool isOffset() const
Whether this pointer is currently stored as an offset.
LazyOffsetPtr & operator=(T *Ptr)
T ** getAddressOfPointer(ExternalASTSource *Source) const
Retrieve the address of the AST node pointer.
uint64_t Ptr
Either a pointer to an AST node or the offset within the external AST source where the AST node can b...
LazyOffsetPtr & operator=(uint64_t Offset)
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer points to.
static Ptr getFromVoidPointer(void *P)
static void * getAsVoidPointer(Ptr P)