public override INode DoResolve(ResolveContext rc) { Label lb = rc.DefineLabel(LabelType.IF); ExitIf = rc.DefineLabel(lb.Name + "_EXIT"); Else = rc.DefineLabel(lb.Name + "_ELSE"); ParentIf = rc.EnclosingIf; rc.EnclosingIf = this; rc.CreateNewState(); rc.CurrentGlobalScope |= ResolveScopes.If; // enter if Expression = (Expression)Expression.DoResolve(rc); TrueStatement = (Statement)TrueStatement.DoResolve(rc); FalseStatement = (Statement)FalseStatement.DoResolve(rc); if (Expression.IsVoid) { ResolveContext.Report.Error(3, Location, "cannot evaluate void type in if statement"); } rc.RestoreOldState(); // exit current if rc.EnclosingIf = ParentIf; return(base.DoResolve(rc)); }
/// <summary> /// Emit code /// </summary> /// <returns>Success or fail</returns> public override bool Emit(EmitContext ec) { if (Expression is IntegralExpression) { EmitIfConstant(ec); } else { // emit expression branchable ec.EmitComment("if-expression evaluation"); Expression.EmitBranchable(ec, Else, false); ec.EmitComment("(" + Expression.CommentString() + ") is true"); TrueStatement.Emit(ec); ec.EmitInstruction(new Jump() { DestinationLabel = ExitIf.Name }); ec.MarkLabel(Else); ec.EmitComment("Else "); FalseStatement.Emit(ec); ec.MarkLabel(ExitIf); } return(true); }