The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
StringType.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: StringType.cs //
6 // Authors: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Francisco Ortin - francisco.ortin@gmail.com //
8 // Description: //
9 // Represent a string type. //
10 // Inheritance: TypeExpression. //
11 // Implements Composite pattern [Leaf]. //
12 // Implements Singleton pattern. //
13 // -------------------------------------------------------------------------- //
14 // Create date: 22-10-2006 //
15 // Modification date: 22-03-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 StringType : TypeExpression {
37 
38  #region Fields
39 
43  private static readonly StringType instance = new StringType();
44 
48  private BCLClassType BCLType = new BCLClassType("System.String", Type.GetType("System.String"));
49 
50  #endregion
51 
52  #region Properties
53 
57  public static StringType Instance {
58  get { return instance; }
59  }
60 
61  #endregion
62 
63  #region Constructors
64 
68  private StringType() {
69  this.typeExpression = "string";
70  this.fullName = "string";
71  }
72 
76  static StringType() {
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  //public override TypeExpression Assignment(TypeExpression operand, AssignmentOperator op, MethodType methodAnalyzed, SortOfUnification unification,
101  // TypeExpression actualImplicitObject, Location location) {
102  // if ((op == AssignmentOperator.Assign) || (op == AssignmentOperator.PlusAssign))
103  // return operand.Promotion(this, op, methodAnalyzed, location);
104  // ErrorManager.Instance.NotifyError(new OperationNotAllowedError(this.FullName, operand.FullName, location));
105  // return null;
106  //}
107 
108  #endregion
109 
110  #region Arithmetic() ANULADA
111  /*
112 
113  public override TypeExpression Arithmetic(TypeExpression operand, Enum op, MethodType methodAnalyzed, bool showErrorMessage, Location loc) {
114  if (op.Equals(ArithmeticOperator.Plus)) {
115  if (operand is StringType)
116  return StringType.Instance;
117  // * Commutative
118  return operand.Arithmetic(this, op, methodAnalyzed, showErrorMessage, loc);
119  }
120  if (showErrorMessage)
121  ErrorManager.Instance.NotifyError(new OperationNotAllowedError(op.ToString(), this.FullName, operand.FullName, loc));
122  return null;
123  }
124  */
125  #endregion
126 
127  #region Relational()ANULADA
128  /*
140  public override objet AcceptOperation(RelationalOperation firstOperand) {
141  if (relationalOperator== RelationalOperator.Equal || op == RelationalOperator.NotEqual) {
142  if (secondOperand.PromotionLevel(this) != -1)
143  return BoolType.Instance;
144  if (showErrorMessage) {
145  ErrorManager.Instance.NotifyError(new TypePromotionError(operand.FullName, this.FullName, loc));
146  return null;
147  }
148  }
149  if (showErrorMessage)
150  ErrorManager.Instance.NotifyError(new OperationNotAllowedError(op.ToString(), this.FullName, operand.FullName, loc));
151  return null;
152  }
153  */
154  #endregion
155 
156  #region Dot() ANULADA
157  //public override TypeExpression Dot(string field, MethodType methodAnalyzed, IList<TypeExpression> previousDot, Location loc) {
170  // return this.BCLType.Dot(field, methodAnalyzed, previousDot, loc);
171  //}
180  //public override TypeExpression Dot(string memberName, IList<TypeExpression> previousDot) {
181  // return this.BCLType.Dot(memberName, previousDot);
182  //}
183  #endregion
184 
185  #region AsClassType()
186  public override ClassType AsClassType() {
192  return this.BCLType;
193  }
194  #endregion
195 
196  // WriteType Promotion
197 
198  #region PromotionLevel() ANULADA
199 
205  //public override int PromotionLevel(TypeExpression type) {
206  // // * String WriteType and bounded type variables
207  // if (TypeExpression.As<StringType>(type)!=null)
208  // return 0;
209  // // * WriteType variable
210  // TypeVariable typeVariable = type as TypeVariable;
211  // if (typeVariable != null && typeVariable.Substitution == null)
212  // // * A free variable is complete promotion
213  // return 0;
214  // // * Union type
215  // UnionType unionType = TypeExpression.As<UnionType>(type);
216  // if (unionType != null)
217  // return unionType.SuperType(this);
218  // // * Field type and bounded type variable
219  // FieldType fieldType = TypeExpression.As<FieldType>(type);
220  // if (fieldType != null)
221  // return this.PromotionLevel(fieldType.FieldTypeExpression);
222  // // * Use the BCL object oriented approach
223  // return this.BCLType.PromotionLevel(type);
224  //}
225 
226  #endregion
227 
228  #region IsValueType()
229 
234  public override bool IsValueType()
235  {
236  return false;
237  }
238 
239  #endregion
240 
241  // WriteType Unification
242 
243  #region Unify
244  public override bool Unify(TypeExpression te, SortOfUnification unification, IList<Pair<TypeExpression, TypeExpression>> previouslyUnified) {
252  StringType st = te as StringType;
253  if (st != null)
254  return true;
255  if (te is TypeVariable && unification != SortOfUnification.Incremental)
256  // * No incremental unification is commutative
257  return te.Unify(this, unification, previouslyUnified);
258  return false;
259  }
260  #endregion
261  }
262 }
static StringType Instance
Gets the unique instance of StringType
Definition: StringType.cs:57
override bool Unify(TypeExpression te, SortOfUnification unification, IList< Pair< TypeExpression, TypeExpression >> previouslyUnified)
This method unifies two type expressions (this and te)
Definition: StringType.cs:251
Represent a string type.
Definition: StringType.cs:36
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
Abstract class that represents all different types.
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
Definition: StringType.cs:234
Represents a generic type expression
Definition: TypeVariable.cs:36
override ClassType AsClassType()
Represent a type as a class. It is mainly used to obtain the BCL representation of types (string=Stri...
Definition: StringType.cs:191
override object AcceptOperation(TypeSystemOperation op, object arg)
Definition: StringType.cs:83
Represents a class type.
Definition: ClassType.cs:35