public override object VisitForeachStatement(ForeachStatement foreachStatement, object data) { if (nameComparer.Equals(from, foreachStatement.VariableName)) { foreachStatement.VariableName = to; } return base.VisitForeachStatement(foreachStatement, data); }
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data) { curBlock.Add(foreachStatement.VariableName); return base.VisitForeachStatement(foreachStatement, data); }
public virtual object VisitForeachStatement(ForeachStatement foreachStatement, object data) { Debug.Assert((foreachStatement != null)); Debug.Assert((foreachStatement.TypeReference != null)); Debug.Assert((foreachStatement.Expression != null)); Debug.Assert((foreachStatement.NextExpression != null)); Debug.Assert((foreachStatement.EmbeddedStatement != null)); foreachStatement.TypeReference.AcceptVisitor(this, data); foreachStatement.Expression.AcceptVisitor(this, data); foreachStatement.NextExpression.AcceptVisitor(this, data); return foreachStatement.EmbeddedStatement.AcceptVisitor(this, data); }
public virtual object VisitForeachStatement(ForeachStatement foreachStatement, object data) { throw new global::System.NotImplementedException("ForeachStatement"); }
public virtual object VisitForeachStatement(ForeachStatement foreachStatement, object data) { Debug.Assert((foreachStatement != null)); Debug.Assert((foreachStatement.TypeReference != null)); Debug.Assert((foreachStatement.Expression != null)); Debug.Assert((foreachStatement.NextExpression != null)); Debug.Assert((foreachStatement.EmbeddedStatement != null)); nodeStack.Push(foreachStatement.TypeReference); foreachStatement.TypeReference.AcceptVisitor(this, data); foreachStatement.TypeReference = ((TypeReference)(nodeStack.Pop())); nodeStack.Push(foreachStatement.Expression); foreachStatement.Expression.AcceptVisitor(this, data); foreachStatement.Expression = ((Expression)(nodeStack.Pop())); nodeStack.Push(foreachStatement.NextExpression); foreachStatement.NextExpression.AcceptVisitor(this, data); foreachStatement.NextExpression = ((Expression)(nodeStack.Pop())); nodeStack.Push(foreachStatement.EmbeddedStatement); foreachStatement.EmbeddedStatement.AcceptVisitor(this, data); foreachStatement.EmbeddedStatement = ((Statement)(nodeStack.Pop())); return null; }
void ForStatement(out Statement statement) { Expression expr = null; Statement embeddedStatement; statement = null; Location startLocation = la.Location; Expect(124); Expression group = null; TypeReference typeReference; string typeName; if (la.kind == 110) { Get(); LoopControlVariable(out typeReference, out typeName); Expect(138); Expr(out group); EndOfStmt(); Block(out embeddedStatement); Expect(163); if (StartOf(24)) { Expr(out expr); } statement = new ForeachStatement(typeReference, typeName, group, embeddedStatement, expr); statement.StartLocation = startLocation; statement.EndLocation = t.EndLocation; } else if (StartOf(42)) { Expression start = null; Expression end = null; Expression step = null; Expression variableExpr = null; Expression nextExpr = null; List<Expression> nextExpressions = null; if (IsLoopVariableDeclaration()) { LoopControlVariable(out typeReference, out typeName); } else { typeReference = null; typeName = null; SimpleExpr(out variableExpr); } Expect(20); Expr(out start); Expect(216); Expr(out end); if (la.kind == 205) { Get(); Expr(out step); } EndOfStmt(); Block(out embeddedStatement); Expect(163); if (StartOf(24)) { Expr(out nextExpr); nextExpressions = new List<Expression>(); nextExpressions.Add(nextExpr); while (la.kind == 22) { Get(); Expr(out nextExpr); nextExpressions.Add(nextExpr); } } statement = new ForNextStatement { TypeReference = typeReference, VariableName = typeName, LoopVariableExpression = variableExpr, Start = start, End = end, Step = step, EmbeddedStatement = embeddedStatement, NextExpressions = nextExpressions }; } else SynErr(309); }
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data) { AddVariable(foreachStatement.TypeReference, foreachStatement.VariableName, foreachStatement.StartLocation, foreachStatement.EndLocation, false, true, foreachStatement.Expression, null, false); if (foreachStatement.Expression != null) { foreachStatement.Expression.AcceptVisitor(this, data); } if (foreachStatement.EmbeddedStatement == null) { return data; } return foreachStatement.EmbeddedStatement.AcceptVisitor(this, data); }
public virtual object TrackedVisitForeachStatement(ForeachStatement foreachStatement, object data) { return base.VisitForeachStatement(foreachStatement, data); }
public sealed override object VisitForeachStatement(ForeachStatement foreachStatement, object data) { this.BeginVisit(foreachStatement); object result = this.TrackedVisitForeachStatement(foreachStatement, data); this.EndVisit(foreachStatement); return result; }
int foreachId = 0; // in case of nested foreach statments public override object VisitForeachStatement(ForeachStatement foreachStatement, object data) { // RG: // foreach (T t in x) // { // stmts; // } // // Emulate with // // for (System.Collections.IEnumerator _it = x.GetEnumerator(); _it.MoveNext(); ) // { // T t = ((T)_it.Current); // // stmts; // } foreachId++; string name = "_it" + foreachId.ToString(); CodeIterationStatement _for1 = new CodeIterationStatement(); breakableStack.Push(new Breakable()); // init CodeVariableDeclarationStatement _decl2 = new CodeVariableDeclarationStatement(); CodeMethodInvokeExpression _invoke1 = new CodeMethodInvokeExpression(); CodeMethodReferenceExpression _GetEnumerator_method1 = new CodeMethodReferenceExpression(); _GetEnumerator_method1.MethodName = "GetEnumerator"; //CodeCastExpression _cast1 = new CodeCastExpression(); //codeStack.Push(NullStmtCollection); //_cast1.Expression = (CodeExpression)foreachStatement.Expression.AcceptVisitor(this, data); //codeStack.Pop(); //CodeTypeReference _IEnumerable_type1 = new CodeTypeReference("System.Collections.IEnumerable"); //_cast1.TargetType = _IEnumerable_type1; //_GetEnumerator_method1.TargetObject = _cast1; codeStack.Push(NullStmtCollection); _GetEnumerator_method1.TargetObject = (CodeExpression)foreachStatement.Expression.AcceptVisitor(this, data); codeStack.Pop(); _invoke1.Method = _GetEnumerator_method1; _decl2.InitExpression = _invoke1; _decl2.Name = name; CodeTypeReference _IEnumerator_type1 = new CodeTypeReference("System.Collections.IEnumerator"); _decl2.Type = _IEnumerator_type1; _for1.InitStatement = _decl2; // Condition CodeMethodInvokeExpression _invoke2 = new CodeMethodInvokeExpression(); CodeMethodReferenceExpression _MoveNext_method1 = new CodeMethodReferenceExpression(); _MoveNext_method1.MethodName = "MoveNext"; CodeVariableReferenceExpression _arg2 = new CodeVariableReferenceExpression(); _arg2.VariableName = name; _MoveNext_method1.TargetObject = _arg2; _invoke2.Method = _MoveNext_method1; _for1.TestExpression = _invoke2; // Empty Increment _for1.IncrementStatement = new CodeExpressionStatement(new CodeSnippetExpression()); // T t = ((T)_it.Current); CodeVariableDeclarationStatement _decl3 = new CodeVariableDeclarationStatement(); CodeCastExpression _cast2 = new CodeCastExpression(); CodePropertyReferenceExpression _prop1 = new CodePropertyReferenceExpression(); _prop1.PropertyName = "Current"; CodeVariableReferenceExpression _arg3 = new CodeVariableReferenceExpression(); _arg3.VariableName = name; _prop1.TargetObject = _arg3; _cast2.Expression = _prop1; CodeTypeReference _System_String_type5 = ConvType(foreachStatement.TypeReference); _cast2.TargetType = _System_String_type5; _decl3.InitExpression = _cast2; _decl3.Name = foreachStatement.VariableName; CodeTypeReference _System_String_type6 = ConvType(foreachStatement.TypeReference); _decl3.Type = _System_String_type6; _for1.Statements.Add(_decl3); _for1.Statements.Add(new CodeSnippetStatement()); codeStack.Push(_for1.Statements); foreachStatement.EmbeddedStatement.AcceptVisitor(this, data); codeStack.Pop(); Breakable breakable = breakableStack.Pop(); if (breakable.IsContinue) { _for1.Statements.Add(new CodeSnippetStatement()); _for1.Statements.Add(new CodeLabeledStatement("continue" + breakable.Id, new CodeExpressionStatement(new CodeSnippetExpression()))); } AddStmt(_for1); if (breakable.IsBreak) { AddStmt(new CodeLabeledStatement("break" + breakable.Id, new CodeExpressionStatement(new CodeSnippetExpression()))); } return _for1; }