[cfe-commits] r39261 - /cfe/cfe/trunk/Driver/clang.cpp
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:42:07 PDT 2007
Author: sabre
Date: Wed Jul 11 11:42:07 2007
New Revision: 39261
URL: http://llvm.org/viewvc/llvm-project?rev=39261&view=rev
Log:
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 :)
Modified:
cfe/cfe/trunk/Driver/clang.cpp
Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39261&r1=39260&r2=39261&view=diff
==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:42:07 2007
@@ -812,22 +812,40 @@
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) {
ASTContext Context(PP);
ASTStreamerTy *Streamer = ASTStreamer_Init(Context, MainFileID);
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 (FD->getBody()) {
- FD->getBody()->dump();
- std::cerr << "\n";
- }
+ PrintFunctionDecl(FD);
+ } else {
+ std::cerr << "Read top-level variable decl: '" << D->getName() << "'\n";
}
}
More information about the cfe-commits
mailing list