]> granicus.if.org Git - clang/commitdiff
Added a comment, minor refactoring of foreach parsing code per Chris's suggestion.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 4 Jan 2008 23:23:46 +0000 (23:23 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 4 Jan 2008 23:23:46 +0000 (23:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45601 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseDecl.cpp
Parse/ParseStmt.cpp

index dccc00e671e1df60767db1b284c049efd3794cda..99be5caf3f20efe341088e93611957791d16a40c 100644 (file)
@@ -296,6 +296,9 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) {
     ConsumeToken();
     return Actions.FinalizeDeclaratorGroup(CurScope, LastDeclInGroup);
   }
+  // 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 (D.getContext()  == Declarator::ForContext && isTokIdentifier_in()) {
     return Actions.FinalizeDeclaratorGroup(CurScope, LastDeclInGroup);
   }
index e55c3f905dc9662cee63483af6e67283f20af096..8cccf23888fdf20245136fd7007d2920c41614f6 100644 (file)
@@ -746,7 +746,7 @@ Parser::StmtResult Parser::ParseForStatement() {
   StmtTy *FirstPart = 0;
   ExprTy *SecondPart = 0;
   StmtTy *ThirdPart = 0;
-  bool foreach = false;
+  bool ForEach = false;
   
   // Parse the first part of the for specifier.
   if (Tok.is(tok::semi)) {  // for (;
@@ -759,7 +759,7 @@ Parser::StmtResult Parser::ParseForStatement() {
     DeclTy *aBlockVarDecl = ParseDeclaration(Declarator::ForContext);
     StmtResult stmtResult = Actions.ActOnDeclStmt(aBlockVarDecl);
     FirstPart = stmtResult.isInvalid ? 0 : stmtResult.Val;
-    if ((foreach = isTokIdentifier_in())) {
+    if ((ForEach = isTokIdentifier_in())) {
       ConsumeToken(); // consume 'in'
       Value = ParseExpression();
       if (!Value.isInvalid)
@@ -778,7 +778,7 @@ Parser::StmtResult Parser::ParseForStatement() {
     if (Tok.is(tok::semi)) {
       ConsumeToken();
     }
-    else if ((foreach = isTokIdentifier_in())) {
+    else if ((ForEach = isTokIdentifier_in())) {
       ConsumeToken(); // consume 'in'
       Value = ParseExpression();
       if (!Value.isInvalid)
@@ -789,7 +789,7 @@ Parser::StmtResult Parser::ParseForStatement() {
       SkipUntil(tok::semi);
     }
   }
-  if (!foreach) {
+  if (!ForEach) {
     // Parse the second part of the for specifier.
     if (Tok.is(tok::semi)) {  // for (...;;
       // no second part.
@@ -842,12 +842,12 @@ Parser::StmtResult Parser::ParseForStatement() {
   if (Body.isInvalid)
     return Body;
   
-  return !foreach ? Actions.ActOnForStmt(ForLoc, LParenLoc, FirstPart, 
-                                         SecondPart, ThirdPart, RParenLoc
-                                         Body.Val)
-                  : Actions.ActOnObjcForCollectionStmt(ForLoc, LParenLoc, 
-                                                       FirstPart, SecondPart, 
-                                                       RParenLoc, Body.Val);
+  if (!ForEach) 
+    return Actions.ActOnForStmt(ForLoc, LParenLoc, FirstPart
+                                SecondPart, ThirdPart, RParenLoc, Body.Val);
+  else
+    return Actions.ActOnObjcForCollectionStmt(ForLoc, LParenLoc, FirstPart, 
+                                              SecondPart, RParenLoc, Body.Val);
 }
 
 /// ParseGotoStatement