The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
ClassTypeProxy.cs
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
3 // Project rROTOR
4 // --------------------------------------------------------------------------
5 // File: ClassTypeProxy.cs
6 // Author: Francisco Ortin - francisco.ortin@gmail.com
7 // Description:
8 // Represents proxy of a class type. It is needed when a class has a
9 // field that is recursively of the same class. It implements a
10 // lazy clone type variables scheme.
11 // Implements the unfold operatations of theoretical type systes.
12 // Inheritance: TypeExpression.
13 // Implements Composite pattern [Composite].
14 // Implements Proxy pattern [Proxy].
15 // --------------------------------------------------------------------------
16 // Create date: 02-05-2007
17 // Modification date: 02-05-2007
19 
20 using System;
21 using System.Collections.Generic;
22 using System.Text;
23 
24 using AST;
25 using ErrorManagement;
26 using Tools;
27 using TypeSystem.Operations;
28 
29 namespace TypeSystem {
37  public class ClassTypeProxy : TypeExpression {
38  #region Fields
39 
43  private ClassType realType = null;
44 
48  private ClassType originalClass;
49 
53  private IDictionary<TypeVariable, TypeVariable> typeVariableMappings;
54 
58  private IList<EquivalenceClass> equivalenceClasses;
59  #endregion
60 
61  #region Properties
62  public ClassType RealType {
66  get {
67  this.unfold();
68  return this.realType;
69  }
70  }
72  //public ClassType OriginalClass {
73  // get {return this.originalClass}
74  //}
75  #endregion
76 
77  #region Constructors
78  public ClassTypeProxy(ClassType originalClass, IDictionary<TypeVariable, TypeVariable> typeVariableMappings, IList<EquivalenceClass> equivalenceClasses) {
85  this.originalClass = originalClass;
86  this.typeVariableMappings = typeVariableMappings;
87  this.equivalenceClasses = equivalenceClasses;
88  this.fullName = originalClass.FullName;
89  }
90  #endregion
91 
92  #region unfold()
93  private void unfold() {
98  if (this.realType == null) {
99  this.realType = (ClassType)this.originalClass.CloneTypeVariables(this.typeVariableMappings, this.equivalenceClasses, new List<ClassType>());
100  // * For each equivalence class we create a new one,
101  // substituting the old type variables for the new ones
102  // * The substitution is not altered
103  // * Since equivalence classes and type variables have a bidirectional association,
104  // the new equivalence classes will make type variables update their new equivalence classes
105  foreach (EquivalenceClass equivalenceClass in equivalenceClasses)
106  equivalenceClass.UpdateEquivalenceClass(typeVariableMappings);
107  // * The new class type is returned
108  this.realType.ValidTypeExpression = false;
109  }
110  }
111 
112  #endregion
113 
114  #region BuildTypeExpressionString()
115 
119  public override string BuildTypeExpressionString(int depthLevel) {
120  if (this.realType.ValidTypeExpression)
121  return this.realType.typeExpression;
122  return this.realType.FullName;
123  }
124 
125  #endregion
126 
127  // WriteType inference
128  #region Dispatcher
129  public override object AcceptOperation(TypeSystemOperation op, object arg) { return op.Exec(this, arg); }
130  #endregion
131 
132  #region Assignment() ANULADA
133  //public override TypeExpression Assignment(TypeExpression operand, AssignmentOperator op, MethodType methodAnalyzed, SortOfUnification unification,
147  // TypeExpression actualImplicitObject, Location loc) {
148  // return this.RealType.Assignment(operand, op, methodAnalyzed, unification, actualImplicitObject, loc);
149  //}
150  #endregion
151 
152  #region Dot() ANULADA
153  //public override TypeExpression Dot(string memberName, MethodType methodAnalyzed, IList<TypeExpression> previousDot, Location loc) {
166  // return this.RealType.Dot(memberName, methodAnalyzed, previousDot, loc);
167  //}
176  //public override TypeExpression Dot(string memberName, IList<TypeExpression> previousDot) {
177  // return this.RealType.Dot(memberName, previousDot);
178  //}
179  #endregion
180 
181  #region Parenthesis() ANULADA
182  //public override TypeExpression Parenthesis(TypeExpression actualImplicitObject, TypeExpression[] arguments, MethodType methodAnalyzed,
195  // SortOfUnification activeSortOfUnification, Location loc) {
196  // return this.RealType.Parenthesis(actualImplicitObject, arguments, methodAnalyzed, activeSortOfUnification, loc);
197  //}
198  #endregion
199 
200  #region AsClassType() ANULADA
201  public override ClassType AsClassType() {
207  return this.originalClass;
208  }
209  #endregion
210 
211  #region Equivalent() ANULADA
212  #endregion
221 
222  // WriteType Promotion
223 
224  #region PromotionLevel() ANULADA
225  //public override int PromotionLevel(TypeExpression type) {
231  // return this.RealType.PromotionLevel(type);
232  //}
233  #endregion
234 
235  #region Promotion() ANULADA
236  //public override TypeExpression Promotion(TypeExpression type, MethodType methodAnalyzed, Location loc) {
247  // return this.RealType.Promotion(type, methodAnalyzed, loc);
248  //}
249  //public override TypeExpression Promotion(TypeExpression type, Enum op, MethodType methodAnalyzed, Location loc) {
250  // return this.RealType.Promotion(type, op, methodAnalyzed, loc);
251  //}
252  #endregion
253 
254  #region EqualsForOverload() ANULADA
255  //public override bool EqualsForOverload(object typeExpression) {
261  // return this.RealType.EqualsForOverload(typeExpression);
262  //}
263  #endregion
264 
265  // WriteType Unification
266 
267  #region Unify
268  public override bool Unify(TypeExpression te, SortOfUnification unification, IList<Pair<TypeExpression, TypeExpression>> previouslyUnified) {
276  return this.RealType.Unify(te, unification, previouslyUnified);
277  }
278  #endregion
279 
280 
281  #region HasTypeVariables()
282  public override bool HasTypeVariables() {
288  return this.RealType.HasTypeVariables();
289  }
290 
291  public bool HasTypeVariables(IList<String> evaluated)
292  {
293  return this.RealType.HasTypeVariables(evaluated);
294  }
295  #endregion
296 
297  #region CloneType()
298  public override TypeExpression CloneType(IDictionary<TypeVariable, TypeVariable> typeVariableMappings) {
308  return this.RealType.CloneType(typeVariableMappings);
309  }
310  #endregion
311 
312 
313  #region CloneTypeVariables()
314  public override TypeExpression CloneTypeVariables(IDictionary<TypeVariable, TypeVariable> typeVariableMappings, IList<EquivalenceClass> equivalenceClasses, IList<ClassType> clonedClasses) {
325  return this.RealType.CloneTypeVariables(typeVariableMappings, equivalenceClasses, clonedClasses);
326  }
327  #endregion
328 
329  // SSA
330 
331  #region Clone()
332  internal override TypeExpression Clone(IDictionary<int, TypeVariable> clonedTypeVariables, IList<EquivalenceClass> equivalenceClasses, MethodType methodAnalyzed) {
343  if (!this.HasTypeVariables())
344  return this;
345  ClassTypeProxy newClassProxy = (ClassTypeProxy)this.MemberwiseClone();
346  if (newClassProxy.realType != null)
347  newClassProxy.realType = (ClassType)newClassProxy.realType.Clone(clonedTypeVariables, equivalenceClasses, methodAnalyzed);
348  return newClassProxy;
349  }
350  #endregion
351 
352  // Loop detection
353 
354  #region Equals&GetHashCode()
355  public override bool Equals(object obj) {
359  return this.RealType.Equals(obj);
360  }
361  public override int GetHashCode() {
362  return this.FullName.GetHashCode();
363  }
364  #endregion
365 
366  #region IsValueType()
367 
372  public override bool IsValueType()
373  {
374  return this.realType.IsValueType();
375  }
376 
377  #endregion
378 
379  }
380 }
ClassType RealType
The real subject of the proxy (see the Proxy design pattern)
override ClassType AsClassType()
Check if the type can make an assignment operation.
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
override TypeExpression CloneTypeVariables(IDictionary< TypeVariable, TypeVariable > typeVariableMappings, IList< EquivalenceClass > equivalenceClasses, IList< ClassType > clonedClasses)
Method that clones each type variable of a type expression. Equivalence classes are not cloned (but i...
Definition: ClassType.cs:540
Abstract class that represents all different types.
override bool HasTypeVariables()
To know if the type expression has some type variables and requieres unification The default implemen...
Represents a proxy of a class type. It implements the unfold operatations of theoretical type systes...
override object AcceptOperation(TypeSystemOperation op, object arg)
override string BuildTypeExpressionString(int depthLevel)
Creates the type expression string.
override TypeExpression CloneTypeVariables(IDictionary< TypeVariable, TypeVariable > typeVariableMappings, IList< EquivalenceClass > equivalenceClasses, IList< ClassType > clonedClasses)
Method that clones each type variable of a type expression. Equivalence classes are not cloned (but i...
override bool Equals(object obj)
To check loops in recursive types, proxy must be equal that the classes they represent ...
ClassTypeProxy(ClassType originalClass, IDictionary< TypeVariable, TypeVariable > typeVariableMappings, IList< EquivalenceClass > equivalenceClasses)
Constructor of the ClassType Proxy
override bool Unify(TypeExpression te, SortOfUnification unification, IList< Pair< TypeExpression, TypeExpression >> previouslyUnified)
Used to not repeat methods in overload
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
bool HasTypeVariables(IList< String > evaluated)
Represents a class type.
Definition: ClassType.cs:35
override TypeExpression CloneType(IDictionary< TypeVariable, TypeVariable > typeVariableMappings)
This method creates a new class type, creating new type variables for each field. Methods are not clo...