a simple, quick check to determine whether the expression starting
with '[' can only be an Objective-C message send. If so, don't parse
it as an array subscript expression. This improves recovery for, e.g.,
[a method1]
[a method2]
so that we now produce
t.m:10:13: error: expected ';' after expression
[a method]
^
instead of some mess about expecting ']'.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105221
91177308-0d34-0410-b5e6-
96231b3b80d8
OwningExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
OwningExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
OwningExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
+ bool isSimpleObjCMessageExpression();
OwningExprResult ParseObjCMessageExpression();
OwningExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
SourceLocation SuperLoc,
default: // Not a postfix-expression suffix.
return move(LHS);
case tok::l_square: { // postfix-expression: p-e '[' expression ']'
+ if (getLang().ObjC1 && isSimpleObjCMessageExpression())
+ return move(LHS);
+
Loc = ConsumeBracket();
OwningExprResult Idx(ParseExpression());
return false;
}
+/// \brief Determine whether the parser is currently referring to a an
+/// Objective-C message send, using a simplified heuristic to avoid overhead.
+///
+/// This routine will only return true for a subset of valid message-send
+/// expressions.
+bool Parser::isSimpleObjCMessageExpression() {
+ assert(Tok.is(tok::l_square) &&
+ "Incorrect start for isSimpleObjCMessageExpression");
+ if (!getLang().ObjC1)
+ return false;
+
+ return GetLookAheadToken(1).is(tok::identifier) &&
+ GetLookAheadToken(2).is(tok::identifier);
+}
+
/// objc-message-expr:
/// '[' objc-receiver objc-message-args ']'
///
int his_ivar; // expected-note 2{{'his_ivar' declared here}}
float wibble;
}
-
+- (void)method;
++ (void)method;
@property int his_prop; // expected-note{{'his_prop' declared here}}
@end
@end
#endif
+void f(A *a) {
+ f(a) // expected-error{{expected ';' after expression}}
+ [a method] // expected-error{{expected ';' after expression}}
+ [A method] // expected-error{{expected ';' after expression}}
+}