aboutsummaryrefslogtreecommitdiff
path: root/include/clang/AST/Redeclarable.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/AST/Redeclarable.h')
-rw-r--r--include/clang/AST/Redeclarable.h102
1 files changed, 49 insertions, 53 deletions
diff --git a/include/clang/AST/Redeclarable.h b/include/clang/AST/Redeclarable.h
index 86b0f356e7b5..c2bd6e6fd136 100644
--- a/include/clang/AST/Redeclarable.h
+++ b/include/clang/AST/Redeclarable.h
@@ -36,7 +36,7 @@ class Decl;
// DeclLink that may point to one of 3 possible states:
// - the "previous" (temporal) element in the chain
// - the "latest" (temporal) element in the chain
-// - the an "uninitialized-latest" value (when newly-constructed)
+// - the "uninitialized-latest" value (when newly-constructed)
//
// - The first element is also often called the canonical element. Every
// element has a pointer to it so that "getCanonical" can be fast.
@@ -48,10 +48,8 @@ class Decl;
// "most-recent" when referring to temporal order: order of addition
// to the chain.
//
-// - To make matters confusing, the DeclLink type uses the term "next"
-// for its pointer-storage internally (thus functions like
-// NextIsPrevious). It's easiest to just ignore the implementation of
-// DeclLink when making sense of the redeclaration chain.
+// - It's easiest to just ignore the implementation of DeclLink when making
+// sense of the redeclaration chain.
//
// - There's also a "definition" link for several types of
// redeclarable, where only one definition should exist at any given
@@ -82,7 +80,7 @@ class Decl;
// | link +-----+ |
// +-->-------------------------------------------+
-/// \brief Provides common interface for the Decls that can be redeclared.
+/// Provides common interface for the Decls that can be redeclared.
template<typename decl_type>
class Redeclarable {
protected:
@@ -105,66 +103,64 @@ protected:
/// previous declaration.
using NotKnownLatest = llvm::PointerUnion<Previous, UninitializedLatest>;
- mutable llvm::PointerUnion<NotKnownLatest, KnownLatest> Next;
+ mutable llvm::PointerUnion<NotKnownLatest, KnownLatest> Link;
public:
enum PreviousTag { PreviousLink };
enum LatestTag { LatestLink };
DeclLink(LatestTag, const ASTContext &Ctx)
- : Next(NotKnownLatest(reinterpret_cast<UninitializedLatest>(&Ctx))) {}
- DeclLink(PreviousTag, decl_type *D) : Next(NotKnownLatest(Previous(D))) {}
+ : Link(NotKnownLatest(reinterpret_cast<UninitializedLatest>(&Ctx))) {}
+ DeclLink(PreviousTag, decl_type *D) : Link(NotKnownLatest(Previous(D))) {}
- bool NextIsPrevious() const {
- return Next.is<NotKnownLatest>() &&
+ bool isFirst() const {
+ return Link.is<KnownLatest>() ||
// FIXME: 'template' is required on the next line due to an
// apparent clang bug.
- Next.get<NotKnownLatest>().template is<Previous>();
+ Link.get<NotKnownLatest>().template is<UninitializedLatest>();
}
- bool NextIsLatest() const { return !NextIsPrevious(); }
-
- decl_type *getNext(const decl_type *D) const {
- if (Next.is<NotKnownLatest>()) {
- NotKnownLatest NKL = Next.get<NotKnownLatest>();
+ decl_type *getPrevious(const decl_type *D) const {
+ if (Link.is<NotKnownLatest>()) {
+ NotKnownLatest NKL = Link.get<NotKnownLatest>();
if (NKL.is<Previous>())
return static_cast<decl_type*>(NKL.get<Previous>());
// Allocate the generational 'most recent' cache now, if needed.
- Next = KnownLatest(*reinterpret_cast<const ASTContext *>(
+ Link = KnownLatest(*reinterpret_cast<const ASTContext *>(
NKL.get<UninitializedLatest>()),
const_cast<decl_type *>(D));
}
- return static_cast<decl_type*>(Next.get<KnownLatest>().get(D));
+ return static_cast<decl_type*>(Link.get<KnownLatest>().get(D));
}
void setPrevious(decl_type *D) {
- assert(NextIsPrevious() && "decl became non-canonical unexpectedly");
- Next = Previous(D);
+ assert(!isFirst() && "decl became non-canonical unexpectedly");
+ Link = Previous(D);
}
void setLatest(decl_type *D) {
- assert(NextIsLatest() && "decl became canonical unexpectedly");
- if (Next.is<NotKnownLatest>()) {
- NotKnownLatest NKL = Next.get<NotKnownLatest>();
- Next = KnownLatest(*reinterpret_cast<const ASTContext *>(
+ assert(isFirst() && "decl became canonical unexpectedly");
+ if (Link.is<NotKnownLatest>()) {
+ NotKnownLatest NKL = Link.get<NotKnownLatest>();
+ Link = KnownLatest(*reinterpret_cast<const ASTContext *>(
NKL.get<UninitializedLatest>()),
D);
} else {
- auto Latest = Next.get<KnownLatest>();
+ auto Latest = Link.get<KnownLatest>();
Latest.set(D);
- Next = Latest;
+ Link = Latest;
}
}
- void markIncomplete() { Next.get<KnownLatest>().markIncomplete(); }
+ void markIncomplete() { Link.get<KnownLatest>().markIncomplete(); }
Decl *getLatestNotUpdated() const {
- assert(NextIsLatest() && "expected a canonical decl");
- if (Next.is<NotKnownLatest>())
+ assert(isFirst() && "expected a canonical decl");
+ if (Link.is<NotKnownLatest>())
return nullptr;
- return Next.get<KnownLatest>().getNotUpdated();
+ return Link.get<KnownLatest>().getNotUpdated();
}
};
@@ -176,10 +172,10 @@ protected:
return DeclLink(DeclLink::LatestLink, Ctx);
}
- /// \brief Points to the next redeclaration in the chain.
+ /// Points to the next redeclaration in the chain.
///
- /// If NextIsPrevious() is true, this is a link to the previous declaration
- /// of this same Decl. If NextIsLatest() is true, this is the first
+ /// If isFirst() is false, this is a link to the previous declaration
+ /// of this same Decl. If isFirst() is true, this is the first
/// declaration and Link points to the latest declaration. For example:
///
/// #1 int f(int x, int y = 1); // <pointer to #3, true>
@@ -192,7 +188,7 @@ protected:
decl_type *First;
decl_type *getNextRedeclaration() const {
- return RedeclLink.getNext(static_cast<const decl_type *>(this));
+ return RedeclLink.getPrevious(static_cast<const decl_type *>(this));
}
public:
@@ -203,10 +199,10 @@ public:
: RedeclLink(LatestDeclLink(Ctx)),
First(static_cast<decl_type *>(this)) {}
- /// \brief Return the previous declaration of this declaration or NULL if this
+ /// Return the previous declaration of this declaration or NULL if this
/// is the first declaration.
decl_type *getPreviousDecl() {
- if (RedeclLink.NextIsPrevious())
+ if (!RedeclLink.isFirst())
return getNextRedeclaration();
return nullptr;
}
@@ -215,32 +211,32 @@ public:
static_cast<const decl_type*>(this))->getPreviousDecl();
}
- /// \brief Return the first declaration of this declaration or itself if this
+ /// Return the first declaration of this declaration or itself if this
/// is the only declaration.
decl_type *getFirstDecl() { return First; }
- /// \brief Return the first declaration of this declaration or itself if this
+ /// Return the first declaration of this declaration or itself if this
/// is the only declaration.
const decl_type *getFirstDecl() const { return First; }
- /// \brief True if this is the first declaration in its redeclaration chain.
- bool isFirstDecl() const { return RedeclLink.NextIsLatest(); }
+ /// True if this is the first declaration in its redeclaration chain.
+ bool isFirstDecl() const { return RedeclLink.isFirst(); }
- /// \brief Returns the most recent (re)declaration of this declaration.
+ /// Returns the most recent (re)declaration of this declaration.
decl_type *getMostRecentDecl() {
return getFirstDecl()->getNextRedeclaration();
}
- /// \brief Returns the most recent (re)declaration of this declaration.
+ /// Returns the most recent (re)declaration of this declaration.
const decl_type *getMostRecentDecl() const {
return getFirstDecl()->getNextRedeclaration();
}
- /// \brief Set the previous declaration. If PrevDecl is NULL, set this as the
+ /// Set the previous declaration. If PrevDecl is NULL, set this as the
/// first and only declaration.
void setPreviousDecl(decl_type *PrevDecl);
- /// \brief Iterates through all the redeclarations of the same decl.
+ /// Iterates through all the redeclarations of the same decl.
class redecl_iterator {
/// Current - The current declaration.
decl_type *Current = nullptr;
@@ -294,7 +290,7 @@ public:
using redecl_range = llvm::iterator_range<redecl_iterator>;
- /// \brief Returns an iterator range for all the redeclarations of the same
+ /// Returns an iterator range for all the redeclarations of the same
/// decl. It will iterate at least once (when this decl is the only one).
redecl_range redecls() const {
return redecl_range(redecl_iterator(const_cast<decl_type *>(
@@ -306,11 +302,11 @@ public:
redecl_iterator redecls_end() const { return redecls().end(); }
};
-/// \brief Get the primary declaration for a declaration from an AST file. That
+/// Get the primary declaration for a declaration from an AST file. That
/// will be the first-loaded declaration.
Decl *getPrimaryMergedDecl(Decl *D);
-/// \brief Provides common interface for the Decls that cannot be redeclared,
+/// Provides common interface for the Decls that cannot be redeclared,
/// but can be merged if the same declaration is brought in from multiple
/// modules.
template<typename decl_type>
@@ -318,25 +314,25 @@ class Mergeable {
public:
Mergeable() = default;
- /// \brief Return the first declaration of this declaration or itself if this
+ /// Return the first declaration of this declaration or itself if this
/// is the only declaration.
decl_type *getFirstDecl() {
- decl_type *D = static_cast<decl_type*>(this);
+ auto *D = static_cast<decl_type *>(this);
if (!D->isFromASTFile())
return D;
return cast<decl_type>(getPrimaryMergedDecl(const_cast<decl_type*>(D)));
}
- /// \brief Return the first declaration of this declaration or itself if this
+ /// Return the first declaration of this declaration or itself if this
/// is the only declaration.
const decl_type *getFirstDecl() const {
- const decl_type *D = static_cast<const decl_type*>(this);
+ const auto *D = static_cast<const decl_type *>(this);
if (!D->isFromASTFile())
return D;
return cast<decl_type>(getPrimaryMergedDecl(const_cast<decl_type*>(D)));
}
- /// \brief Returns true if this is the first declaration.
+ /// Returns true if this is the first declaration.
bool isFirstDecl() const { return getFirstDecl() == this; }
};