Go to the documentation of this file.
13 #ifndef LLVM_CLANG_AST_REDECLARABLE_H
14 #define LLVM_CLANG_AST_REDECLARABLE_H
17 #include "llvm/ADT/DenseMapInfo.h"
18 #include "llvm/ADT/PointerUnion.h"
19 #include "llvm/ADT/iterator_range.h"
20 #include "llvm/Support/Casting.h"
83 template<
typename decl_type>
96 using UninitializedLatest =
const void *;
103 using NotKnownLatest = llvm::PointerUnion<Previous, UninitializedLatest>;
105 mutable llvm::PointerUnion<NotKnownLatest, KnownLatest> Link;
112 : Link(NotKnownLatest(reinterpret_cast<UninitializedLatest>(&Ctx))) {}
119 Link.get<NotKnownLatest>().template is<UninitializedLatest>();
123 if (Link.is<NotKnownLatest>()) {
124 NotKnownLatest NKL = Link.get<NotKnownLatest>();
126 return static_cast<decl_type*
>(NKL.get<
Previous>());
130 NKL.get<UninitializedLatest>()),
131 const_cast<decl_type *
>(D));
134 return static_cast<decl_type*
>(Link.get<
KnownLatest>().get(D));
138 assert(!
isFirst() &&
"decl became non-canonical unexpectedly");
143 assert(
isFirst() &&
"decl became canonical unexpectedly");
144 if (Link.is<NotKnownLatest>()) {
145 NotKnownLatest NKL = Link.get<NotKnownLatest>();
147 NKL.get<UninitializedLatest>()),
159 assert(
isFirst() &&
"expected a canonical decl");
160 if (Link.is<NotKnownLatest>())
200 First(static_cast<decl_type *>(this)) {}
210 return const_cast<decl_type *
>(
242 decl_type *Current =
nullptr;
244 bool PassedFirst =
false;
260 assert(Current &&
"Advancing while iterator has reached end");
263 if (Current->isFirstDecl()) {
265 assert(0 &&
"Passed first decl twice, invalid redecl chain!");
273 decl_type *Next = Current->getNextRedeclaration();
274 Current = (Next != Starter) ? Next :
nullptr;
285 return x.Current == y.Current;
288 return x.Current != y.Current;
297 return redecl_range(redecl_iterator(
const_cast<decl_type *
>(
298 static_cast<const decl_type *
>(
this))),
313 template<
typename decl_type>
321 auto *D =
static_cast<decl_type *
>(
this);
322 if (!D->isFromASTFile())
330 const auto *D =
static_cast<const decl_type *
>(
this);
331 if (!D->isFromASTFile())
357 operator decl_type *() {
return Ptr; }
358 operator const decl_type *()
const {
return Ptr; }
367 return LHS.Ptr == RHS.Ptr;
370 return LHS.Ptr != RHS.Ptr;
377 decl_type *Ptr =
nullptr;
384 template <
typename decl_type>
393 P.Ptr = BaseInfo::getEmptyKey();
399 P.Ptr = BaseInfo::getTombstoneKey();
404 return BaseInfo::getHashValue(
P);
409 return BaseInfo::isEqual(LHS, RHS);
413 template <
typename decl_type>
423 static constexpr
int NumLowBitsAvailable =
429 #endif // LLVM_CLANG_AST_REDECLARABLE_H
reference operator*() const
Iterates through all the redeclarations of the same decl.
YAML serialization mapping.
Provides common interface for the Decls that can be redeclared.
virtual void CompleteRedeclChain(const Decl *D)
Gives the external AST source an opportunity to complete the redeclaration chain for a declaration.
redecl_iterator redecls_begin() const
static DeclLink PreviousDeclLink(decl_type *D)
const decl_type * getFirstDecl() const
Return the first declaration of this declaration or itself if this is the only declaration.
redecl_iterator redecls_end() const
static CanonicalDeclPtr getTombstoneKey()
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
llvm::iterator_range< redecl_iterator > redecl_range
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
redecl_iterator()=default
friend bool operator==(redecl_iterator x, redecl_iterator y)
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
redecl_iterator operator++(int)
friend bool operator!=(CanonicalDeclPtr LHS, CanonicalDeclPtr RHS)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CanonicalDeclPtr()=default
A lazy value (of type T) that is within an AST node of type Owner, where the value might change in la...
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Decl * getPrimaryMergedDecl(Decl *D)
Get the primary declaration for a declaration from an AST file.
std::ptrdiff_t difference_type
Decl * getLatestNotUpdated() const
Redeclarable(const ASTContext &Ctx)
DeclLink RedeclLink
Points to the next redeclaration in the chain.
pointer operator->() const
decl_type * getPrevious(const decl_type *D) const
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
static DeclLink LatestDeclLink(const ASTContext &Ctx)
DeclLink(LatestTag, const ASTContext &Ctx)
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
const decl_type & operator*() const
IRgen optimization opportunities The common pattern of short x
const decl_type * operator->() const
redecl_iterator & operator++()
Provides support for incremental compilation.
CanonicalDeclPtr(decl_type *Ptr)
void setPrevious(decl_type *D)
const decl_type * getMostRecentDecl() const
Returns the most recent (re)declaration of this declaration.
Provides common interface for the Decls that cannot be redeclared, but can be merged if the same decl...
void set(T NewValue)
Set the value of this pointer, in the current generation.
void setLatest(decl_type *D)
DeclLink(PreviousTag, decl_type *D)
static const Decl * getCanonicalDecl(const Decl *D)
const decl_type * getPreviousDecl() const
decl_type * getNextRedeclaration() const
Decl - This represents one declaration (or definition), e.g.
DenseMapInfo< decl_type * > BaseInfo
const decl_type * getFirstDecl() const
Return the first declaration of this declaration or itself if this is the only declaration.
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
static clang::CanonicalDeclPtr< decl_type > getFromVoidPointer(void *P)
friend bool operator!=(redecl_iterator x, redecl_iterator y)
__PTRDIFF_TYPE__ ptrdiff_t
A signed integer type that is the result of subtracting two pointers.
static unsigned getHashValue(const CanonicalDeclPtr &P)
bool isFirstDecl() const
Returns true if this is the first declaration.
A wrapper class around a pointer that always points to its canonical declaration.
CanonicalDeclPtr & operator=(const CanonicalDeclPtr &)=default
friend bool operator==(CanonicalDeclPtr LHS, CanonicalDeclPtr RHS)
static bool isEqual(const CanonicalDeclPtr &LHS, const CanonicalDeclPtr &RHS)
redecl_iterator(decl_type *C)
std::forward_iterator_tag iterator_category
static void * getAsVoidPointer(clang::CanonicalDeclPtr< decl_type > P)
static CanonicalDeclPtr getEmptyKey()