]> granicus.if.org Git - clang/commitdiff
handle the full assignment-expression grammar when using an
authorChris Lattner <sabre@nondot.org>
Mon, 2 Jun 2008 21:31:07 +0000 (21:31 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 2 Jun 2008 21:31:07 +0000 (21:31 +0000)
objc message send in an initializer expression.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51882 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/Parser.h
lib/Parse/ParseExpr.cpp
lib/Parse/ParseInit.cpp
test/Parser/objc-init.m

index 84fe49a76721e959c9184da0e874b108ea8e056c..3d3e20079535c79f99e241abd42e7611769ba85b 100644 (file)
@@ -403,6 +403,9 @@ private:
   ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
                                             IdentifierInfo *ReceiverName,
                                             ExprTy *ReceiverExpr);
+  ExprResult ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracloc,
+                                                         IdentifierInfo *ReceiverName,
+                                                         ExprTy *ReceiverExpr);
     
   //===--------------------------------------------------------------------===//
   // C99 6.8: Statements and Blocks.
index 523f6473417b3cbcff35337093a911ab362ccb78..4bccc38266481171cc9c7e1da8f8e4b38cd079a8 100644 (file)
@@ -200,6 +200,27 @@ Parser::ExprResult Parser::ParseAssignmentExpression() {
   return ParseRHSOfBinaryExpression(LHS, prec::Assignment);
 }
 
+/// ParseAssignmentExprWithObjCMessageExprStart - Parse an assignment expression
+/// where part of an objc message send has already been parsed.  In this case
+/// LBracLoc indicates the location of the '[' of the message send, and either
+/// ReceiverName or ReceiverExpr is non-null indicating the receiver of the
+/// message.
+///
+/// Since this handles full assignment-expression's, it handles postfix
+/// expressions and other binary operators for these expressions as well.
+Parser::ExprResult 
+Parser::ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracLoc,
+                                                   IdentifierInfo *ReceiverName,
+                                                    ExprTy *ReceiverExpr) {
+  ExprResult R = ParseObjCMessageExpressionBody(LBracLoc, ReceiverName,
+                                                ReceiverExpr);
+  if (R.isInvalid) return R;
+  R = ParsePostfixExpressionSuffix(R);
+  if (R.isInvalid) return R;
+  return ParseRHSOfBinaryExpression(R, 2);
+}
+
+
 Parser::ExprResult Parser::ParseConstantExpression() {
   ExprResult LHS = ParseCastExpression(false);
   if (LHS.isInvalid) return LHS;
index c40fe88c217bc7b54c95ea95d8630cdb2267fec2..a1fe04b731208a9fe6c3b8f07be6ab2c5b7a86ae 100644 (file)
@@ -98,8 +98,7 @@ Parser::ExprResult Parser::ParseInitializerWithPotentialDesignator() {
         // [4][foo bar].
         IdentifierInfo *Name = Tok.getIdentifierInfo();
         ConsumeToken();
-        ExprResult R = ParseObjCMessageExpressionBody(StartLoc, Name, 0);
-        return ParsePostfixExpressionSuffix(R);
+        return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, Name, 0);
       }
       
       // Note that we parse this as an assignment expression, not a constant
@@ -113,13 +112,13 @@ Parser::ExprResult Parser::ParseInitializerWithPotentialDesignator() {
       
       // Given an expression, we could either have a designator (if the next
       // tokens are '...' or ']' or an objc message send.  If this is an objc
-      // message send, handle it now.
+      // message send, handle it now.  An objc-message send is the start of 
+      // an assignment-expression production.
       if (getLang().ObjC1 && Tok.isNot(tok::ellipsis) && 
           Tok.isNot(tok::r_square)) {
         // FIXME: Emit ext_gnu_missing_equal_designator for inits like
         // [4][foo bar].
-        ExprResult R = ParseObjCMessageExpressionBody(StartLoc, 0, Idx.Val);
-        return ParsePostfixExpressionSuffix(R);
+        return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, 0,Idx.Val);
       }
       
       // Handle the gnu array range extension.
index ce7acaf92534c54007d01fdf315fc43ca90117c1..303d80cf7ce8399893eff0eff612fcc7d9424e84 100644 (file)
@@ -3,6 +3,7 @@
 
 @interface NSNumber;
 - () METH;
+- (unsigned) METH2;
 @end
 
 void test1() {
@@ -15,3 +16,8 @@ void test2(NSNumber x) {
 }
 
 
+// rdar://5977581
+void test3() {
+  unsigned x[] = {[NSNumber METH2]+2};
+}
+