From: Samuel Benzaquen Date: Fri, 19 Sep 2014 16:10:03 +0000 (+0000) Subject: Make DynTypedNode have the dynamic type of the object, instead of its static type. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8453970c1cd82504041e8591ea9f3f354cacafd;p=clang Make DynTypedNode have the dynamic type of the object, instead of its static type. Summary: Make DynTypedNode have the dynamic type of the object, instead of its static type. Some optimizations that are in the works require that the nodes have the right type. Reviewers: klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D5411 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@218127 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTTypeTraits.h b/include/clang/AST/ASTTypeTraits.h index 0eff94c191..8457568784 100644 --- a/include/clang/AST/ASTTypeTraits.h +++ b/include/clang/AST/ASTTypeTraits.h @@ -53,6 +53,13 @@ public: 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 @@ private: } 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; diff --git a/lib/AST/ASTTypeTraits.cpp b/lib/AST/ASTTypeTraits.cpp index baa8e48779..ebcbd955b6 100644 --- a/lib/AST/ASTTypeTraits.cpp +++ b/lib/AST/ASTTypeTraits.cpp @@ -62,6 +62,34 @@ bool ASTNodeKind::isBaseOf(NodeKindId Base, NodeKindId Derived, 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())