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.
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,
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));