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"
83template<
typename decl_type>
94 using UninitializedLatest =
const void *;
96 using Previous =
Decl *;
101 using NotKnownLatest = llvm::PointerUnion<Previous, UninitializedLatest>;
103 mutable llvm::PointerUnion<NotKnownLatest, KnownLatest> Link;
110 : Link(NotKnownLatest(reinterpret_cast<UninitializedLatest>(&Ctx))) {}
119 if (NotKnownLatest NKL = dyn_cast<NotKnownLatest>(Link)) {
120 if (
auto *Prev = dyn_cast<Previous>(NKL))
121 return static_cast<decl_type *
>(Prev);
124 Link = KnownLatest(*
reinterpret_cast<const ASTContext *
>(
126 const_cast<decl_type *
>(D));
133 assert(!
isFirst() &&
"decl became non-canonical unexpectedly");
138 assert(
isFirst() &&
"decl became canonical unexpectedly");
139 if (NotKnownLatest NKL = dyn_cast<NotKnownLatest>(Link)) {
140 Link = KnownLatest(*
reinterpret_cast<const ASTContext *
>(
153 assert(
isFirst() &&
"expected a canonical decl");
184 return RedeclLink.getPrevious(
static_cast<const decl_type *
>(
this));
196 First(static_cast<decl_type *>(this)) {}
206 return const_cast<decl_type *
>(
238 decl_type *Current =
nullptr;
239 decl_type *Starter =
nullptr;
240 bool PassedFirst =
false;
256 assert(Current &&
"Advancing while iterator has reached end");
259 if (Current->isFirstDecl()) {
261 assert(0 &&
"Passed first decl twice, invalid redecl chain!");
269 decl_type *
Next = Current->getNextRedeclaration();
270 Current = (
Next != Starter) ?
Next :
nullptr;
281 return x.Current == y.Current;
284 return x.Current != y.Current;
293 return redecl_range(redecl_iterator(
const_cast<decl_type *
>(
294 static_cast<const decl_type *
>(
this))),
309template<
typename decl_type>
317 auto *D =
static_cast<decl_type *
>(
this);
318 if (!D->isFromASTFile())
326 const auto *D =
static_cast<const decl_type *
>(
this);
327 if (!D->isFromASTFile())
353 operator decl_type *() {
return Ptr; }
354 operator const decl_type *()
const {
return Ptr; }
363 return LHS.Ptr == RHS.Ptr;
366 return LHS.Ptr != RHS.Ptr;
373 decl_type *Ptr =
nullptr;
380template <
typename decl_type>
386 return BaseInfo::getHashValue(P);
391 return BaseInfo::isEqual(LHS, RHS);
395template <
typename decl_type>
static const Decl * getCanonicalDecl(const Decl *D)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
A wrapper class around a pointer that always points to its canonical declaration.
CanonicalDeclPtr(const CanonicalDeclPtr &)=default
const decl_type * operator->() const
CanonicalDeclPtr & operator=(const CanonicalDeclPtr &)=default
const decl_type & operator*() const
CanonicalDeclPtr(decl_type *Ptr)
friend bool operator==(CanonicalDeclPtr LHS, CanonicalDeclPtr RHS)
CanonicalDeclPtr()=default
friend bool operator!=(CanonicalDeclPtr LHS, CanonicalDeclPtr RHS)
Decl - This represents one declaration (or definition), e.g.
bool isFirstDecl() const
Returns true if this is the first declaration.
const decl_type * getFirstDecl() const
Return the first declaration of this declaration or itself if this is the only declaration.
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
DeclLink(LatestTag, const ASTContext &Ctx)
DeclLink(PreviousTag, decl_type *D)
void setPrevious(decl_type *D)
Decl * getLatestNotUpdated() const
void setLatest(decl_type *D)
decl_type * getPrevious(const decl_type *D) const
friend bool operator!=(const redecl_iterator &x, const redecl_iterator &y)
friend bool operator==(const redecl_iterator &x, const redecl_iterator &y)
redecl_iterator(decl_type *C)
redecl_iterator()=default
std::forward_iterator_tag iterator_category
std::ptrdiff_t difference_type
reference operator*() const
redecl_iterator operator++(int)
redecl_iterator & operator++()
pointer operator->() const
friend class IncrementalParser
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
friend class ASTDeclMerger
const decl_type * getMostRecentDecl() const
Returns the most recent (re)declaration of this declaration.
const decl_type * getFirstDecl() const
Return the first declaration of this declaration or itself if this is the only declaration.
decl_type * getNextRedeclaration() const
Redeclarable(const ASTContext &Ctx)
friend class ASTDeclReader
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
redecl_iterator redecls_end() const
const decl_type * getPreviousDecl() const
TranslationUnitDecl * First
friend class ASTDeclWriter
llvm::iterator_range< redecl_iterator > redecl_range
friend class ASTDeclUnmerger
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
static DeclLink LatestDeclLink(const ASTContext &Ctx)
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
redecl_iterator redecls_begin() const
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
static DeclLink PreviousDeclLink(decl_type *D)
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
Decl * getPrimaryMergedDecl(Decl *D)
Get the primary declaration for a declaration from an AST file.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
U cast(CodeGen::Address addr)
Diagnostic wrappers for TextAPI types for error reporting.
A lazy Decl value where the value might change in later generations of the external AST source.
static unsigned getHashValue(const CanonicalDeclPtr &P)
static bool isEqual(const CanonicalDeclPtr &LHS, const CanonicalDeclPtr &RHS)
clang::CanonicalDeclPtr< decl_type > CanonicalDeclPtr
DenseMapInfo< decl_type * > BaseInfo
static void * getAsVoidPointer(clang::CanonicalDeclPtr< decl_type > P)
static clang::CanonicalDeclPtr< decl_type > getFromVoidPointer(void *P)
static constexpr int NumLowBitsAvailable