implement dumper support for declstmt's. The dumper is now "done".

llvm-svn: 40969
This commit is contained in:
Chris Lattner 2007-08-09 18:03:18 +00:00
parent db3b3ff74b
commit 8f184b12fc
1 changed files with 31 additions and 25 deletions

View File

@ -37,21 +37,21 @@ namespace {
StmtDumper(FILE *f, unsigned maxDepth) StmtDumper(FILE *f, unsigned maxDepth)
: F(f), IndentLevel(0), MaxDepth(maxDepth) {} : F(f), IndentLevel(0), MaxDepth(maxDepth) {}
void DumpSubTree(Stmt *S, int SubIndent = 1) { void DumpSubTree(Stmt *S) {
// Prune the recursion if not using dump all. // Prune the recursion if not using dump all.
if (MaxDepth == 0) return; if (MaxDepth == 0) return;
IndentLevel += SubIndent; ++IndentLevel;
if (S) { if (S) {
S->visit(*this); S->visit(*this);
} else { } else {
Indent(); Indent();
fprintf(F, "<<<NULL>>>\n"); fprintf(F, "<<<NULL>>>\n");
} }
IndentLevel -= SubIndent; --IndentLevel;
} }
void PrintRawDecl(Decl *D); void DumpDeclarator(Decl *D);
void Indent() const { void Indent() const {
for (int i = 0, e = IndentLevel; i < e; ++i) for (int i = 0, e = IndentLevel; i < e; ++i)
@ -94,42 +94,43 @@ void StmtDumper::VisitStmt(Stmt *Node) {
fprintf(F, "<<unknown stmt type>>\n"); fprintf(F, "<<unknown stmt type>>\n");
} }
void StmtDumper::PrintRawDecl(Decl *D) { void StmtDumper::DumpDeclarator(Decl *D) {
#if 0
// FIXME: Need to complete/beautify this... this code simply shows the // FIXME: Need to complete/beautify this... this code simply shows the
// nodes are where they need to be. // nodes are where they need to be.
if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) { if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
OS << "typedef " << localType->getUnderlyingType().getAsString(); fprintf(F, "\"typedef %s %s\"",
OS << " " << localType->getName(); localType->getUnderlyingType().getAsString().c_str(),
localType->getName());
} else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
fprintf(F, "\"");
// Emit storage class for vardecls. // Emit storage class for vardecls.
if (VarDecl *V = dyn_cast<VarDecl>(VD)) { if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
switch (V->getStorageClass()) { switch (V->getStorageClass()) {
default: assert(0 && "Unknown storage class!"); default: assert(0 && "Unknown storage class!");
case VarDecl::None: break; case VarDecl::None: break;
case VarDecl::Extern: OS << "extern "; break; case VarDecl::Extern: fprintf(F, "extern "); break;
case VarDecl::Static: OS << "static "; break; case VarDecl::Static: fprintf(F, "static "); break;
case VarDecl::Auto: OS << "auto "; break; case VarDecl::Auto: fprintf(F, "auto "); break;
case VarDecl::Register: OS << "register "; break; case VarDecl::Register: fprintf(F, "register "); break;
} }
} }
std::string Name = VD->getName(); std::string Name = VD->getName();
VD->getType().getAsStringInternal(Name); VD->getType().getAsStringInternal(Name);
OS << Name; fprintf(F, "%s", Name.c_str());
// If this is a vardecl with an initializer, emit it. // If this is a vardecl with an initializer, emit it.
if (VarDecl *V = dyn_cast<VarDecl>(VD)) { if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
if (V->getInit()) { if (V->getInit()) {
OS << " = "; fprintf(F, " =\n");
DumpExpr(V->getInit()); DumpSubTree(V->getInit());
} }
} }
fprintf(F, "\"");
} else { } else {
// FIXME: "struct x;" // FIXME: "struct x;"
assert(0 && "Unexpected decl"); assert(0 && "Unexpected decl");
} }
#endif
} }
@ -140,15 +141,18 @@ void StmtDumper::VisitNullStmt(NullStmt *Node) {
void StmtDumper::VisitDeclStmt(DeclStmt *Node) { void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
DumpStmt(Node); DumpStmt(Node);
// FIXME: implement this better :) fprintf(F, "\n");
fprintf(F, ")");
#if 0
for (Decl *D = Node->getDecl(); D; D = D->getNextDeclarator()) { for (Decl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
++IndentLevel;
Indent(); Indent();
PrintRawDecl(D); fprintf(F, "%p ", (void*)D);
OS << ";\n"; DumpDeclarator(D);
if (D->getNextDeclarator())
fprintf(F, "\n");
--IndentLevel;
} }
#endif
fprintf(F, ")");
} }
void StmtDumper::VisitCompoundStmt(CompoundStmt *Node) { void StmtDumper::VisitCompoundStmt(CompoundStmt *Node) {
@ -472,7 +476,9 @@ void StmtDumper::VisitChooseExpr(ChooseExpr *Node) {
fprintf(F, ")"); fprintf(F, ")");
} }
// C++ //===----------------------------------------------------------------------===//
// C++ Expressions
//===----------------------------------------------------------------------===//
void StmtDumper::VisitCXXCastExpr(CXXCastExpr *Node) { void StmtDumper::VisitCXXCastExpr(CXXCastExpr *Node) {
DumpExpr(Node); DumpExpr(Node);