~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Misc/Reports/Irony/Scripting/AST/IfNode.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#region License
 
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 
 
8
 * MIT License.
 
9
 * You must not remove this notice from this software.
 
10
 * **********************************************************************************/
 
11
#endregion
 
12
 
 
13
using System;
 
14
using System.Collections.Generic;
 
15
using System.Text;
 
16
using Irony.Scripting.Runtime;
 
17
 
 
18
namespace Irony.Scripting.Ast {
 
19
  public class IfNode : AstNode {
 
20
    public AstNode Test;
 
21
    public AstNode IfTrue;
 
22
    public AstNode IfFalse;
 
23
 
 
24
    public IfNode(NodeArgs args, AstNode test, AstNode ifTrue, AstNode ifFalse): base(args) {
 
25
      ChildNodes.Clear();
 
26
 
 
27
      Test = test;
 
28
      AddChild("Test", Test);
 
29
      
 
30
      IfTrue = ifTrue;
 
31
      if (IfTrue.IsEmpty()) 
 
32
        IfTrue = null;
 
33
      AddChild("IfTrue", IfTrue);
 
34
 
 
35
      IfFalse = ifFalse;
 
36
      if (IfFalse.IsEmpty()) IfFalse = null;
 
37
      AddChild("IfFalse", IfFalse);
 
38
    }
 
39
 
 
40
    public override void OnCodeAnalysis(CodeAnalysisArgs args) {
 
41
      switch (args.Phase) {
 
42
        case CodeAnalysisPhase.MarkTailCalls:
 
43
          if (IsSet(AstNodeFlags.IsTail)) {
 
44
            if (IfTrue != null)
 
45
              IfTrue.Flags |= AstNodeFlags.IsTail;
 
46
            if (IfFalse != null)
 
47
              IfFalse.Flags |= AstNodeFlags.IsTail;
 
48
          }
 
49
          break;
 
50
      }
 
51
      base.OnCodeAnalysis(args);
 
52
    }
 
53
 
 
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);
 
58
      } else {
 
59
        if (IfFalse != null)   IfFalse.Evaluate(context);
 
60
      }
 
61
    }
 
62
  }//class
 
63
 
 
64
}//namespace