Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ParadoxReplaceVisitor.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using SiliconStudio.Shaders.Ast;
4 using SiliconStudio.Shaders.Visitor;
5 
6 namespace SiliconStudio.Paradox.Shaders.Parser.Mixins
7 {
8  /// <summary>
9  /// Class to replace a node by another in an AST
10  /// </summary>
11  internal class ParadoxReplaceVisitor : ShaderVisitor
12  {
13  #region Private members
14 
15  /// <summary>
16  /// The node to replace
17  /// </summary>
18  protected Node nodeToReplace;
19 
20  /// <summary>
21  /// the replacement node
22  /// </summary>
23  protected Node replacementNode;
24 
25  /// <summary>
26  /// a boolean stating that the operation is complete
27  /// </summary>
28  protected bool complete = false;
29 
30  #endregion
31 
32  #region Constructor
33 
34  public ParadoxReplaceVisitor(Node toReplace, Node replacement) : base(false, false)
35  {
36  nodeToReplace = toReplace;
37  replacementNode = replacement;
38  }
39 
40  #endregion
41 
42  #region Public method
43 
44  public bool Run(Node startNode)
45  {
46  Visit(startNode);
47 
48  return complete;
49  }
50 
51  #endregion
52 
53  #region Protected method
54 
55  [Visit]
56  protected override Node Visit(Node node)
57  {
58  if (node == nodeToReplace)
59  {
60  complete = true;
61  return replacementNode;
62  }
63 
64  return base.Visit(node);
65  }
66 
67  #endregion
68  }
69 }
Abstract node.
Definition: Node.cs:15
document false