18 using System.Collections.Generic;
19 using System.Reflection;
21 using System.Text.RegularExpressions;
24 using ErrorManagement;
26 using TypeSystem.Operations;
28 namespace TypeSystem {
44 protected List<TypeExpression>
typeSet =
new List<TypeExpression>();
54 get {
return this.typeSet.Count; }
61 get {
return this.typeSet; }
90 if (intersection != null) {
92 added = added && this.AddType(t);
93 this.ValidTypeExpression =
false;
96 Predicate<TypeExpression> predicate = delegate(
TypeExpression te2) {
99 if (this.
typeSet.Find(predicate)== null) {
100 this.typeSet.Add(type);
101 this.ValidTypeExpression =
false;
115 if (this.ValidTypeExpression)
return this.typeExpression;
116 if (depthLevel <= 0)
return this.FullName;
120 for (
int i = 0; i < this.typeSet.Count; i++) {
121 aux.AppendFormat(
"{0}", this.typeSet[i].BuildTypeExpressionString(depthLevel-1));
122 if (i < this.
typeSet.Count - 1)
123 aux.AppendFormat(
" ,");
126 this.typeExpression = aux.ToString();
127 this.ValidTypeExpression =
true;
128 return this.typeExpression;
132 #region BuildFullName()
139 for (
int i = 0; i < this.typeSet.Count; i++) {
140 aux.AppendFormat(
"{0}", this.typeSet[i].FullName);
141 if (i < this.
typeSet.Count - 1)
142 aux.AppendFormat(
" ,");
145 this.fullName = aux.ToString();
151 #region overloadResolution()
162 int min = -1, index = -1, minNumFreeVariables = Int32.MaxValue;
166 Dictionary<int, int> promotionValues =
new Dictionary<int, int>();
169 System.Diagnostics.Debug.Assert(
false,
"There should be no empty intersection types.");
173 for (
int i = 0; i < this.typeSet.Count; i++) {
174 MethodType mt = TypeExpression.As<MethodType>(this.typeSet[i]);
177 aux = mt.Promotion(arguments, location);
179 if ((min >= aux) || (min == -1)) {
182 promotionValues[index] = min;
192 foreach (KeyValuePair<int, int> pair
in promotionValues)
193 if (pair.Value == min) {
194 aux = ((MethodType)this.
typeSet[pair.Key]).GetNumberFreeVariables();
195 if (aux < minNumFreeVariables)
196 minNumFreeVariables = aux;
200 foreach (KeyValuePair<int, int> pair
in promotionValues)
201 if (pair.Value == min && ((MethodType)this.typeSet[pair.Key]).GetNumberFreeVariables() == minNumFreeVariables)
202 bestMethods = UnionType.collect(bestMethods,
this.typeSet[pair.Key]);
208 #region Parenthesis() ANULADA
244 Pair<TypeExpression,TypeExpression> pair =
new Pair<TypeExpression, TypeExpression>(
this, te);
245 if (previouslyUnified.Contains(pair))
247 previouslyUnified.Add(pair);
250 this.ValidTypeExpression =
false;
251 te.ValidTypeExpression =
false;
258 #region HasTypeVariables()
266 return this.hasTypeVariablesCache;
267 bool toReturn =
false;
269 if (type.HasTypeVariables()) {
273 this.validHasTypeVariables =
true;
274 return this.hasTypeVariablesCache = toReturn;
278 #region CloneTypeVariables()
279 public override TypeExpression CloneTypeVariables(IDictionary<TypeVariable, TypeVariable> typeVariableMappings, IList<EquivalenceClass> equivalenceClasses, IList<ClassType> clonedClasses) {
293 IList<TypeExpression> oldTypeSet = this.typeSet;
294 newType.typeSet =
new List<TypeExpression>();
296 newType.typeSet.Add(oldType.CloneTypeVariables(typeVariableMappings, equivalenceClasses, clonedClasses));
297 newType.ValidTypeExpression =
false;
305 internal override TypeExpression Clone(IDictionary<int, TypeVariable> clonedTypeVariables, IList<EquivalenceClass> equivalenceClasses, MethodType methodAnalyzed) {
319 newIntersectionType.typeSet =
new List<TypeExpression>();
322 newIntersectionType.typeSet.Add(type.Clone(clonedTypeVariables, equivalenceClasses, methodAnalyzed));
323 return newIntersectionType;
327 #region IsValueType()
335 throw new Exception(
"The method or operation is not implemented.");
TypeExpression overloadResolution(TypeExpression[] arguments, Location location)
A public method for being used as a global overload resolution process
override bool Unify(TypeExpression te, SortOfUnification unification, IList< Pair< TypeExpression, TypeExpression >> previouslyUnified)
Check if the type can make a method operation.
Represents a error produced when tries to make an operation not allowed for the specified type...
IList< TypeExpression > TypeSet
Gets the list of type expressions
override object AcceptOperation(TypeSystemOperation op, object arg)
bool validHasTypeVariables
To cache the result of the HasTypeVariables method
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.
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
IntersectionType()
Constructor of Intersection
override string BuildTypeExpressionString(int depthLevel)
Returns the type expression like a string
Abstract class that represents all different types.
System.Text.StringBuilder StringBuilder
No location information is provided within this class, because the exec methods invoked by the proper...
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
IntersectionType(TypeExpression te)
bool AddType(TypeExpression type)
Adds a new type expression.
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...
override void BuildFullName()
Creates/Updates the full name of the type expression
List< TypeExpression > typeSet
Stores a set of type expression
override bool HasTypeVariables()
To know if the type expression has some type variables and requieres unification The default implemen...
int Count
Gets the number of type expressions
Representa an intersection type.
Represents a error produced when the attribute identifier is not defined.