The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CastConstraint.cs
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
3 // Project rROTOR
4 // --------------------------------------------------------------------------
5 // File: CastConstraint.cs
6 // Author: Francisco Ortin - francisco.ortin@gmail.com
7 // Description:
8 // Cast constraint to be executed each time the associated method
9 // has been called. It represents constraints of the form:
10 // (op1)op2 (op2 might be converted int a op1)
11 // Implements Composite pattern [Leaf].
12 // Implements Command pattern [Concrete Command].
13 // Implements Memento pattern [Memento].
14 // --------------------------------------------------------------------------
15 // Create date: 13-07-2007
16 // Modification date: 13-07-2007
18 
19 using System;
20 using System.Collections.Generic;
21 using System.Text;
22 
23 using ErrorManagement;
24 using TypeSystem.Operations;
25 
26 namespace TypeSystem.Constraints {
32  #region Fields
33  private TypeExpression castType;
37 
38  #endregion
39 
40  #region Properties
41  public TypeExpression CastType {
45  get { return this.castType; }
46  }
47 
48  #endregion
49 
50 
51  #region Constructor
52  public CastConstraint(TypeExpression firstOperand, TypeExpression castType, Location loc)
59  : base(firstOperand, loc) {
60  this.castType = castType;
61  }
62  #endregion
63 
64  #region BuildTypeExpressionString()
65  protected override string BuildTypeExpressionString() {
66  return String.Format("({0}){1}", this.CastType.FullName, this.FirstOperand.FullName);
67  }
68  #endregion
69 
70  #region EqualsAndGetHashCode
71  public override bool Equals(object obj) {
72  CastConstraint constraint = obj as CastConstraint;
73  if (constraint == null)
74  return false;
75  return this.FirstOperand.Equals(constraint.FirstOperand) && this.CastType.Equals(constraint.CastType);
76  }
77  public override int GetHashCode() {
78  return this.FirstOperand.GetHashCode()*this.CastType.GetHashCode();
79  }
80  #endregion
81 
82 
83  #region CloneTypeVariables()
84  public override Constraint CloneTypeVariables(IDictionary<TypeVariable, TypeVariable> typeVariableMappings, IList<EquivalenceClass> equivalenceClasses) {
93  TypeExpression newFirstOperand = this.FirstOperand.CloneTypeVariables(typeVariableMappings, equivalenceClasses, new List<ClassType>()),
94  newCastType = this.CastType.CloneTypeVariables(typeVariableMappings, equivalenceClasses, new List<ClassType>());
95  return new CastConstraint(newFirstOperand, newCastType, this.Location);
96  }
97  #endregion
98 
99  #region Check()
100  public override TypeExpression Check(MethodType methodAnalyzed, TypeExpression actualImplicitObject, bool showInvocationMessage,
110  SortOfUnification activeSortOfUnification, Location location) {
111  TypeExpression result = (TypeExpression)this.FirstOperand.AcceptOperation(new CastOperation (this.CastType, methodAnalyzed,this.Location), null);
112  if (result == null && showInvocationMessage) {
113  ErrorManager.Instance.NotifyError(new ConstraintError(location));
114  return null;
115  }
116  // * If no error exists, we return the casttype
117  return this.CastType;
118  }
119  #endregion
120 
121 
122  }
123 }
These clase implements cast operation over a type expression that is encapsulated in a message pass t...
override bool Equals(object obj)
Represents a error produced when a constraint has not been satisfied
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
TypeExpression CastType
The cast type
Abstract class that represents all different types.
Representa a method type.
Definition: MethodType.cs:37
virtual object AcceptOperation(TypeSystemOperation op, object arg)