14 #ifndef LLVM_CLANG_AST_REDECLARABLE_H
15 #define LLVM_CLANG_AST_REDECLARABLE_H
18 #include "llvm/ADT/PointerIntPair.h"
19 #include "llvm/Support/Casting.h"
26 template<
typename decl_type>
39 typedef const void *UninitializedLatest;
46 typedef llvm::PointerUnion<Previous, UninitializedLatest> NotKnownLatest;
48 mutable llvm::PointerUnion<NotKnownLatest, KnownLatest> Next;
55 : Next(NotKnownLatest(reinterpret_cast<UninitializedLatest>(&Ctx))) {}
57 : Next(NotKnownLatest(
Previous(D))) {}
60 return Next.is<NotKnownLatest>() &&
63 Next.get<NotKnownLatest>().template is<Previous>();
68 decl_type *
getNext(
const decl_type *D)
const {
69 if (Next.is<NotKnownLatest>()) {
70 NotKnownLatest NKL = Next.get<NotKnownLatest>();
72 return static_cast<decl_type*>(NKL.get<
Previous>());
75 Next =
KnownLatest(*reinterpret_cast<const ASTContext *>(
76 NKL.get<UninitializedLatest>()),
77 const_cast<decl_type *>(D));
80 return static_cast<decl_type*
>(Next.get<
KnownLatest>().
get(D));
84 assert(
NextIsPrevious() &&
"decl became non-canonical unexpectedly");
89 assert(
NextIsLatest() &&
"decl became canonical unexpectedly");
90 if (Next.is<NotKnownLatest>()) {
91 NotKnownLatest NKL = Next.get<NotKnownLatest>();
92 Next =
KnownLatest(*reinterpret_cast<const ASTContext *>(
93 NKL.get<UninitializedLatest>()),
106 if (Next.is<NotKnownLatest>())
150 return const_cast<decl_type *
>(
195 : Current(C), Starter(C), PassedFirst(
false) { }
201 assert(Current &&
"Advancing while iterator has reached end");
203 if (Current->isFirstDecl()) {
205 assert(0 &&
"Passed first decl twice, invalid redecl chain!");
213 decl_type *
Next = Current->getNextRedeclaration();
214 Current = (Next != Starter) ? Next :
nullptr;
225 return x.Current == y.Current;
228 return x.Current != y.Current;
237 return redecl_range(redecl_iterator(const_cast<decl_type *>(
238 static_cast<const decl_type *>(
this))),
256 template<
typename decl_type>
264 decl_type *D =
static_cast<decl_type*
>(
this);
265 if (!D->isFromASTFile())
273 const decl_type *D =
static_cast<const decl_type*
>(
this);
274 if (!D->isFromASTFile())
const decl_type * getPreviousDecl() const
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
decl_type * getNext(const decl_type *D) const
void setPrevious(decl_type *D)
virtual void CompleteRedeclChain(const Decl *D)
Gives the external AST source an opportunity to complete the redeclaration chain for a declaration...
bool isFirstDecl() const
Returns true if this is the first declaration.
static DeclLink LatestDeclLink(const ASTContext &Ctx)
DeclLink(LatestTag, const ASTContext &Ctx)
Provides common interface for the Decls that can be redeclared.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool NextIsPrevious() const
redecl_iterator redecls_begin() const
friend bool operator==(redecl_iterator x, redecl_iterator y)
const decl_type * getFirstDecl() const
Return the first declaration of this declaration or itself if this is the only declaration.
DeclLink(PreviousTag, decl_type *D)
decl_type * getNextRedeclaration() const
DeclLink RedeclLink
Points to the next redeclaration in the chain.
reference operator*() const
pointer operator->() const
bool NextIsLatest() const
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
redecl_iterator operator++(int)
Iterates through all the redeclarations of the same decl.
const decl_type * getFirstDecl() const
Return the first declaration of this declaration or itself if this is the only declaration.
static DeclLink PreviousDeclLink(decl_type *D)
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
Decl * getPrimaryMergedDecl(Decl *D)
Get the primary declaration for a declaration from an AST file.
std::ptrdiff_t difference_type
redecl_iterator & operator++()
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_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Redeclarable(const ASTContext &Ctx)
std::forward_iterator_tag iterator_category
redecl_iterator redecls_end() const
__PTRDIFF_TYPE__ ptrdiff_t
A signed integer type that is the result of subtracting two pointers.
const decl_type * getMostRecentDecl() const
Returns the most recent (re)declaration of this declaration.
void set(T NewValue)
Set the value of this pointer, in the current generation.
Provides common interface for the Decls that cannot be redeclared, but can be merged if the same decl...
friend bool operator!=(redecl_iterator x, redecl_iterator y)
void setLatest(decl_type *D)
redecl_iterator(decl_type *C)
Decl * getLatestNotUpdated() const
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
A lazy value (of type T) that is within an AST node of type Owner, where the value might change in la...