The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
ConstraintAdapter.cs
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
3 // Project rROTOR
4 // --------------------------------------------------------------------------
5 // File: ConstraintAdapter.cs
6 // Author: Francisco Ortin - francisco.ortin@gmail.com
7 // Description:
8 // Constraint adater to refactor the common elements to all the contraints,
9 // but the ConstraintList constraints.
10 // It is the implementation of the adapter design pattern, using
11 // implementation inheritance.
12 // Implements Adapter pattern [Adapter].
13 // Implements (partially) Memento pattern [Memento].
14 // --------------------------------------------------------------------------
15 // Create date: 25-04-2007
16 // Modification date: 25-04-2007
18 
19 using System;
20 using System.Collections.Generic;
21 using System.Text;
22 using ErrorManagement;
23 
24 namespace TypeSystem.Constraints {
25  abstract class ConstraintAdapter: Constraint {
26  #region Fields
27  private TypeExpression firstOperand;
31 
35  private TypeVariable returnType;
39  private Location location;
40  #endregion
41 
42  #region Properties
43  public Location Location {
44  get { return location; }
45  }
49  public TypeExpression FirstOperand {
50  get { return this.firstOperand; }
51  }
52 
56  public TypeVariable ReturnType {
57  get { return this.returnType; }
58  }
59 
60  #endregion
61 
62 
63 
64  #region Constructor
65  public ConstraintAdapter(TypeExpression firstOperand, Location loc) {
71  this.firstOperand = firstOperand;
72  this.returnType = TypeVariable.NewTypeVariable;
73  this.location = loc;
74  }
81 protected ConstraintAdapter(TypeExpression firstOperand, TypeVariable returnType, Location loc) {
82  this.firstOperand = firstOperand;
83  this.returnType = returnType;
84  this.location = loc;
85  }
86  #endregion
87 
88  #region EqualsAndGetHashCode
89  public override bool Equals(object obj) {
90  ArithmeticConstraint constraint = obj as ArithmeticConstraint;
91  if (constraint == null)
92  return false;
93  return this.returnType.Variable == constraint.returnType.Variable;
94  }
95  public override int GetHashCode() {
96  return this.returnType.Variable;
97  }
98  #endregion
99 
100  }
101 }
static TypeVariable NewTypeVariable
Gets a new identify to the variable type
Definition: TypeVariable.cs:67
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
ConstraintAdapter(TypeExpression firstOperand, TypeVariable returnType, Location loc)
Private constructor that receives the retun type variable
Abstract class that represents all different types.
Represents a generic type expression
Definition: TypeVariable.cs:36
It represents constraints of the form: ret := op1 op op2 Where op is an arithmetic operator ...