The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
IntType.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: IntType.cs //
6 // Authors: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Francisco Ortin - francisco.ortin@gmail.com //
8 // Description: //
9 // Represent a integer 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 
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 {
37  public class IntType : TypeExpression {
38  #region Fields
39 
43  private static IntType instance;
44 
48  private BCLClassType BCLType = new BCLClassType("System.Int32", Type.GetType("System.Int32"));
49 
50  #endregion
51 
52  #region Properties
53 
57  public static IntType Instance {
58  get {
59  if (instance == null)
60  instance = new IntType();
61  return instance;
62  }
63  }
64 
65  #endregion
66 
67  #region Constructors
68 
72  private IntType() {
73  this.typeExpression = "int";
74  this.fullName = "int";
75  }
76 
77  #endregion
78 
79  // WriteType Inference
80 
81  #region Dispatcher
82  public override object AcceptOperation(TypeSystemOperation op, object arg) { return op.Exec(this, arg); }
83  #endregion
84 
85  #region Assignment() ANULADA
86 
100  //public override TypeExpression Assignment(TypeExpression operand, AssignmentOperator op, MethodType methodAnalyzed, SortOfUnification unification,
101  // TypeExpression actualImplicitObject, Location location) {
102  // return operand.Promotion(this, op, methodAnalyzed, location);
103  //}
104 
105  #endregion
106 
107  #region Arithmetic() ANULADA
108  /*
120  public override TypeExpression Arithmetic(TypeExpression operand, Enum op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
121  if (operand.PromotionLevel(this) != -1)
122  return IntType.instance;
123  if (op.Equals(ArithmeticOperator.Plus) && operand.Equivalent(StringType.Instance))
124  return StringType.Instance;
125  return operand.Arithmetic(this, op, methodAnalyzed, showErrorMessage, loc);
126  }
127 
138  public override TypeExpression Arithmetic(UnaryOperator op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
139  return IntType.Instance;
140  }
141  */
142  #endregion
143 
144  #region Relational() anulada
145  /* anulafa
157  public override TypeExpression Relational(TypeExpression operand, RelationalOperator op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
158  if (operand.PromotionLevel(DoubleType.Instance) != -1)
159  return BoolType.Instance;
160  return operand.Relational(this,op,methodAnalyzed,showErrorMessage,loc);
161  }
162  */
163  #endregion
164 
165  #region Dot() anulada
166  //public override TypeExpression Dot(string field, MethodType methodAnalyzed, IList<TypeExpression> previousDot, Location loc) {
179  // return this.BCLType.Dot(field, methodAnalyzed, previousDot, loc);
180  //}
189  //public override TypeExpression Dot(string memberName, IList<TypeExpression> previousDot) {
190  // return this.BCLType.Dot(memberName, previousDot);
191  //}
192  #endregion
193 
194  #region AsClassType()
195  public override ClassType AsClassType() {
201  return this.BCLType;
202  }
203  #endregion
204 
205  // WriteType Promotion
206 
207  #region PromotionLevel() ANULADA
208  //public override int PromotionLevel(TypeExpression type) {
214  // // * Int type and bounded type variable
215  // if (TypeExpression.As<IntType>(type)!=null)
216  // return 0;
217  // // * Double type and bounded type variable
218  // if (TypeExpression.As<DoubleType>(type) != null)
219  // return 1;
220  // // * WriteType variable
221  // TypeVariable typeVariable = type as TypeVariable;
222  // if (typeVariable != null && typeVariable.Substitution == null)
223  // return 0;
224  // // * Union type
225  // UnionType unionType = TypeExpression.As<UnionType>(type);
226  // if (unionType != null)
227  // return unionType.SuperType(this);
228  // // * Field type and bounded type variable
229  // FieldType fieldType = TypeExpression.As<FieldType>(type);
230  // if (fieldType != null)
231  // return this.PromotionLevel(fieldType.FieldTypeExpression);
232  // // * Use the BCL object oriented approach
233  // return this.BCLType.PromotionLevel(type);
234  //}
235 
236  #endregion
237 
238  // WriteType Unification
239 
240  #region Unify
241  public override bool Unify(TypeExpression te, SortOfUnification unification, IList<Pair<TypeExpression, TypeExpression>> previouslyUnified) {
249  IntType it = te as IntType;
250  if (it != null)
251  return true;
252  if (te is TypeVariable && unification!=SortOfUnification.Incremental)
253  // * No incremental unification is commutative
254  return te.Unify(this, unification, previouslyUnified);
255  if (te is FieldType && unification == SortOfUnification.Equivalent)
256  return ((FieldType)te).FieldTypeExpression.Unify(this, unification, previouslyUnified);
257  return false;
258  }
259  #endregion
260 
261  // Code Generation
262 
263  #region ILType()
264 
269  public override string ILType()
270  {
271  return "int32";
272  }
273 
274  #endregion
275 
276  #region IsValueType()
277 
282  public override bool IsValueType()
283  {
284  return true;
285  }
286 
287  #endregion
288 
289 
290  }
291 }
override ClassType AsClassType()
Check if the type can make an assignment operation.
Definition: IntType.cs:200
override string ILType()
Gets the string type to use in IL code.
Definition: IntType.cs:269
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
Abstract class that represents all different types.
Represent a integer type.
Definition: IntType.cs:37
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
Definition: IntType.cs:282
static IntType Instance
Gets the unique instance of IntType
Definition: IntType.cs:57
override object AcceptOperation(TypeSystemOperation op, object arg)
Definition: IntType.cs:82
Represents a class type.
Definition: ClassType.cs:35
override bool Unify(TypeExpression te, SortOfUnification unification, IList< Pair< TypeExpression, TypeExpression >> previouslyUnified)
Returns a value that indicates a promotion level.
Definition: IntType.cs:248