[llvm-branch-commits] [cfe-branch] r105232 - in /cfe/branches/Apple/whitney/lib/Parse: ParseExpr.cpp ParseObjc.cpp
Daniel Dunbar
daniel at zuster.org
Mon May 31 11:35:42 PDT 2010
Author: ddunbar
Date: Mon May 31 13:35:42 2010
New Revision: 105232
URL: http://llvm.org/viewvc/llvm-project?rev=105232&view=rev
Log:
Merge r105229:
--
Author: Chris Lattner <clattner at apple.com>
Date: Mon May 31 18:18:22 2010 +0000
Minor tweaks on doug's objc recovery patch: the caller
of isSimpleObjCMessageExpression checks the language,
so change a dynamic check into an assert.
isSimpleObjCMessageExpression is expensive, so only do it
in the common case when it is likely to matter: when the [
of the postfix expr starts on a new line. This should avoid
doing lookahead for every array expression.
Modified:
cfe/branches/Apple/whitney/lib/Parse/ParseExpr.cpp
cfe/branches/Apple/whitney/lib/Parse/ParseObjc.cpp
Modified: cfe/branches/Apple/whitney/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Parse/ParseExpr.cpp?rev=105232&r1=105231&r2=105232&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Parse/ParseExpr.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Parse/ParseExpr.cpp Mon May 31 13:35:42 2010
@@ -961,7 +961,14 @@
default: // Not a postfix-expression suffix.
return move(LHS);
case tok::l_square: { // postfix-expression: p-e '[' expression ']'
- if (getLang().ObjC1 && isSimpleObjCMessageExpression())
+ // If we have a array postfix expression that starts on a new line and
+ // Objective-C is enabled, it is highly likely that the user forgot a
+ // semicolon after the base expression and that the array postfix-expr is
+ // actually another message send. In this case, do some look-ahead to see
+ // if the contents of the square brackets are obviously not a valid
+ // expression and recover by pretending there is no suffix.
+ if (getLang().ObjC1 && Tok.isAtStartOfLine() &&
+ isSimpleObjCMessageExpression())
return move(LHS);
Loc = ConsumeBracket();
Modified: cfe/branches/Apple/whitney/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Parse/ParseObjc.cpp?rev=105232&r1=105231&r2=105232&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Parse/ParseObjc.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Parse/ParseObjc.cpp Mon May 31 13:35:42 2010
@@ -1730,7 +1730,6 @@
/// expression
/// simple-type-specifier
/// typename-specifier
-
bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) {
if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) ||
Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope))
@@ -1800,11 +1799,8 @@
/// This routine will only return true for a subset of valid message-send
/// expressions.
bool Parser::isSimpleObjCMessageExpression() {
- assert(Tok.is(tok::l_square) &&
+ assert(Tok.is(tok::l_square) && getLang().ObjC1 &&
"Incorrect start for isSimpleObjCMessageExpression");
- if (!getLang().ObjC1)
- return false;
-
return GetLookAheadToken(1).is(tok::identifier) &&
GetLookAheadToken(2).is(tok::identifier);
}
@@ -1855,7 +1851,9 @@
return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(),
TypeOrExpr, ExprArg(Actions));
- } else if (Tok.is(tok::identifier)) {
+ }
+
+ if (Tok.is(tok::identifier)) {
IdentifierInfo *Name = Tok.getIdentifierInfo();
SourceLocation NameLoc = Tok.getLocation();
TypeTy *ReceiverType;
More information about the llvm-branch-commits
mailing list