Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
VariableReferenceExpression.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;
4 using System.Collections.Generic;
5 
6 namespace SiliconStudio.Shaders.Ast
7 {
8  /// <summary>
9  /// A reference to a variable.
10  /// </summary>
12  {
13  /// <summary>
14  /// Initializes a new instance of the <see cref="VariableReferenceExpression"/> class.
15  /// </summary>
17  {
18  }
19 
20  /// <summary>
21  /// Initializes a new instance of the <see cref="VariableReferenceExpression"/> class.
22  /// </summary>
23  /// <param name="variable">The variable.</param>
25  {
26  Name = variable.Name;
27  TypeInference.TargetType = variable.Type.ResolveType();
28  }
29 
30  /// <summary>
31  /// Initializes a new instance of the <see cref="VariableReferenceExpression"/> class.
32  /// </summary>
33  /// <param name="name">The name.</param>
35  {
36  Name = name;
37  }
38 
39  /// <summary>
40  /// Gets or sets the name.
41  /// </summary>
42  /// <value>
43  /// The name.
44  /// </value>
45  public Identifier Name { get; set; }
46 
47  ///// <summary>
48  ///// Gets or sets the variable.
49  ///// </summary>
50  ///// <value>
51  ///// The variable.
52  ///// </value>
53  //[VisitorIgnore]
54  //public Variable Variable
55  //{
56  // get
57  // {
58  // return (Variable)TypeInference.Declaration;
59  // }
60  // set
61  // {
62  // TypeInference.Declaration = value;
63  // }
64  //}
65 
66  /// <inheritdoc/>
67  public override IEnumerable<Node> Childrens()
68  {
69  ChildrenList.Clear();
70  ChildrenList.Add(Name);
71  return ChildrenList;
72  }
73 
74  /// <summary>
75  /// Gets a name of the variable referenced by an expression.
76  /// </summary>
77  /// <param name="expression">The expression.</param>
78  /// <returns>Name of the variable referenced. If the expression is not a VariableReferenceExpression, returns null</returns>
79  public static string GetVariableName(Expression expression)
80  {
81  var variableReferenceExpression = expression as VariableReferenceExpression;
82  return variableReferenceExpression == null ? null : variableReferenceExpression.Name.Text;
83  }
84 
85  /// <inheritdoc/>
86  public override string ToString()
87  {
88  return Name;
89  }
90  }
91 }
static string GetVariableName(Expression expression)
Gets a name of the variable referenced by an expression.
override IEnumerable< Node > Childrens()
Gets the child nodes. An enumeration of child nodes
A variable declaration.
Definition: Variable.cs:11
VariableReferenceExpression()
Initializes a new instance of the VariableReferenceExpression class.
VariableReferenceExpression(Identifier name)
Initializes a new instance of the VariableReferenceExpression class.
VariableReferenceExpression(Variable variable)
Initializes a new instance of the VariableReferenceExpression class.