Pretty print the function prototype. For example, print:

void (*signal(int arga, void (*argb)(double Y)))(void* Z) {}

as:

void (*signal(int arga, void (*argb)(double)))(void *) {
}

go C :)

llvm-svn: 39261
This commit is contained in:
Chris Lattner 2007-01-21 23:11:09 +00:00
parent ec040b1d89
commit ef1387808f
1 changed files with 27 additions and 9 deletions

View File

@ -812,22 +812,40 @@ static void BuildASTs(Preprocessor &PP, unsigned MainFileID) {
ASTStreamer_Terminate(Streamer); ASTStreamer_Terminate(Streamer);
} }
static void PrintFunctionDecl(FunctionDecl *FD) {
FunctionTypeProto *FT = cast<FunctionTypeProto>(FD->getType());
std::string Proto = FD->getName();
Proto += "(";
for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) {
if (i) Proto += ", ";
VarDecl *Param = FD->getParamDecl(i);
std::string ParamStr = Param->getName();
Param->getType().getAsString(ParamStr);
Proto += ParamStr;
}
Proto += ")";
FT->getResultType().getAsString(Proto);
std::cerr << "\n" << Proto;
if (FD->getBody()) {
std::cerr << " ";
FD->getBody()->dump();
std::cerr << "\n";
}
}
static void PrintASTs(Preprocessor &PP, unsigned MainFileID) { static void PrintASTs(Preprocessor &PP, unsigned MainFileID) {
ASTContext Context(PP); ASTContext Context(PP);
ASTStreamerTy *Streamer = ASTStreamer_Init(Context, MainFileID); ASTStreamerTy *Streamer = ASTStreamer_Init(Context, MainFileID);
while (Decl *D = ASTStreamer_ReadTopLevelDecl(Streamer)) { while (Decl *D = ASTStreamer_ReadTopLevelDecl(Streamer)) {
std::cerr << "Read top-level decl: '";
if (const IdentifierInfo *II = D->getIdentifier())
std::cerr << II->getName() << "'\n";
else
std::cerr << "\n";
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
if (FD->getBody()) { PrintFunctionDecl(FD);
FD->getBody()->dump(); } else {
std::cerr << "\n"; std::cerr << "Read top-level variable decl: '" << D->getName() << "'\n";
}
} }
} }