[cfe-commits] r40956 - /cfe/trunk/AST/StmtDumper.cpp

Chris Lattner sabre at nondot.org
Wed Aug 8 17:36:22 PDT 2007


Author: lattner
Date: Wed Aug  8 19:36:22 2007
New Revision: 40956

URL: http://llvm.org/viewvc/llvm-project?rev=40956&view=rev
Log:
Dump out types for expressions, and handle typedefs nicely.  
This allows us to dump:

typedef short S;
int test(S X, long long Y) {
  return X < ((100));
}

as:

typedef short S;

int test(S X, long long Y)
(CompoundStmt 0x2905d40
  (ReturnStmt 0x2905d30
    (BinaryOperator 0x2905d10 'int' '<'
      (ImplicitCastExpr 0x2905d00 'int'
        (DeclRefExpr 0x2905c80 'S':'short' Decl='X' 0x2905c20))
      (ParenExpr 0x2905ce0 'int'
        (ParenExpr 0x2905cc0 'int'
          (IntegerLiteral 0x2905ca0 'int' 100))))))


Modified:
    cfe/trunk/AST/StmtDumper.cpp

Modified: cfe/trunk/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtDumper.cpp?rev=40956&r1=40955&r2=40956&view=diff

==============================================================================
--- cfe/trunk/AST/StmtDumper.cpp (original)
+++ cfe/trunk/AST/StmtDumper.cpp Wed Aug  8 19:36:22 2007
@@ -58,6 +58,15 @@
         fprintf(F, "  ");
     }
     
+    void DumpType(QualType T) const {
+      fprintf(F, "'%s'", T.getAsString().c_str());
+
+      // If the type is directly a typedef, strip off typedefness to give at
+      // least one level of concreteness.
+      if (TypedefType *TDT = dyn_cast<TypedefType>(T))
+        fprintf(F, ":'%s'", TDT->LookThroughTypedefs().getAsString().c_str());
+    }
+    
     void DumpStmt(const Stmt *Node) const {
       Indent();
       fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
@@ -65,7 +74,8 @@
     
     void DumpExpr(Expr *Node) const {
       DumpStmt(Node);
-      // TODO: DUMP TYPE
+      fprintf(F, " ");
+      DumpType(Node->getType());
     }
     
     virtual void VisitStmt(Stmt *Node);





More information about the cfe-commits mailing list