3 using System.Collections.Generic;
5 using SiliconStudio.Shaders.Ast;
7 namespace SiliconStudio.Shaders.Visitor
19 #region Constructors and Destructors
26 protected ShaderVisitor(
bool buildScopeDeclaration,
bool useNodeStack) : base(useNodeStack)
28 nodeProcessor = OnNodeProcessor;
29 if (buildScopeDeclaration)
31 ScopeStack =
new Stack<ScopeDeclaration>();
32 ScopeStack.Push(this.NewScope());
48 public Node ParentNode
52 return NodeStack.Count > 1 ? NodeStack[NodeStack.Count - 2] : null;
59 protected Stack<ScopeDeclaration> ScopeStack {
get;
private set; }
63 #region Public Methods
68 return node.Childrens(nodeProcessor);
73 return VisitDynamic(nodeArg);
83 return ScopeStack.SelectMany(scopeDecl => scopeDecl.FindDeclaration(name));
93 return FindDeclarations(name).FirstOrDefault();
98 if (ScopeStack != null)
101 if (declaration != null)
106 foreach (var variable
in ((Variable)declaration).Instances())
107 ScopeStack.Peek().AddDeclaration(variable);
111 ScopeStack.Peek().AddDeclaration(declaration);
116 if (scopeContainer != null)
118 ScopeStack.Push(this.NewScope(scopeContainer));
delegate Node NodeProcessor(Node node, ref NodeProcessorContext nodeProcessorContext)
Processor for a single node.
virtual ScopeDeclaration NewScope(IScopeContainer container=null)
A tag interface to identify a container for scope declarations.
A Scope declaration provides a way to retrieve all scope declaration (variable, methods...etc.) and attached nodes.
virtual Node Visit(Node node)
ShaderVisitor(bool buildScopeDeclaration, bool useNodeStack)
Initializes a new instance of the ShaderVisitor class.
override bool PreVisitNode(Node node)
Called before visiting the node.
IDeclaration FindDeclaration(string name)
Finds a declaration by its name.
virtual IEnumerable< IDeclaration > FindDeclarations(string name)
Finds a list of declaration by its name.
Toplevel interface for a declaration.
override void PostVisitNode(Node node, bool nodeVisited)
Called after visiting the node.