diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-05-31 18:18:22 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-05-31 18:18:22 +0000 |
| commit | 47054fbbe93625c63bf9d802fdf06d7a2e64ce78 (patch) | |
| tree | ca261c386b7864f8e790f606605ad1323fe701b2 /clang/lib | |
| parent | 14c46517b5d8037acef1e97a074d6e00bb598615 (diff) | |
| download | bcm5719-llvm-47054fbbe93625c63bf9d802fdf06d7a2e64ce78.tar.gz bcm5719-llvm-47054fbbe93625c63bf9d802fdf06d7a2e64ce78.zip | |
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.
llvm-svn: 105229
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Parse/ParseExpr.cpp | 9 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseObjc.cpp | 10 |
2 files changed, 12 insertions, 7 deletions
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 093f9738ca9..cc69bdc0658 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -961,7 +961,14 @@ Parser::ParsePostfixExpressionSuffix(OwningExprResult LHS) { 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(); diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index 34b8187be51..365733d8c4c 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -1730,7 +1730,6 @@ Parser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { /// 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 @@ bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) { /// 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 @@ Parser::OwningExprResult Parser::ParseObjCMessageExpression() { 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; |

