public override void Emit(CodeWriter writer) { Condition.Emit(writer); var endLabel = new Label(); if (this.FalseBody == null) { // single body writer.JumpWhenFalse(endLabel); TrueBody.Emit(writer); } else { // double body var falseLabel = new Label(); writer.JumpWhenFalse(falseLabel); TrueBody.Emit(writer); writer.Jump(endLabel); writer.DefineLabel(falseLabel); FalseBody.Emit(writer); } writer.DefineLabel(endLabel); }
public override string WriteLua(int indentLevel) { StringBuilder str = new StringBuilder(); if (IsElseIf) { str.Append($"elseif {Condition} then\n"); } else { str.Append($"if {Condition} then\n"); } if (TrueBody != null) { str.Append(TrueBody.PrintBlock(indentLevel).AddIndent()); } if (FalseBody != null) { str.Append("\n"); // Check for elseif if (FalseBody.Instructions.Count() == 1 && FalseBody.Instructions.First() is IfStatement s && s.Follow == null) { s.IsElseIf = true; str.Append(FalseBody.PrintBlock(indentLevel)); } else { for (int i = 0; i < indentLevel; i++) { str.Append("\t"); } str.Append("else\n"); str.Append(FalseBody.PrintBlock(indentLevel).AddIndent()); } }
public override void Compile(sunCompiler compiler) { Condition.Compile(compiler); var falsePrologue = new sunJumpNotEqualSite(compiler.Binary); TrueBody.Compile(compiler); var trueEpilogue = new sunJumpSite(compiler.Binary); falsePrologue.Relocate(); FalseBody.Compile(compiler); trueEpilogue.Relocate(); }
public override void Compile(sunCompiler compiler) { Condition.Compile(compiler); var trueBodyEpilogue = new sunJumpNotEqualSite(compiler.Binary); TrueBody.Compile(compiler); var falseBody = FalseBody; if (falseBody != null) { var falseBodyEpilogue = new sunJumpSite(compiler.Binary); trueBodyEpilogue.Relocate(); falseBody.Compile(compiler); falseBodyEpilogue.Relocate(); } else { trueBodyEpilogue.Relocate(); } }
sunExpressionFlags sunTerm.GetExpressionFlags(sunContext context) { return(Condition.Analyze(context) | TrueBody.Analyze(context) | FalseBody.Analyze(context)); }
public override string ToString() { return($"if ({Condition.ToString()}) {TrueBody.ToString()}"); }