The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
DotConstraint.cs
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
3 // Project rROTOR
4 // --------------------------------------------------------------------------
5 // File: DotConstraint.cs
6 // Author: Francisco Ortin - francisco.ortin@gmail.com
7 // Description:
8 // Member access constraint to be executed each time the associated method
9 // has been called.
10 // It represents constraints of the form:
11 // ret := op1 . memberName
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 string memberName;
41  #endregion
42 
43  #region Properties
44  public string MemberName {
48  get { return this.memberName; }
49  }
50  #endregion
51 
52 
53  #region Constructor
54  public DotConstraint(TypeExpression firstOperand, string memberName, Location location)
61  : base(firstOperand, location) {
62  this.memberName = memberName;
63  }
70  private DotConstraint(TypeExpression firstOperand, string memberName, TypeVariable returnType, Location location)
71  : base(firstOperand, returnType, location) {
72  this.memberName = memberName;
73  }
74  #endregion
75 
76  #region BuildTypeExpressionString()
77  protected override string BuildTypeExpressionString() {
78  return String.Format("{0}:={1}.{2}", this.ReturnType.FullName, this.FirstOperand.FullName, this.MemberName);
79  }
80  #endregion
81 
82  #region CloneTypeVariables()
83  public override Constraint CloneTypeVariables(IDictionary<TypeVariable, TypeVariable> typeVariableMappings, IList<EquivalenceClass> equivalenceClasses) {
92  TypeExpression newFirstOperand = this.FirstOperand.CloneTypeVariables(typeVariableMappings, equivalenceClasses, new List<ClassType>());
93  TypeVariable newReturnType = (TypeVariable)this.ReturnType.CloneTypeVariables(typeVariableMappings, equivalenceClasses, new List<ClassType>());
94  return new DotConstraint(newFirstOperand, this.memberName, newReturnType, this.Location);
95  }
96  #endregion
97 
98  #region Check()
99  public override TypeExpression Check(MethodType methodAnalyzed, TypeExpression actualImplicitObject, bool showInvocationMessage,
110  SortOfUnification activeSortOfUnification, Location location) {
111  TypeExpression result = (TypeExpression) this.FirstOperand.AcceptOperation(DotOperation.Create(this.memberName, methodAnalyzed, new List<TypeExpression>(), this.Location), null);
112  if (result == null && showInvocationMessage) {
113  ErrorManager.Instance.NotifyError(new ConstraintError(location));
114  return null;
115  }
116  // * If no error exists, we unify the return type variable with the actual result
117  this.ReturnType.Unify(result, SortOfUnification.Equivalent, new List<Pair<TypeExpression, TypeExpression>>());
118  this.ReturnType.ValidTypeExpression = this.ValidTypeExpression = false;
119  return this.ReturnType;
120  }
121  #endregion
122 
123 
124  }
125 }
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
override string BuildTypeExpressionString()
Abstract class that represents all different types.
Represents a generic type expression
Definition: TypeVariable.cs:36
Implements a factory method pattern. Virtual constructor. Role: factory Implements a double dispatche...
Definition: DotOperation.cs:11
static DotOperation Create(string memberName, IList< TypeExpression > previousDot)
Definition: DotOperation.cs:20
Representa a method type.
Definition: MethodType.cs:37
virtual object AcceptOperation(TypeSystemOperation op, object arg)
It represents constraints of the form: ret := op1 . memberName