The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CloneConstraint.cs
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
3 // Project rROTOR
4 // --------------------------------------------------------------------------
5 // File: CloneConstraint.cs
6 // Author: Francisco Ortin - francisco.ortin@gmail.com
7 // Description:
8 // A postponed clone operation for SSA algoritm.
9 // It represents constraints of the form:
10 // ret := Clone(op1)
11 // Implements Composite pattern [Leaf].
12 // Implements Command pattern [Concrete Command].
13 // Implements Memento pattern [Memento].
14 // --------------------------------------------------------------------------
15 // Create date: 11-06-2007
16 // Modification date: 1-06-2007
18 
19 using System;
20 using System.Collections.Generic;
21 using System.Text;
22 
23 using AST;
24 using ErrorManagement;
25 using Tools;
26 using Semantic.SSAAlgorithm;
27 
28 namespace TypeSystem.Constraints {
30  // It represents constraints of the form:
31  // ret := Clone(op1)
34 
35  #region Fields
36  #endregion
37 
38  #region Properties
39  #endregion
40 
41 
42  #region Constructor
43  public CloneConstraint(TypeExpression firstOperand)
48  : base(firstOperand, new Location()) {
49  }
55  private CloneConstraint(TypeExpression firstOperand, TypeVariable returnType)
56  : base(firstOperand, returnType, new Location()) {
57  }
58  #endregion
59 
60  #region BuildTypeExpressionString()
61  protected override string BuildTypeExpressionString() {
62  return String.Format("{0}:=Clone({1})", this.ReturnType.FullName, this.FirstOperand.FullName);
63  }
64  #endregion
65 
66  #region CloneTypeVariables()
67  public override Constraint CloneTypeVariables(IDictionary<TypeVariable, TypeVariable> typeVariableMappings, IList<EquivalenceClass> equivalenceClasses) {
76  TypeExpression newFirstOperand = this.FirstOperand.CloneTypeVariables(typeVariableMappings, equivalenceClasses, new List<ClassType>());
77  TypeVariable newReturnType = (TypeVariable)this.ReturnType.CloneTypeVariables(typeVariableMappings, equivalenceClasses, new List<ClassType>());
78  return new CloneConstraint(newFirstOperand, newReturnType);
79  }
80  #endregion
81 
82  #region Check()
83  public override TypeExpression Check(MethodType methodAnalyzed, TypeExpression actualImplicitObject, bool showInvocationMessage,
94  SortOfUnification activeSortOfUnification, Location location) {
95  TypeExpression result = SSAHelper.CloneType(this.FirstOperand,methodAnalyzed);
96  this.ReturnType.Unify(result, SortOfUnification.Equivalent, new List<Pair<TypeExpression, TypeExpression>>());
97  this.ReturnType.ValidTypeExpression = this.ValidTypeExpression = false;
98  return this.ReturnType;
99  }
100  #endregion
101 
102 
103  }
104 }
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...
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
Representa a method type.
Definition: MethodType.cs:37