[PATCH] D94877: Add API to retrieve a clade kind from ASTNodeKind
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 19 14:52:26 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0cd0eb6e0a81: Add API to retrieve a clade kind from ASTNodeKind (authored by stephenkelly).
Changed prior to commit:
https://reviews.llvm.org/D94877?vs=317226&id=317703#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D94877/new/
https://reviews.llvm.org/D94877
Files:
clang/include/clang/AST/ASTTypeTraits.h
clang/lib/AST/ASTTypeTraits.cpp
clang/unittests/AST/ASTTypeTraitsTest.cpp
Index: clang/unittests/AST/ASTTypeTraitsTest.cpp
===================================================================
--- clang/unittests/AST/ASTTypeTraitsTest.cpp
+++ clang/unittests/AST/ASTTypeTraitsTest.cpp
@@ -39,6 +39,18 @@
EXPECT_TRUE(DNT<Decl>().isSame(DNT<Decl>()));
}
+TEST(DynTypedNode, Clades) {
+ EXPECT_TRUE(DNT<Stmt>().getCladeKind().isSame(DNT<Stmt>()));
+ EXPECT_TRUE(DNT<Decl>().getCladeKind().isSame(DNT<Decl>()));
+
+ EXPECT_TRUE(DNT<CXXMethodDecl>().getCladeKind().isSame(DNT<Decl>()));
+ EXPECT_TRUE(DNT<CXXMemberCallExpr>().getCladeKind().isSame(DNT<Stmt>()));
+
+ EXPECT_FALSE(DNT<CXXMemberCallExpr>().getCladeKind().isSame(DNT<Decl>()));
+
+ EXPECT_TRUE(ASTNodeKind().getCladeKind().isNone());
+}
+
TEST(ASTNodeKind, BaseDistances) {
unsigned Distance = 1;
EXPECT_TRUE(DNT<Expr>().isBaseOf(DNT<Expr>(), &Distance));
Index: clang/lib/AST/ASTTypeTraits.cpp
===================================================================
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -63,6 +63,17 @@
return Derived == Base;
}
+ASTNodeKind ASTNodeKind::getCladeKind() const {
+ NodeKindId LastId = KindId;
+ while (LastId) {
+ NodeKindId ParentId = AllKindInfo[LastId].ParentId;
+ if (ParentId == NKI_None)
+ return LastId;
+ LastId = ParentId;
+ }
+ return NKI_None;
+}
+
StringRef ASTNodeKind::asStringRef() const { return AllKindInfo[KindId].Name; }
ASTNodeKind ASTNodeKind::getMostDerivedType(ASTNodeKind Kind1,
Index: clang/include/clang/AST/ASTTypeTraits.h
===================================================================
--- clang/include/clang/AST/ASTTypeTraits.h
+++ clang/include/clang/AST/ASTTypeTraits.h
@@ -100,6 +100,8 @@
static ASTNodeKind getMostDerivedCommonAncestor(ASTNodeKind Kind1,
ASTNodeKind Kind2);
+ ASTNodeKind getCladeKind() const;
+
/// Hooks for using ASTNodeKind as a key in a DenseMap.
struct DenseMapInfo {
// ASTNodeKind() is a good empty key because it is represented as a 0.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94877.317703.patch
Type: text/x-patch
Size: 2064 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210119/6cc304f8/attachment-0001.bin>
More information about the cfe-commits
mailing list