15 #ifndef LLVM_CLANG_AST_EXTERNALASTSOURCE_H 16 #define LLVM_CLANG_AST_EXTERNALASTSOURCE_H 23 #include "llvm/ADT/ArrayRef.h" 24 #include "llvm/ADT/DenseMap.h" 25 #include "llvm/ADT/IntrusiveRefCntPtr.h" 26 #include "llvm/ADT/Optional.h" 27 #include "llvm/ADT/PointerUnion.h" 28 #include "llvm/ADT/STLExtras.h" 29 #include "llvm/ADT/SmallVector.h" 30 #include "llvm/ADT/StringRef.h" 31 #include "llvm/ADT/iterator.h" 32 #include "llvm/Support/PointerLikeTypeTraits.h" 44 class CXXBaseSpecifier;
45 class CXXCtorInitializer;
47 class DeclarationName;
51 class ObjCInterfaceDecl;
69 uint32_t CurrentGeneration = 0;
73 bool SemaSource =
false;
171 StringRef PCHModuleName;
175 const Module *ClangModule =
nullptr;
181 : PCHModuleName(
std::move(Name)), Path(
std::move(Path)),
182 ASTFile(
std::move(ASTFile)), Signature(Signature) {}
185 std::string getModuleName()
const;
208 llvm::function_ref<
bool(
Decl::Kind)> IsKindWeWant,
299 const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
300 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
301 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
302 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets);
313 : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
346 template<
typename T,
typename OffsT, T* (ExternalASTSource::*Get)(OffsT Offset)>
353 mutable uint64_t Ptr = 0;
360 assert((Offset << 1 >> 1) == Offset &&
"Offsets must require < 63 bits");
366 this->Ptr =
reinterpret_cast<uint64_t
>(Ptr);
371 assert((Offset << 1 >> 1) == Offset &&
"Offsets must require < 63 bits");
375 Ptr = (Offset << 1) | 0x01;
383 explicit operator bool()
const {
return Ptr != 0; }
401 "Cannot deserialize a lazy pointer without an AST source");
402 Ptr =
reinterpret_cast<uint64_t
>((Source->*Get)(Ptr >> 1));
404 return reinterpret_cast<T*
>(Ptr);
411 template<
typename Owner,
typename T,
void (ExternalASTSource::*Update)(Owner)>
417 uint32_t LastGeneration = 0;
421 : ExternalSource(Source), LastValue(Value) {}
435 : Value(makeValue(Ctx, Value)) {}
445 Value.template get<LazyData *>()->LastGeneration = 0;
449 void set(
T NewValue) {
450 if (
LazyData *LazyVal = Value.template dyn_cast<LazyData*>()) {
451 LazyVal->LastValue = NewValue;
462 if (
LazyData *LazyVal = Value.template dyn_cast<LazyData*>()) {
463 if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) {
464 LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration();
465 (LazyVal->ExternalSource->*
Update)(O);
467 return LazyVal->LastValue;
469 return Value.template get<T>();
474 if (
LazyData *LazyVal = Value.template dyn_cast<LazyData*>())
475 return LazyVal->LastValue;
476 return Value.template get<T>();
491 template<
typename Owner,
typename T,
515 template<
typename T,
typename Source,
517 unsigned LoadedStorage = 2,
unsigned LocalStorage = 4>
540 :
public llvm::iterator_adaptor_base<
541 iterator, int, std::random_access_iterator_tag,
T, int, T *, T &> {
547 : iterator::iterator_adaptor_base(Position), Self(Self) {}
549 bool isLoaded()
const {
return this->I < 0; }
556 return Self->Loaded.end()[this->I];
557 return Self->Local.begin()[this->I];
561 iterator
begin(Source *source,
bool LocalOnly =
false) {
563 return iterator(
this, 0);
566 (source->*Loader)(Loaded);
567 return iterator(
this, -(
int)Loaded.size());
571 return iterator(
this, Local.size());
575 Local.push_back(LocalValue);
578 void erase(iterator From, iterator To) {
579 if (From.isLoaded() && To.isLoaded()) {
580 Loaded.erase(&*From, &*To);
584 if (From.isLoaded()) {
585 Loaded.erase(&*From, Loaded.end());
586 From = begin(
nullptr,
true);
589 Local.erase(&*From, &*To);
613 #endif // LLVM_CLANG_AST_EXTERNALASTSOURCE_H
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.
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...
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
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)
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Stmt - This represents one statement.
Defines the clang::Module class, which describes a module in the source code.
Decl - This represents one declaration (or definition), e.g.
virtual uint32_t GetNumExternalSelectors()
Returns the number of selectors known to the external 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.
NotUpdatedTag
Create a pointer that is not potentially updated by later generations of the external AST source...
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.
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)
RecordDecl - Represents a struct/union/class.
void FindExternalLexicalDecls(const DeclContext *DC, SmallVectorImpl< Decl *> &Result)
Finds all declarations lexically contained within the given DeclContext.
One of these records is kept for each identifier that is lexed.
static DeclContextLookupResult SetExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name, ArrayRef< NamedDecl *> Decls)
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.
StringRef getPath() const
void erase(iterator From, iterator To)
uint32_t incrementGeneration(ASTContext &C)
Increment the current generation.
uint32_t getGeneration() const
Get the current generation of this AST source.
T getNotUpdated() const
Get the most recently computed value of this pointer without updating it.
The signature of a module, which is a hash of the AST content.
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.
ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile, ASTFileSignature Signature)
virtual void updateOutOfDateIdentifier(IdentifierInfo &II)
Update an out-of-date identifier.
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 FinishedDeserializing()
Notify ExternalASTSource that we finished the deserialization of a decl or type.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
static DeclContextLookupResult SetNoExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name)
iterator::reference operator*() const
A cache of the value of this pointer, in the most recent generation in which we queried it...
LazyGenerationalUpdatePtr(ValueType V)
Represents an ObjC class declaration.
const Module * getModuleOrNull() const
virtual void completeVisibleDeclsMap(const DeclContext *DC)
Ensures that the table of all visible declarations inside this context is up to date.
ASTFileSignature getSignature() const
ExternalASTSource()=default
const FunctionProtoType * T
The result type of a method or function.
static void * getAsVoidPointer(Ptr P)
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...
An abstract interface that should be implemented by external AST sources that also provide informatio...
Abstract interface for external sources of AST nodes.
StringRef getASTFile() const
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.
static LazyGenerationalUpdatePtr getFromOpaqueValue(void *Ptr)
void push_back(const T &LocalValue)
ExternalASTSource * ExternalSource
MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)
bool isValid() const
Whether this pointer is non-NULL.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
virtual Module * getModule(unsigned ID)
Retrieve the module that corresponds to the given module ID.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
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...
DeclarationName - The name of a declaration.
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 ~ExternalASTSource()
virtual ExtKind hasExternalDefinitions(const Decl *D)
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.
Defines the clang::SourceLocation class and associated facilities.
LazyGenerationalUpdatePtr(const ASTContext &Ctx, T Value=T())
bool isOffset() const
Whether this pointer is currently stored as an offset.
Kind
Lists the kind of concrete classes of Decl.
Iteration over the elements in the vector.
Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...
llvm::PointerUnion< T, LazyData * > ValueType
A lazy value (of type T) that is within an AST node of type Owner, where the value might change in la...
LazyOffsetPtr(uint64_t Offset)
static Ptr getFromVoidPointer(void *P)