5 using DynVarManagement;
6 using TypeSystem.Constraints;
7 namespace TypeSystem.Operations {
55 this.secondOperand = secondOperand;
56 this.binaryOperator = binaryOperator;
57 this.methodAnalyzed = methodAnalyzed;
58 this.showErrorMessage = showErrorMessage;
59 this.location = location;
63 #region BoolType +-secondOperand
64 public override object Exec(
BoolType firstOperand,
object arg) {
76 if (this.showErrorMessage)
77 ErrorManager.Instance.NotifyError(
new TypePromotionError(firstOperand.
FullName,
this.secondOperand.FullName,
this.binaryOperator.ToString(), this.location));
82 #region DoubleType +-secondOperand
83 public override object Exec(
DoubleType firstOperand,
object arg) {
91 if ((
int)this.secondOperand.AcceptOperation(
new PromotionLevelOperation(firstOperand), arg) != -1)
95 if (methodAnalyzed != null && ((TypeVariable)secondOperand).Substitution == null)
99 methodAnalyzed.AddConstraint(constraint);
100 return constraint.ReturnType;
108 return secondOperand.
AcceptOperation(ArithmeticalOperation.Create(firstOperand,
this.binaryOperator,
this.methodAnalyzed,
this.showErrorMessage,
this.location), arg);
112 #region IntType +-secondOperand
113 public override object Exec(
IntType firstOperand,
object arg) {
121 if ((
int)this.secondOperand.AcceptOperation(
new PromotionLevelOperation(firstOperand), arg) != -1)
123 if (secondOperand is TypeVariable && ((TypeVariable) secondOperand).Substitution == null)
125 if (methodAnalyzed != null)
129 binaryOperator, location);
130 methodAnalyzed.AddConstraint(constraint);
131 return constraint.ReturnType;
138 return this.secondOperand.
AcceptOperation(ArithmeticalOperation.Create(firstOperand,
this.binaryOperator,
this.methodAnalyzed,
this.showErrorMessage,
this.location), arg);
142 #region CharType +-secondOperand
143 public override object Exec(
CharType firstOperand,
object arg) {
151 if ((
int)this.secondOperand.
AcceptOperation(
new PromotionLevelOperation(firstOperand), arg) != -1)
153 if (secondOperand is TypeVariable && ((TypeVariable)secondOperand).Substitution == null)
155 if (methodAnalyzed != null)
159 binaryOperator, location);
160 methodAnalyzed.AddConstraint(constraint);
161 return constraint.ReturnType;
168 return this.secondOperand.
AcceptOperation(ArithmeticalOperation.Create(firstOperand,
this.binaryOperator,
this.methodAnalyzed,
this.showErrorMessage,
this.location), arg);
172 #region StringType +-secondOperand
184 if (promotableToStringInAddition(this.secondOperand))
190 return ReportError(firstOperand);
213 #region NullType +-secondOperand
214 public override object Exec(
NullType firstOperand,
object arg) {
224 if (showErrorMessage)
230 #region FieldType +-secondOperand
231 public override object Exec(
FieldType firstOperand,
object arg) {
242 return firstOperand.FieldTypeExpression.AcceptOperation(
this, arg);
247 #region PropertyType +-secondOperand
248 public override object Exec(
PropertyType firstOperand,
object arg) {
259 return firstOperand.PropertyTypeExpression.AcceptOperation(ArithmeticalOperation.Create(firstOperand, this.binaryOperator, this.methodAnalyzed, this.showErrorMessage, this.location), arg);
265 #region TypeVariable +-secondOperand
266 public override object Exec(TypeVariable firstOperand,
object arg) {
275 DynVarOptions.Instance.AssignDynamism(firstOperand.Substitution, firstOperand.IsDynamic);
276 return firstOperand.Substitution.AcceptOperation(
this, arg);
278 if (methodAnalyzed != null) {
281 methodAnalyzed.AddConstraint(constraint);
282 return constraint.ReturnType;
284 if (showErrorMessage)
285 ErrorManager.Instance.NotifyError(
new OperationNotAllowedError(binaryOperator.ToString(), firstOperand.FullName, secondOperand.FullName, location));
291 #region UnionType +-secondOperand
292 public override object Exec(
UnionType firstOperand,
object arg) {
306 methodAnalyzed.AddConstraint(constraint);
307 return constraint.ReturnType;
312 if (ret == null && !firstOperand.
IsDynamic)
315 returnType = UnionType.collect(returnType, ret);
318 if (showErrorMessage && firstOperand.
IsDynamic && returnType == null)
319 ErrorManager.Instance.NotifyError(
new NoTypeAcceptsOperation(firstOperand.
FullName,
this.binaryOperator.ToString(), secondOperand.FullName, location));
324 #region Report Errors
335 if (this.showErrorMessage)
336 ErrorManager.Instance.NotifyError(
new OperationNotAllowedError(this.binaryOperator.ToString(), tE.FullName, this.secondOperand.FullName, this.location));
static StringType Instance
Gets the unique instance of StringType
override string FullName
The full name in type variables is calculated just in time
Represents a error produced when tries to make an operation not allowed for the specified type...
static DoubleType Instance
Gets the unique instance of DoubleType
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.
Represent a character type.
Abstract class that represents all different types.
Represents a generic type expression
virtual string FullName
Gets the full name of the type Note: WriteType expression is the longest recursive representation of ...
No location information is provided within this class, because the exec methods invoked by the proper...
Represent a integer type.
Represents a double type.
ArithmeticOperator
Arithmetic binary operators
TypeExpression FieldTypeExpression
Gets the field type.
override object ReportError(TypeExpression tE)
If showMessages is true it raises and error. It returns null
virtual bool IsDynamic
Indicates if the type has been set as dynamic
Location location
The location (file, line, column) of text being analysed.
override object Exec(StringType firstOperand, object arg)
The first Operand is a StringType so the second must be promotable in such way that the whole operati...
This class instantiates elements of type UnaryArithmeticalOperation, and BinaryArithmeticalOperation...
override bool IsFreshVariable()
To know if it is a type variable with no substitution
Representa a property type.
override object AcceptOperation(TypeSystemOperation op, object arg)
Representa a method type.
It represents constraints of the form: ret := op1 op op2 Where op is an arithmetic operator ...
override object AcceptOperation(TypeSystemOperation op, object arg)
static IntType Instance
Gets the unique instance of IntType
Enum binaryOperator
operand to apply to the operands.
bool showErrorMessage
Indicates if an error message should be shown (used for dynamic types)
IList< TypeExpression > TypeSet
Gets the list of type expressions
TypeExpression Substitution
Gets the substitution; null if it does not exist
TypeExpression PropertyTypeExpression
Gets the property type.
static ArithmeticalOperation Create(UnaryOperator unaryOperator, MethodType methodAnalyzed, bool showErrorMessage, Location location)
A factory Method to create UnaryAritmeticaslOperation objects Implements a factory method...
MethodType methodAnalyzed
the actual method being analised.
Represents a error produced when a dynamic union type has no valid type to be applied an operation ...
virtual object AcceptOperation(TypeSystemOperation op, object arg)