[cfe-commits] r58213 - /cfe/trunk/lib/Parse/ParseInit.cpp

Chris Lattner sabre at nondot.org
Sun Oct 26 16:06:54 PDT 2008


Author: lattner
Date: Sun Oct 26 18:06:54 2008
New Revision: 58213

URL: http://llvm.org/viewvc/llvm-project?rev=58213&view=rev
Log:
improve comments, build array and array range designator nodes, 
fix an obscure memory leak.

Modified:
    cfe/trunk/lib/Parse/ParseInit.cpp

Modified: cfe/trunk/lib/Parse/ParseInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseInit.cpp?rev=58213&r1=58212&r2=58213&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseInit.cpp (original)
+++ cfe/trunk/lib/Parse/ParseInit.cpp Sun Oct 26 18:06:54 2008
@@ -104,11 +104,18 @@
     // We must have either an array designator now or an objc message send.
     assert(Tok.is(tok::l_square) && "Unexpected token!");
     
-    // array-designator: '[' constant-expression ']'
-    // array-designator: '[' constant-expression '...' constant-expression ']'
-    // When designation is empty, this can be '[' objc-message-expr ']'.  Note
-    // that we also have the case of [4][foo bar], which is the gnu designator
-    // extension + objc message send.
+    // Handle the two forms of array designator:
+    //   array-designator: '[' constant-expression ']'
+    //   array-designator: '[' constant-expression '...' constant-expression ']'
+    //
+    // Also, we have to handle the case where the expression after the
+    // designator an an objc message send: '[' objc-message-expr ']'.
+    // Interesting cases are:
+    //   [foo bar]         -> objc message send
+    //   [foo]             -> array designator
+    //   [foo ... bar]     -> array designator
+    //   [4][foo bar]      -> obsolete GNU designation with objc message send.
+    //
     SourceLocation StartLoc = ConsumeBracket();
     
     // If Objective-C is enabled and this is a typename or other identifier
@@ -140,17 +147,26 @@
       // [4][foo bar].
       return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, 0,Idx.Val);
     }
-    
-    // Handle the gnu array range extension.
-    if (Tok.is(tok::ellipsis)) {
+
+    // Create designation if we haven't already.
+    if (Desig == 0)
+      Desig = &Designations.CreateDesignation(InitNum);
+    
+    // If this is a normal array designator, remember it.
+    if (Tok.isNot(tok::ellipsis)) {
+      Desig->AddDesignator(Designator::getArray(Idx.Val));
+    } else {
+      // Handle the gnu array range extension.
       Diag(Tok, diag::ext_gnu_array_range);
       ConsumeToken();
       
       ExprResult RHS = ParseConstantExpression();
       if (RHS.isInvalid) {
+        Actions.DeleteExpr(Idx.Val);
         SkipUntil(tok::r_square);
         return RHS;
       }
+      Desig->AddDesignator(Designator::getArrayRange(Idx.Val, RHS.Val));
     }
     
     MatchRHSPunctuation(tok::r_square, StartLoc);





More information about the cfe-commits mailing list