Split the for loop in different states to produce a complete For loop node in the...
authorMiguel de Icaza <miguel@gnome.org>
Fri, 6 Apr 2012 21:04:06 +0000 (17:04 -0400)
committerMiguel de Icaza <miguel@gnome.org>
Fri, 6 Apr 2012 21:04:16 +0000 (17:04 -0400)
mcs/mcs/cs-parser.jay
mcs/mcs/cs-tokenizer.cs

index b17c4ca0563dcf3704059afeed18b77fb22de142..c3b9f28642fc57abb532656a9a76eff5607df700 100644 (file)
@@ -5177,23 +5177,21 @@ for_statement_cont
        : opt_for_initializer SEMICOLON
          {
                ((For) $0).Initializer = (Statement) $1;
+
+               // Pass the "For" object to the iterator_part4
+               oob_stack.Push ($0);
          }
-         opt_for_condition SEMICOLON
-         {
-               ((For) $0).Condition = (BooleanExpression) $4;
-         }
-         opt_for_iterator CLOSE_PARENS
-         {
-               ((For) $0).Iterator = (Statement) $7;
-         }
+         for_condition_and_iterator_part
          embedded_statement
          {
-               if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
-                       Warning_EmptyStatement (GetLocation ($10));
+               var locations = (Tuple<Location,Location>) $4;
+               oob_stack.Pop ();
+               if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
+                       Warning_EmptyStatement (GetLocation ($5));
          
                For f = ((For) $0);
-               f.Statement = (Statement) $10;
-               lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation ($5), GetLocation ($8));
+               f.Statement = (Statement) $5;
+               lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
 
                $$ = end_block (GetLocation ($2));
          }
@@ -5204,6 +5202,45 @@ for_statement_cont
          }
        ;
 
+for_condition_and_iterator_part
+       : opt_for_condition SEMICOLON
+         {
+               For f = (For) oob_stack.Peek ();
+               f.Condition = (BooleanExpression) $1;
+         }
+         for_iterator_part {
+               $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
+         }
+
+       // Handle errors in the case of opt_for_condition being followed by
+       // a close parenthesis
+       | opt_for_condition close_parens_close_brace {
+               report.Error (1525, GetLocation ($2), "Unexpected symbol expected ';'");
+               For f = (For) oob_stack.Peek ();
+               f.Condition = (BooleanExpression) $1;
+               $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
+         }
+       ;
+
+for_iterator_part
+       : opt_for_iterator CLOSE_PARENS {
+               For f = (For) oob_stack.Peek ();
+               f.Iterator = (Statement) $1;
+               $$ = GetLocation ($2);
+         }
+       | opt_for_iterator CLOSE_BRACE {
+               report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
+               For f = (For) oob_stack.Peek ();
+               f.Iterator = (Statement) $1;
+               $$ = GetLocation ($2);
+         }
+       ; 
+
+close_parens_close_brace 
+       : CLOSE_PARENS
+       | CLOSE_BRACE { lexer.putback ('}'); }
+       ;
+
 opt_for_initializer
        : /* empty */           { $$ = new EmptyStatement (lexer.Location); }
        | for_initializer       
@@ -6526,7 +6563,7 @@ public void parse ()
                        if (yacc_verbose_flag > 0)
                                throw;
                
-                       report.Error (589, lexer.Location, "Internal compiler error during parsing");
+                       report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
                }
        }
 }
index 4de9ed219b6a8c3c7fd9b03395d026905877d08c..e61ea864c3b4eaa04419dac0cc704c4f1eeb131f 100644 (file)
@@ -139,6 +139,11 @@ namespace Mono.CSharp
                                pos = 0;
                        }
 
+                       public override string ToString ()
+                       {
+                               return string.Format ("Token '{0}' at {1},{2}", Value, row, column);
+                       }
+                       
                        public Location Location {
                                get { return new Location (row, column); }
                        }