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"
41class ASTSourceDescriptor;
42class CXXBaseSpecifier;
43class CXXCtorInitializer;
49class ObjCInterfaceDecl;
67 uint32_t CurrentGeneration = 0;
195 llvm::function_ref<
bool(
Decl::Kind)> IsKindWeWant,
287 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
288 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
289 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets);
315 virtual bool isA(
const void *ClassID)
const {
return ClassID == &ID; }
339template<
typename T,
typename OffsT, T* (ExternalASTSource::*Get)(OffsT Offset)>
346 static constexpr size_t DataSize = std::max(
sizeof(uint64_t),
sizeof(
T *));
350 return Data[llvm::sys::IsBigEndianHost ?
DataSize - 1 : 0];
353 template <
typename U>
U &
As(
bool New)
const {
355 Data + (llvm::sys::IsBigEndianHost ?
DataSize -
sizeof(
U) : 0);
358 return *std::launder(
reinterpret_cast<U *
>(Obj));
362 uint64_t &
GetU64()
const {
return As<uint64_t>(
false); }
363 void SetPtr(
T *Ptr)
const { As<T *>(
true) = Ptr; }
364 void SetU64(uint64_t U64)
const { As<uint64_t>(
true) = U64; }
371 assert((Offset << 1 >> 1) == Offset &&
"Offsets must require < 63 bits");
375 SetU64((Offset << 1) | 0x01);
384 assert((Offset << 1 >> 1) == Offset &&
"Offsets must require < 63 bits");
388 SetU64((Offset << 1) | 0x01);
414 "Cannot deserialize a lazy pointer without an AST source");
432template<
typename Owner,
typename T,
void (ExternalASTSource::*Update)(Owner)>
469 if (
auto *LazyVal =
Value.template dyn_cast<LazyData *>()) {
470 LazyVal->LastValue = NewValue;
481 if (
auto *LazyVal =
Value.template dyn_cast<LazyData *>()) {
482 if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) {
483 LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration();
484 (LazyVal->ExternalSource->*
Update)(O);
486 return LazyVal->LastValue;
488 return cast<T>(
Value);
493 if (
auto *LazyVal =
Value.template dyn_cast<LazyData *>())
494 return LazyVal->LastValue;
495 return cast<T>(
Value);
510template<
typename Owner,
typename T,
519 static constexpr int NumLowBitsAvailable =
533template<
typename T,
typename Source,
534 void (Source::*Loader)(SmallVectorImpl<T>&),
535 unsigned LoadedStorage = 2,
unsigned LocalStorage = 4>
558 :
public llvm::iterator_adaptor_base<
565 :
iterator::iterator_adaptor_base(Position), Self(Self) {}
567 bool isLoaded()
const {
return this->I < 0; }
574 return Self->Loaded.end()[this->I];
575 return Self->Local.begin()[this->I];
584 (source->*Loader)(Loaded);
585 return iterator(
this, -(
int)Loaded.size());
589 return iterator(
this, Local.size());
593 Local.push_back(LocalValue);
597 if (From.isLoaded() && To.isLoaded()) {
598 Loaded.erase(&*From, &*To);
602 if (From.isLoaded()) {
603 Loaded.erase(&*From, Loaded.end());
604 From = begin(
nullptr,
true);
607 Local.erase(&*From, &*To);
622 &ExternalASTSource::GetExternalCXXCtorInitializers>;
627 &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 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 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.
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
Either a pointer to an AST node or the offset within the external AST source where the AST node can b...
void SetPtr(T *Ptr) const
unsigned char GetLSB() const
static Ptr getFromVoidPointer(void *P)
static void * getAsVoidPointer(Ptr P)