Index: cfe/trunk/include/clang/AST/ASTTypeTraits.h =================================================================== --- cfe/trunk/include/clang/AST/ASTTypeTraits.h +++ cfe/trunk/include/clang/AST/ASTTypeTraits.h @@ -53,6 +53,13 @@ return ASTNodeKind(KindToKindId::Id); } + /// \{ + /// \brief Construct an identifier for the dynamic type of the node + static ASTNodeKind getFromNode(const Decl &D); + static ASTNodeKind getFromNode(const Stmt &S); + static ASTNodeKind getFromNode(const Type &T); + /// \} + /// \brief Returns \c true if \c this and \c Other represent the same kind. bool isSame(ASTNodeKind Other) const; @@ -241,7 +248,7 @@ } static DynTypedNode create(const BaseT &Node) { DynTypedNode Result; - Result.NodeKind = ASTNodeKind::getFromNodeKind(); + Result.NodeKind = ASTNodeKind::getFromNode(Node); Result.MemoizationData = &Node; new (Result.Storage.buffer) const BaseT * (&Node); return Result; Index: cfe/trunk/lib/AST/ASTTypeTraits.cpp =================================================================== --- cfe/trunk/lib/AST/ASTTypeTraits.cpp +++ cfe/trunk/lib/AST/ASTTypeTraits.cpp @@ -62,6 +62,34 @@ StringRef ASTNodeKind::asStringRef() const { return AllKindInfo[KindId].Name; } +ASTNodeKind ASTNodeKind::getFromNode(const Decl &D) { + switch (D.getKind()) { +#define DECL(DERIVED, BASE) \ + case Decl::DERIVED: return ASTNodeKind(NKI_##DERIVED##Decl); +#define ABSTRACT_DECL(D) +#include "clang/AST/DeclNodes.inc" + }; +} + +ASTNodeKind ASTNodeKind::getFromNode(const Stmt &S) { + switch (S.getStmtClass()) { + case Stmt::NoStmtClass: return NKI_None; +#define STMT(CLASS, PARENT) \ + case Stmt::CLASS##Class: return ASTNodeKind(NKI_##CLASS); +#define ABSTRACT_STMT(S) +#include "clang/AST/StmtNodes.inc" + } +} + +ASTNodeKind ASTNodeKind::getFromNode(const Type &T) { + switch (T.getTypeClass()) { +#define TYPE(Class, Base) \ + case Type::Class: return ASTNodeKind(NKI_##Class##Type); +#define ABSTRACT_TYPE(Class, Base) +#include "clang/AST/TypeNodes.def" + } +} + void DynTypedNode::print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const { if (const TemplateArgument *TA = get())