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"
85 Source->StartedDeserializing();
89 Source->FinishedDeserializing();
208 llvm::function_ref<
bool(
Decl::Kind)> IsKindWeWant,
300 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
301 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
302 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets);
328 virtual bool isA(
const void *ClassID)
const {
return ClassID == &ID; }
352template<
typename T,
typename OffsT, T* (ExternalASTSource::*Get)(OffsT Offset)>
359 static constexpr size_t DataSize = std::max(
sizeof(uint64_t),
sizeof(
T *));
363 return Data[llvm::sys::IsBigEndianHost ?
DataSize - 1 : 0];
366 template <
typename U>
U &
As(
bool New)
const {
368 Data + (llvm::sys::IsBigEndianHost ?
DataSize -
sizeof(
U) : 0);
371 return *std::launder(
reinterpret_cast<U *
>(Obj));
384 assert((Offset << 1 >> 1) == Offset &&
"Offsets must require < 63 bits");
388 SetU64((Offset << 1) | 0x01);
397 assert((Offset << 1 >> 1) == Offset &&
"Offsets must require < 63 bits");
401 SetU64((Offset << 1) | 0x01);
427 "Cannot deserialize a lazy pointer without an AST source");
458 using ValueType = llvm::PointerUnion<Decl *, LazyData *>;
474 if (
auto *LazyVal =
Value.template dyn_cast<LazyData *>()) {
475 LazyVal->LastValue = NewValue;
483 if (
auto *LazyVal =
Value.template dyn_cast<LazyData *>()) {
484 if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) {
485 LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration();
486 LazyVal->ExternalSource->CompleteRedeclChain(O);
488 return LazyVal->LastValue;
495 if (
auto *LazyVal =
Value.template dyn_cast<LazyData *>())
496 return LazyVal->LastValue;
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 ...
Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...
Represents a base class of a C++ class.
Represents a C++ base or member initializer.
Represents a C++ struct/union/class.
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.
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 bool wasThisDeclarationADefinition(const FunctionDecl *FD)
True if this function declaration was a definition before in its own module.
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 bool LoadExternalSpecializations(const Decl *D, bool OnlyPartial)
Load all the external specializations for the Decl.
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 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 bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name, const DeclContext *OriginalDC)
Find all declarations with the given name in the given context, and add them to the context by callin...
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.
friend class ExternalSemaSource
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...
Represents a member of a struct/union/class.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Represents a function declaration or definition.
One of these records is kept for each identifier that is lexed.
Describes a module or submodule.
This represents a decl that may have a name.
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.
Represents a variable declaration or definition.
Top level wrappers for InstallAPI frontend operations.
LazyOffsetPtr< Stmt, uint64_t, &ExternalASTSource::GetExternalDeclStmt > LazyDeclStmtPtr
A lazy pointer to a statement.
LazyOffsetPtr< CXXCtorInitializer *, uint64_t, &ExternalASTSource::GetExternalCXXCtorInitializers > LazyCXXCtorInitializersPtr
A lazy pointer to a set of CXXCtorInitializers.
LazyOffsetPtr< CXXBaseSpecifier, uint64_t, &ExternalASTSource::GetExternalCXXBaseSpecifiers > LazyCXXBaseSpecifiersPtr
A lazy pointer to a set of CXXBaseSpecifiers.
LazyOffsetPtr< Decl, GlobalDeclID, &ExternalASTSource::GetExternalDecl > LazyDeclPtr
A lazy pointer to a declaration.
@ Result
The result type of a method or function.
const FunctionProtoType * T
U cast(CodeGen::Address addr)
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Diagnostic wrappers for TextAPI types for error reporting.
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)
ExternalASTSource * ExternalSource
LazyData(ExternalASTSource *Source, Decl *Value)
A lazy Decl value where the value might change in later generations of the external AST source.
Decl * get(const Decl *O)
Get the value of this pointer, updating its owner if necessary.
LazyGenerationalDeclPtr(const ASTContext &Ctx, Decl *Value=nullptr)
LazyGenerationalDeclPtr(ValueType V)
llvm::PointerUnion< Decl *, LazyData * > ValueType
void markIncomplete()
Forcibly set this pointer (which must be lazy) as needing updates.
void set(Decl *NewValue)
Set the value of this pointer, in the current generation.
static ValueType makeValue(const ASTContext &Ctx, Decl *Value)
Decl * getNotUpdated() const
Get the most recently computed value of this pointer without updating it.
static LazyGenerationalDeclPtr getFromOpaqueValue(void *Ptr)
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.
void SetU64(uint64_t U64) const
uint64_t & GetU64() const
LazyOffsetPtr & operator=(uint64_t Offset)
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer points to.
unsigned char Data[DataSize]
static constexpr size_t DataSize
void SetPtr(T *Ptr) const
unsigned char GetLSB() const
static void * getAsVoidPointer(Ptr P)
static Ptr getFromVoidPointer(void *P)
static constexpr int NumLowBitsAvailable
clang::LazyGenerationalDeclPtr Ptr