2
/* **********************************************************************************
3
* Copyright (c) Roman Ivantsov
4
* This source code is subject to terms and conditions of the MIT License
5
* for Irony. A copy of the license can be found in the License.txt file
6
* at the root of this distribution.
7
* By using this source code in any fashion, you are agreeing to be bound by the terms of the
9
* You must not remove this notice from this software.
10
* **********************************************************************************/
14
using System.Collections.Generic;
16
using Irony.Scripting.Runtime;
18
namespace Irony.Scripting.Ast {
19
public class IfNode : AstNode {
21
public AstNode IfTrue;
22
public AstNode IfFalse;
24
public IfNode(NodeArgs args, AstNode test, AstNode ifTrue, AstNode ifFalse): base(args) {
28
AddChild("Test", Test);
33
AddChild("IfTrue", IfTrue);
36
if (IfFalse.IsEmpty()) IfFalse = null;
37
AddChild("IfFalse", IfFalse);
40
public override void OnCodeAnalysis(CodeAnalysisArgs args) {
42
case CodeAnalysisPhase.MarkTailCalls:
43
if (IsSet(AstNodeFlags.IsTail)) {
45
IfTrue.Flags |= AstNodeFlags.IsTail;
47
IfFalse.Flags |= AstNodeFlags.IsTail;
51
base.OnCodeAnalysis(args);
54
protected override void DoEvaluate(EvaluationContext context) {
55
Test.Evaluate(context);
56
if (context.Runtime.IsTrue(context.CurrentResult)) {
57
if (IfTrue != null) IfTrue.Evaluate(context);
59
if (IfFalse != null) IfFalse.Evaluate(context);