18 using System.Collections.Generic;
22 using TypeSystem.Constraints;
23 using ErrorManagement;
25 using TypeSystem.Operations;
27 namespace TypeSystem {
57 get {
return this.baseClass; }
65 get {
return this.isConcreteType; }
69 while (klass != null) {
70 klass.isConcreteType = value;
71 klass = klass.baseClass;
88 this.name = identifier;
89 this.Modifiers = modifiers;
99 this.Modifiers =
new List<Modifier>();
104 #region AddBaseClass()
114 this.baseClass = inheritedClass;
120 #region BuildTypeExpressionString()
126 if (this.ValidTypeExpression)
127 return this.typeExpression;
129 return this.FullName;
132 tE.AppendFormat(
"Class({0},", this.BuildTypeExpressionString(depthLevel - 1));
135 for (
int i = 0; i < this.modifierList.Count - 1; i++) {
136 tE.AppendFormat(
" {0} x", this.modifierList[i]);
138 tE.AppendFormat(
" {0}", this.modifierList[this.modifierList.Count - 1]);
144 tE.Append(this.baseClass.FullName);
149 for (
int i = 0; i < this.interfaceList.Count - 1; i++) {
150 tE.AppendFormat(
" {0} x", this.interfaceList[i].FullName);
152 tE.AppendFormat(
" {0}", this.interfaceList[this.interfaceList.Count - 1].FullName);
158 Dictionary<string, AccessModifier>.KeyCollection keys = this.Members.Keys;
160 foreach (
string key
in keys) {
161 tE.Append(this.Members[key].Type.BuildTypeExpressionString(depthLevel - 1));
162 if (i < keys.Count - 1)
168 this.ValidTypeExpression =
true;
169 return this.typeExpression = tE.ToString();
180 #region Assignment() ANULADA
217 #region Dot() ANULADA
264 IList<TypeExpression> typeSet=null;
266 if (member is UnionType)
267 typeSet=((UnionType)member).TypeSet;
269 typeSet=((IntersectionType)member).TypeSet;
275 else anyValid =
true;
281 if (memberType == null || memberType.
MemberInfo == null)
294 #region InheritsFrom()
306 while (myBase != null) {
309 myBase = myBase.BaseClass;
312 return base.InheritsFrom(superType);
316 #region Parenthesis() ANULADA
338 #region AsClassType()
351 #region PromotionLevel()
437 Pair<TypeExpression, TypeExpression> pair =
new Pair<TypeExpression, TypeExpression>(
this, te);
438 if (previouslyUnified.Contains(pair))
440 previouslyUnified.Add(pair);
453 foreach (
string key
in this.
Fields.Keys) {
454 FieldType thisField = (FieldType)this.
Fields[key].Type,
455 teField = (FieldType)ct.Fields[key].Type;
456 if (thisField.FieldTypeExpression is ClassTypeProxy || teField.FieldTypeExpression is ClassTypeProxy)
457 success = thisField.FieldTypeExpression.FullName.Equals(teField.FieldTypeExpression.FullName);
458 else if (!(thisField.Unify(teField, unification, previouslyUnified)))
465 this.baseClass.Unify(ct.baseClass, unification, previouslyUnified);
468 this.ConcreteType = ct.ConcreteType = this.ConcreteType || ct.ConcreteType;
471 else if (te is TypeVariable) {
472 TypeVariable typeVariable = (TypeVariable)te;
475 success = typeVariable.Unify(
this, unification, previouslyUnified);
477 else if (typeVariable.Substitution != null)
479 success = this.Unify(typeVariable.Substitution, unification, previouslyUnified);
480 else success =
false;
483 else if (te is UnionType)
484 success = te.Unify(
this, unification, previouslyUnified);
486 else if (te is ClassTypeProxy)
487 success = this.Unify(((ClassTypeProxy)te).RealType, unification, previouslyUnified);
488 else if (te is FieldType)
489 success = this.Unify(((FieldType)te).FieldTypeExpression, unification, previouslyUnified);
490 else success =
false;
492 this.ValidTypeExpression =
false;
493 te.ValidTypeExpression =
false;
513 IList<EquivalenceClass> equivalenceClasses =
new List<EquivalenceClass>();
520 foreach (EquivalenceClass equivalenceClass
in equivalenceClasses)
521 equivalenceClass.UpdateEquivalenceClass(typeVariableMappings);
523 newClassType.ValidTypeExpression =
false;
529 #region CloneTypeVariables()
530 public override TypeExpression CloneTypeVariables(IDictionary<TypeVariable, TypeVariable> typeVariableMappings, IList<EquivalenceClass> equivalenceClasses, IList<ClassType> clonedClasses) {
545 if (!clonedClasses.Contains(
this))
546 clonedClasses.Add(
this);
548 return new ClassTypeProxy(
this, typeVariableMappings, equivalenceClasses);
551 newClassType.ConcreteType = this.ConcreteType;
552 newClassType.IsDynamic = this.IsDynamic;
553 Dictionary<string, AccessModifier> oldFields = this.Fields;
554 newClassType.fieldList =
new Dictionary<string, AccessModifier>();
556 foreach (KeyValuePair<string, AccessModifier> pair
in oldFields) {
560 FieldType fieldType = (FieldType)pair.Value.Type.CloneTypeVariables(typeVariableMappings, equivalenceClasses, clonedClasses);
561 fieldType.MemberInfo.Class = newClassType;
562 newClassType.AddMember(pair.Key, fieldType.MemberInfo);
565 foreach (KeyValuePair<string, AccessModifier> pair
in this.
Methods) {
566 AccessModifier accesModifier = (AccessModifier)pair.Value.Clone();
567 accesModifier.Class = newClassType;
568 newClassType.AddMember(pair.Key, accesModifier);
572 newClassType.ValidTypeExpression =
false;
579 #region UpdateEquivalenceClass()
580 public override void UpdateEquivalenceClass(IDictionary<TypeVariable, TypeVariable> typeVariableMappings, IList<TypeExpression> previouslyUpdated) {
588 if (previouslyUpdated.Contains(
this))
590 previouslyUpdated.Add(
this);
595 foreach (KeyValuePair<string, AccessModifier> pair
in this.
fieldList)
596 if (pair.Value.Type.HasTypeVariables())
597 pair.Value.Type.UpdateEquivalenceClass(typeVariableMappings, previouslyUpdated);
598 this.baseClass.UpdateEquivalenceClass(typeVariableMappings, previouslyUpdated);
599 this.ValidTypeExpression =
false;
603 #region ReplaceTypeVariables()
604 public override void ReplaceTypeVariables(IDictionary<TypeVariable, TypeVariable> typeVariableMappings) {
612 foreach (KeyValuePair<string, AccessModifier> pair
in this.fieldList)
613 if (pair.Value.Type.HasTypeVariables())
614 pair.Value.Type.ReplaceTypeVariables(typeVariableMappings);
615 this.ValidTypeExpression =
false;
622 internal override TypeExpression Clone(IDictionary<int, TypeVariable> clonedTypeVariables, IList<EquivalenceClass> equivalenceClasses, MethodType methodAnalyzed) {
637 ClassType newClassType = (
ClassType)this.MemberwiseClone();
639 newClassType.fieldList =
new Dictionary<string, AccessModifier>();
640 newClassType.Members =
new Dictionary<string, AccessModifier>();
641 foreach (KeyValuePair<string, AccessModifier> pair
in this.
Fields)
643 IMemberType newFieldType = null;
644 if (pair.Value.Type is FieldType)
645 newFieldType = (IMemberType)((FieldType)pair.Value.Type).Clone(clonedTypeVariables, equivalenceClasses, methodAnalyzed);
647 newFieldType = (IMemberType)pair.Value.Type.Clone(clonedTypeVariables, equivalenceClasses, methodAnalyzed);
648 AccessModifier newAccessModifier =
new AccessModifier(pair.Value.Modifiers, pair.Value.MemberIdentifier, newFieldType,
false);
649 newClassType.fieldList[pair.Key] = newAccessModifier;
650 newClassType.Members[pair.Key] = newAccessModifier;
652 foreach (KeyValuePair<string, AccessModifier> pair
in this.
Methods)
653 newClassType.Members[pair.Key] = pair.Value;
656 newClassType.baseClass = (ClassType)this.BaseClass.Clone(clonedTypeVariables, equivalenceClasses, methodAnalyzed);
658 newClassType.ValidTypeExpression =
false;
663 internal TypeExpression Clone(IDictionary<int, TypeVariable> clonedTypeVariables, IList<EquivalenceClass> equivalenceClasses, MethodType methodAnalyzed, IDictionary<String, TypeExpression> evaluated)
668 ClassType newClassType = (
ClassType)this.MemberwiseClone();
669 if (evaluated.Keys.Contains(
this.FullName))
671 evaluated.Add(this.FullName, newClassType);
673 newClassType.fieldList =
new Dictionary<string, AccessModifier>();
674 newClassType.Members =
new Dictionary<string, AccessModifier>();
675 foreach (KeyValuePair<string, AccessModifier> pair
in this.Fields)
677 IMemberType newFieldType = null;
678 if (pair.Value.Type is FieldType)
679 newFieldType = (IMemberType)((FieldType)pair.Value.Type).Clone(clonedTypeVariables, equivalenceClasses, methodAnalyzed, evaluated);
681 newFieldType = (IMemberType)pair.Value.Type.Clone(clonedTypeVariables, equivalenceClasses, methodAnalyzed);
682 AccessModifier newAccessModifier =
new AccessModifier(pair.Value.Modifiers, pair.Value.MemberIdentifier, newFieldType,
false);
683 newClassType.fieldList[pair.Key] = newAccessModifier;
684 newClassType.Members[pair.Key] = newAccessModifier;
686 foreach (KeyValuePair<string, AccessModifier> pair
in this.Methods)
687 newClassType.Members[pair.Key] = pair.Value;
690 newClassType.baseClass = (ClassType)this.BaseClass.Clone(clonedTypeVariables, equivalenceClasses, methodAnalyzed);
692 newClassType.ValidTypeExpression =
false;
699 #region Equals&GetHashCode()
700 public override bool Equals(
object obj) {
705 if (parameter == null) {
706 ClassTypeProxy proxy = obj as ClassTypeProxy;
709 parameter = proxy.RealType;
711 if (!this.
FullName.Equals(parameter.FullName))
713 foreach (KeyValuePair<string, AccessModifier> pair
in this.fieldList)
714 if (!pair.Value.Type.FullName.Equals(parameter.fieldList[pair.Key].Type.FullName))
719 return this.FullName.GetHashCode();
725 #region IsConcreteType()
732 TypeVariable typeVariable = actualImplicitObject as TypeVariable;
733 if (typeVariable != null)
734 actualImplicitObject = typeVariable.Substitution;
735 ClassType classType = actualImplicitObject as
ClassType;
739 if (unionType != null && unionType.
Count > 0)
755 aux.AppendFormat(
"class {0}", this.fullName);
756 return aux.ToString();
761 #region IsValueType()
bool validAccess(TypeExpression member)
Validates the correct access to members, taking into account the information hiding level...
override void AddBaseClass(ClassType inheritedClass, Location location)
Adds a new inherited type
List< InterfaceType > interfaceList
Represents the identifiers of the interfaces
int Count
Gets the number of type expressions
Dictionary< string, AccessModifier > Fields
Gets the field list
override void ReplaceTypeVariables(IDictionary< TypeVariable, TypeVariable > typeVariableMappings)
Replaces type variables substituting the old type variables for the new ones.
AccessModifier MemberInfo
Gets or sets the attribute information of method type
override int GetHashCode()
List< Modifier > modifierList
Stores the modifiers belong to the class type
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...
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...
UserType(string identifier)
Constructor of UserType
static ClassType IsConcreteType(TypeExpression actualImplicitObject)
Tells if the parameter is a concrete class type
Dictionary< string, AccessModifier > Methods
Gets the method list
override TypeExpression CloneType(IDictionary< TypeVariable, TypeVariable > typeVariableMappings)
This method creates a new class type, creating new type variables for each field. Methods are not clo...
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...
bool hasModifier(Modifier mod)
To know if a modifier is supported
override bool HasTypeVariables()
To know if the type expression has some type variables and requieres unification The default implemen...
Abstract class that represents all different types.
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
override ClassType AsClassType()
Check if the type can make a method operation.
System.Text.StringBuilder StringBuilder
virtual string FullName
Gets the full name of the type Note: WriteType expression is the longest recursive representation of ...
No location information is provided within this class, because the exec methods invoked by the proper...
bool isConcreteType
Indicates if the class holds a concrete type. Opposite to an abstract type, a concrete type holds the...
Dictionary< string, AccessModifier > fieldList
Represents all class fields.
string name
Class identifier;
Dictionary< string, AccessModifier > Members
Gets and sets the attribute list
bool ConcreteType
Indicates if the class holds a concrete type. Opposite to an abstract type, a concrete type holds the...
override bool Equals(object obj)
To check loops in recursive types, proxy must be equal that the classes they represent ...
ClassType(string name)
Constructor of ClassType
Represents the error occurred when a class has multiple base classes.
string fullName
Represents the full name of the type Note: WriteType expression is the longest recursive representati...
Modifier
Indicates differents modifiers to use in class (only public, internal or static), fields or methods...
override string BuildTypeExpressionString(int depthLevel)
Creates the type expression string.
UserType Class
Gets or sets the class type reference
ClassType BaseClass
Gets the base type (null if not exists).
IList< TypeExpression > TypeSet
Gets the list of type expressions
override string ILType()
Gets the string type to use in IL code.
override object AcceptOperation(TypeSystemOperation op, object arg)
Representa an intersection type.
override bool Unify(TypeExpression te, SortOfUnification unification, IList< Pair< TypeExpression, TypeExpression >> previouslyUnified)
Returns a value thdat indicates a promotion level.
ClassType baseClass
If exists, represents the base class (simple inheritance)
Represents a class or interface type.
override bool InheritsFrom(UserType superType)
Tells if the implicit object is a subtype of the superType
ClassType(string identifier, string fullName, List< Modifier > modifiers)
Constructor of ClassType
Representa a class attribute (fields or methods).