24 using System.Collections.Generic;
28 using ErrorManagement;
30 using TypeSystem.Operations;
32 namespace TypeSystem.Constraints {
54 private bool isBinary;
63 get {
return this.secondOperand; }
69 public Enum BinaryOperator {
72 throw new InvalidOperationException(
"Not binary operator is defined for unary expressions");
83 throw new InvalidOperationException(
"Not unary operator is defined for binary expressions");
91 public bool IsBinary {
92 get {
return this.isBinary; }
106 : base(firstOperand, location) {
107 this.secondOperand = secondOperand;
109 this.isBinary =
true;
120 : base(firstOperand, returnType, location) {
121 this.secondOperand = secondOperand;
123 this.isBinary =
true;
132 : base(firstOperand, location) {
134 this.isBinary =
false;
144 : base(firstOperand, returnType, location) {
146 this.isBinary =
false;
150 #region BuildTypeExpressionString()
154 return String.Format(
"{0}:={1} {2} {3}", this.ReturnType.FullName, this.FirstOperand.FullName, op.ToString(), this.SecondOperand.FullName);
156 return String.Format(
"{0}:={1} {2}", this.ReturnType.FullName, op.ToString(), this.FirstOperand.FullName);
160 #region CloneTypeVariables()
161 public override Constraint CloneTypeVariables(IDictionary<TypeVariable, TypeVariable> typeVariableMappings, IList<EquivalenceClass> equivalenceClasses) {
170 TypeExpression newFirstOperand = this.FirstOperand.CloneTypeVariables(typeVariableMappings, equivalenceClasses,
new List<ClassType>());
174 TypeExpression newSecondOperand = this.SecondOperand.CloneTypeVariables(typeVariableMappings, equivalenceClasses,
new List<ClassType>());
183 public override TypeExpression Check(MethodType methodAnalyzed, TypeExpression actualImplicitObject,
bool showInvocationMessage,
192 TypeExpression result;
194 result= (TypeExpression) this.FirstOperand.AcceptOperation(
ArithmeticalOperation.
Create(
this.SecondOperand,
this.BinaryOperator, methodAnalyzed,
true,
this.Location), null);
196 result = (TypeExpression)this.FirstOperand.AcceptOperation(
ArithmeticalOperation.
Create(
this.UnaryOperator, methodAnalyzed,
true,
this.Location), null);
197 if (result == null && showInvocationMessage) {
202 this.ReturnType.Unify(result, SortOfUnification.Equivalent,
new List<Pair<TypeExpression, TypeExpression>>());
203 this.ReturnType.ValidTypeExpression = this.ValidTypeExpression =
false;
204 return this.ReturnType;
override TypeExpression CloneTypeVariables(IDictionary< TypeVariable, TypeVariable > typeVariableMappings, IList< EquivalenceClass > equivalenceClasses, IList< ClassType > clonedClasses)
Method that clones each type variable of a type expression. Equivalence classes are not cloned (but i...
Represents a error produced when a constraint has not been satisfied
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.
Abstract class that represents all different types.
Represents a generic type expression
ArithmeticConstraint(TypeExpression firstOperand, UnaryOperator op, Location location)
Constructor for unary arithmetic operations
override string BuildTypeExpressionString()
UnaryOperator
Unary operators
This class instantiates elements of type UnaryArithmeticalOperation, and BinaryArithmeticalOperation...
It represents constraints of the form: ret := op1 op op2 Where op is an arithmetic operator ...
static ArithmeticalOperation Create(UnaryOperator unaryOperator, MethodType methodAnalyzed, bool showErrorMessage, Location location)
A factory Method to create UnaryAritmeticaslOperation objects Implements a factory method...