[cfe-commits] r58212 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Parse/ParseInit.cpp

Chris Lattner sabre at nondot.org
Sun Oct 26 15:59:19 PDT 2008


Author: lattner
Date: Sun Oct 26 17:59:19 2008
New Revision: 58212

URL: http://llvm.org/viewvc/llvm-project?rev=58212&view=rev
Log:
improve comments, build a Designation for field designators and
improve diagnostic for a malformed field designator.


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Parse/ParseInit.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=58212&r1=58211&r2=58212&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Sun Oct 26 17:59:19 2008
@@ -961,6 +961,8 @@
      "offsetof requires array type, '%0' invalid")
 DIAG(ext_offsetof_extended_field_designator, EXTENSION,
      "using extended field designator is an extension")
+DIAG(err_expected_field_designator, ERROR,
+     "expected a field designator, such as '.field = 4'")
      
 DIAG(err_invalid_suffix_integer_constant, ERROR,
      "invalid suffix '%0' on integer constant")

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseInit.cpp (original)
+++ cfe/trunk/lib/Parse/ParseInit.cpp Sun Oct 26 17:59:19 2008
@@ -76,13 +76,28 @@
     return ParseInitializer();
   }
   
+  // Desig - This is initialized when we see our first designator.  We may have
+  // an objc message send with no designator, so we don't want to create this
+  // eagerly.
+  Designation *Desig = 0;
+  
   // Parse each designator in the designator list until we find an initializer.
   while (Tok.is(tok::period) || Tok.is(tok::l_square)) {
     if (Tok.is(tok::period)) {
       // designator: '.' identifier
       ConsumeToken();
-      if (ExpectAndConsume(tok::identifier, diag::err_expected_ident))
+      
+      // Create designation if we haven't already.
+      if (Desig == 0)
+        Desig = &Designations.CreateDesignation(InitNum);
+      
+      if (Tok.isNot(tok::identifier)) {
+        Diag(Tok.getLocation(), diag::err_expected_field_designator);
         return ExprResult(true);
+      }
+      
+      Desig->AddDesignator(Designator::getField(Tok.getIdentifierInfo()));
+      ConsumeToken(); // Eat the identifier.
       continue;
     }
     
@@ -141,19 +156,21 @@
     MatchRHSPunctuation(tok::r_square, StartLoc);
   }
 
+  // Okay, we're done with the designator sequence.  We know that there must be
+  // at least one designator, because the only case we can get into this method
+  // without a designator is when we have an objc message send.  That case is
+  // handled and returned from above.
+  
+  // Handle a normal designator sequence end, which is an equal.
   if (Tok.is(tok::equal)) {
-    // We read some number (at least one due to the grammar we implemented)
-    // of designators and found an '=' sign.  The following tokens must be
-    // the initializer.
     ConsumeToken();
     return ParseInitializer();
   }
   
-  // We read some number (at least one due to the grammar we implemented)
-  // of designators and found something that isn't an = or an initializer.
-  // If we have exactly one array designator [TODO CHECK], this is the GNU
-  // 'designation: array-designator' extension.  Otherwise, it is a parse
-  // error.
+  // We read some number of designators and found something that isn't an = or
+  // an initializer.  If we have exactly one array designator [TODO CHECK], this
+  // is the GNU 'designation: array-designator' extension.  Otherwise, it is a
+  // parse error.
   SourceLocation Loc = Tok.getLocation();
   ExprResult Init = ParseInitializer();
   if (Init.isInvalid) return Init;





More information about the cfe-commits mailing list