The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
NullType.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: NullType.cs //
6 // Authors: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Francisco Ortin - francisco.ortin@gmail.com //
8 // Description: //
9 // Represent a null type. //
10 // Inheritance: TypeExpression. //
11 // Implements Composite pattern [Leaf]. //
12 // Implements Singleton pattern. //
13 // -------------------------------------------------------------------------- //
14 // Create date: 05-04-2007 //
15 // Modification date: 05-04-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 NullType : TypeExpression {
37 
38  #region Fields
39 
43  private static readonly NullType instance = new NullType();
44 
45  #endregion
46 
47  #region Properties
48 
52  public static NullType Instance {
53  get { return instance; }
54  }
55 
56  #endregion
57 
58  #region Constructors
59 
63  private NullType() {
64  this.typeExpression = "null";
65  this.fullName = "null";
66  }
67 
71  static NullType() {
72  }
73 
74  #endregion
75 
76  // WriteType Inference
77 
78  #region Dispatcher
79  public override object AcceptOperation(TypeSystemOperation op, object arg) { return op.Exec(this, arg); }
80  #endregion
81 
82  #region Assignment() ANULADA
83 
97  //public override TypeExpression Assignment(TypeExpression operand, AssignmentOperator op, MethodType methodAnalyzed, SortOfUnification unification,
98  // TypeExpression actualImplicitObject, Location location) {
99  // if (op == AssignmentOperator.Assign)
100  // return operand;
101  // else
102  // ErrorManager.Instance.NotifyError(new AssignmentError(operand.FullName, this.FullName, location));
103  // return null;
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 (op.Equals(ArithmeticOperator.Plus) && operand.Equivalent(StringType.Instance))
122  return StringType.Instance;
123  if (showErrorMessage)
124  ErrorManager.Instance.NotifyError(new TypePromotionError(operand.FullName, this.FullName, op.ToString(), loc));
125  return null;
126  } */
127  #endregion
128 
129  // WriteType Promotion
130 
131  #region PromotionLevel() ANULADA
132 
138  //public override int PromotionLevel(TypeExpression type) {
139  // // * Built-in types: no promotion, except string
140  // if (type is BoolType || type is CharType || type is DoubleType || type is IntType || type is VoidType)
141  // return -1;
142  // // * BCL Value Types (structs): No promotion
143  // BCLClassType bclClass = TypeExpression.As<BCLClassType>(type);
144  // if (bclClass != null) {
145  // if (bclClass.TypeInfo.IsValueType)
146  // return -1;
147  // // * Correct promotion to classes that are not value types
148  // return 0;
149  // }
150  // // * WriteType variable
151  // TypeVariable typeVariable = type as TypeVariable;
152  // if (typeVariable != null) {
153  // if (typeVariable.Substitution != null)
154  // // * If the variable is bounded, the promotion is the one of its substitution
155  // return this.PromotionLevel(typeVariable.EquivalenceClass.Substitution);
156  // // * A free variable is complete promotion
157  // return 0;
158  // }
159  // // * Union type
160  // UnionType unionType = TypeExpression.As<UnionType>(type);
161  // if (unionType != null)
162  // return unionType.SuperType(this);
163  // // * Field type and bounded type variable
164  // FieldType fieldType = TypeExpression.As<FieldType>(type);
165  // if (fieldType != null)
166  // return this.PromotionLevel(fieldType.FieldTypeExpression);
167  // // * Correct Promotion
168  // return 0;
169  //}
170 
171  #endregion
172 
173  // WriteType Unification
174 
175  #region Unify
176  public override bool Unify(TypeExpression te, SortOfUnification unification, IList<Pair<TypeExpression, TypeExpression>> previouslyUnified) {
184 
185  throw new NotImplementedException("NullType.Unify() Not implemented");
186  }
187  #endregion
188 
189  #region IsValueType()
190 
195  public override bool IsValueType()
196  {
197  return false;
198  }
199 
200  #endregion
201 
202  public bool Equals(NullType other)
203  {
204  return true;
205  }
206 
207  public override bool Equals(object obj)
208  {
209  if (obj.GetType() != typeof (NullType))
210  return false;
211  return Equals((NullType) obj);
212  }
213 
214  public override int GetHashCode()
215  {
216  return 0;
217  }
218  }
219 }
static NullType Instance
Gets the unique instance of NullType
Definition: NullType.cs:52
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
Abstract class that represents all different types.
override object AcceptOperation(TypeSystemOperation op, object arg)
Definition: NullType.cs:79
override bool Unify(TypeExpression te, SortOfUnification unification, IList< Pair< TypeExpression, TypeExpression >> previouslyUnified)
&lt;summary&gt; // Check if the type can make an assignment operation. //
Definition: NullType.cs:183
bool Equals(NullType other)
Definition: NullType.cs:202
Represent a null type.
Definition: NullType.cs:36
override int GetHashCode()
Definition: NullType.cs:214
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
Definition: NullType.cs:195
override bool Equals(object obj)
Definition: NullType.cs:207