The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
BoolType.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: BoolType.cs //
6 // Authors: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Francisco Ortin - francisco.ortin@gmail.com //
8 // Description: //
9 // Represent a bool type. //
10 // Inheritance: TypeExpression. //
11 // Implements Composite pattern [Leaf]. //
12 // Implements Singleton pattern. //
13 // -------------------------------------------------------------------------- //
14 // Create date: 09-02-2007 //
15 // Modification date: 22-03-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 //VISTO
27 namespace TypeSystem {
36  public class BoolType : TypeExpression {
37  #region Fields
38 
42  private static readonly BoolType instance = new BoolType();
43 
47  private BCLClassType BCLType = new BCLClassType("System.Boolean", Type.GetType("System.Boolean"));
48 
49 
50  #endregion
51 
52  #region Properties
53 
57  public static BoolType Instance {
58  get { return instance; }
59  }
60 
61  #endregion
62 
63  #region Constructors
64 
68  private BoolType() {
69  this.typeExpression = "bool";
70  this.fullName = "bool";
71  }
72 
76  static BoolType() {
77  }
78 
79  #endregion
80 
81  // WriteType Inference
82 
83  #region Dispatcher
84  public override object AcceptOperation(TypeSystemOperation op, object arg) { return op.Exec(this, arg); }
85  #endregion
86 
87  #region Assignment() ANULADA
88 
109 
110  #endregion
111 
112  #region Relational() ANULADA
113  /*
125  public override TypeExpression Relational(TypeExpression operand, RelationalOperator op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
126  if ((op == RelationalOperator.Equal) || (op == RelationalOperator.NotEqual)) {
127  if (operand.PromotionLevel(this) != -1)
128  return BoolType.Instance;
129  if (showErrorMessage) {
130  ErrorManager.Instance.NotifyError(new TypePromotionError(operand.FullName, this.FullName, loc));
131  return null;
132  }
133  }
134  if (showErrorMessage)
135  ErrorManager.Instance.NotifyError(new OperationNotAllowedError(op.ToString(), this.FullName, operand.FullName, loc));
136  return null;
137  }
138  */
139  #endregion
140 
141  #region Arithmetic ANULADA
142  /*
154  public override TypeExpression Arithmetic(TypeExpression operand, Enum op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
155  if (op.Equals(ArithmeticOperator.Plus) && operand.Equivalent(StringType.Instance))
156  return StringType.Instance;
157  if (showErrorMessage)
158  ErrorManager.Instance.NotifyError(new TypePromotionError(operand.FullName, this.FullName, op.ToString(), loc));
159  return null;
160  }
161  * */
162  #endregion
163 
164  #region Dot() ANULADA
165  //public override TypeExpression Dot(string field, MethodType methodAnalyzed, IList<TypeExpression> previousDot, Location loc) {
178  // return this.BCLType.Dot(field, methodAnalyzed, previousDot, loc);
179  //}
188  //public override TypeExpression Dot(string memberName, IList<TypeExpression> previousDot) {
189  // return this.BCLType.Dot(memberName, previousDot);
190  //}
191  #endregion
192 
193  #region AsClassType()
194  public override ClassType AsClassType() {
200  return this.BCLType;
201  }
202  #endregion
203 
204  // WriteType Promotion
205 
206  #region PromotionLevel() ANULADA
207  //public override int PromotionLevel(TypeExpression type) {
213  // // * Bool type and type variable
214  // if (TypeExpression.As<BoolType>(type)!=null)
215  // return 0;
216  // // * WriteType variable
217  // TypeVariable typeVariable = type as TypeVariable;
218  // if (typeVariable != null && typeVariable.Substitution==null)
219  // // * A free variable is complete promotion
220  // return 0;
221  // // * Union type
222  // UnionType unionType = TypeExpression.As<UnionType>(type);
223  // if (unionType != null)
224  // return unionType.SuperType(this);
225  // // * Field type and bounded type variable
226  // FieldType fieldType = TypeExpression.As<FieldType>(type);
227  // if (fieldType != null)
228  // return this.PromotionLevel(fieldType.FieldTypeExpression);
229  // // * Use the BCL object oriented approach
230  // return this.BCLType.PromotionLevel(type);
231  //}
232 
233  #endregion
234 
235  // WriteType Unification
236 
237  #region Unify
238  public override bool Unify(TypeExpression te, SortOfUnification unification, IList<Pair<TypeExpression, TypeExpression>> previouslyUnified) {
246  BoolType bt = te as BoolType;
247  if (bt != null)
248  return true;
249  if (te is TypeVariable && unification != SortOfUnification.Incremental)
250  // * No incremental unification is commutative
251  return te.Unify(this, unification, previouslyUnified);
252  return false;
253  }
254  #endregion
255 
256  #region IsValueType()
257 
262  public override bool IsValueType()
263  {
264  return true;
265  }
266 
267  #endregion
268 
269  }
270 }
override object AcceptOperation(TypeSystemOperation op, object arg)
Definition: BoolType.cs:84
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
override bool Unify(TypeExpression te, SortOfUnification unification, IList< Pair< TypeExpression, TypeExpression >> previouslyUnified)
This method unifies two type expressions (this and te)
Definition: BoolType.cs:245
Abstract class that represents all different types.
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
Definition: BoolType.cs:262
override ClassType AsClassType()
Represent a type as a class. It is mainly used to obtain the BCL representation of types (string=Stri...
Definition: BoolType.cs:199
static BoolType Instance
Gets the unique instance of BoolType
Definition: BoolType.cs:57
Represent a bool type.
Definition: BoolType.cs:36
Represents a class type.
Definition: ClassType.cs:35