The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CastOperation.cs
Go to the documentation of this file.
1 
2 using ErrorManagement;
3 using TypeSystem.Constraints;
4 namespace TypeSystem.Operations {
11  #region Fields
12  protected TypeExpression castType;
23  protected Location location;
27  protected bool showErrorMessages;
28  #endregion
29 
30  #region Constructor
31  public CastOperation(TypeExpression castType, MethodType methodAnalyzed, Location location) {
38  this.castType = castType;
39  this.methodAnalyzed = methodAnalyzed;
40  this.location = location;
41  }
42  #endregion
43 
44  #region (TypeExpression) --->castType
45  public override object Exec(TypeExpression from, object arg) {
53  if (this.castType == null)
54  return null;
55  if (((int)castType.AcceptOperation(new PromotionLevelOperation(from), arg) != -1) || ((int)from.AcceptOperation(new PromotionLevelOperation(castType), arg) != -1))
56  return castType;
57  return ReportError(from);
58  }
59  #endregion
60 
61  #region (TypeVarible) --->castType
62  public override object Exec(TypeVariable from, object arg) {
72  if (from.Substitution != null) {
73  return from.Substitution.AcceptOperation(this, arg);
74  }
75  if (this.methodAnalyzed != null) {
76  // * A constraint is added to the method analyzed
77  CastConstraint constraint = new CastConstraint(from, this.castType, this.location);
78  this.methodAnalyzed.AddConstraint(constraint);
79  return constraint.ReturnType;
80  }
81  return ReportError(from);
82  }
83  #endregion
84 
85  #region (FieldType) --->castType
86  public override object Exec(FieldType from, object arg) {
94  if (from.FieldTypeExpression != null)
95  return from.FieldTypeExpression.AcceptOperation(this, arg);
96  return null;
97  }
98  #endregion
99 
100 
106  public override object ReportError(TypeExpression from) {
107  ErrorManager.Instance.NotifyError(new TypeCastError(from.FullName, this.castType.FullName, this.location));
108  return null;
109  }
110  }
111 }
Its operation AcceptOperation() returns an integer value that indicates a promotion level between two...
These clase implements cast operation over a type expression that is encapsulated in a message pass t...
It represents constraints of the form (op1)op2 (op2 might be converted int a op1) ...
This class encapsulates a location in a specific file. Implements an Inmutable pattern. So it can be used in any context, that is his internal fields never change.
Definition: Location.cs:24
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
override object ReportError(TypeExpression from)
If showMessages is true it raises and error. It returns null
Abstract class that represents all different types.
Represents a generic type expression
Definition: TypeVariable.cs:36
virtual string FullName
Gets the full name of the type Note: WriteType expression is the longest recursive representation of ...
bool showErrorMessages
Indicates if an error message should be shown (used for dynamic types)
Location location
The location (file, line, column) of text being analysed
Representa a method type.
Definition: MethodType.cs:37
TypeExpression Substitution
Gets the substitution; null if it does not exist
MethodType methodAnalyzed
The method that is being analyzed when the operation is performed.
Represents a error produced when a type cast can not be applied to specified expressions.