[cfe-commits] r38902 - in /cfe/cfe/trunk: Parse/ParseDecl.cpp Parse/ParseStmt.cpp include/clang/Basic/DiagnosticKinds.def

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


Author: sabre
Date: Wed Jul 11 11:25:37 2007
New Revision: 38902

URL: http://llvm.org/viewvc/llvm-project?rev=38902&view=rev
Log:
implement the GNU case-range extension.  Add todo's for other missing gnu extensions.

Modified:
    cfe/cfe/trunk/Parse/ParseDecl.cpp
    cfe/cfe/trunk/Parse/ParseStmt.cpp
    cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def

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

==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:25:37 2007
@@ -302,22 +302,29 @@
 
 /// ParseStructUnionSpecifier
 ///       struct-or-union-specifier: [C99 6.7.2.1]
-///         struct-or-union identifier[opt] '{' struct-declaration-list '}'
+///         struct-or-union identifier[opt] '{' struct-contents '}'
 ///         struct-or-union identifier
 ///       struct-or-union:
 ///         'struct'
 ///         'union'
+///       struct-contents:
+///         struct-declaration-list
+/// [EXT]   empty
+/// [GNU]   "struct-declaration-list" without terminatoring ';'   [TODO]
 ///       struct-declaration-list:
-///          struct-declaration
-///          struct-declaration-list struct-declaration
-///        struct-declaration:
-///          specifier-qualifier-list struct-declarator-list ';'
-///        struct-declarator-list:
-///          struct-declarator
-///          struct-declarator-list ',' struct-declarator
-///        struct-declarator:
-///          declarator
-///          declarator[opt] ':' constant-expression
+///         struct-declaration
+///         struct-declaration-list struct-declaration
+/// [OBC]   '@' 'defs' '(' class-name ')'                         [TODO]
+///       struct-declaration:
+///         specifier-qualifier-list struct-declarator-list ';'
+/// [GNU]   __extension__ struct-declaration                       [TODO]
+/// [GNU]   specifier-qualifier-list ';'                           [TODO]
+///       struct-declarator-list:
+///         struct-declarator
+///         struct-declarator-list ',' struct-declarator
+///       struct-declarator:
+///         declarator
+///         declarator[opt] ':' constant-expression
 ///
 void Parser::ParseStructUnionSpecifier(DeclSpec &DS) {
   assert((Tok.getKind() == tok::kw_struct ||
@@ -410,6 +417,8 @@
 ///       enum-specifier: [C99 6.7.2.2]
 ///         'enum' identifier[opt] '{' enumerator-list '}'
 /// [C99]   'enum' identifier[opt] '{' enumerator-list ',' '}'
+/// [GNU]   'enum' identifier[opt] '{' enumerator-list '}' attributes [TODO]
+/// [GNU]   'enum' identifier[opt] '{' enumerator-list ',' '}' attributes [TODO]
 ///         'enum' identifier
 ///       enumerator-list:
 ///         enumerator

Modified: cfe/cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseStmt.cpp?rev=38902&r1=38901&r2=38902&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseStmt.cpp Wed Jul 11 11:25:37 2007
@@ -237,8 +237,7 @@
 /// ParseCaseStatement
 ///       labeled-statement:
 ///         'case' constant-expression ':' statement
-///
-/// FIXME: Handle GNU case-range extension.
+/// [GNU]   'case' constant-expression '...' constant-expression ':' statement
 ///
 /// Note that this does not parse the 'statement' at the end.
 ///
@@ -246,7 +245,23 @@
   assert(Tok.getKind() == tok::kw_case && "Not a case stmt!");
   ConsumeToken();  // eat the 'case'.
 
-  ParseAssignmentExpression(); // Expr without commas.
+  ExprResult Res = ParseConstantExpression();
+  if (Res.isInvalid) {
+    SkipUntil(tok::colon);
+    return;
+  }
+  
+  // GNU case range extension.
+  if (Tok.getKind() == tok::ellipsis) {
+    Diag(Tok, diag::ext_gnu_case_range);
+    ConsumeToken();
+    
+    ExprResult RHS = ParseConstantExpression();
+    if (RHS.isInvalid) {
+      SkipUntil(tok::colon);
+      return;
+    }
+  }
   
   if (Tok.getKind() == tok::colon) {
     ConsumeToken();

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

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:25:37 2007
@@ -282,6 +282,9 @@
      "use of GNU 'missing =' extension in designator")
 DIAG(ext_gnu_old_style_field_designator, EXTENSION,
      "use of GNU old-style field designator extension")
+DIAG(ext_gnu_case_range, EXTENSION,
+     "use of GNU case range extension")
+     
 // Generic errors.
 DIAG(err_parse_error, ERROR,
      "parse error")





More information about the cfe-commits mailing list