Make the driver print function bodies at -parse-print-ast

llvm-svn: 39048
This commit is contained in:
Chris Lattner 2006-10-25 05:11:20 +00:00
parent b19f796e97
commit 6d9a685d75
8 changed files with 35 additions and 8 deletions

View File

@ -12,4 +12,9 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/Decl.h"
using namespace llvm;
using namespace clang;
// Out-of-line virtual method providing a home for Decl.
Decl::~Decl() {
}

View File

@ -196,7 +196,7 @@ ASTBuilder::ParseCompoundStmt(SourceLocation L, SourceLocation R,
Action::StmtResult
ASTBuilder::ParseReturnStmt(SourceLocation ReturnLoc,
ExprTy *RetValExp) {
return new ReturnStmt((Expr*)RetValExp);
}
//===--------------------------------------------------------------------===//

View File

@ -22,18 +22,19 @@ void Stmt::dump() const {
std::cerr << "<null>";
return;
}
bool isExpr = dynamic_cast<const Expr*>(this) != 0;
if (isExpr) std::cerr << "(";
if (isExpr()) std::cerr << "(";
dump_impl();
if (isExpr) std::cerr << ")";
if (isExpr()) std::cerr << ")";
}
void CompoundStmt::dump_impl() const {
std::cerr << "{\n";
for (unsigned i = 0, e = Body.size(); i != e; ++i)
for (unsigned i = 0, e = Body.size(); i != e; ++i) {
Body[i]->dump();
std::cerr << "\n";
}
std::cerr << "}";
}

View File

@ -790,11 +790,15 @@ static void PrintASTs(Preprocessor &PP, unsigned MainFileID) {
ASTStreamerTy *Streamer = ASTStreamer_Init(PP, MainFileID, true);
while (Decl *D = ASTStreamer_ReadTopLevelDecl(Streamer)) {
std::cerr << "Read top-level decl: ";
std::cerr << "Read top-level decl: '";
if (const IdentifierInfo *II = D->getIdentifier())
std::cerr << II->getName() << "\n";
std::cerr << II->getName() << "'\n";
else
std::cerr << "\n";
if (FunctionDecl *FD = D->isFunctionDecl()) {
FD->getBody()->dump();
std::cerr << "\n";
}
}
ASTStreamer_Terminate(Streamer);

View File

@ -196,7 +196,7 @@ ASTBuilder::ParseCompoundStmt(SourceLocation L, SourceLocation R,
Action::StmtResult
ASTBuilder::ParseReturnStmt(SourceLocation ReturnLoc,
ExprTy *RetValExp) {
return new ReturnStmt((Expr*)RetValExp);
}
//===--------------------------------------------------------------------===//

View File

@ -21,6 +21,7 @@ namespace llvm {
namespace clang {
class IdentifierInfo;
class Stmt;
class FunctionDecl;
/// Decl - This represents one declaration (or definition), e.g. a variable,
/// typedef, function, struct, etc.
@ -43,12 +44,17 @@ class Decl {
public:
Decl(IdentifierInfo *Id, const Declarator &D, Decl *next)
: Identifier(Id), DeclarationSpecifier(D.getDeclSpec()), Next(next) {}
virtual ~Decl();
const IdentifierInfo *getIdentifier() const { return Identifier; }
const DeclSpec &getDeclSpec() const { return DeclarationSpecifier; }
Decl *getNext() const { return Next; }
// FIXME: Implement cast/dyn_cast/etc
virtual FunctionDecl *isFunctionDecl() { return 0; }
virtual const FunctionDecl *isFunctionDecl() const { return 0; }
};
/// FunctionDecl - An instance of this class is created to represent a function
@ -62,6 +68,11 @@ public:
Stmt *getBody() const { return Body; }
void setBody(Stmt *B) { Body = B; }
// FIXME: Implement cast/dyn_cast/etc
virtual FunctionDecl *isFunctionDecl() { return this; }
virtual const FunctionDecl *isFunctionDecl() const { return this; }
};
/// VarDecl - An instance of this class is created to represent a variable

View File

@ -32,6 +32,9 @@ public:
Expr() {}
~Expr() {}
// FIXME: move to isa/dyncast etc.
virtual bool isExpr() const { return true; }
};
//===----------------------------------------------------------------------===//

View File

@ -33,6 +33,9 @@ public:
// FIXME: Change to non-virtual method that uses visitor pattern to do this.
void dump() const;
// FIXME: move to isa/dyncast etc.
virtual bool isExpr() const { return false; }
private:
virtual void dump_impl() const = 0;
};