public ForStatement (Statement initializer, Expression condition, Statement increment, BlockStatement body) { this.initializer = initializer; this.condition = condition; this.increment = increment; this.body = body; }
public void EmitStatement(Statement node, int si) { switch (node.CodeNodeType) { case CodeNodeType.ReturnStatement: EmitReturnStatement((ReturnStatement)node, si); break; case CodeNodeType.ExpressionStatement: EmitExpressionStatement((ExpressionStatement)node, si); break; default: Helper.NotSupported(); break; } }
public abstract void Write (Statement statement);
void VisitExpressionStatementExpression (Statement statement) { var expression_statement = statement as ExpressionStatement; if (expression_statement == null) throw new ArgumentException (); Visit (expression_statement.Expression); }
public override void Write (Statement statement) { Visit (statement); WriteLine (); }
void Add (Statement statement) { if (statement == null) throw new ArgumentNullException ("statement"); var block_statements = GetOrCreateStatementListAt (current_block.Index); if (current_label != null) { var label = new LabeledStatement (current_label); current_label = null; block_statements.Add (label); } block_statements.Add (statement); }
void AddLoop (Instruction instruction, Statement loop, BlockStatement body) { var data = annotations.GetData<LoopData> (instruction); MoveStatementsToBlock (data.Body, body); Add (loop); }
public override void VisitExpressionStatement (ExpressionStatement node) { switch (state) { case State.Begin: if (!TryGetAssignedVariable (node, out variable)) break; initializer = node; state = State.Initializer; return; case State.Condition: VariableReference candidate; if (!TryGetAssignedVariable (node, out candidate)) break; if (variable != candidate) break; state = State.Increment; increment = node; Match = true; break; } Continue = false; }
private bool VisitExpressionStatement (Statement node) { var expression_statement = node as ExpressionStatement; if (expression_statement == null) return false; switch (state) { case State.Begin: case State.WhileBody: if (!VisitAssignExpression (expression_statement.Expression)) return false; break; case State.IfBody: if (!VisitMethodInvocationExpression (expression_statement.Expression)) return false; break; } return true; }
public ForeachMatcher (Statement statement, Statement next_statement) { this.statement = statement; this.next_statement = next_statement; }
bool VisitWhileStatement (Statement node) { var while_statement = node as WhileStatement; if (while_statement == null || while_statement.Body.Statements.Count < 1) return false; state = State.WhileCondition; if (!VisitMethodInvocationExpression (while_statement.Condition)) return false; state = State.WhileBody; if (!VisitExpressionStatement (while_statement.Body.Statements [0])) return false; this.while_body = new BlockStatement (); for (int i = 1; i < while_statement.Body.Statements.Count; i++) { this.while_body.Statements.Add (while_statement.Body.Statements [i]); } return true; }
bool VisitIfStatement (Statement statement) { var if_statement = statement as IfStatement; if (if_statement == null || if_statement.Else != null || if_statement.Then.Statements.Count != 1) return false; var binary_expression = if_statement.Condition as BinaryExpression; if (binary_expression == null || binary_expression.Operator != BinaryOperator.ValueInequality) return false; var enumerator_reference = binary_expression.Left as VariableReferenceExpression; if (enumerator_reference == null || !IsEnumerator (enumerator_reference)) return false; var null_literal = binary_expression.Right as LiteralExpression; if (null_literal == null || null_literal.Value != null) return false; state = State.IfBody; if (!VisitExpressionStatement (if_statement.Then.Statements [0])) return false; return true; }
bool VisitTryStatement (Statement node) { var try_statement = node as TryStatement; if (try_statement == null) return false; if (!IsValidTryStatement (try_statement)) return false; if (!VisitWhileStatement (try_statement.Try.Statements [0])) return false; if (!VisitIfStatement (try_statement.Finally.Statements [0])) return false; return true; }