]> granicus.if.org Git - clang/commitdiff
Add support for dispatching an objc message to a variable
authorChris Lattner <sabre@nondot.org>
Fri, 25 Jan 2008 19:43:26 +0000 (19:43 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 25 Jan 2008 19:43:26 +0000 (19:43 +0000)
in an initializer list.

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

Parse/ParseInit.cpp
Parse/ParseObjc.cpp
test/Parser/objc-init.m

index 9c5b6d8921b429c0c61415e96d7cfebcc84a1b16..45cf86e5b448061be5bcb10fd42fbf5ee56ddb2c 100644 (file)
@@ -94,6 +94,8 @@ Parser::ExprResult Parser::ParseInitializerWithPotentialDesignator() {
       // If Objective-C is enabled and this is a typename or other identifier
       // receiver, parse this as a message send expression.
       if (getLang().ObjC1 && isTokObjCMessageIdentifierReceiver()) {
+        // FIXME: Emit ext_gnu_missing_equal_designator for inits like
+        // [4][foo bar].
         IdentifierInfo *Name = Tok.getIdentifierInfo();
         ConsumeToken();
         ExprResult R = ParseObjCMessageExpressionBody(StartLoc, Name, 0);
@@ -101,14 +103,25 @@ Parser::ExprResult Parser::ParseInitializerWithPotentialDesignator() {
       }
       
       // Note that we parse this as an assignment expression, not a constant
-      // expression (allowing *=, =, etc).  Sema needs to validate that the
-      // expression is a constant.
+      // expression (allowing *=, =, etc) to handle the objc case.  Sema needs
+      // to validate that the expression is a constant.
       ExprResult Idx = ParseAssignmentExpression();
       if (Idx.isInvalid) {
         SkipUntil(tok::r_square);
         return Idx;
       }
       
+      // 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.
+      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);
+      }
+      
       // Handle the gnu array range extension.
       if (Tok.is(tok::ellipsis)) {
         Diag(Tok, diag::ext_gnu_array_range);
index e100c259f9f523f37486251330f6337684f3603d..c07a16ca47748b67848ae2b853c5f4a98bd941f0 100644 (file)
@@ -1276,7 +1276,7 @@ Parser::ExprResult Parser::ParseObjCMessageExpression() {
   ExprResult Res = ParseAssignmentExpression();
   if (Res.isInvalid) {
     Diag(Tok, diag::err_invalid_receiver_to_message);
-    SkipUntil(tok::identifier);
+    SkipUntil(tok::r_square);
     return Res;
   }
   return ParseObjCMessageExpressionBody(LBracLoc, 0, Res.Val);
index 43e6c2e26ec3a1db1dc648b1c300e2cdacfe58d3..ce7acaf92534c54007d01fdf315fc43ca90117c1 100644 (file)
@@ -3,11 +3,15 @@
 
 @interface NSNumber;
 - () METH;
-
 @end
 
-int main() {
+void test1() {
        id objects[] = {[NSNumber METH]};
+}
+
+void test2(NSNumber x) {
+       id objects[] = {[x METH]};
        return 0;
 }
 
+