The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
PropertyType.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: PropertyType.cs //
6 // Author: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Description: //
8 // Represents a property type. //
9 // Inheritance: MemberType. //
10 // Implements Composite pattern [Composite]. //
11 // -------------------------------------------------------------------------- //
12 // Create date: 16-03-2007 //
13 // Modification date: 29-03-2007 //
15 
16 using System;
17 using System.Collections.Generic;
18 using System.Text;
19 using System.Text.RegularExpressions;
20 
21 using AST;
22 using ErrorManagement;
23 using Tools;
24 using TypeSystem.Operations;
25 //VISTO
26 namespace TypeSystem {
35  #region Fields
36 
40  private TypeExpression propertyType;
41 
45  private bool setAccess;
46 
50  private bool getAccess;
51 
55  private AccessModifier memberInfo;
56 
57  #endregion
58 
59  #region Properties
60 
65  get { return this.propertyType; }
66  }
67 
72  get { return this.memberInfo; }
73  set {
74  if (this.memberInfo == null) {
75  this.memberInfo = value;
76  }
77  else
78  ErrorManager.Instance.NotifyError(new ClassTypeInfoError(this.memberInfo.MemberIdentifier, this.memberInfo.Class.FullName, value.Class.FullName));
79  }
80  }
81 
82  #endregion
83 
84  #region Constructor
85 
92  public PropertyType(TypeExpression type, bool canRead, bool canWrite) {
93  this.propertyType = type;
94  this.getAccess = canRead;
95  this.setAccess = canWrite;
96  this.BuildFullName();
97  }
98 
99  #endregion
100 
101  #region BuildTypeExpressionString
102 
106  public override string BuildTypeExpressionString(int depthLevel) {
107  if (this.ValidTypeExpression) return this.typeExpression;
108  if (depthLevel <= 0) return this.FullName;
109 
110  //this.fullName = this.MemberInfo.Class.FullName + "." + this.MemberInfo.MemberIdentifier;
111  if (this.propertyType == null)
112  return "null";
113  this.fullName = this.propertyType.FullName;
114 
115  StringBuilder tE = new StringBuilder();
116  // tE: Property(IdClass, IdProperty, mods, type)
117  tE.AppendFormat("Property({0}, {1},", this.MemberInfo.Class.BuildTypeExpressionString(depthLevel-1), this.MemberInfo.MemberIdentifier);
118  // modifiers
119  if (this.MemberInfo.Modifiers.Count != 0) {
120  for (int i = 0; i < this.MemberInfo.Modifiers.Count - 1; i++) {
121  tE.AppendFormat(" {0} x", this.MemberInfo.Modifiers[i]);
122  }
123  tE.AppendFormat(" {0}", this.MemberInfo.Modifiers[this.MemberInfo.Modifiers.Count - 1]);
124  }
125  tE.Append(", ");
126 
127  // type
128  tE.Append(this.propertyType.BuildTypeExpressionString(depthLevel-1));
129  tE.Append(")");
130  this.ValidTypeExpression = true;
131  return this.typeExpression=tE.ToString();
132  }
133  #endregion
134 
135  #region BuildFullName()
136  public override void BuildFullName() {
140  if (this.MemberInfo != null)
141  this.fullName = String.Format("{0}.{1}:{2}", this.MemberInfo.Class.FullName,
142  this.MemberInfo.MemberIdentifier, this.propertyType.FullName);
143  else
144  this.fullName = this.propertyType.FullName;
145  }
146  #endregion
147 
148  // WriteType inference
149 
150  #region Dispatcher
151  public override object AcceptOperation(TypeSystemOperation op, object arg) { return op.Exec(this, arg); }
152  #endregion
153 
154  #region Dot() ANULADA
155 
168  //public override TypeExpression Dot(string field, MethodType methodAnalyzed, IList<TypeExpression> previousDot, Location loc) {
169  // if (propertyType != null)
170  // return this.propertyType.Dot(field, methodAnalyzed, previousDot, loc);
171  // return null;
172  //}
181  //public override TypeExpression Dot(string memberName, IList<TypeExpression> previousDot) {
182  // if (propertyType != null)
183  // return this.propertyType.Dot(memberName, previousDot);
184  // return null;
185  //}
186  #endregion
187 
188  #region Bracket() ANULADA
189 
200  //public override TypeExpression Bracket(TypeExpression index, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
201  // if (propertyType != null)
202  // return this.propertyType.Bracket(index, methodAnalyzed, showErrorMessage, loc);
203  // return null;
204  //}
205 
206  #endregion
207 
208  #region Assignment() ANULADA
209 
223  //public override TypeExpression Assignment(TypeExpression operand, AssignmentOperator op, MethodType methodOrClassAnalyzed, SortOfUnification unification,
224  // TypeExpression actualImplicitObject, Location location) {
225  // if (!this.MemberInfo.hasModifier(Modifier.CanWrite)) {
226  // ErrorManager.Instance.NotifyError(new PropertyWriteError(this.MemberInfo.MemberIdentifier, location));
227  // return null;
228  // }
229  // if (this.propertyType != null)
230  // return this.propertyType.Assignment(operand, op, null, unification, actualImplicitObject, location);
231  // return null;
232  //}
233 
234  #endregion
235 
236  #region Arithmetic() ANULADA
237  /*
238 
250  public override TypeExpression Arithmetic(TypeExpression operand, Enum op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
251  if (propertyType != null)
252  return this.propertyType.Arithmetic(operand, op, methodAnalyzed, showErrorMessage, loc);
253  return null;
254  }
255 
266  public override TypeExpression Arithmetic(UnaryOperator op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
267  return this.propertyType.Arithmetic(op, methodAnalyzed, showErrorMessage, loc);
268  }
269  */
270  #endregion
271 
272  #region Relational() ANULADA
273  /*
274 
286  public override TypeExpression Relational(TypeExpression operand, RelationalOperator op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
287  if (propertyType != null)
288  return this.propertyType.Relational(operand, op, methodAnalyzed, showErrorMessage, loc);
289  return null;
290  }
291  */
292  #endregion
293 
294  // WriteType Promotion
295 
296  #region PromotionLevel() ANULADA
297  //public override int PromotionLevel(TypeExpression type) {
303  // if (propertyType != null)
304  // return this.propertyType.PromotionLevel(type);
305  // return -1;
306  //}
307 
308  #endregion
309 
310 
311  // WriteType Unification
312 
313  #region Unify
314  public override bool Unify(TypeExpression te, SortOfUnification unification, IList<Pair<TypeExpression, TypeExpression>> previouslyUnified) {
322  // * Clears the type expression cache
323  this.ValidTypeExpression = false;
324  te.ValidTypeExpression = false;
325  // TODO (not implemented yet; it is not possible to define var properties)
326  return false;
327  }
328  #endregion
329 
330  #region HasTypeVariables()
331  public override bool HasTypeVariables() {
337  if (this.validHasTypeVariables)
338  return this.hasTypeVariablesCache;
339  bool toReturn = this.propertyType.HasTypeVariables();
340  this.validHasTypeVariables = true;
341  return this.hasTypeVariablesCache = toReturn;
342 
343  }
344  #endregion
345 
346  // SSA
347 
348  #region Clone()
349  internal override TypeExpression Clone(IDictionary<int, TypeVariable> clonedTypeVariables, IList<EquivalenceClass> equivalenceClasses, MethodType methodAnalyzed) {
360  if (!this.HasTypeVariables())
361  return this;
362  PropertyType newPropertyType = (PropertyType)this.MemberwiseClone();
363  if (newPropertyType.propertyType != null)
364  newPropertyType.propertyType = newPropertyType.propertyType.Clone(clonedTypeVariables,equivalenceClasses, methodAnalyzed);
365  return newPropertyType;
366  }
367  #endregion
368 
369  // Code Generation
370 
371  #region ILType()
372 
377  public override string ILType()
378  {
379  return this.propertyType.ILType();
380  }
381 
382  #endregion
383 
384  #region IsValueType()
385 
390  public override bool IsValueType()
391  {
392  return this.propertyType.IsValueType();
393  }
394 
395  #endregion
396 
397 
398  }
399 }
Represents a error produced when a MethodType has class information and tries to assign other class i...
bool validHasTypeVariables
To cache the result of the HasTypeVariables method
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
override string BuildTypeExpressionString(int depthLevel)
Creates the type expression string.
string MemberIdentifier
Gets the attribute name
Abstract class that represents all different types.
override void BuildFullName()
Creates/Updates the full name of the type expression
System.Text.StringBuilder StringBuilder
Definition: CSharpParser.cs:4
override string ILType()
Gets the string type to use in IL code.
override object AcceptOperation(TypeSystemOperation op, object arg)
Representa a property type.
Definition: PropertyType.cs:34
List< Modifier > Modifiers
Gets the modifiers of the element
Association Class between ClassType and MethodType (or Fields). Represents the access modifier inform...
AccessModifier MemberInfo
Gets or sets the attribute information of method type
Definition: PropertyType.cs:71
TypeExpression PropertyTypeExpression
Gets the property type.
Definition: PropertyType.cs:64
PropertyType(TypeExpression type, bool canRead, bool canWrite)
Constructor of PropertyType
Definition: PropertyType.cs:92
override bool Unify(TypeExpression te, SortOfUnification unification, IList< Pair< TypeExpression, TypeExpression >> previouslyUnified)
Check if the type can make an array operation.
override bool HasTypeVariables()
To know if the type expression has some type variables and requieres unification The default implemen...
Representa a class attribute (fields or methods).
Definition: IMemberType.cs:32