The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CharType.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: CharType.cs //
6 // Authors: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Francisco Ortin - francisco.ortin@gmail.com //
8 // Description: //
9 // Represent a character type. //
10 // Inheritance: TypeExpression. //
11 // Implements Composite pattern [Leaf]. //
12 // Implements Singleton pattern. //
13 
14 // -------------------------------------------------------------------------- //
15 // Create date: 22-10-2006 //
16 // Modification date: 22-03-2007 //
18 
19 using System;
20 using System.Collections.Generic;
21 using System.Text;
22 
23 using AST;
24 using ErrorManagement;
25 using Tools;
26 using TypeSystem.Operations;
27 
28 namespace TypeSystem {
29  //VISTO
38  public class CharType : TypeExpression {
39  #region Fields
40 
44  private static readonly CharType instance = new CharType();
45 
49  private BCLClassType BCLType = new BCLClassType("System.Char", Type.GetType("System.Char"));
50 
51  #endregion
52 
53  #region Properties
54 
58  public static CharType Instance {
59  get { return instance; }
60  }
61 
62  #endregion
63 
64  #region Constructors
65 
69  private CharType() {
70  this.typeExpression = "char";
71  this.fullName = "char";
72  }
73 
77  static CharType() {
78  }
79 
80  #endregion
81 
82  // WriteType Inference
83 
84  #region Dispatcher
85 
86  public override object AcceptOperation(TypeSystemOperation op, object arg) { return op.Exec(this, arg); }
87 
88  #endregion
89 
90  #region Assignment() ANULADA
91 
105  //public override TypeExpression Assignment(TypeExpression operand, AssignmentOperator op, MethodType methodAnalyzed, SortOfUnification unification,
106  // TypeExpression actualImplicitObject, Location loc) {
107  // return operand.Promotion(this, op, methodAnalyzed, loc);
108  //}
109 
110  #endregion
111 
112  #region Arithmetic() ANULADA
113  /*
125  public override TypeExpression Arithmetic(TypeExpression operand, Enum op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
126  if (operand.PromotionLevel(this) != -1)
127  return CharType.instance;
128  if (op.Equals(ArithmeticOperator.Plus) && operand.Equivalent(StringType.Instance))
129  return StringType.Instance;
130  return (TypeExpression)ArithmeticalOperation.Create(this, op, methodAnalyzed, showErrorMessage, loc).AcceptOperation(operand);
131  }
132 
143  public override TypeExpression Arithmetic(UnaryOperator op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
144  return CharType.Instance;
145  }
146  */
147  #endregion
148 
149  #region Relational() ANULADA
150  /*
162  public override TypeExpression Relational(TypeExpression operand, RelationalOperator op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
163  if (operand.PromotionLevel(DoubleType.Instance) != -1)
164  return BoolType.Instance;
165  return operand.Relational(this, op, methodAnalyzed, showErrorMessage, loc);
166  }
167 
168 
169  * */
170  #endregion
171 
172  #region Dot() ANULADA
173  //public override TypeExpression Dot(string field, MethodType methodAnalyzed, IList<TypeExpression> previousDot, Location loc) {
186  // return this.BCLType.Dot(field, methodAnalyzed, previousDot, loc);
187  //}
196  //public override TypeExpression Dot(string memberName, IList<TypeExpression> previousDot) {
197  // return this.BCLType.Dot(memberName, previousDot);
198  //}
199  #endregion
200 
201  #region AsClassType()
202  public override ClassType AsClassType() {
208  return this.BCLType;
209  }
210  #endregion
211 
212  // WriteType Promotion
213 
214  #region PromotionLevel() ANULADA
215 
221  //public override int PromotionLevel(TypeExpression type) {
222  // // * Char type and type variable
223  // if (TypeExpression.As<CharType>(type) != null)
224  // return 0;
225  // // * Int type and type variable
226  // if (TypeExpression.As<IntType>(type)!=null)
227  // return 1;
228  // // * Double type and type variable
229  // if (TypeExpression.As<DoubleType>(type)!=null)
230  // return 2;
231  // // * Free type variables
232  // TypeVariable typeVariable = type as TypeVariable;
233  // if (typeVariable != null && typeVariable.Substitution == null)
234  // // * A free variable is complete promotion
235  // return 0;
236  // // * Union type
237  // UnionType unionType = TypeExpression.As<UnionType>(type);
238  // if (unionType != null)
239  // return unionType.SuperType(this);
240  // // * Field type and bounded type variable
241  // FieldType fieldType = TypeExpression.As<FieldType>(type);
242  // if (fieldType != null)
243  // return this.PromotionLevel(fieldType.FieldTypeExpression);
244  // // * Use the BCL object oriented approach
245  // return this.BCLType.PromotionLevel(type);
246  //}
247 
248  #endregion
249 
250  // WriteType Unification
251  #region Unify
252  public override bool Unify(TypeExpression te, SortOfUnification unification, IList<Pair<TypeExpression, TypeExpression>> previouslyUnified) {
260  CharType ct = te as CharType;
261  if (ct != null)
262  return true;
263  if (te is TypeVariable && unification!=SortOfUnification.Incremental)
264  // * No incremental unification is commutative
265  return te.Unify(this, unification, previouslyUnified);
266  if (te is FieldType && unification == SortOfUnification.Equivalent)
267  return ((FieldType)te).FieldTypeExpression.Unify(this, unification, previouslyUnified);
268  return false;
269  }
270  #endregion
271 
272  #region IsValueType()
273 
278  public override bool IsValueType()
279  {
280  return true;
281  }
282 
283  #endregion
284 
285 
286  }
287 }
static CharType Instance
Gets the unique instance of CharType
Definition: CharType.cs:58
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
Definition: CharType.cs:278
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
Represent a character type.
Definition: CharType.cs:38
Abstract class that represents all different types.
override bool Unify(TypeExpression te, SortOfUnification unification, IList< Pair< TypeExpression, TypeExpression >> previouslyUnified)
Returns a value that indicates a promotion level.
Definition: CharType.cs:259
override object AcceptOperation(TypeSystemOperation op, object arg)
Definition: CharType.cs:86
override ClassType AsClassType()
Check if the type can make an assignment operation.
Definition: CharType.cs:207
Represents a class type.
Definition: ClassType.cs:35