From: Fariborz Jahanian Date: Mon, 12 Nov 2007 20:13:27 +0000 (+0000) Subject: 'super' nailed. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0523aaf9759cd9524956f0930558737458849743;p=clang 'super' nailed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44025 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index c3dae856ea..19d32bd486 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -1237,7 +1237,8 @@ Parser::ExprResult Parser::ParseObjCMessageExpression() { ExprTy *ReceiverExpr = 0; // Parse receiver if (Tok.is(tok::identifier) && - Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)) { + (Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope) + || !strcmp(Tok.getIdentifierInfo()->getName(), "super"))) { ReceiverName = Tok.getIdentifierInfo(); ConsumeToken(); } else { @@ -1308,7 +1309,8 @@ Parser::ExprResult Parser::ParseObjCMessageExpression() { // We've just parsed a keyword message. if (ReceiverName) - return Actions.ActOnClassMessage(ReceiverName, Sel, LBracloc, RBracloc, + return Actions.ActOnClassMessage(CurScope, + ReceiverName, Sel, LBracloc, RBracloc, &KeyExprs[0]); return Actions.ActOnInstanceMessage(ReceiverExpr, Sel, LBracloc, RBracloc, &KeyExprs[0]); diff --git a/Sema/Sema.h b/Sema/Sema.h index 4c66e10301..a443c94e3b 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -565,6 +565,7 @@ public: // ArgExprs is optional - if it is present, the number of expressions // is obtained from Sel.getNumArgs(). virtual ExprResult ActOnClassMessage( + Scope *S, IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs); diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 124eb14dc6..643f586fd5 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -2060,13 +2060,34 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, // ArgExprs is optional - if it is present, the number of expressions // is obtained from Sel.getNumArgs(). Sema::ExprResult Sema::ActOnClassMessage( + Scope *S, IdentifierInfo *receiverName, Selector Sel, SourceLocation lbrac, SourceLocation rbrac, ExprTy **Args) { assert(receiverName && "missing receiver class name"); Expr **ArgExprs = reinterpret_cast(Args); - ObjcInterfaceDecl* ClassDecl = getObjCInterfaceDecl(receiverName); + ObjcInterfaceDecl* ClassDecl = 0; + if (!strcmp(receiverName->getName(), "super") && CurMethodDecl) { + ClassDecl = CurMethodDecl->getClassInterface()->getSuperClass(); + if (CurMethodDecl->isInstance()) { + 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); + + return ActOnInstanceMessage(ReceiverExpr.Val, Sel, lbrac, rbrac, + Args); + } + // class method + if (ClassDecl) + receiverName = ClassDecl->getIdentifier(); + } + else + ClassDecl = getObjCInterfaceDecl(receiverName); ObjcMethodDecl *Method = ClassDecl->lookupClassMethod(Sel); QualType returnType; diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 7f2ca690d1..bfbcfb93dc 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -591,6 +591,7 @@ public: // ArgExprs is optional - if it is present, the number of expressions // is obtained from Sel.getNumArgs(). virtual ExprResult ActOnClassMessage( + Scope *S, IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac,