[cfe-commits] r68010 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseDecl.cpp lib/Parse/ParseStmt.cpp test/Parser/objc-foreach-error-1.m test/Parser/objc-foreach-syntax.m

Chris Lattner sabre at nondot.org
Sun Mar 29 10:27:54 PDT 2009


Author: lattner
Date: Sun Mar 29 12:27:48 2009
New Revision: 68010

URL: http://llvm.org/viewvc/llvm-project?rev=68010&view=rev
Log:
hoist some code for handling objc foreach construct out of Declaration processing
into ParseForStatement.  Merge two tests into one.

Removed:
    cfe/trunk/test/Parser/objc-foreach-error-1.m
Modified:
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Parse/ParseStmt.cpp
    cfe/trunk/test/Parser/objc-foreach-syntax.m

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=68010&r1=68009&r2=68010&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sun Mar 29 12:27:48 2009
@@ -809,7 +809,8 @@
   // C99 6.7: Declarations.
   
   DeclGroupPtrTy ParseDeclaration(unsigned Context);
-  DeclGroupPtrTy ParseSimpleDeclaration(unsigned Context);
+  DeclGroupPtrTy ParseSimpleDeclaration(unsigned Context,
+                                        bool RequireSemi = true);
   DeclGroupPtrTy ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D);
   DeclPtrTy ParseFunctionStatementBody(DeclPtrTy Decl);
   void ParseDeclarationSpecifiers(DeclSpec &DS, 

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sun Mar 29 12:27:48 2009
@@ -257,7 +257,11 @@
 ///         declaration-specifiers init-declarator-list[opt] ';'
 ///[C90/C++]init-declarator-list ';'                             [TODO]
 /// [OMP]   threadprivate-directive                              [TODO]
-Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration(unsigned Context) {
+///
+/// If RequireSemi is false, this does not check for a ';' at the end of the
+/// declaration.
+Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration(unsigned Context,
+                                                      bool RequireSemi) {
   // Parse the common declaration-specifiers piece.
   DeclSpec DS;
   ParseDeclarationSpecifiers(DS);
@@ -275,22 +279,16 @@
   
   DeclGroupPtrTy DG =
     ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo);
+
+  // If the client wants to check what comes after the declaration, just return
+  // immediately without checking anything!
+  if (!RequireSemi) return DG;
   
   if (Tok.is(tok::semi)) {
     ConsumeToken();
-    // for(is key; in keys) is error.
-    if (Context == Declarator::ForContext && isTokIdentifier_in())
-      Diag(Tok, diag::err_parse_error);
-    
     return DG;
   }
   
-  // If this is an ObjC2 for-each loop, this is a successful declarator
-  // parse.  The syntax for these looks like:
-  // 'for' '(' declaration 'in' expr ')' statement
-  if (Context == Declarator::ForContext && isTokIdentifier_in())
-    return DG;
-  
   Diag(Tok, diag::err_expected_semi_declation);
   // Skip to end of block or statement
   SkipUntil(tok::r_brace, true, true);

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Sun Mar 29 12:27:48 2009
@@ -912,12 +912,18 @@
       Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
 
     SourceLocation DeclStart = Tok.getLocation();
-    DeclGroupPtrTy VarDecls = ParseSimpleDeclaration(Declarator::ForContext);
-    // FIXME: Pass in the right location for the end of the declstmt.
-    FirstPart = Actions.ActOnDeclStmt(VarDecls, DeclStart, DeclStart);
-    if ((ForEach = isTokIdentifier_in())) {
+    DeclGroupPtrTy DG = ParseSimpleDeclaration(Declarator::ForContext, false);
+    FirstPart = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
+    
+    if (Tok.is(tok::semi)) {  // for (int x = 4;
+      ConsumeToken();
+    } else if ((ForEach = isTokIdentifier_in())) {
+      // ObjC: for (id x in expr) 
       ConsumeToken(); // consume 'in'
       SecondPart = ParseExpression();
+    } else {
+      Diag(Tok, diag::err_expected_semi_for);
+      SkipUntil(tok::semi);
     }
   } else {
     Value = ParseExpression();

Removed: cfe/trunk/test/Parser/objc-foreach-error-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-foreach-error-1.m?rev=68009&view=auto

==============================================================================
--- cfe/trunk/test/Parser/objc-foreach-error-1.m (original)
+++ cfe/trunk/test/Parser/objc-foreach-error-1.m (removed)
@@ -1,24 +0,0 @@
-// RUN: clang-cc -fsyntax-only -verify %s
-
-ce MyList // expected-error {{invalid token after top level declarator}}
- at end
-
-
- at implementation MyList
-- (unsigned int)countByEnumeratingWithState:  (struct __objcFastEnumerationState *)state objects:  (id *)items count:(unsigned int)stackcount
-{
-     return 0;
-}
- at end
-
-
-int LOOP();
-
- at implementation MyList (BasicTest)  // expected-error {{cannot find interface declaration for 'MyList'}}
-- (void)compilerTestAgainst {
-MyList * el;  // expected-error {{use of undeclared identifier 'MyList'}}
-     for (el in @"foo")    // expected-error {{use of undeclared identifier 'el'}}
-	  { LOOP(); }
-}
- at end
-

Modified: cfe/trunk/test/Parser/objc-foreach-syntax.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-foreach-syntax.m?rev=68010&r1=68009&r2=68010&view=diff

==============================================================================
--- cfe/trunk/test/Parser/objc-foreach-syntax.m (original)
+++ cfe/trunk/test/Parser/objc-foreach-syntax.m Sun Mar 29 12:27:48 2009
@@ -1,7 +1,28 @@
 // RUN: clang-cc -fsyntax-only -verify %s
 
-static int test_NSURLGetResourceValueForKey( id keys )
+ce MyList // expected-error {{invalid token after top level declarator}}
+ at end
+
+
+ at implementation MyList
+- (unsigned int)countByEnumeratingWithState:  (struct __objcFastEnumerationState *)state objects:  (id *)items count:(unsigned int)stackcount
 {
- for ( id key; in keys) {  // expected-error {{parse error}}
-  } 
+     return 0;
+}
+ at end
+
+
+int LOOP();
+
+ at implementation MyList (BasicTest)  // expected-error {{cannot find interface declaration for 'MyList'}}
+- (void)compilerTestAgainst {
+MyList * el;  // expected-error {{use of undeclared identifier 'MyList'}}
+     for (el in @"foo")    // expected-error {{use of undeclared identifier 'el'}}
+	  { LOOP(); }
+}
+ at end
+
+
+static int test7(id keys) {
+  for (id key; in keys) ;  // expected-error {{use of undeclared identifier 'in'}}
 }





More information about the cfe-commits mailing list