The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
DoubleType.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: DoubleType.cs //
6 // Authors: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Francisco Ortin - francisco.ortin@gmail.com //
8 // Description: //
9 // Represents a double type. //
10 // Inheritance: TypeExpression. //
11 // Implements Composite pattern [Leaf]. //
12 // Implements Singleton pattern. //
13 // -------------------------------------------------------------------------- //
14 // Create date: 15-10-2006 //
15 // Modification date: 05-06-2007 //
17 //viSTO
18 using System;
19 using System.Collections.Generic;
20 using System.Text;
21 
22 using AST;
23 using ErrorManagement;
24 using Tools;
25 using TypeSystem.Operations;
26 
27 namespace TypeSystem {
36  public class DoubleType : TypeExpression {
37  #region Fields
38 
42  private static readonly DoubleType instance = new DoubleType();
43 
47  private BCLClassType BCLType = new BCLClassType("System.Double", Type.GetType("System.Double"));
48 
49 
50  #endregion
51 
52  #region Properties
53 
57  public static DoubleType Instance {
58  get { return instance; }
59  }
60 
61  #endregion
62 
63  #region Constructors
64 
68  private DoubleType() {
69  this.typeExpression = "double";
70  this.fullName = "double";
71  }
72 
76  static DoubleType() {
77  }
78 
79  #endregion
80 
81  // WriteType Inference
82  #region Dispatcher
83  public override object AcceptOperation(TypeSystemOperation op, object arg) { return op.Exec(this, arg); }
84  #endregion
85 
86  #region Assignment() ANULADA
87 
101  //public override TypeExpression Assignment(TypeExpression operand, AssignmentOperator op, MethodType methodAnalyzed, SortOfUnification unification,
102  // TypeExpression actualImplicitObject, Location location) {
103  // return operand.Promotion(this, op, methodAnalyzed, location);
104  //}
105 
106  #endregion
107 
108  #region Arithmetic() ANULADA
109  /*
121  public override TypeExpression Arithmetic(TypeExpression operand, Enum op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
122  if (operand.PromotionLevel(this) != -1)
123  return DoubleType.instance;
124  if (op.Equals(ArithmeticOperator.Plus) && operand.Equivalent(StringType.Instance))
125  return StringType.Instance;
126  return (TypeExpression)ArithmeticalOperation.Create(this, op, methodAnalyzed, showErrorMessage, loc).AcceptOperation(operand);
127  }
128 
139  public override TypeExpression Arithmetic(UnaryOperator op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
140  return DoubleType.Instance;
141  }
142  */
143  #endregion
144 
145  #region Relational()ANULADA
146  /*
158  public override TypeExpression Relational(TypeExpression operand, RelationalOperator op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
159  if (operand.PromotionLevel(DoubleType.Instance) != -1)
160  return BoolType.Instance;
161  return operand.Relational(this, op, methodAnalyzed, showErrorMessage, loc);
162  }
163  */
164  #endregion
165 
166  #region Dot() ANULADA
167  //public override TypeExpression Dot(string field, MethodType methodAnalyzed, IList<TypeExpression> previousDot, Location loc) {
180  // return this.BCLType.Dot(field, methodAnalyzed, previousDot, loc);
181  //}
190  //public override TypeExpression Dot(string memberName, IList<TypeExpression> previousDot) {
191  // return this.BCLType.Dot(memberName, previousDot);
192  //}
193  #endregion
194 
195  #region AsClassType()
196  public override ClassType AsClassType() {
202  return this.BCLType;
203  }
204  #endregion
205 
206  // WriteType Promotion
207 
208 
209  #region PromotionLevel() ANULADA
210 
216  //public override object AcceptOperation(TypeExpression type) {
217  // // * Double type and bounded type variable
218  // if (TypeExpression.As<DoubleType>(type)!=null)
219  // return 0;
220  // // * WriteType variable
221  // TypeVariable typeVariable = type as TypeVariable;
222  // if (typeVariable != null && typeVariable.Substitution == null)
223  // // * A free variable is complete promotion
224  // return 0;
225  // // * Union type
226  // UnionType unionType = TypeExpression.As<UnionType>(type);
227  // if (unionType != null)
228  // return unionType.SuperType(this);
229  // // * Field type and bounded type variable
230  // FieldType fieldType = TypeExpression.As<FieldType>(type);
231  // if (fieldType != null)
232  // return this.PromotionLevel(fieldType.FieldTypeExpression);
233  // // * Use the BCL object oriented approach
234  // return this.BCLType.PromotionLevel(type);
235  //}
236 
237  #endregion
238 
239  // WriteType Unification
240 
241  #region Unify
242  public override bool Unify(TypeExpression te, SortOfUnification unification, IList<Pair<TypeExpression, TypeExpression>> previouslyUnified) {
250  DoubleType dt = te as DoubleType;
251  if (dt != null)
252  return true;
253  if (te is TypeVariable && unification!=SortOfUnification.Incremental)
254  // * No incremental unification is commutative
255  return te.Unify(this, unification, previouslyUnified);
256  if(te is FieldType && unification == SortOfUnification.Equivalent)
257  return ((FieldType)te).FieldTypeExpression.Unify(this, unification, previouslyUnified);
258  return false;
259  }
260  #endregion
261 
262  // Code Generation
263 
264  #region ILType()
265 
270  public override string ILType()
271  {
272  return "float64";
273  }
274 
275  #endregion
276 
277  #region IsValueType()
278 
283  public override bool IsValueType()
284  {
285  return true;
286  }
287 
288  #endregion
289 
290 
291  }
292 }
override bool Unify(TypeExpression te, SortOfUnification unification, IList< Pair< TypeExpression, TypeExpression >> previouslyUnified)
This method unifies two type expressions (this and te)
Definition: DoubleType.cs:249
static DoubleType Instance
Gets the unique instance of DoubleType
Definition: DoubleType.cs:57
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
override ClassType AsClassType()
Represent a type as a class. It is mainly used to obtain the BCL representation of types (string=Stri...
Definition: DoubleType.cs:201
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
Definition: DoubleType.cs:283
Abstract class that represents all different types.
Represents a double type.
Definition: DoubleType.cs:36
override object AcceptOperation(TypeSystemOperation op, object arg)
Definition: DoubleType.cs:83
Represents a class type.
Definition: ClassType.cs:35
override string ILType()
Gets the string type to use in IL code.
Definition: DoubleType.cs:270