Inheritance: ICSharpCode.NRefactory.Ast.StatementWithEmbeddedStatement
Esempio n. 1
0
 public virtual object VisitForStatement(ForStatement forStatement, object data) {
     throw CreateException(forStatement);
 }
Esempio n. 2
0
 public override object VisitForStatement (ForStatement node, object data)
 {
     if (node.Initializers.Count > 1)
         throw CreateException (node, "Too many initializers");
     
     PushLocals ();
     
     EnableSemicolon = false;
     Write ("for(");
     
     foreach (var item in node.Initializers) {
         if (item != node.Initializers[0])
             WriteComma ();
         item.AcceptVisitor (this, null);
     }
     Write ("; ");
     
     node.Condition.AcceptVisitor (this, null);
     Write ("; ");
     
     foreach (var item in node.Iterator) {
         if (item != node.Iterator[0])
             WriteComma ();
         item.AcceptVisitor (this, null);
     }
     Write (")");
     EnableSemicolon = true;
     
     EmitBlockOrIndentedLine (node.EmbeddedStatement);
     
     PopLocals ();
     return null;
 }
		public virtual object VisitForStatement(ForStatement forStatement, object data) {
			Debug.Assert((forStatement != null));
			Debug.Assert((forStatement.Initializers != null));
			Debug.Assert((forStatement.Condition != null));
			Debug.Assert((forStatement.Iterator != null));
			Debug.Assert((forStatement.EmbeddedStatement != null));
			for (int i = 0; i < forStatement.Initializers.Count; i++) {
				Statement o = forStatement.Initializers[i];
				Debug.Assert(o != null);
				nodeStack.Push(o);
				o.AcceptVisitor(this, data);
				o = (Statement)nodeStack.Pop();
				if (o == null)
					forStatement.Initializers.RemoveAt(i--);
				else
					forStatement.Initializers[i] = o;
			}
			nodeStack.Push(forStatement.Condition);
			forStatement.Condition.AcceptVisitor(this, data);
			forStatement.Condition = ((Expression)(nodeStack.Pop()));
			for (int i = 0; i < forStatement.Iterator.Count; i++) {
				Statement o = forStatement.Iterator[i];
				Debug.Assert(o != null);
				nodeStack.Push(o);
				o.AcceptVisitor(this, data);
				o = (Statement)nodeStack.Pop();
				if (o == null)
					forStatement.Iterator.RemoveAt(i--);
				else
					forStatement.Iterator[i] = o;
			}
			nodeStack.Push(forStatement.EmbeddedStatement);
			forStatement.EmbeddedStatement.AcceptVisitor(this, data);
			forStatement.EmbeddedStatement = ((Statement)(nodeStack.Pop()));
			return null;
		}
Esempio n. 4
0
		public virtual object VisitForStatement(ForStatement forStatement, object data) {
			throw new global::System.NotImplementedException("ForStatement");
		}
		public sealed override object VisitForStatement(ForStatement forStatement, object data) {
			this.BeginVisit(forStatement);
			object result = this.TrackedVisitForStatement(forStatement, data);
			this.EndVisit(forStatement);
			return result;
		}
 public override object VisitForStatement(ForStatement forStatement, object data)
 {
     base.VisitForStatement(forStatement, data);
     ConvertForStatement(forStatement);
     return null;
 }
Esempio n. 7
0
	void EmbeddedStatement(
#line  1555 "cs.ATG" 
out Statement statement) {

#line  1557 "cs.ATG" 
		TypeReference type = null;
		Expression expr = null;
		Statement embeddedStatement = null;
		BlockStatement block = null;
		statement = null;
		

#line  1564 "cs.ATG" 
		Location startLocation = la.Location; 
		if (la.kind == 16) {
			Block(
#line  1566 "cs.ATG" 
out block);

#line  1566 "cs.ATG" 
			statement = block; 
		} else if (la.kind == 11) {
			lexer.NextToken();

#line  1569 "cs.ATG" 
			statement = new EmptyStatement(); 
		} else if (
#line  1572 "cs.ATG" 
UnCheckedAndLBrace()) {

#line  1572 "cs.ATG" 
			bool isChecked = true; 
			if (la.kind == 58) {
				lexer.NextToken();
			} else if (la.kind == 118) {
				lexer.NextToken();

#line  1573 "cs.ATG" 
				isChecked = false;
			} else SynErr(198);
			Block(
#line  1574 "cs.ATG" 
out block);

#line  1574 "cs.ATG" 
			statement = isChecked ? (Statement)new CheckedStatement(block) : (Statement)new UncheckedStatement(block); 
		} else if (la.kind == 79) {
			IfStatement(
#line  1577 "cs.ATG" 
out statement);
		} else if (la.kind == 110) {
			lexer.NextToken();

#line  1579 "cs.ATG" 
			List<SwitchSection> switchSections = new List<SwitchSection>(); 
			Expect(20);
			Expr(
#line  1580 "cs.ATG" 
out expr);
			Expect(21);
			Expect(16);
			SwitchSections(
#line  1581 "cs.ATG" 
switchSections);
			Expect(17);

#line  1583 "cs.ATG" 
			statement = new SwitchStatement(expr, switchSections); 
		} else if (la.kind == 125) {
			lexer.NextToken();
			Expect(20);
			Expr(
#line  1586 "cs.ATG" 
out expr);
			Expect(21);
			EmbeddedStatement(
#line  1587 "cs.ATG" 
out embeddedStatement);

#line  1588 "cs.ATG" 
			statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start);
		} else if (la.kind == 65) {
			lexer.NextToken();
			EmbeddedStatement(
#line  1590 "cs.ATG" 
out embeddedStatement);
			Expect(125);
			Expect(20);
			Expr(
#line  1591 "cs.ATG" 
out expr);
			Expect(21);
			Expect(11);

#line  1592 "cs.ATG" 
			statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.End); 
		} else if (la.kind == 76) {
			lexer.NextToken();

#line  1594 "cs.ATG" 
			List<Statement> initializer = null; List<Statement> iterator = null; 
			Expect(20);
			if (StartOf(6)) {
				ForInitializer(
#line  1595 "cs.ATG" 
out initializer);
			}
			Expect(11);
			if (StartOf(6)) {
				Expr(
#line  1596 "cs.ATG" 
out expr);
			}
			Expect(11);
			if (StartOf(6)) {
				ForIterator(
#line  1597 "cs.ATG" 
out iterator);
			}
			Expect(21);
			EmbeddedStatement(
#line  1598 "cs.ATG" 
out embeddedStatement);

#line  1599 "cs.ATG" 
			statement = new ForStatement(initializer, expr, iterator, embeddedStatement); 
		} else if (la.kind == 77) {
			lexer.NextToken();
			Expect(20);
			Type(
#line  1601 "cs.ATG" 
out type);
			Identifier();

#line  1601 "cs.ATG" 
			string varName = t.val; 
			Expect(81);
			Expr(
#line  1602 "cs.ATG" 
out expr);
			Expect(21);
			EmbeddedStatement(
#line  1603 "cs.ATG" 
out embeddedStatement);

#line  1604 "cs.ATG" 
			statement = new ForeachStatement(type, varName , expr, embeddedStatement); 
		} else if (la.kind == 53) {
			lexer.NextToken();
			Expect(11);

#line  1607 "cs.ATG" 
			statement = new BreakStatement(); 
		} else if (la.kind == 61) {
			lexer.NextToken();
			Expect(11);

#line  1608 "cs.ATG" 
			statement = new ContinueStatement(); 
		} else if (la.kind == 78) {
			GotoStatement(
#line  1609 "cs.ATG" 
out statement);
		} else if (
#line  1611 "cs.ATG" 
IsYieldStatement()) {
			Expect(132);
			if (la.kind == 101) {
				lexer.NextToken();
				Expr(
#line  1612 "cs.ATG" 
out expr);

#line  1612 "cs.ATG" 
				statement = new YieldStatement(new ReturnStatement(expr)); 
			} else if (la.kind == 53) {
				lexer.NextToken();

#line  1613 "cs.ATG" 
				statement = new YieldStatement(new BreakStatement()); 
			} else SynErr(199);
			Expect(11);
		} else if (la.kind == 101) {
			lexer.NextToken();
			if (StartOf(6)) {
				Expr(
#line  1616 "cs.ATG" 
out expr);
			}
			Expect(11);

#line  1616 "cs.ATG" 
			statement = new ReturnStatement(expr); 
		} else if (la.kind == 112) {
			lexer.NextToken();
			if (StartOf(6)) {
				Expr(
#line  1617 "cs.ATG" 
out expr);
			}
			Expect(11);

#line  1617 "cs.ATG" 
			statement = new ThrowStatement(expr); 
		} else if (StartOf(6)) {
			StatementExpr(
#line  1620 "cs.ATG" 
out statement);
			while (!(la.kind == 0 || la.kind == 11)) {SynErr(200); lexer.NextToken(); }
			Expect(11);
		} else if (la.kind == 114) {
			TryStatement(
#line  1623 "cs.ATG" 
out statement);
		} else if (la.kind == 86) {
			lexer.NextToken();
			Expect(20);
			Expr(
#line  1626 "cs.ATG" 
out expr);
			Expect(21);
			EmbeddedStatement(
#line  1627 "cs.ATG" 
out embeddedStatement);

#line  1627 "cs.ATG" 
			statement = new LockStatement(expr, embeddedStatement); 
		} else if (la.kind == 121) {

#line  1630 "cs.ATG" 
			Statement resourceAcquisitionStmt = null; 
			lexer.NextToken();
			Expect(20);
			ResourceAcquisition(
#line  1632 "cs.ATG" 
out resourceAcquisitionStmt);
			Expect(21);
			EmbeddedStatement(
#line  1633 "cs.ATG" 
out embeddedStatement);

#line  1633 "cs.ATG" 
			statement = new UsingStatement(resourceAcquisitionStmt, embeddedStatement); 
		} else if (la.kind == 119) {
			lexer.NextToken();
			Block(
#line  1636 "cs.ATG" 
out block);

#line  1636 "cs.ATG" 
			statement = new UnsafeStatement(block); 
		} else if (la.kind == 74) {

#line  1638 "cs.ATG" 
			Statement pointerDeclarationStmt = null; 
			lexer.NextToken();
			Expect(20);
			ResourceAcquisition(
#line  1640 "cs.ATG" 
out pointerDeclarationStmt);
			Expect(21);
			EmbeddedStatement(
#line  1641 "cs.ATG" 
out embeddedStatement);

#line  1641 "cs.ATG" 
			statement = new FixedStatement(pointerDeclarationStmt, embeddedStatement); 
		} else SynErr(201);

#line  1643 "cs.ATG" 
		if (statement != null) {
		statement.StartLocation = startLocation;
		statement.EndLocation = t.EndLocation;
		}
		
	}
Esempio n. 8
0
            public override object VisitForStatement(ForStatement forStatement, object data)
            {
                UnlockWith(forStatement);

                return base.VisitForStatement(forStatement, data);
            }
Esempio n. 9
0
        public override object VisitForStatement(ForStatement forStatement, object data)
        {
            base.VisitForStatement(forStatement, data);

            // Restore loop initializer
            if (forStatement.Initializers.Count == 0) {
                LocalVariableDeclaration varDeclr = forStatement.Previous() as LocalVariableDeclaration;
                if (varDeclr != null) {
                    varDeclr.ReplaceWith(Statement.Null);
                    forStatement.Initializers.Add(varDeclr);
                }
            }

            // Restore loop condition
            if (forStatement.Condition.IsNull &&
                forStatement.EmbeddedStatement.Children.Count >= 3)
            {
                IfElseStatement  condition = forStatement.EmbeddedStatement.Children[0] as IfElseStatement;
                BreakStatement   breakStmt = forStatement.EmbeddedStatement.Children[1] as BreakStatement;
                LabelStatement   label     = forStatement.EmbeddedStatement.Children[2] as LabelStatement;
                if (condition != null && breakStmt != null && label != null &&
                    condition.TrueStatement.Count == 1)
                {
                    GotoStatement gotoStmt = condition.TrueStatement[0] as GotoStatement;
                    if (gotoStmt != null && gotoStmt.Label == label.Label) {
                        condition.Remove();
                        breakStmt.Remove();
                        forStatement.Condition = condition.Condition;
                    }
                }
            }

            // Restore loop condition (version 2)
            if (forStatement.Condition.IsNull) {
                IfElseStatement condition = forStatement.EmbeddedStatement.Children.First as IfElseStatement;
                if (condition != null &&
                    condition.TrueStatement.Count == 1 &&
                    condition.TrueStatement[0] is BlockStatement &&
                    condition.TrueStatement[0].Children.Count == 1 &&
                    condition.TrueStatement[0].Children.First is BreakStatement &&
                    condition.FalseStatement.Count == 1 &&
                    condition.FalseStatement[0] is BlockStatement &&
                    condition.FalseStatement[0].Children.Count == 0)
                {
                    condition.Remove();
                    forStatement.Condition = new UnaryOperatorExpression(condition.Condition, UnaryOperatorType.Not);
                }
            }

            // Restore loop iterator
            if (forStatement.EmbeddedStatement.Children.Count > 0 &&
                forStatement.Iterator.Count == 0)
            {
                ExpressionStatement lastStmt = forStatement.EmbeddedStatement.Children.Last as ExpressionStatement;
                if (lastStmt != null &&
                    (lastStmt.Expression is AssignmentExpression || lastStmt.Expression is UnaryOperatorExpression)) {
                    lastStmt.Remove();
                    forStatement.Iterator.Add(lastStmt);
                }
            }

            return null;
        }
Esempio n. 10
0
 public override object VisitForStatement(ForStatement forStatement, object data)
 {
     forStatement.Condition.Parent = forStatement;
     forStatement.EmbeddedStatement.Parent = forStatement;
     foreach (Statement statement in forStatement.Initializers)
         statement.Parent = forStatement;
     foreach (Statement iterator in forStatement.Iterator)
         iterator.Parent = forStatement;
     return base.VisitForStatement(forStatement, data);
 }
 private bool IsMatch(ForStatement left, ForStatement data)
 {
     return true;
 }
Esempio n. 12
0
 public override object VisitForStatement(ForStatement forStatement, object data)
 {
     enteredLoops.Push(forStatement);
     base.VisitForStatement(forStatement, data);
     enteredLoops.Pop();
     return null;
 }
		public override object VisitForStatement(ForStatement forStatement, object data)
		{
			CodeIterationStatement forLoop = new CodeIterationStatement();
			
			if (forStatement.Initializers.Count > 0)  {
				if (forStatement.Initializers.Count > 1) {
					throw new NotSupportedException("CodeDom does not support Multiple For-Loop Initializer Statements");
				}
				
				foreach (object o in forStatement.Initializers) {
					if (o is Expression) {
						forLoop.InitStatement = new CodeExpressionStatement((CodeExpression)((Expression)o).AcceptVisitor(this,data));
					}
					if (o is Statement) {
						codeStack.Push(NullStmtCollection);
						forLoop.InitStatement = (CodeStatement)((Statement)o).AcceptVisitor(this, data);
						codeStack.Pop();
					}
				}
			}
			
			if (forStatement.Condition == null) {
				forLoop.TestExpression = new CodePrimitiveExpression(true);
			} else {
				forLoop.TestExpression = (CodeExpression)forStatement.Condition.AcceptVisitor(this, data);
			}
			
			codeStack.Push(forLoop.Statements);
			forStatement.EmbeddedStatement.AcceptVisitor(this, data);
			codeStack.Pop();
			
			if (forStatement.Iterator.Count > 0) {
				if (forStatement.Initializers.Count > 1) {
					throw new NotSupportedException("CodeDom does not support Multiple For-Loop Iterator Statements");
				}
				
				foreach (Statement stmt in forStatement.Iterator) {
					forLoop.IncrementStatement = (CodeStatement)stmt.AcceptVisitor(this, data);
				}
			}
			
			AddStmt(forLoop);
			
			return forLoop;
		}
Esempio n. 14
0
 public override object VisitForStatement(ForStatement forStatement, object data)
 {
     forStatement.Condition = Deparenthesize(forStatement.Condition);
     return base.VisitForStatement(forStatement, data);
 }
		/// <summary>
		/// Converts from an NRefactory for loop:
		/// 
		/// for (int i = 0; i &lt; 5; i = i + 1)
		/// 
		/// to Python's:
		/// 
		/// i = 0
		/// while i &lt; 5:
		/// </summary>
		public override object TrackedVisitForStatement(ForStatement forStatement, object data)
		{
			// Convert the for loop's initializers.
			foreach (Statement statement in forStatement.Initializers) {
				statement.AcceptVisitor(this, data);
			}

			// Convert the for loop's test expression.
			AppendIndented("while ");
			forStatement.Condition.AcceptVisitor(this, data);
			Append(":");
			AppendLine();
			
			// Visit the for loop's body.
			IncreaseIndent();
			forStatement.EmbeddedStatement.AcceptVisitor(this, data);
			
			// Convert the for loop's increment statement.
			foreach (Statement statement in forStatement.Iterator) {
				statement.AcceptVisitor(this, data);
			}
			DecreaseIndent();
			
			return null;
		}
		public override object VisitForStatement(ForStatement forStatement, object data)
		{
			return base.VisitForStatement(forStatement, true);
		}
        void ConvertForStatement(ForStatement forStatement)
        {
            //   ForStatement -> ForNextStatement when for-loop is simple

            // only the following forms of the for-statement are allowed:
            // for (TypeReference name = start; name < oneAfterEnd; name += step)
            // for (name = start; name < oneAfterEnd; name += step)
            // for (TypeReference name = start; name <= end; name += step)
            // for (name = start; name <= end; name += step)
            // for (TypeReference name = start; name > oneAfterEnd; name -= step)
            // for (name = start; name > oneAfterEnd; name -= step)
            // for (TypeReference name = start; name >= end; name -= step)
            // for (name = start; name >= end; name -= step)

            // check if the form is valid and collect TypeReference, name, start, end and step
            if (forStatement.Initializers.Count != 1)
                return;
            if (forStatement.Iterator.Count != 1)
                return;
            ExpressionStatement statement = forStatement.Iterator[0] as ExpressionStatement;
            if (statement == null)
                return;
            AssignmentExpression iterator = statement.Expression as AssignmentExpression;
            if (iterator == null || (iterator.Op != AssignmentOperatorType.Add && iterator.Op != AssignmentOperatorType.Subtract))
                return;
            IdentifierExpression iteratorIdentifier = iterator.Left as IdentifierExpression;
            if (iteratorIdentifier == null)
                return;
            PrimitiveExpression stepExpression = iterator.Right as PrimitiveExpression;
            if (stepExpression == null || !(stepExpression.Value is int))
                return;
            int step = (int)stepExpression.Value;
            if (iterator.Op == AssignmentOperatorType.Subtract)
                step = -step;

            BinaryOperatorExpression condition = forStatement.Condition as BinaryOperatorExpression;
            if (condition == null || !(condition.Left is IdentifierExpression))
                return;
            if ((condition.Left as IdentifierExpression).Identifier != iteratorIdentifier.Identifier)
                return;
            Expression end;
            if (iterator.Op == AssignmentOperatorType.Subtract) {
                if (condition.Op == BinaryOperatorType.GreaterThanOrEqual) {
                    end = condition.Right;
                } else if (condition.Op == BinaryOperatorType.GreaterThan) {
                    end = Expression.AddInteger(condition.Right, 1);
                } else {
                    return;
                }
            } else {
                if (condition.Op == BinaryOperatorType.LessThanOrEqual) {
                    end = condition.Right;
                } else if (condition.Op == BinaryOperatorType.LessThan) {
                    end = Expression.AddInteger(condition.Right, -1);
                } else {
                    return;
                }
            }

            Expression start;
            TypeReference typeReference = null;
            LocalVariableDeclaration varDecl = forStatement.Initializers[0] as LocalVariableDeclaration;
            if (varDecl != null) {
                if (varDecl.Variables.Count != 1
                    || varDecl.Variables[0].Name != iteratorIdentifier.Identifier
                    || varDecl.Variables[0].Initializer == null)
                    return;
                typeReference = varDecl.GetTypeForVariable(0);
                start = varDecl.Variables[0].Initializer;
            } else {
                statement = forStatement.Initializers[0] as ExpressionStatement;
                if (statement == null)
                    return;
                AssignmentExpression assign = statement.Expression as AssignmentExpression;
                if (assign == null || assign.Op != AssignmentOperatorType.Assign)
                    return;
                if (!(assign.Left is IdentifierExpression))
                    return;
                if ((assign.Left as IdentifierExpression).Identifier != iteratorIdentifier.Identifier)
                    return;
                start = assign.Right;
            }

            ReplaceCurrentNode(
                new ForNextStatement {
                    TypeReference = typeReference,
                    VariableName = iteratorIdentifier.Identifier,
                    Start = start,
                    End = end,
                    Step = (step == 1) ? null : new PrimitiveExpression(step, step.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)),
                    EmbeddedStatement = forStatement.EmbeddedStatement
                });
        }
 public virtual bool VisitForStatement(ForStatement forStatement, object d)
 {
     if ((forStatement == null)) {
         return SetFailure();
     }
     if ((d == null)) {
         return SetFailure();
     }
     if ((forStatement.Initializers == null)) {
         return SetFailure();
     }
     if ((forStatement.Condition == null)) {
         return SetFailure();
     }
     if ((forStatement.Iterator == null)) {
         return SetFailure();
     }
     if ((forStatement.EmbeddedStatement == null)) {
         return SetFailure();
     }
     if(forStatement.GetType() != d.GetType()) {return SetFailure();}
     var data = (ForStatement)d;
     if (!IsMatch(forStatement, data)) {
         return SetFailure();
     }
     if (forStatement.Initializers.Count == data.Initializers.Count) {
     for (int i=0; i<forStatement.Initializers.Count;i++) {
         Statement o = forStatement.Initializers[i];
         if(o == null){return SetFailure();}
         if((bool)o.AcceptVisitor(this, data.Initializers[i]) == false) return SetFailure();
     }			}			else { return SetFailure(); }
     forStatement.Condition.AcceptVisitor(this, data.Condition);
     if (forStatement.Iterator.Count == data.Iterator.Count) {
     for (int i=0; i<forStatement.Iterator.Count;i++) {
         Statement o = forStatement.Iterator[i];
         if(o == null){return SetFailure();}
         if((bool)o.AcceptVisitor(this, data.Iterator[i]) == false) return SetFailure();
     }			}			else { return SetFailure(); }
     return forStatement.EmbeddedStatement.AcceptVisitor(this, data.EmbeddedStatement);
 }
Esempio n. 19
0
        public override object VisitForStatement(ForStatement forStatement, object data)
        {
            CodeIterationStatement forLoop = new CodeIterationStatement();
            breakableStack.Push(new Breakable());

            codeStack.Push(NullStmtCollection);

            if (forStatement.Initializers.Count > 0)
            {
                if (forStatement.Initializers.Count > 1)
                {
                    throw new NotSupportedException("CodeDom does not support Multiple For-Loop Initializer Statements");
                }

                foreach (object o in forStatement.Initializers)
                {
                    if (o is Expression)
                    {
                        forLoop.InitStatement = new CodeExpressionStatement((CodeExpression)((Expression)o).AcceptVisitor(this, data));
                    }
                    if (o is Statement)
                    {
                        forLoop.InitStatement = (CodeStatement)((Statement)o).AcceptVisitor(this, data);
                    }
                }
            }
            else
            {
                // RG: need to handle empty InitStatement
                forLoop.InitStatement = new CodeExpressionStatement(new CodeSnippetExpression());
            }

            if (forStatement.Condition == null) {
                forLoop.TestExpression = new CodePrimitiveExpression(true);
            } else {
                forLoop.TestExpression = (CodeExpression)forStatement.Condition.AcceptVisitor(this, data);
            }

            codeStack.Push(forLoop.Statements);
            forStatement.EmbeddedStatement.AcceptVisitor(this, data);
            codeStack.Pop();

            if (forStatement.Iterator.Count > 0)
            {
                if (forStatement.Initializers.Count > 1)
                {
                    throw new NotSupportedException("CodeDom does not support Multiple For-Loop Iterator Statements");
                }

                foreach (Statement stmt in forStatement.Iterator)
                {
                    forLoop.IncrementStatement = (CodeStatement)stmt.AcceptVisitor(this, data);
                }
            }
            else
            {
                // RG: need to handle empty IncrementStatement
                forLoop.IncrementStatement = new CodeExpressionStatement(new CodeSnippetExpression());
            }

            codeStack.Pop();

            Breakable breakable = breakableStack.Pop();

            if (breakable.IsContinue)
            {
                forLoop.Statements.Add(new CodeSnippetStatement());
                forLoop.Statements.Add(new CodeLabeledStatement("continue" + breakable.Id, new CodeExpressionStatement(new CodeSnippetExpression())));
            }

            AddStmt(forLoop);

            if (breakable.IsBreak)
            {
                AddStmt(new CodeLabeledStatement("break" + breakable.Id, new CodeExpressionStatement(new CodeSnippetExpression())));
            }

            return forLoop;
        }
			public void VisitStatement (ForStatement statement, MethodProperties meth)
			{
				meth.CyclometricComplexity++;
				VisitExpression(statement.Condition, meth);
				
				foreach(var innerStatement in ((ForStatement)statement).EmbeddedStatement.Children)
					VisitStatement(innerStatement, meth);
			}
		public override object VisitForStatement(ForStatement forStatement, object data)
		{
			// uses LocalVariableDeclaration, we just have to put the end location on the stack
			if (forStatement.EmbeddedStatement.EndLocation.IsEmpty) {
				return base.VisitForStatement(forStatement, data);
			} else {
				endLocationStack.Push(forStatement.EmbeddedStatement.EndLocation);
				base.VisitForStatement(forStatement, data);
				endLocationStack.Pop();
				return null;
			}
		}
 public object VisitForStatement(ForStatement forStatement, object data)
 {
     throw new NotImplementedException ();
 }
		public virtual object TrackedVisitForStatement(ForStatement forStatement, object data) {
			return base.VisitForStatement(forStatement, data);
		}
Esempio n. 24
0
 public virtual object VisitForStatement(ForStatement forStatement, object data)
 {
     Debug.Assert((forStatement != null));
     Debug.Assert((forStatement.Initializers != null));
     Debug.Assert((forStatement.Condition != null));
     Debug.Assert((forStatement.Iterator != null));
     Debug.Assert((forStatement.EmbeddedStatement != null));
     foreach (Statement o in forStatement.Initializers) {
         Debug.Assert(o != null);
         o.AcceptVisitor(this, data);
     }
     forStatement.Condition.AcceptVisitor(this, data);
     foreach (Statement o in forStatement.Iterator) {
         Debug.Assert(o != null);
         o.AcceptVisitor(this, data);
     }
     return forStatement.EmbeddedStatement.AcceptVisitor(this, data);
 }
 public override object TrackedVisitForStatement(ForStatement forStatement, object data)
 {
     foreach (Statement initializer in forStatement.Initializers)
     {
         initializer.AcceptVisitor(this, data);
     }
     this.AppendIndented("while ");
     forStatement.Condition.AcceptVisitor(this, data);
     this.Append(":");
     this.AppendLine();
     this.IncreaseIndent();
     forStatement.EmbeddedStatement.AcceptVisitor(this, data);
     foreach (Statement iterator in forStatement.Iterator)
     {
         iterator.AcceptVisitor(this, data);
     }
     this.DecreaseIndent();
     return null;
 }
Esempio n. 26
0
	void EmbeddedStatement(
#line  1473 "cs.ATG" 
out Statement statement) {

#line  1475 "cs.ATG" 
		TypeReference type = null;
		Expression expr = null;
		Statement embeddedStatement = null;
		statement = null;
		

#line  1481 "cs.ATG" 
		Location startLocation = la.Location; 
		if (la.kind == 16) {
			Block(
#line  1483 "cs.ATG" 
out statement);
		} else if (la.kind == 11) {
			lexer.NextToken();

#line  1486 "cs.ATG" 
			statement = new EmptyStatement(); 
		} else if (
#line  1489 "cs.ATG" 
UnCheckedAndLBrace()) {

#line  1489 "cs.ATG" 
			Statement block; bool isChecked = true; 
			if (la.kind == 58) {
				lexer.NextToken();
			} else if (la.kind == 118) {
				lexer.NextToken();

#line  1490 "cs.ATG" 
				isChecked = false;
			} else SynErr(196);
			Block(
#line  1491 "cs.ATG" 
out block);

#line  1491 "cs.ATG" 
			statement = isChecked ? (Statement)new CheckedStatement(block) : (Statement)new UncheckedStatement(block); 
		} else if (la.kind == 79) {
			IfStatement(
#line  1494 "cs.ATG" 
out statement);
		} else if (la.kind == 110) {
			lexer.NextToken();

#line  1496 "cs.ATG" 
			List<SwitchSection> switchSections = new List<SwitchSection>(); 
			Expect(20);
			Expr(
#line  1497 "cs.ATG" 
out expr);
			Expect(21);
			Expect(16);
			SwitchSections(
#line  1498 "cs.ATG" 
switchSections);
			Expect(17);

#line  1499 "cs.ATG" 
			statement = new SwitchStatement(expr, switchSections); 
		} else if (la.kind == 125) {
			lexer.NextToken();
			Expect(20);
			Expr(
#line  1502 "cs.ATG" 
out expr);
			Expect(21);
			EmbeddedStatement(
#line  1503 "cs.ATG" 
out embeddedStatement);

#line  1504 "cs.ATG" 
			statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start);
		} else if (la.kind == 65) {
			lexer.NextToken();
			EmbeddedStatement(
#line  1506 "cs.ATG" 
out embeddedStatement);
			Expect(125);
			Expect(20);
			Expr(
#line  1507 "cs.ATG" 
out expr);
			Expect(21);
			Expect(11);

#line  1508 "cs.ATG" 
			statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.End); 
		} else if (la.kind == 76) {
			lexer.NextToken();

#line  1510 "cs.ATG" 
			List<Statement> initializer = null; List<Statement> iterator = null; 
			Expect(20);
			if (StartOf(6)) {
				ForInitializer(
#line  1511 "cs.ATG" 
out initializer);
			}
			Expect(11);
			if (StartOf(6)) {
				Expr(
#line  1512 "cs.ATG" 
out expr);
			}
			Expect(11);
			if (StartOf(6)) {
				ForIterator(
#line  1513 "cs.ATG" 
out iterator);
			}
			Expect(21);
			EmbeddedStatement(
#line  1514 "cs.ATG" 
out embeddedStatement);

#line  1514 "cs.ATG" 
			statement = new ForStatement(initializer, expr, iterator, embeddedStatement); 
		} else if (la.kind == 77) {
			lexer.NextToken();
			Expect(20);
			Type(
#line  1516 "cs.ATG" 
out type);
			Identifier();

#line  1516 "cs.ATG" 
			string varName = t.val; 
			Expect(81);
			Expr(
#line  1517 "cs.ATG" 
out expr);
			Expect(21);
			EmbeddedStatement(
#line  1518 "cs.ATG" 
out embeddedStatement);

#line  1519 "cs.ATG" 
			statement = new ForeachStatement(type, varName , expr, embeddedStatement); 
		} else if (la.kind == 53) {
			lexer.NextToken();
			Expect(11);

#line  1522 "cs.ATG" 
			statement = new BreakStatement(); 
		} else if (la.kind == 61) {
			lexer.NextToken();
			Expect(11);

#line  1523 "cs.ATG" 
			statement = new ContinueStatement(); 
		} else if (la.kind == 78) {
			GotoStatement(
#line  1524 "cs.ATG" 
out statement);
		} else if (
#line  1526 "cs.ATG" 
IsYieldStatement()) {
			Expect(132);
			if (la.kind == 101) {
				lexer.NextToken();
				Expr(
#line  1527 "cs.ATG" 
out expr);

#line  1527 "cs.ATG" 
				statement = new YieldStatement(new ReturnStatement(expr)); 
			} else if (la.kind == 53) {
				lexer.NextToken();

#line  1528 "cs.ATG" 
				statement = new YieldStatement(new BreakStatement()); 
			} else SynErr(197);
			Expect(11);
		} else if (la.kind == 101) {
			lexer.NextToken();
			if (StartOf(6)) {
				Expr(
#line  1531 "cs.ATG" 
out expr);
			}
			Expect(11);

#line  1531 "cs.ATG" 
			statement = new ReturnStatement(expr); 
		} else if (la.kind == 112) {
			lexer.NextToken();
			if (StartOf(6)) {
				Expr(
#line  1532 "cs.ATG" 
out expr);
			}
			Expect(11);

#line  1532 "cs.ATG" 
			statement = new ThrowStatement(expr); 
		} else if (StartOf(6)) {
			StatementExpr(
#line  1535 "cs.ATG" 
out statement);
			while (!(la.kind == 0 || la.kind == 11)) {SynErr(198); lexer.NextToken(); }
			Expect(11);
		} else if (la.kind == 114) {
			TryStatement(
#line  1538 "cs.ATG" 
out statement);
		} else if (la.kind == 86) {
			lexer.NextToken();
			Expect(20);
			Expr(
#line  1541 "cs.ATG" 
out expr);
			Expect(21);
			EmbeddedStatement(
#line  1542 "cs.ATG" 
out embeddedStatement);

#line  1542 "cs.ATG" 
			statement = new LockStatement(expr, embeddedStatement); 
		} else if (la.kind == 121) {

#line  1545 "cs.ATG" 
			Statement resourceAcquisitionStmt = null; 
			lexer.NextToken();
			Expect(20);
			ResourceAcquisition(
#line  1547 "cs.ATG" 
out resourceAcquisitionStmt);
			Expect(21);
			EmbeddedStatement(
#line  1548 "cs.ATG" 
out embeddedStatement);

#line  1548 "cs.ATG" 
			statement = new UsingStatement(resourceAcquisitionStmt, embeddedStatement); 
		} else if (la.kind == 119) {
			lexer.NextToken();
			Block(
#line  1551 "cs.ATG" 
out embeddedStatement);

#line  1551 "cs.ATG" 
			statement = new UnsafeStatement(embeddedStatement); 
		} else if (la.kind == 74) {
			lexer.NextToken();
			Expect(20);
			Type(
#line  1554 "cs.ATG" 
out type);

#line  1554 "cs.ATG" 
			if (type == null || type.PointerNestingLevel == 0) Error("can only fix pointer types");
			List<VariableDeclaration> pointerDeclarators = new List<VariableDeclaration>(1);
			
			Identifier();

#line  1557 "cs.ATG" 
			string identifier = t.val; 
			Expect(3);
			Expr(
#line  1558 "cs.ATG" 
out expr);

#line  1558 "cs.ATG" 
			pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); 
			while (la.kind == 14) {
				lexer.NextToken();
				Identifier();

#line  1560 "cs.ATG" 
				identifier = t.val; 
				Expect(3);
				Expr(
#line  1561 "cs.ATG" 
out expr);

#line  1561 "cs.ATG" 
				pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); 
			}
			Expect(21);
			EmbeddedStatement(
#line  1563 "cs.ATG" 
out embeddedStatement);

#line  1563 "cs.ATG" 
			statement = new FixedStatement(type, pointerDeclarators, embeddedStatement); 
		} else SynErr(199);

#line  1565 "cs.ATG" 
		if (statement != null) {
		statement.StartLocation = startLocation;
		statement.EndLocation = t.EndLocation;
		}
		
	}