The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
RelationalConstraint.cs
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
3 // Project rROTOR
4 // --------------------------------------------------------------------------
5 // File: RelationalConstraint.cs
6 // Author: Francisco Ortin - francisco.ortin@gmail.com
7 // Description:
8 // Relational constraint to be executed each time the associated method
9 // has been called.
10 // It represents constraints of the form:
11 // ret := op1 op op2
12 // where op is an relational operator (== != >= <= > <)
13 // Implements Composite pattern [Leaf].
14 // Implements Command pattern [Concrete Command].
15 // Implements Memento pattern [Memento].
16 // --------------------------------------------------------------------------
17 // Create date: 25-04-2007
18 // Modification date: 25-04-2007
20 
21 using System;
22 using System.Collections.Generic;
23 using System.Text;
24 
25 using AST;
26 using ErrorManagement;
27 using Tools;
28 using TypeSystem.Operations;
29 
30 
31 namespace TypeSystem.Constraints {
38 
39  #region Fields
40  private TypeExpression secondOperand;
44 
48  private RelationalOperator op;
49  #endregion
50 
51  #region Properties
52  public TypeExpression SecondOperand {
56  get { return this.secondOperand; }
57  }
58 
62  public RelationalOperator Operator {
63  get { return this.op; }
64  }
65  #endregion
66 
67 
68  #region Constructor
69  public RelationalConstraint(TypeExpression firstOperand, TypeExpression secondOperand, RelationalOperator op, Location location)
77  : base(firstOperand, location) {
78  this.secondOperand = secondOperand;
79  this.op = op;
80  }
89  private RelationalConstraint(TypeExpression firstOperand, TypeExpression secondOperand, TypeVariable returnType, RelationalOperator op, Location location)
90  : base(firstOperand, returnType, location) {
91  this.secondOperand = secondOperand;
92  this.op = op;
93  }
94  #endregion
95 
96  #region BuildTypeExpressionString()
97  protected override string BuildTypeExpressionString() {
98  return String.Format("{0}:={1} {2} {3}", this.ReturnType.FullName, this.FirstOperand.FullName, op.ToString(), this.SecondOperand.FullName);
99  }
100  #endregion
101 
102  #region CloneTypeVariables()
103  public override Constraint CloneTypeVariables(IDictionary<TypeVariable, TypeVariable> typeVariableMappings, IList<EquivalenceClass> equivalenceClasses) {
112  TypeExpression newFirstOperand = this.FirstOperand.CloneTypeVariables(typeVariableMappings, equivalenceClasses, new List<ClassType>()),
113  newSecondOperand = this.SecondOperand.CloneTypeVariables(typeVariableMappings, equivalenceClasses, new List<ClassType>());
114  TypeVariable newReturnType = (TypeVariable)this.ReturnType.CloneTypeVariables(typeVariableMappings, equivalenceClasses, new List<ClassType>());
115  return new RelationalConstraint(newFirstOperand, newSecondOperand, newReturnType, this.Operator, this.Location);
116  }
117  #endregion
118 
119  #region Check()
120  public override TypeExpression Check(MethodType methodAnalyzed, TypeExpression actualImplicitObject, bool showInvocationMessage,
129  SortOfUnification activeSortOfUnification, Location location) {
130  TypeExpression result = (TypeExpression) this.FirstOperand.AcceptOperation(new RelationalOperation(this.SecondOperand, this.Operator, methodAnalyzed, true, this.Location), null);
131  if (result == null && showInvocationMessage) {
132  ErrorManager.Instance.NotifyError(new ConstraintError(location));
133  return null;
134  }
135  // * If no error exists, we unify the return type variable with the actual result
136  this.ReturnType.Unify(result, SortOfUnification.Equivalent, new List<Pair<TypeExpression, TypeExpression>>());
137  this.ReturnType.ValidTypeExpression = this.ValidTypeExpression = false;
138  return this.ReturnType;
139  }
140  #endregion
141 
142 
143  }
144 }
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.
Definition: Location.cs:24
Abstract class that represents all different types.
Represents a generic type expression
Definition: TypeVariable.cs:36
RelationalOperator
Relational binary operators
Representa a method type.
Definition: MethodType.cs:37
It represents constraints of the form: ret := op1 op op2 where op is an relational operator (== != &gt;=...
virtual object AcceptOperation(TypeSystemOperation op, object arg)