From 7617c7d2951f4cffb2de4dd4addbbf8884b6a2aa Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 15 Sep 2010 15:09:43 +0000 Subject: [PATCH] Extend bracket insertion to message sends to "super", e.g., super method:arg] will now recover nicely and insert the '[' before 'super'. llvm-svn: 113971 --- clang/lib/Parse/ParseExpr.cpp | 12 ++++++++++++ clang/test/FixIt/fixit-objc-message.m | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index e466af2d6147..0f9154827e94 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -663,6 +663,18 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, break; } + // In an Objective-C method, if we have "super" followed by an identifier, + // the token sequence is ill-fomed. However, if there's a ':' or ']' after + // that identifier, this is probably a message send with a missing open + // bracket. Treat it as such. + if (getLang().ObjC1 && &II == Ident_super && Tok.is(tok::identifier) && + getCurScope()->isInObjcMethodScope() && + (NextToken().is(tok::colon) || NextToken().is(tok::r_square))) { + Res = ParseObjCMessageExpressionBody(SourceLocation(), ILoc, ParsedType(), + 0); + break; + } + // Make sure to pass down the right value for isAddressOfOperand. if (isAddressOfOperand && isPostfixExpressionSuffixStart()) isAddressOfOperand = false; diff --git a/clang/test/FixIt/fixit-objc-message.m b/clang/test/FixIt/fixit-objc-message.m index f19b489f997b..72728d20adc7 100644 --- a/clang/test/FixIt/fixit-objc-message.m +++ b/clang/test/FixIt/fixit-objc-message.m @@ -18,4 +18,18 @@ void f(A *a, int i, int j) { a method1:5+2 second:+(3.14159)]; a method1:[a method1:3 second:j] second:i++] a getBlah]; + + int array[17]; + (void)array[a method1:5+2 second:+(3.14159)]]; } + +@interface B : A +- (int)method1:(int)x second:(float)y; +@end + +@implementation B +- (int)method1:(int)x second:(float)y { + super method1:x second:y]; + return super getBlah]; +} +@end