[cfe-commits] r38831 - /cfe/cfe/trunk/Parse/ParseDecl.cpp

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:25:01 PDT 2007


Author: sabre
Date: Wed Jul 11 11:25:00 2007
New Revision: 38831

URL: http://llvm.org/viewvc/llvm-project?rev=38831&view=rev
Log:
Improve handling of [*]

Modified:
    cfe/cfe/trunk/Parse/ParseDecl.cpp

Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=38831&r1=38830&r2=38831&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:25:00 2007
@@ -557,16 +557,33 @@
   }
   
   // Handle "direct-declarator [ type-qual-list[opt] * ]".
-  // Check that the ']' token is present to avoid incorrectly parsing
-  // expressions starting with '*' as [*].
   bool isStar = false;
-  if (Tok.getKind() == tok::star /*FIXME: && nexttok == tok::r_square*/) {
-    if (StaticLoc.isValid())
-      Diag(StaticLoc, diag::err_unspecified_vla_size_with_static);
-    StaticLoc = SourceLocation();  // Drop the static.
-    isStar = true;
+  if (Tok.getKind() == tok::star) {
+    // Remember the '*' token, in case we have to un-get it.
+    LexerToken StarTok = Tok;
     ConsumeToken();
-  } else if (Tok.getKind() != tok::r_square) {
+
+    // Check that the ']' token is present to avoid incorrectly parsing
+    // expressions starting with '*' as [*].
+    if (Tok.getKind() == tok::r_square) {
+      if (StaticLoc.isValid())
+        Diag(StaticLoc, diag::err_unspecified_vla_size_with_static);
+      StaticLoc = SourceLocation();  // Drop the static.
+      isStar = true;
+      ConsumeToken();
+    } else {
+      // Otherwise, the * must have been some expression (such as '*ptr') that
+      // started an assign-expr.  We already consumed the token, but now we need
+      // to reparse it.
+      // FIXME: There are two options here: first, we could push 'StarTok' and
+      // Tok back into the preprocessor as a macro expansion context, so they
+      // will be read again.  Second, we could parse the rest of the assign-expr
+      // then apply the dereference.
+      assert(0 && "FIXME: int X[*p] unimplemented");
+    }
+  }
+  
+  if (!isStar && Tok.getKind() != tok::r_square) {
     // Parse the assignment-expression now.
     assert(0 && "expr parsing not impl yet!");
   }





More information about the cfe-commits mailing list