[cfe-commits] r39592 - /cfe/cfe/trunk/AST/StmtPrinter.cpp
clattner at cs.uiuc.edu
clattner at cs.uiuc.edu
Wed Jul 11 09:46:02 PDT 2007
Author: clattner
Date: Wed Jul 11 11:46:01 2007
New Revision: 39592
URL: http://llvm.org/viewvc/llvm-project?rev=39592&view=rev
Log:
Various improvements to the tree printer, including printing decls in for stmts prettier etc
Modified:
cfe/cfe/trunk/AST/StmtPrinter.cpp
Modified: cfe/cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/StmtPrinter.cpp?rev=39592&r1=39591&r2=39592&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/cfe/trunk/AST/StmtPrinter.cpp Wed Jul 11 11:46:01 2007
@@ -47,6 +47,7 @@
}
void PrintRawCompoundStmt(CompoundStmt *S);
+ void PrintRawDecl(Decl *D);
void PrintExpr(Expr *E) {
if (E)
@@ -87,36 +88,45 @@
Indent() << "}";
}
-void StmtPrinter::VisitNullStmt(NullStmt *Node) {
- Indent() << ";\n";
-}
-
-void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
- // FIXME: Need to complete/beautify this...this code simply shows the
+void StmtPrinter::PrintRawDecl(Decl *D) {
+ // FIXME: Need to complete/beautify this... this code simply shows the
// nodes are where they need to be.
- if (TypedefDecl *localType = dyn_cast<TypedefDecl>(Node->getDecl())) {
- Indent() << "typedef " << localType->getUnderlyingType().getAsString();
- OS << " " << localType->getName() << ";\n";
- } else if (ValueDecl *VD = dyn_cast<ValueDecl>(Node->getDecl())) {
- Indent();
+ if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
+ OS << "typedef " << localType->getUnderlyingType().getAsString();
+ OS << " " << localType->getName();
+ } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
// Emit storage class for vardecls.
if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
switch (V->getStorageClass()) {
- default: assert(0 && "Unknown storage class!");
- case VarDecl::None: break;
- case VarDecl::Extern: OS << "extern "; break;
- case VarDecl::Static: OS << "static "; break;
- case VarDecl::Auto: OS << "auto "; break;
- case VarDecl::Register: OS << "register "; break;
+ default: assert(0 && "Unknown storage class!");
+ case VarDecl::None: break;
+ case VarDecl::Extern: OS << "extern "; break;
+ case VarDecl::Static: OS << "static "; break;
+ case VarDecl::Auto: OS << "auto "; break;
+ case VarDecl::Register: OS << "register "; break;
}
}
std::string Name = VD->getName();
VD->getType().getAsStringInternal(Name);
- OS << Name << ";\n";
- } else
+ OS << Name;
+
+ // FIXME: Initializer for vardecl
+ } else {
// FIXME: "struct x;"
assert(0 && "Unexpected decl");
+ }
+}
+
+
+void StmtPrinter::VisitNullStmt(NullStmt *Node) {
+ Indent() << ";\n";
+}
+
+void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
+ Indent();
+ PrintRawDecl(Node->getDecl());
+ OS << ";\n";
}
void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
@@ -208,14 +218,18 @@
void StmtPrinter::VisitForStmt(ForStmt *Node) {
Indent() << "for (";
- if (Node->getFirst())
- PrintExpr((Expr*)Node->getFirst());
+ if (Node->getInit()) {
+ if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
+ PrintRawDecl(DS->getDecl());
+ else
+ PrintExpr(cast<Expr>(Node->getInit()));
+ }
OS << "; ";
- if (Node->getSecond())
- PrintExpr(Node->getSecond());
+ if (Node->getCond())
+ PrintExpr(Node->getCond());
OS << "; ";
- if (Node->getThird())
- PrintExpr(Node->getThird());
+ if (Node->getInc())
+ PrintExpr(Node->getInc());
OS << ")\n";
PrintStmt(Node->getBody());
}
More information about the cfe-commits
mailing list