17 using System.Collections.Generic;
18 using System.Reflection;
20 using System.Text.RegularExpressions;
23 using ErrorManagement;
25 using TypeSystem.Constraints;
26 using TypeSystem.Operations;
28 namespace TypeSystem {
39 private List<TypeExpression> typeSet =
new List<TypeExpression>();
51 get {
return this.typeSet.Count; }
58 get {
return this.typeSet; }
86 added = this.AddType(t) && added;
87 this.ValidTypeExpression =
false;
91 if (existingType == null) {
92 this.typeSet.Add(type);
93 this.ValidTypeExpression =
false;
107 if (this.ValidTypeExpression)
return this.typeExpression;
108 if (depthLevel <= 0)
return this.FullName;
112 for (
int i = 0; i < this.typeSet.Count; i++) {
113 aux.AppendFormat(
"{0}", this.typeSet[i].BuildTypeExpressionString(depthLevel - 1));
114 if (i < this.typeSet.Count - 1)
115 aux.AppendFormat(
" ,");
118 this.typeExpression = aux.ToString();
119 this.ValidTypeExpression =
true;
120 return this.typeExpression;
124 #region BuildFullName()
131 for (
int i = 0; i < this.typeSet.Count; i++) {
132 aux.AppendFormat(
"{0}", this.typeSet[i].FullName);
133 if (i < this.typeSet.Count - 1)
134 aux.AppendFormat(
" ,");
137 this.fullName = aux.ToString();
147 #region Assignment ANULADA
176 #region Equivalent() ANULADA
190 #region Dot() ANULADA
263 #region Bracket() ANULADA
294 #region Parenthesis() ANULADA
327 #region Arithmetic() ANULADA
396 #region Relational()ANULADA
435 #region PromotionLevel() ANULADA
556 int lowerLevelOfPromotion = Int32.MaxValue;
559 if (aux != -1 && aux < lowerLevelOfPromotion)
560 lowerLevelOfPromotion = aux;
562 return lowerLevelOfPromotion == Int32.MaxValue ? -1 : lowerLevelOfPromotion;
579 Pair<TypeExpression, TypeExpression> pair =
new Pair<TypeExpression, TypeExpression>(
this, te);
580 if (previouslyUnified.Contains(pair))
582 previouslyUnified.Add(pair);
586 bool equivalent =
true;
595 te.Unify(type, SortOfUnification.Incremental, previouslyUnified);
597 this.ValidTypeExpression =
false;
598 te.ValidTypeExpression =
false;
603 #region HasTypeVariables()
611 return this.hasTypeVariablesCache;
612 bool toReturn =
false;
614 if (type.HasTypeVariables()) {
618 this.validHasTypeVariables =
true;
619 return this.hasTypeVariablesCache = toReturn;
623 #region IsFreshVariable()
638 #region CloneTypeVariables()
639 public override TypeExpression CloneTypeVariables(IDictionary<TypeVariable, TypeVariable> typeVariableMappings, IList<EquivalenceClass> equivalenceClasses, IList<ClassType> clonedClasses) {
653 IList<TypeExpression> oldTypeSet = this.typeSet;
654 newType.typeSet =
new List<TypeExpression>();
656 newType.typeSet.Add(oldType.CloneTypeVariables(typeVariableMappings, equivalenceClasses, clonedClasses));
657 newType.ValidTypeExpression =
false;
676 if (collection == null)
678 UnionType union = collection as UnionType;
679 if (collection != null)
680 union = new UnionType(collection);
681 if (newType is UnionType)
684 union.AddType(newType);
696 #region UpdateEquivalenceClass()
697 public override void UpdateEquivalenceClass(IDictionary<TypeVariable, TypeVariable> typeVariableMappings, IList<TypeExpression> previouslyUpdated) {
705 if (previouslyUpdated.Contains(
this))
707 previouslyUpdated.Add(
this);
714 type.UpdateEquivalenceClass(typeVariableMappings, previouslyUpdated);
715 type.ValidTypeExpression =
false;
717 this.ValidTypeExpression =
false;
721 #region ReplaceTypeVariables()
722 public override void ReplaceTypeVariables(IDictionary<TypeVariable, TypeVariable> typeVariableMappings) {
730 for (
int i = 0; i < this.typeSet.Count; i++) {
731 TypeVariable typeVariable = this.typeSet[i] as TypeVariable;
732 if (typeVariable == null) {
734 this.typeSet[i].ReplaceTypeVariables(typeVariableMappings);
736 else if (typeVariableMappings.ContainsKey(typeVariable))
737 this.typeSet[i] = typeVariableMappings[typeVariable];
738 this.ValidTypeExpression =
false;
751 return this.Freeze(
new List<TypeExpression>());
761 if(evaluated.Contains(type))
765 if (type is TypeVariable)
766 newUnionType.AddType(((TypeVariable)type).Freeze(evaluated));
770 newUnionType.AddType(((
UnionType) type).Freeze(evaluated));
772 newUnionType.AddType(type.Freeze());
782 internal override TypeExpression Clone(IDictionary<int, TypeVariable> clonedTypeVariables, IList<EquivalenceClass> equivalenceClasses,
MethodType methodAnalyzed) {
796 newUnionType.typeSet =
new List<TypeExpression>();
799 newUnionType.typeSet.Add(type.Clone(clonedTypeVariables, equivalenceClasses, methodAnalyzed));
807 public override bool Remove(TypeVariable toRemove) {
815 for (i = 0; i < this.typeSet.Count; i++) {
816 TypeVariable typeVariable = this.typeSet[i] as TypeVariable;
817 if (typeVariable != null && typeVariable.Variable == toRemove.Variable) {
818 this.typeSet.RemoveAt(i);
819 this.ValidTypeExpression =
false;
822 if (this.typeSet[i].
Remove(toRemove)) {
823 this.typeSet[i].ValidTypeExpression =
false;
827 return i < this.typeSet.Count;
845 #region IsValueType()
859 if (evaluated.Contains(type))
869 if (type is TypeVariable)
880 if (!((UnionType) type).IsValueType(evaluated))
883 else if (type is TypeVariable)
901 #region HasFreshVariable()
916 #region HasIntersectionVariable()
931 #region ContainsValueType()
939 for (
int i = 0; i < this.typeSet.Count; i++) {
941 if (this.typeSet[i] == type)
950 #region ContainsDifferentReturns()
960 for (
int i = 0; i < this.typeSet.Count; i++) {
961 if (this.typeSet[i] is TypeVariable)
966 if (aux != null && aux != current)
int SuperType(TypeExpression subType)
Check if the type can make an assignment operation.
override void ReplaceTypeVariables(IDictionary< TypeVariable, TypeVariable > typeVariableMappings)
Replaces type variables substituting the old type variables for the new ones.
override bool Unify(TypeExpression te, SortOfUnification unification, IList< Pair< TypeExpression, TypeExpression >> previouslyUnified)
This method unifies two type expressions (this and te)
int Count
Gets the number of type expressions
override bool HasFreshVariable()
To know if it is a type variable with no substitution
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
UnionType(TypeExpression te)
bool validHasTypeVariables
To cache the result of the HasTypeVariables method
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
bool ContainsDifferentReturns()
Returns true if the union type contains method types and this methods returns differents types...
Abstract class that represents all different types.
UnionType()
Constructor of Intersection
override TypeExpression Freeze()
WriteType variable may change its type's substitution (e.g., field type variables) This method return...
System.Text.StringBuilder StringBuilder
override object AcceptOperation(TypeSystemOperation op, object arg)
override void BuildFullName()
Creates/Updates the full name of the type expression
No location information is provided within this class, because the exec methods invoked by the proper...
override bool HasIntersectionVariable()
To know if it has a element with intersection.
bool IsValueType(IList< TypeExpression > evaluated)
virtual bool IsFreshVariable()
To know if it is a type variable with no substitution
abstract bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
override bool HasTypeVariables()
To know if the type expression has some type variables and requieres unification The default implemen...
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 string ILType()
Gets the string type to use in IL code.
override bool Remove(TypeVariable toRemove)
When loops are detected, it is necesary to suppress a new extra variable returned in the return type ...
virtual bool IsDynamic
Indicates if the type has been set as dynamic
virtual bool HasTypeVariables()
To know if the type expression has some type variables and requieres unification The default implemen...
bool AddType(TypeExpression type)
Adds a new type expression.
override bool IsFreshVariable()
To know if it is a type variable with no substitution
Representa a method type.
override string BuildTypeExpressionString(int depthLevel)
Returns the type expression like a string
IList< TypeExpression > TypeSet
Gets the list of type expressions
bool ContainsValueType(TypeExpression type)
Returns true if the union type contains the specified value type.
override void UpdateEquivalenceClass(IDictionary< TypeVariable, TypeVariable > typeVariableMappings, IList< TypeExpression > previouslyUpdated)
Replaces the equivalence class of type variables substituting the old type variables for the new ones...
TypeExpression Freeze(IList< TypeExpression > evaluated)
Representa an intersection type.
static TypeExpression collect(TypeExpression collection, TypeExpression newType)
This static helper method group a newType into a union collection of types.
virtual object AcceptOperation(TypeSystemOperation op, object arg)