CLanguage by praeclarum

<PackageReference Include="CLanguage" Version="0.5.26" />

 IfStatement

public class IfStatement : Statement
using CLanguage.Interpreter; using System; namespace CLanguage.Syntax { public class IfStatement : Statement { public Expression Condition { get; set; } public Statement TrueStatement { get; set; } public Statement FalseStatement { get; set; } public override bool AlwaysReturns { get { bool alwaysReturns = TrueStatement.AlwaysReturns; bool flag = FalseStatement != null && FalseStatement.AlwaysReturns; return alwaysReturns & flag; } } public IfStatement(Expression condition, Statement trueStatement, Statement falseStatement, Location loc) { if (condition == null) throw new ArgumentNullException("condition"); if (trueStatement == null) throw new ArgumentNullException("trueStatement"); Condition = condition; TrueStatement = trueStatement; FalseStatement = falseStatement; base.Location = loc; } public IfStatement(Expression condition, Statement trueStatement, Location loc) { if (condition == null) throw new ArgumentNullException("condition"); if (trueStatement == null) throw new ArgumentNullException("trueStatement"); Condition = condition; TrueStatement = trueStatement; FalseStatement = null; base.Location = loc; } protected override void DoEmit(EmitContext ec) { Label label = ec.DefineLabel(); Condition.Emit(ec); ec.EmitCastToBoolean(Condition.GetEvaluatedCType(ec)); if (FalseStatement == null) { ec.Emit(OpCode.BranchIfFalse, label); TrueStatement.Emit(ec); } else { Label label2 = ec.DefineLabel(); ec.Emit(OpCode.BranchIfFalse, label2); TrueStatement.Emit(ec); ec.Emit(OpCode.Jump, label); ec.EmitLabel(label2); FalseStatement.Emit(ec); } ec.EmitLabel(label); } public override string ToString() { return $"""{Condition}""{TrueStatement}"""; } } }