The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
ConstraintList.cs
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
3 // Project rROTOR
4 // --------------------------------------------------------------------------
5 // File: ConstraintList.cs
6 // Author: Francisco Ortin - francisco.ortin@gmail.com
7 // Description:
8 // Composite class capable of representing a (possible empty)
9 // set of constraints.
10 // Implements Composite pattern [Composite].
11 // --------------------------------------------------------------------------
12 // Create date: 05-04-2007
13 // Modification date: 05-04-2007
15 
16 using System;
17 using System.Collections.Generic;
18 using System.Text;
19 using ErrorManagement;
20 
21 namespace TypeSystem.Constraints
22 {
26  public class ConstraintList : Constraint
27  {
28  #region Fields
29  private IList<Constraint> constraints = new List<Constraint>();
33  #endregion
34 
35  #region Properties
36  public IList<Constraint> Constraints
40  {
41  get { return this.constraints; }
42  }
43 
47  public int Count
48  {
49  get { return constraints.Count; }
50  }
51 
57  public Constraint this[int index]
58  {
59  get { return this.constraints[index]; }
60  }
61 
62 
63  #endregion
64 
65  #region BuildTypeExpressionString()
66  protected override string BuildTypeExpressionString()
67  {
68  StringBuilder sb = new StringBuilder();
69  for (int i = 0; i < this.constraints.Count; i++)
70  {
71  sb.Append(this.constraints[i].ToString());
72  if (i < this.constraints.Count - 1)
73  sb.Append(", ");
74  }
75  return sb.ToString();
76  }
77  #endregion
78 
79  #region Add()
80  public bool Add(Constraint constraint)
86  {
87  this.constraints.Add(constraint);
88  return true;
89  }
90  #endregion
91 
92  #region isEmpty()
93  public override bool isEmpty()
94  {
95  return this.constraints.Count == 0;
96  }
97  #endregion
98 
99  #region CloneTypeVariables()
100  public override Constraint CloneTypeVariables(IDictionary<TypeVariable, TypeVariable> typeVariableMappings, IList<EquivalenceClass> equivalenceClasses)
109  {
110  ConstraintList newConstraint = new ConstraintList();
111  foreach (Constraint constraint in this.constraints)
112  newConstraint.Add(constraint.CloneTypeVariables(typeVariableMappings, equivalenceClasses));
113  newConstraint.ValidTypeExpression = false;
114  return newConstraint;
115  }
116  #endregion
117 
118  #region Check()
119  public override TypeExpression Check(MethodType methodAnalyzed, TypeExpression actualImplicitObject, bool showInvocationMessage,
130  SortOfUnification activeSortOfUnification, Location location)
131  {
132  TypeExpression result = null;
133  foreach (Constraint constraint in this.constraints)
134  result = constraint.Check(methodAnalyzed, actualImplicitObject, showInvocationMessage, activeSortOfUnification, location);
135  return result;
136  }
137  #endregion
138 
139  }
140 }
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.
System.Text.StringBuilder StringBuilder
Definition: CSharpParser.cs:4
override bool isEmpty()
To know if any constraint has been set
Representa a method type.
Definition: MethodType.cs:37