r218127 - Make DynTypedNode have the dynamic type of the object, instead of its static type.

Samuel Benzaquen sbenza at google.com
Fri Sep 19 09:10:03 PDT 2014


Author: sbenza
Date: Fri Sep 19 11:10:03 2014
New Revision: 218127

URL: http://llvm.org/viewvc/llvm-project?rev=218127&view=rev
Log:
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

Modified:
    cfe/trunk/include/clang/AST/ASTTypeTraits.h
    cfe/trunk/lib/AST/ASTTypeTraits.cpp

Modified: cfe/trunk/include/clang/AST/ASTTypeTraits.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTTypeTraits.h?rev=218127&r1=218126&r2=218127&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTTypeTraits.h (original)
+++ cfe/trunk/include/clang/AST/ASTTypeTraits.h Fri Sep 19 11:10:03 2014
@@ -53,6 +53,13 @@ public:
     return ASTNodeKind(KindToKindId<T>::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<T>();
+      Result.NodeKind = ASTNodeKind::getFromNode(Node);
       Result.MemoizationData = &Node;
       new (Result.Storage.buffer) const BaseT * (&Node);
       return Result;

Modified: cfe/trunk/lib/AST/ASTTypeTraits.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTTypeTraits.cpp?rev=218127&r1=218126&r2=218127&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTTypeTraits.cpp (original)
+++ cfe/trunk/lib/AST/ASTTypeTraits.cpp Fri Sep 19 11:10:03 2014
@@ -62,6 +62,34 @@ bool ASTNodeKind::isBaseOf(NodeKindId Ba
 
 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<TemplateArgument>())





More information about the cfe-commits mailing list