[cfe-commits] r52580 - in /cfe/trunk: Driver/RewriteObjC.cpp include/clang/AST/Expr.h lib/AST/StmtDumper.cpp lib/AST/StmtPrinter.cpp lib/Sema/SemaExprObjC.cpp test/Rewriter/objc-super-test.m
Chris Lattner
sabre at nondot.org
Sat Jun 21 11:04:54 PDT 2008
Author: lattner
Date: Sat Jun 21 13:04:54 2008
New Revision: 52580
URL: http://llvm.org/viewvc/llvm-project?rev=52580&view=rev
Log:
Switch 'super' from being a weird cast thing to being a predefined expr node.
Patch by David Chisnall with objc rewriter and stmtdumper updates from me.
Modified:
cfe/trunk/Driver/RewriteObjC.cpp
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/StmtDumper.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/Rewriter/objc-super-test.m
Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=52580&r1=52579&r2=52580&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Sat Jun 21 13:04:54 2008
@@ -1848,31 +1848,14 @@
// check if we are sending a message to 'super'
if (!CurMethodDecl || !CurMethodDecl->isInstance()) return 0;
- CastExpr *CE = dyn_cast<CastExpr>(recExpr);
- if (!CE) return 0;
-
- DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr());
- if (!DRE) return 0;
-
- ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl());
- if (!PVD) return 0;
-
- if (strcmp(PVD->getName(), "self") != 0)
- return 0;
-
- // is this id<P1..> type?
- if (CE->getType()->isObjCQualifiedIdType())
- return 0;
- const PointerType *PT = CE->getType()->getAsPointerType();
- if (!PT) return 0;
-
- ObjCInterfaceType *IT = dyn_cast<ObjCInterfaceType>(PT->getPointeeType());
- if (!IT) return 0;
-
- if (IT->getDecl() != CurMethodDecl->getClassInterface()->getSuperClass())
- return 0;
-
- return IT->getDecl();
+ if (PreDefinedExpr *PDE = dyn_cast<PreDefinedExpr>(recExpr))
+ if (PDE->getIdentType() == PreDefinedExpr::ObjCSuper) {
+ const PointerType *PT = PDE->getType()->getAsPointerType();
+ assert(PT);
+ ObjCInterfaceType *IT = cast<ObjCInterfaceType>(PT->getPointeeType());
+ return IT->getDecl();
+ }
+ return 0;
}
// struct objc_super { struct objc_object *receiver; struct objc_class *super; };
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=52580&r1=52579&r2=52580&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Jun 21 13:04:54 2008
@@ -222,7 +222,10 @@
enum IdentType {
Func,
Function,
- PrettyFunction
+ PrettyFunction,
+ ObjCSelf, // self
+ ObjCCmd, // _cmd
+ ObjCSuper // super
};
private:
Modified: cfe/trunk/lib/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtDumper.cpp?rev=52580&r1=52579&r2=52580&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtDumper.cpp (original)
+++ cfe/trunk/lib/AST/StmtDumper.cpp Sat Jun 21 13:04:54 2008
@@ -311,17 +311,13 @@
void StmtDumper::VisitPreDefinedExpr(PreDefinedExpr *Node) {
DumpExpr(Node);
switch (Node->getIdentType()) {
- default:
- assert(0 && "unknown case");
- case PreDefinedExpr::Func:
- fprintf(F, " __func__");
- break;
- case PreDefinedExpr::Function:
- fprintf(F, " __FUNCTION__");
- break;
- case PreDefinedExpr::PrettyFunction:
- fprintf(F, " __PRETTY_FUNCTION__");
- break;
+ default: assert(0 && "unknown case");
+ case PreDefinedExpr::Func: fprintf(F, " __func__"); break;
+ case PreDefinedExpr::Function: fprintf(F, " __FUNCTION__"); break;
+ case PreDefinedExpr::PrettyFunction: fprintf(F, " __PRETTY_FUNCTION__");break;
+ case PreDefinedExpr::ObjCSelf: fprintf(F, "self"); break;
+ case PreDefinedExpr::ObjCCmd: fprintf(F, "_cmd"); break;
+ case PreDefinedExpr::ObjCSuper: fprintf(F, "super"); break;
}
}
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=52580&r1=52579&r2=52580&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Sat Jun 21 13:04:54 2008
@@ -509,6 +509,9 @@
case PreDefinedExpr::PrettyFunction:
OS << "__PRETTY_FUNCTION__";
break;
+ case PreDefinedExpr::ObjCSuper:
+ OS << "super";
+ break;
}
}
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=52580&r1=52579&r2=52580&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Sat Jun 21 13:04:54 2008
@@ -149,14 +149,10 @@
return Diag(lbrac, diag::error_no_super_class,
CurMethodDecl->getClassInterface()->getName());
if (CurMethodDecl->isInstance()) {
- // Synthesize a cast to the super class. This hack allows us to loosely
- // represent super without creating a special expression node.
- IdentifierInfo &II = Context.Idents.get("self");
- ExprResult ReceiverExpr = ActOnIdentifierExpr(S, lbrac, II, false);
QualType superTy = Context.getObjCInterfaceType(ClassDecl);
superTy = Context.getPointerType(superTy);
- ReceiverExpr = ActOnCastExpr(SourceLocation(), superTy.getAsOpaquePtr(),
- SourceLocation(), ReceiverExpr.Val);
+ ExprResult ReceiverExpr = new PreDefinedExpr(SourceLocation(), superTy,
+ PreDefinedExpr::ObjCSuper);
// We are really in an instance method, redirect.
return ActOnInstanceMessage(ReceiverExpr.Val, Sel, lbrac, rbrac,
Args, NumArgs);
Modified: cfe/trunk/test/Rewriter/objc-super-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-super-test.m?rev=52580&r1=52579&r2=52580&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/objc-super-test.m (original)
+++ cfe/trunk/test/Rewriter/objc-super-test.m Sat Jun 21 13:04:54 2008
@@ -1,4 +1,4 @@
-// RUN: clang -rewrite-objc %s -o=-
+// RUN: clang -rewrite-objc %s -o - | grep objc_msgSendSuper | grep MainMethod
@interface SUPER
- (int) MainMethod;
More information about the cfe-commits
mailing list