private bool IsSingleIfStatement(List<AbsynStatement> stms, out AbsynIf elseIf) { elseIf = null; if (stms.Count != 1) return false; elseIf = stms[0] as AbsynIf; return elseIf != null; }
private void WriteIf(AbsynIf ifs) { writer.WriteKeyword("if"); writer.Write(" ("); WriteExpression(ifs.Condition); writer.Write(")"); writer.Terminate(); WriteIndentedStatements(ifs.Then, false); if (ifs.Else != null && ifs.Else.Count > 0) { writer.Indent(); writer.WriteKeyword("else"); AbsynIf elseIf; if (IsSingleIfStatement(ifs.Else, out elseIf)) { writer.Write(" "); WriteIf(elseIf); } else { writer.Terminate(); WriteIndentedStatements(ifs.Else, false); } } }
public void VisitIf(AbsynIf ifStm) { stms.Add(ifStm); }
public void VisitIf(AbsynIf ifs) { writer.Indent(); WriteIf(ifs); }
private AbsynIf EmitIfCondition(Expression exp, Conditional cond, AbsynStatementEmitter emitter) { if (cond is IfElse || cond is IfThenElse) { exp = exp.Invert(); } AbsynIf ifStm = new AbsynIf(); ifStm.Condition = exp; emitter.EmitStatement(ifStm); return ifStm; }