From f95861a4ab6bbd6a975ed079dd70eb1cc22f4467 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 21 Apr 2010 20:01:04 +0000 Subject: [PATCH] Eliminate unused code in Sema::ActOnSuperMessage and use early exits to reduce nesting. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102022 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprObjC.cpp | 96 ++++++++++++--------------------------- 1 file changed, 28 insertions(+), 68 deletions(-) diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index d284100859..e9c391c3e9 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -596,83 +596,43 @@ Sema::OwningExprResult Sema::ActOnSuperMessage(Scope *S, MultiExprArg Args) { // Determine whether we are inside a method or not. ObjCMethodDecl *Method = getCurMethodDecl(); - if (Method) { - ObjCInterfaceDecl *Class = Method->getClassInterface(); - if (!Class) { - Diag(SuperLoc, diag::error_no_super_class_message) - << Method->getDeclName(); - return ExprError(); - } - - if (ObjCInterfaceDecl *Super = Class->getSuperClass()) { - // We are in a method whose class has a superclass, so 'super' - // is acting as a keyword. - if (Method->isInstanceMethod()) { - // Since we are in an instance method, this is an instance - // message to the superclass instance. - QualType SuperTy = Context.getObjCInterfaceType(Super); - SuperTy = Context.getObjCObjectPointerType(SuperTy); - return BuildInstanceMessage(ExprArg(*this), SuperTy, SuperLoc, - Sel, LBracLoc, SelectorLoc, RBracLoc, - move(Args)); - } - - // Since we are in a class method, this is a class message to - // the superclass. - return BuildClassMessage(/*ReceiverTypeInfo=*/0, - Context.getObjCInterfaceType(Super), - SuperLoc, Sel, LBracLoc, SelectorLoc, - RBracLoc, move(Args)); - } + if (!Method) { + Diag(SuperLoc, diag::err_invalid_receiver_to_message_super); + return ExprError(); + } - // The current class does not have a superclass. - Diag(SuperLoc, diag::error_no_super_class) << Class->getIdentifier(); + ObjCInterfaceDecl *Class = Method->getClassInterface(); + if (!Class) { + Diag(SuperLoc, diag::error_no_super_class_message) + << Method->getDeclName(); return ExprError(); } - Diag(SuperLoc, diag::err_invalid_receiver_to_message_super); - return ExprError(); - -#if 0 - // We are not inside a method, or the method is in a class that has - // no superclass, so perform normal name lookup on "super". - IdentifierInfo &SuperId = Context.Idents.get("super"); - NamedDecl *Super = LookupSingleName(S, &SuperId, SuperLoc, - LookupOrdinaryName); + ObjCInterfaceDecl *Super = Class->getSuperClass(); if (!Super) { - Diag(SuperLoc, diag::err_undeclared_var_use) << &SuperId; + // The current class does not have a superclass. + Diag(SuperLoc, diag::error_no_super_class) << Class->getIdentifier(); return ExprError(); } - if (isa(Super) || isa(Super)) { - // Name lookup found a type named 'super'; create a class message - // sending to it. - QualType SuperType = - isa(Super)? Context.getTypeDeclType(cast(Super)) - : Context.getObjCInterfaceType(cast(Super)); - TypeSourceInfo *SuperTypeInfo - = Context.getTrivialTypeSourceInfo(SuperType, SuperLoc); - return BuildClassMessage(SuperTypeInfo, SuperType, - /*SuperLoc=*/SourceLocation(), - Sel, LBracLoc, SelectorLoc, RBracLoc, - move(Args)); + // We are in a method whose class has a superclass, so 'super' + // is acting as a keyword. + if (Method->isInstanceMethod()) { + // Since we are in an instance method, this is an instance + // message to the superclass instance. + QualType SuperTy = Context.getObjCInterfaceType(Super); + SuperTy = Context.getObjCObjectPointerType(SuperTy); + return BuildInstanceMessage(ExprArg(*this), SuperTy, SuperLoc, + Sel, LBracLoc, SelectorLoc, RBracLoc, + move(Args)); } - - // Assume that "super" is the name of a value of some - // sort. Type-check it as an id-expression. - CXXScopeSpec SS; - UnqualifiedId Id; - Id.setIdentifier(&SuperId, SuperLoc); - OwningExprResult Receiver = ActOnIdExpression(S, SS, Id, false, false); - if (Receiver.isInvalid() || !Receiver.get()) - return ExprError(); - - Expr *ReceiverExpr = static_cast(Receiver.get()); - return BuildInstanceMessage(move(Receiver), ReceiverExpr->getType(), - /*SuperLoc=*/SourceLocation(), - Sel, LBracLoc, SelectorLoc, RBracLoc, - move(Args)); -#endif + + // Since we are in a class method, this is a class message to + // the superclass. + return BuildClassMessage(/*ReceiverTypeInfo=*/0, + Context.getObjCInterfaceType(Super), + SuperLoc, Sel, LBracLoc, SelectorLoc, + RBracLoc, move(Args)); } /// \brief Build an Objective-C class message expression. -- 2.40.0