The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
SquareBracketConstraint.cs
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
3 // Project rROTOR
4 // --------------------------------------------------------------------------
5 // File: SquareBracketConstraint.cs
6 // Author: Francisco Ortin - francisco.ortin@gmail.com
7 // Description:
8 // Array access constraint to be executed each time the associated method
9 // has been called.
10 // It represents constraints of the form:
11 // ret := op1 [ op2 ]
12 // Implements Composite pattern [Leaf].
13 // Implements Command pattern [Concrete Command].
14 // Implements Memento pattern [Memento].
15 // --------------------------------------------------------------------------
16 // Create date: 26-04-2007
17 // Modification date: 26-04-2007
19 
20 using System;
21 using System.Collections.Generic;
22 using System.Text;
23 
24 using AST;
25 using ErrorManagement;
26 using Tools;
27 using TypeSystem.Operations;
28 
29 namespace TypeSystem.Constraints {
35 
36  #region Fields
37  private TypeExpression secondOperand;
41  #endregion
42 
43  #region Properties
44  public TypeExpression SecondOperand {
48  get { return this.secondOperand; }
49  }
50  #endregion
51 
52 
53  #region Constructor
54  public SquareBracketConstraint(TypeExpression firstOperand, TypeExpression secondOperand, Location location) :
61  base(firstOperand, location) {
62  this.secondOperand = secondOperand;
63  }
71  private SquareBracketConstraint(TypeExpression firstOperand, TypeExpression secondOperand, TypeVariable returnType, Location location)
72  : base(firstOperand, returnType, location) {
73  this.secondOperand = secondOperand;
74  }
75  #endregion
76 
77  #region BuildTypeExpressionString()
78  protected override string BuildTypeExpressionString() {
79  return String.Format("{0}:={1} [ {2} ]", this.ReturnType.FullName, this.FirstOperand.FullName, this.SecondOperand.FullName);
80  }
81  #endregion
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  newSecondOperand = this.SecondOperand.CloneTypeVariables(typeVariableMappings, equivalenceClasses, new List<ClassType>());
95  TypeVariable newReturnType = (TypeVariable)this.ReturnType.CloneTypeVariables(typeVariableMappings, equivalenceClasses, new List<ClassType>());
96  return new SquareBracketConstraint(newFirstOperand, newSecondOperand, newReturnType, this.Location);
97  }
98  #endregion
99 
100  #region Check()
101  public override TypeExpression Check(MethodType methodAnalyzed, TypeExpression actualImplicitObject, bool showInvocationMessage,
112  SortOfUnification activeSortOfUnification, Location location) {
113  TypeExpression result = (TypeExpression)this.FirstOperand.AcceptOperation(new SquareBracketOperation(this.SecondOperand, methodAnalyzed, true, this.Location), null);
114  if (result == null && showInvocationMessage) {
115  ErrorManager.Instance.NotifyError(new ConstraintError(location));
116  return null;
117  }
118  // * If no error exists, we unify the return type variable with the actual result
119  this.ReturnType.Unify(result, SortOfUnification.Equivalent, new List<Pair<TypeExpression, TypeExpression>>());
120  this.ReturnType.ValidTypeExpression = this.ValidTypeExpression = false;
121  return this.ReturnType;
122  }
123  #endregion
124 
125 
126  }
127 }
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
Implements bracket operation of a type expression. Implments double dispatcher pattern.
Representa a method type.
Definition: MethodType.cs:37
It represents constraints of the form: ret := ret := op1 [ op2 ]
virtual object AcceptOperation(TypeSystemOperation op, object arg)