Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
StreamFieldVisitor.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.Paradox.Shaders.Parser.Ast;
4 using SiliconStudio.Shaders.Ast;
5 using SiliconStudio.Shaders.Visitor;
6 
7 namespace SiliconStudio.Paradox.Shaders.Parser.Mixins
8 {
9  internal class StreamFieldVisitor : ShaderVisitor
10  {
11  private Variable typeInference = null;
12 
13  private Expression arrayIndex;
14 
15  public StreamFieldVisitor(Variable variable, Expression index = null)
16  : base(false, false)
17  {
18  typeInference = variable;
19  arrayIndex = index;
20  }
21 
22  public Expression Run(Expression expression)
23  {
24  return Visit(expression);
25  }
26 
27  [Visit]
28  private Expression Visit(Expression expression)
29  {
30  Visit((Node)expression);
31 
32  if ((expression is VariableReferenceExpression || expression is MemberReferenceExpression || expression is IndexerExpression) && expression.TypeInference.TargetType is ParadoxType) // TODO: exclude constants, test real type
33  {
34  var mre = new MemberReferenceExpression(expression, typeInference.Name) { TypeInference = { Declaration = typeInference, TargetType = typeInference.Type.ResolveType() } };
35  if (arrayIndex == null)
36  return mre;
37  else
38  {
39  var ire = new IndexerExpression(mre, arrayIndex);
40  return ire;
41  }
42  }
43 
44  return expression;
45  }
46  }
47 }
TypeBase TargetType
Gets or sets the type.
Abstract node.
Definition: Node.cs:15
TypeInference TypeInference
Gets or sets the type reference.
Definition: Expression.cs:28
A variable declaration.
Definition: Variable.cs:11
A member reference in the form {this}.{Name}
document false