Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ParadoxReplaceAppend.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 System.Collections.Generic;
4 using System.Linq;
5 
6 using SiliconStudio.Shaders.Ast;
7 using SiliconStudio.Shaders.Visitor;
8 
9 namespace SiliconStudio.Paradox.Shaders.Parser.Mixins
10 {
11  internal class ParadoxReplaceAppend : ShaderVisitor
12  {
13  #region Private members
14 
15  /// <summary>
16  /// List of append methods
17  /// </summary>
18  private HashSet<MethodInvocationExpression> appendMethodsList;
19 
20  /// <summary>
21  /// List of output statements replacing the append method
22  /// </summary>
23  private List<Statement> outputStatements;
24 
25  /// <summary>
26  /// Variable replacing the stream in the append function
27  /// </summary>
28  private VariableReferenceExpression outputVre;
29 
30  #endregion
31 
32  #region Constructor
33 
34  public ParadoxReplaceAppend(HashSet<MethodInvocationExpression> appendList, List<Statement> output, VariableReferenceExpression vre)
35  : base(false, false)
36  {
37  appendMethodsList = appendList;
38  outputStatements = output;
39  outputVre = vre;
40  }
41 
42  #endregion
43 
44  #region Public method
45 
46  public void Run(Node startNode)
47  {
48  Visit(startNode);
49  }
50 
51  #endregion
52 
53  #region Protected method
54 
55  [Visit]
56  protected Node Visit(ExpressionStatement expressionStatement)
57  {
58  Visit((Node)expressionStatement);
59 
60  if (appendMethodsList.Contains(expressionStatement.Expression))
61  {
62  var appendMethodCall = expressionStatement.Expression as MethodInvocationExpression;
63  var blockStatement = new BlockStatement();
64  blockStatement.Statements.AddRange(outputStatements);
65  appendMethodCall.Arguments[0] = outputVre;
66  blockStatement.Statements.Add(expressionStatement);
67  return blockStatement;
68  }
69  return expressionStatement;
70  }
71 
72  #endregion
73  }
74 }
Expression Expression
Gets or sets the expression.
Abstract node.
Definition: Node.cs:15
document false