[llvm-branch-commits] [cfe-branch] r105230 - in /cfe/branches/Apple/whitney: include/clang/Parse/Parser.h lib/Parse/ParseExpr.cpp lib/Parse/ParseObjc.cpp test/FixIt/typo.m

Daniel Dunbar daniel at zuster.org
Mon May 31 11:35:37 PDT 2010


Author: ddunbar
Date: Mon May 31 13:35:37 2010
New Revision: 105230

URL: http://llvm.org/viewvc/llvm-project?rev=105230&view=rev
Log:
Merge r105221:
--
Author: Douglas Gregor <dgregor at apple.com>
Date:   Mon May 31 14:40:22 2010 +0000

    When we see the a '[' in a postfix expression in Objective-C, perform
    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 ']'.

Modified:
    cfe/branches/Apple/whitney/include/clang/Parse/Parser.h
    cfe/branches/Apple/whitney/lib/Parse/ParseExpr.cpp
    cfe/branches/Apple/whitney/lib/Parse/ParseObjc.cpp
    cfe/branches/Apple/whitney/test/FixIt/typo.m

Modified: cfe/branches/Apple/whitney/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/include/clang/Parse/Parser.h?rev=105230&r1=105229&r2=105230&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/include/clang/Parse/Parser.h (original)
+++ cfe/branches/Apple/whitney/include/clang/Parse/Parser.h Mon May 31 13:35:37 2010
@@ -1059,6 +1059,7 @@
   OwningExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
   OwningExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
   OwningExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
+  bool isSimpleObjCMessageExpression();
   OwningExprResult ParseObjCMessageExpression();
   OwningExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
                                                   SourceLocation SuperLoc,

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=105230&r1=105229&r2=105230&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Parse/ParseExpr.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Parse/ParseExpr.cpp Mon May 31 13:35:37 2010
@@ -961,6 +961,9 @@
     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());
 

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=105230&r1=105229&r2=105230&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Parse/ParseObjc.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Parse/ParseObjc.cpp Mon May 31 13:35:37 2010
@@ -1794,6 +1794,21 @@
   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 ']'
 ///

Modified: cfe/branches/Apple/whitney/test/FixIt/typo.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/FixIt/typo.m?rev=105230&r1=105229&r2=105230&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/FixIt/typo.m (original)
+++ cfe/branches/Apple/whitney/test/FixIt/typo.m Mon May 31 13:35:37 2010
@@ -24,7 +24,8 @@
   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
 
@@ -145,4 +146,9 @@
 @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}}
+}
 





More information about the llvm-branch-commits mailing list