The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
UnconstrainedDot.cs
Go to the documentation of this file.
1 using TypeSystem;
2 using AST;
3 using ErrorManagement;
4 using System.Collections.Generic;
5 using DynVarManagement;
6 //TODO: INtentar hacer este fichero con templates
7 namespace TypeSystem.Operations {
8 
9  internal class UnconstrainedDotOperation : DotOperation {
10 
11  #region Fields
12  protected string memberName;
13  protected IList<TypeExpression> previousDot;
14  #endregion
15  #region Constructor
16  internal UnconstrainedDotOperation(string memberName, IList<TypeExpression> previousDot) {
17  this.memberName = memberName;
18  this.previousDot = previousDot;
19  }
20  #endregion
21  public override DotKind kindOfDot {
22  get { return DotKind.Unconstrained; }
23  }
24  #region Array.
25  public override object Exec(ArrayType d, object arg) {
26  return d.AsClassType().AcceptOperation(new UnconstrainedDotOperation(this.memberName, this.previousDot), arg);
27  }
28  #endregion
29 
30  #region BCLClass.member
31 
32  public override object Exec(BCLClassType d, object arg) {
33  // * Has the attribute been previosly found?
34  if (d.Members.ContainsKey(this.memberName))
35  return d.Members[this.memberName].Type;
36 
37  // * Let's try introspection
38  TypeExpression member = d.FindMember(this.memberName);
39  if (member != null)
40  return member;
41 
42  // * Search in base class
43  if (d.BaseClass != null)
44  return d.BaseClass.AcceptOperation(new UnconstrainedDotOperation(this.memberName, this.previousDot), arg);
45 
46  return null;
47  }
48  #endregion
49 
50  #region BCLInterfaceType.member
51  public override object Exec(BCLInterfaceType d, object arg) {
52  // * Has the attribute previously found?
53  if (d.Members.ContainsKey(memberName))
54  return d.Members[memberName].Type;
55 
56  // * Lets use introspection
57  TypeExpression memberType = d.FindMember(memberName);
58  if (memberType != null)
59  return memberType;
60 
61  // * Search in the inhirtance tree
62  foreach (BCLInterfaceType interfaze in d.InterfaceList) {
63  // * Does this interface support this attribute?
64  TypeExpression member = (TypeExpression)interfaze.AcceptOperation(this, arg);
65  if (member != null)
66  return member;
67  }
68  // * not found
69  return null;
70  }
71 
72  #endregion
73 
74  #region BoolType.member
75 
76  public override object Exec(BoolType d, object arg) {
77  return d.AsClassType().AcceptOperation(this, arg);
78  }
79 
80  #endregion
81 
82  #region CharType.member
83  public override object Exec(CharType d, object arg) {
84  return d.AsClassType().AcceptOperation(this, arg);
85  }
86 
87  #endregion
88 
89  #region ClassType.member
90  public override object Exec(ClassType d, object arg) {
91  if (d.Members.ContainsKey(this.memberName))
92  return d.Members[memberName].Type;
93  if (d.BaseClass != null) // Search in inherit class
94  return d.BaseClass.AcceptOperation(this, arg);
95  return null;
96  }
97  #endregion
98 
99  #region ClassTypeProxy.member
100 
101  public override object Exec(ClassTypeProxy d, object arg) {
102  return d.RealType.AcceptOperation(this, arg);
103  }
104 
105  #endregion
106 
107  #region Double.member
108  public override object Exec(DoubleType d, object arg) {
109  return d.AsClassType().AcceptOperation(this, arg);
110  }
111  #endregion
112 
113  #region FieldType.member
114 
115  public override object Exec(FieldType d, object arg) {
116  if (d.FieldTypeExpression != null)
117  return d.FieldTypeExpression.AcceptOperation(new UnconstrainedDotOperation(this.memberName, this.previousDot), arg);
118  return null;
119  }
120  #endregion
121 
122  #region InterfaceType.member
123 
124  public override object Exec(InterfaceType d, object arg) {
125  if (d.Members.ContainsKey(this.memberName))
126  return d.Members[this.memberName].Type;
127  foreach (InterfaceType interfaze in d.InterfaceList) {
128  // * Does this interface support this attribute?
129  TypeExpression member = (TypeExpression)interfaze.AcceptOperation(this, arg);
130  if (member != null)
131  return member;
132  }
133  // * not found
134  return null;
135  }
136  #endregion
137 
138  #region Int.member
139  public override object Exec(IntType d, object arg) {
140  return d.AsClassType().AcceptOperation(this, arg);
141  }
142  #endregion
143 
144  #region Property.member
145 
146  public override object Exec(PropertyType d, object arg) {
147  if (d.PropertyTypeExpression != null)
148  return d.PropertyTypeExpression.AcceptOperation(this, arg);
149  return null;
150  }
151  #endregion
152 
153  #region String.member
154 
155  public override object Exec(StringType d, object arg) {
156  return d.AsClassType().AcceptOperation(this, arg);
157  }
158  #endregion
159 
160  #region TypeExpression.member
161  public override object Exec(TypeExpression d, object arg) {
162  return null;
163  }
164  #endregion
165 
166  #region TypeVariable.member
167  public override object Exec(TypeVariable d, object arg) {
168  if (d.Substitution != null) {
169  DynVarOptions.Instance.AssignDynamism(d.Substitution, d.IsDynamic);
170  return d.Substitution.AcceptOperation(this, arg);
171  }
172  return TypeVariable.NewTypeVariable; // * A fresh TV, but no constraint is generated
173  }
174  #endregion
175 
176  #region UnionType.member
177  public override object Exec(UnionType d, object arg) {
178  // * Infinite loop detection
179  if (this.previousDot.Contains(d))
180  return null;
181  previousDot.Add(d);
182 
183  TypeExpression returnType = null;
184  foreach (TypeExpression type in d.TypeSet) {
185  TypeExpression ret = (TypeExpression)type.AcceptOperation(this, arg);
186  if (ret == null && !d.IsDynamic)
187  return null;
188  if (ret != null)
189  returnType = UnionType.collect(returnType, ret);
190  }
191  return returnType;
192  }
193  #endregion
194 
195  #region Report Errors
196  // IN this case no error is reporterd
197  public override object ReportError(TypeExpression tE) {
198  System.Diagnostics.Debug.Assert(false, "No implementado");
199  return null;
200  }
201  #endregion
202  }
203 }
static TypeVariable NewTypeVariable
Gets a new identify to the variable type
Definition: TypeVariable.cs:67
Representa a union type.
Definition: UnionType.cs:36
Representa an array type.
Definition: ArrayType.cs:35
override object AcceptOperation(TypeSystemOperation op, object arg)
TypeExpression FindMember(string memberName)
Represent a string type.
Definition: StringType.cs:36
Represents a interface type.
Represent a character type.
Definition: CharType.cs:38
Abstract class that represents all different types.
Represents a generic type expression
Definition: TypeVariable.cs:36
Represents a proxy of a class type. It implements the unfold operatations of theoretical type systes...
Represent a integer type.
Definition: IntType.cs:37
Represents a double type.
Definition: DoubleType.cs:36
Dictionary< string, AccessModifier > Members
Gets and sets the attribute list
Definition: UserType.cs:103
TypeExpression FieldTypeExpression
Gets the field type.
Definition: FieldType.cs:58
List< InterfaceType > InterfaceList
Gets the list of interfaces
Definition: UserType.cs:157
virtual bool IsDynamic
Indicates if the type has been set as dynamic
Dictionary< string, AccessModifier > Members
Gets and sets the attribute list
Definition: IBCLUserType.cs:32
Representa a property type.
Definition: PropertyType.cs:34
ClassType BaseClass
Gets the base type (null if not exists).
Definition: ClassType.cs:56
IList< TypeExpression > TypeSet
Gets the list of type expressions
Definition: UnionType.cs:57
TypeExpression Substitution
Gets the substitution; null if it does not exist
Represent a bool type.
Definition: BoolType.cs:36
TypeExpression PropertyTypeExpression
Gets the property type.
Definition: PropertyType.cs:64
Represents a class type.
Definition: ClassType.cs:35
Representa a field type.
Definition: FieldType.cs:37
virtual object AcceptOperation(TypeSystemOperation op, object arg)
TypeExpression FindMember(string memberName)
Definition: BCLClassType.cs:44