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>());
129 Link =
KnownLatest(*reinterpret_cast<const ASTContext *>(
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>();
146 Link =
KnownLatest(*reinterpret_cast<const ASTContext *>(
147 NKL.get<UninitializedLatest>()),
159 assert(
isFirst() &&
"expected a canonical decl");
160 if (Link.is<NotKnownLatest>())
190 return RedeclLink.getPrevious(static_cast<const decl_type *>(
this));
199 First(static_cast<decl_type *>(this)) {}
204 if (!RedeclLink.isFirst())
209 return const_cast<decl_type *
>(
241 decl_type *Current =
nullptr;
243 bool PassedFirst =
false;
259 assert(Current &&
"Advancing while iterator has reached end");
261 if (Current->isFirstDecl()) {
263 assert(0 &&
"Passed first decl twice, invalid redecl chain!");
271 decl_type *Next = Current->getNextRedeclaration();
272 Current = (Next != Starter) ? Next :
nullptr;
283 return x.Current == y.Current;
286 return x.Current != y.Current;
295 return redecl_range(redecl_iterator(const_cast<decl_type *>(
296 static_cast<const decl_type *>(
this))),
311 template<
typename decl_type>
319 auto *D =
static_cast<decl_type *
>(
this);
328 const auto *D =
static_cast<const decl_type *
>(
this);
355 operator decl_type *() {
return Ptr; }
356 operator const decl_type *()
const {
return Ptr; }
367 decl_type *Ptr =
nullptr;
374 template <
typename decl_type>
383 P.Ptr = BaseInfo::getEmptyKey();
389 P.Ptr = BaseInfo::getTombstoneKey();
394 return BaseInfo::getHashValue(P);
399 return BaseInfo::isEqual(LHS, RHS);
405 #endif // LLVM_CLANG_AST_REDECLARABLE_H static const Decl * getCanonicalDecl(const Decl *D)
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Decl - This represents one declaration (or definition), e.g.
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
static unsigned getHashValue(const CanonicalDeclPtr &P)
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...
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 ...
static bool isEqual(const CanonicalDeclPtr &LHS, const CanonicalDeclPtr &RHS)
friend bool operator==(redecl_iterator x, redecl_iterator y)
decl_type * getPrevious(const decl_type *D) const
DeclLink(PreviousTag, decl_type *D)
const decl_type * getPreviousDecl() const
DeclLink RedeclLink
Points to the next redeclaration in the chain.
static CanonicalDeclPtr getEmptyKey()
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
CanonicalDeclPtr(decl_type *Ptr)
static CanonicalDeclPtr getTombstoneKey()
std::ptrdiff_t difference_type
redecl_iterator operator++(int)
const decl_type & operator*() const
redecl_iterator redecls_begin() const
const decl_type * getMostRecentDecl() const
Returns the most recent (re)declaration of this declaration.
Iterates through all the redeclarations of the same decl.
static DeclLink PreviousDeclLink(decl_type *D)
Decl * getPrimaryMergedDecl(Decl *D)
Get the primary declaration for a declaration from an AST file.
pointer operator->() const
redecl_iterator & operator++()
T get(Owner O)
Get the value of this pointer, updating its owner if necessary.
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Redeclarable(const ASTContext &Ctx)
const decl_type * operator->() const
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
const decl_type * getFirstDecl() const
Return the first declaration of this declaration or itself if this is the only declaration.
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
__PTRDIFF_TYPE__ ptrdiff_t
A signed integer type that is the result of subtracting two pointers.
Dataflow Directional Tag Classes.
redecl_iterator redecls_end() const
llvm::iterator_range< redecl_iterator > redecl_range
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)
Decl * getLatestNotUpdated() const
decl_type * getNextRedeclaration() const
redecl_iterator(decl_type *C)
const decl_type * getFirstDecl() const
Return the first declaration of this declaration or itself if this is the only declaration.
std::forward_iterator_tag iterator_category
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...
reference operator*() const
bool isFirstDecl() const
Returns true if this is the first declaration.
A wrapper class around a pointer that always points to its canonical declaration. ...