Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Typedef.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;
5 using System.Collections.Generic;
6 using System.Text;
7 
8 namespace SiliconStudio.Shaders.Ast.Hlsl
9 {
10  /// <summary>
11  /// Typedef declaration.
12  /// </summary>
13  public class Typedef : TypeBase, IDeclaration
14  {
15  #region Constructors and Destructors
16 
17  /// <summary>
18  /// Initializes a new instance of the <see cref = "Typedef" /> class.
19  /// </summary>
20  public Typedef() : this(null)
21  {
22  }
23 
24  /// <summary>
25  /// Initializes a new instance of the <see cref="Typedef"/> class.
26  /// </summary>
27  /// <param name="typeBase">
28  /// The type base.
29  /// </param>
30  public Typedef(TypeBase typeBase)
31  {
32  Type = typeBase;
33  Qualifiers = Qualifier.None;
34  }
35 
36  #endregion
37 
38  #region Public Properties
39 
40  /// <summary>
41  /// Gets or sets the names.
42  /// </summary>
43  /// <value>
44  /// The names.
45  /// </value>
46  public List<Typedef> SubDeclarators { get; set; }
47 
48  /// <summary>
49  /// Gets or sets the type.
50  /// </summary>
51  /// <value>
52  /// The type.
53  /// </value>
54  public TypeBase Type { get; set; }
55 
56  /// <summary>
57  /// Gets a value indicating whether this instance is group.
58  /// </summary>
59  /// <value>
60  /// <c>true</c> if this instance is group; otherwise, <c>false</c>.
61  /// </value>
62  public bool IsGroup
63  {
64  get
65  {
66  return SubDeclarators != null && SubDeclarators.Count > 0;
67  }
68  }
69 
70  #endregion
71 
72  #region Public Methods
73 
74  /// <inheritdoc />
75  public override IEnumerable<Node> Childrens()
76  {
77  ChildrenList.Clear();
78  ChildrenList.Add(Type);
79  if (IsGroup)
80  ChildrenList.AddRange(SubDeclarators);
81  return ChildrenList;
82  }
83 
84  /// <inheritdoc/>
85  public override TypeBase ResolveType()
86  {
87  var type = TypeInference.TargetType ?? Type;
88  return type.ResolveType();
89  }
90 
91  /// <inheritdoc />
92  public override string ToString()
93  {
94  var builder = new StringBuilder();
95  if (IsGroup)
96  {
97  for (int i = 0; i < SubDeclarators.Count; i++)
98  {
99  var typedefDeclarator = SubDeclarators[i];
100  if (i > 0)
101  builder.Append(", ");
102  builder.Append(typedefDeclarator.Name);
103  }
104  }
105  else
106  {
107  builder.Append(Name);
108  }
109 
110  return string.Format("typedef{0} {1} {2}", Qualifiers, Type, builder);
111  }
112 
113  #endregion
114 
115  }
116 }
Typedef(TypeBase typeBase)
Initializes a new instance of the Typedef class.
Definition: Typedef.cs:30
override IEnumerable< Node > Childrens()
Gets the child nodes. An enumeration of child nodes
Definition: Typedef.cs:75
Typedef()
Initializes a new instance of the Typedef class.
Definition: Typedef.cs:20
override TypeBase ResolveType()
Resolves the type. The resolved type.
Definition: Typedef.cs:85
Base type for all types.
Definition: TypeBase.cs:11
Toplevel interface for a declaration.
Definition: IDeclaration.cs:8