[cfe-commits] r43986 - in /cfe/trunk: Driver/ASTConsumers.cpp Parse/ParseObjc.cpp test/Sema/method-def-2.m
Fariborz Jahanian
fjahanian at apple.com
Sat Nov 10 12:59:14 PST 2007
Author: fjahanian
Date: Sat Nov 10 14:59:13 2007
New Revision: 43986
URL: http://llvm.org/viewvc/llvm-project?rev=43986&view=rev
Log:
pretty priting for method definitions.
Added:
cfe/trunk/test/Sema/method-def-2.m
Modified:
cfe/trunk/Driver/ASTConsumers.cpp
cfe/trunk/Parse/ParseObjc.cpp
Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=43986&r1=43985&r2=43986&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Sat Nov 10 14:59:13 2007
@@ -73,6 +73,58 @@
fprintf(stderr, "typedef %s;\n", S.c_str());
}
+static void PrintObjcMethodDecl(ObjcMethodDecl *OMD) {
+ if (OMD->isInstance())
+ fprintf(stderr, "\n- ");
+ else
+ fprintf(stderr, "\n+ ");
+ if (!OMD->getResultType().isNull())
+ fprintf(stderr, "(%s) ", OMD->getResultType().getAsString().c_str());
+ // FIXME: just print original selector name!
+ fprintf(stderr, "%s ", OMD->getSelector().getName().c_str());
+
+ for (int i = 0; i < OMD->getNumParams(); i++) {
+ ParmVarDecl *PDecl = OMD->getParamDecl(i);
+ // FIXME: selector is missing here!
+ fprintf(stderr, " :(%s) %s", PDecl->getType().getAsString().c_str(),
+ PDecl->getName());
+ }
+}
+
+static void PrintObjcImplementationDecl(ObjcImplementationDecl *OID) {
+ std::string I = OID->getName();
+ ObjcInterfaceDecl *SID = OID->getSuperClass();
+ if (SID) {
+ std::string S = SID->getName();
+ fprintf(stderr, "@implementation %s : %s", I.c_str(), S.c_str());
+ }
+ else
+ fprintf(stderr, "@implementation %s", I.c_str());
+
+ for (int i = 0; i < OID->getNumInstanceMethods(); i++) {
+ PrintObjcMethodDecl(OID->getInstanceMethods()[i]);
+ ObjcMethodDecl *OMD = OID->getInstanceMethods()[i];
+ if (OMD->getBody()) {
+ fprintf(stderr, " ");
+ OMD->getBody()->dumpPretty();
+ fprintf(stderr, "\n");
+ }
+ }
+
+ for (int i = 0; i < OID->getNumClassMethods(); i++) {
+ PrintObjcMethodDecl(OID->getClassMethods()[i]);
+ ObjcMethodDecl *OMD = OID->getClassMethods()[i];
+ if (OMD->getBody()) {
+ fprintf(stderr, " ");
+ OMD->getBody()->dumpPretty();
+ fprintf(stderr, "\n");
+ }
+ }
+
+ fprintf(stderr,"@end\n");
+}
+
+
static void PrintObjcInterfaceDecl(ObjcInterfaceDecl *OID) {
std::string I = OID->getName();
ObjcInterfaceDecl *SID = OID->getSuperClass();
@@ -232,8 +284,7 @@
fprintf(stderr, ";\n");
} else if (ObjcImplementationDecl *OID =
dyn_cast<ObjcImplementationDecl>(D)) {
- fprintf(stderr, "@implementation %s [printing todo]\n",
- OID->getName());
+ PrintObjcImplementationDecl(OID);
} else if (ObjcCategoryImplDecl *OID =
dyn_cast<ObjcCategoryImplDecl>(D)) {
PrintObjcCategoryImplDecl(OID);
Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=43986&r1=43985&r2=43986&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Sat Nov 10 14:59:13 2007
@@ -38,7 +38,7 @@
case tok::objc_protocol:
return ParseObjCAtProtocolDeclaration(AtLoc);
case tok::objc_implementation:
- return ObjcImpDecl = ParseObjCAtImplementationDeclaration(AtLoc);
+ return ParseObjCAtImplementationDeclaration(AtLoc);
case tok::objc_end:
return ParseObjCAtEndDeclaration(AtLoc);
case tok::objc_compatibility_alias:
@@ -911,7 +911,8 @@
DeclTy *ImplCatType = Actions.ActOnStartCategoryImplementation(
atLoc, nameId, nameLoc, categoryId,
categoryLoc);
- return ImplCatType;
+ ObjcImpDecl = ImplCatType;
+ return 0;
}
// We have a class implementation
SourceLocation superClassLoc;
@@ -932,8 +933,9 @@
if (Tok.is(tok::l_brace)) // we have ivars
ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc);
+ ObjcImpDecl = ImplClsType;
- return ImplClsType;
+ return 0;
}
Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) {
@@ -949,11 +951,10 @@
&AllImplMethods[0], AllImplMethods.size(),
(DeclTy **)0, 0,
atLoc);
- ObjcImpDecl = 0;
AllImplMethods.clear();
}
- return 0;
+ return ObjcImpDecl;
}
/// compatibility-alias-decl:
Added: cfe/trunk/test/Sema/method-def-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/method-def-2.m?rev=43986&view=auto
==============================================================================
--- cfe/trunk/test/Sema/method-def-2.m (added)
+++ cfe/trunk/test/Sema/method-def-2.m Sat Nov 10 14:59:13 2007
@@ -0,0 +1,19 @@
+// RUN: clang -ast-print %s
+extern void abort(void);
+#define CHECK_IF(expr) if(!(expr)) abort()
+
+static double d = 4.5920234e2;
+
+ at interface Foo
+-(void) brokenType: (int)x floatingPoint: (double)y;
+ at end
+
+
+ at implementation Foo
+-(void) brokenType: (int)x floatingPoint: (double)y
+{
+ CHECK_IF(x == 459);
+ CHECK_IF(y == d);
+}
+ at end
+
More information about the cfe-commits
mailing list