The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
SingleIdentifierExpression.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: SingleIdentifierExpression.cs //
6 // Authors: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Francisco Ortin - francisco.ortin@gmail.com //
8 // Description: //
9 // Encapsulates a identifier expression of our programming language. //
10 // Inheritance: Expression. //
11 // Implements Composite pattern [Leaf]. //
12 // Implements Visitor pattern [Concrete Element]. //
13 // -------------------------------------------------------------------------- //
14 // Create date: 05-12-2006 //
15 // Modification date: 06-04-2007 //
17 
18 using System;
19 using System.Collections.Generic;
20 using System.Text;
21 
22 using Symbols;
23 using Tools;
24 using TypeSystem;
25 using ErrorManagement;
26 using CodeGeneration;
27 using TypeSystem.Operations;
28 using AST.Operations;
29 
30 namespace AST {
31  #region enum IdentifierMode
32 
36  public enum IdentifierMode {
37  Instance,
38  UserType,
39  NameSpace
40  }
41 
42  #endregion
43 
53  #region Field
54 
58  private IdentifierMode idMode;
59 
63  private Symbol symbol;
64 
68  private int indexOfSSA;
69 
73  private string ilName = "";
74 
75  private ILReservedWords ilReservedWords;
76  #endregion
77 
78  #region Properties
79 
84  set { this.idMode = value; }
85  get { return this.idMode; }
86  }
87 
91  public Symbol IdSymbol {
92  get { return this.symbol; }
93  set { this.symbol = value; }
94  }
95 
99  public int IndexOfSSA {
100  get { return this.indexOfSSA; }
101  set { this.indexOfSSA = value; }
102  }
103 
110  get { return this.frozenTypeExpression; }
111  set { this.frozenTypeExpression = value; }
112  }
113 
114  #region ILName
115 
119  public string ILName {
120 
121  get {
122  // the ilName field is alredy defined, so it is returned
123  if (!this.ilName.Equals(""))
124  return this.ilName;
125  // ilName is blank
126  // if the node is provided by SSA algorithm, the proper subscript is added as a number
127  // to the parameter, and assigned to this.ilName
128  if (this.indexOfSSA != -1)
129  SSARename();
130  else // assign this.Identifier to ilName, if it's a keyworkd of IL Language the returned string is sourronded by a pair of '
131  this.ilName = this.ilReservedWords.MakeILComplaint(this.Identifier);
132 
133  return this.ilName;
134  }
135  }
139  private void SSARename() {
140  StringBuilder aux = new StringBuilder();
141  aux.AppendFormat("{0}__{1}", this.Identifier, this.indexOfSSA);
142  this.ilName = aux.ToString();
143  }
144 
145  #endregion
146 
147  #endregion
148 
149  #region Constructor
150 
158  public SingleIdentifierExpression(string idenfifier, Location location)
159  : base(location) {
160 
161  this.Identifier = idenfifier;
162  this.idMode = IdentifierMode.Instance;
163  this.indexOfSSA = -1;
164  this.ilReservedWords = new ILReservedWords();
165  }
166 
167  #endregion
168 
169  #region Accept()
170 
177  public override Object Accept(Visitor v, Object o) {
178  return v.Visit(this, o);
179  }
180  #endregion
181 
182  #region Dispatcher AstOperation
183  public override object AcceptOperation(AstOperation op, object arg) {
191  return op.Exec(this, arg);
192  }
193 
194  #endregion
195 
196  #region Equals&GetHashCode
197  public override bool Equals(object obj) {
198  if (this.GetHashCode() != obj.GetHashCode())
199  return false;
201  if (singleId == null)
202  return false;
203  return this.Identifier.Equals(singleId.Identifier) && this.indexOfSSA == singleId.indexOfSSA;
204  }
205  public override int GetHashCode() {
206  return this.Identifier.GetHashCode() * this.indexOfSSA;
207  }
208  #endregion
209  }
210 }
Encapsulates a name expression of our programming language.
Abstract class to define different visits over the abstract syntax tree.
Definition: Visitor.cs:29
This class encapsulates a location in a specific file. Implements an Inmutable pattern. So it can be used in any context, that is his internal fields never change.
Definition: Location.cs:24
This class represent the entry wnen sending a message to an operation object. derived from AstNode ...
Abstract class that represents all different types.
System.Text.StringBuilder StringBuilder
Definition: CSharpParser.cs:4
This class represents a symbol associated with its identifier.
Definition: Symbol.cs:26
Encapsulates a identifier expression of our programming language.
IdentifierMode
Represents how to use the identifier
SingleIdentifierExpression(string idenfifier, Location location)
Constructor of SingleIdentifierExpression
int IndexOfSSA
Gets or sets the index associated with SSA algorithm
string ILName
Gets the IL name associated to the declaration identifier.
Location location
Location: Encapsulates in one object the line, column and filename
Definition: AstNode.cs:39
Symbol IdSymbol
Gets or sets the symbol of the identifier.
IdentifierMode IdMode
Gets the mode to use de identifier.
override object AcceptOperation(AstOperation op, object arg)
Dispatches expressions to the operation passed as argument. It provokes the execution of op...
TypeExpression FrozenTypeExpression
WriteType variable may change its type's substitution (e.g., field type variables) This attribute sav...
override Object Accept(Visitor v, Object o)
Accept method of a concrete visitor.