diff --git a/clang/include/clang/AST/ASTTypeTraits.h b/clang/include/clang/AST/ASTTypeTraits.h --- a/clang/include/clang/AST/ASTTypeTraits.h +++ b/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. diff --git a/clang/lib/AST/ASTTypeTraits.cpp b/clang/lib/AST/ASTTypeTraits.cpp --- a/clang/lib/AST/ASTTypeTraits.cpp +++ b/clang/lib/AST/ASTTypeTraits.cpp @@ -63,6 +63,17 @@ return Derived == Base; } +ASTNodeKind ASTNodeKind::getCladeKind() const { + auto LastId = KindId; + while (LastId) { + auto 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,