The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
ParenthesisOperation.cs
Go to the documentation of this file.
1 using ErrorManagement;
2 using System.Collections.Generic;
3 using TypeSystem.Constraints;
4 using DynVarManagement;
5 namespace TypeSystem.Operations {
11 
12  #region Fields
13  private TypeExpression actualImplicitObject;
14  private TypeExpression[] arguments;
15  private MethodType methodAnalyzed;
16  private SortOfUnification activeSortOfUnification;
17  private Location location;
18  #endregion
19 
20  #region Constructor
21  public ParenthesisOperation(TypeExpression actualImplicitObject, TypeExpression[] arguments, MethodType methodAnalyzed, SortOfUnification activeSortOfUnification, Location location) {
22  this.actualImplicitObject = actualImplicitObject;
23  this.arguments = arguments;
24  this.methodAnalyzed = methodAnalyzed;
25  this.activeSortOfUnification = activeSortOfUnification;
26  this.location = location;
27  }
28  #endregion
29 
30  #region BCLClassType ()
31  public override object Exec(BCLClassType caller, object arg) {
32  // * Load the constructors
33  if (caller.Constructors == null)
34  caller.FindConstructor(this.location);
35 
36  // * Follows the superclass behaviour
37  // * Actually Base Class return the GrandFather Class.
38 
39  return caller.BaseClass.AcceptOperation(this, arg);
40  }
41  #endregion
42 
43  #region ClassType ()
44  public override object Exec(ClassType caller, object arg) {
45  //TODO: comprobar si es el name de caller.
46  MethodType method = (MethodType)caller.AcceptOperation(DotOperation.Create(caller.Name, new List<TypeExpression>()), arg);
47  if (method == null)
48  return null;
49  return method.AcceptOperation(this, arg);
50  }
51  #endregion
52 
53  #region ClassTypeProxy ()
54  public override object Exec(ClassTypeProxy caller, object arg) {
55  return caller.RealType.AcceptOperation(this, arg);
56  }
57  #endregion
58 
59  #region IntersectionType ()
60  public override object Exec(IntersectionType caller, object arg) {
61  TypeExpression method = caller.overloadResolution(this.arguments, this.location);
62  if (method == null)
63  return null;
64  return method.AcceptOperation(this, arg);
65  }
66  #endregion
67 
68  #region MethodType
69  public override object Exec(MethodType caller, object arg) {
70  // * Quits if there's some error in the arguments
71  if (this.arguments == null)
72  return null;
73 
74  // * An instance method cannot be call from a static method without using an object
75  if ((!caller.MemberInfo.Modifiers.Contains(Modifier.Static)) && this.methodAnalyzed != null &&
76  this.methodAnalyzed.MemberInfo.Modifiers.Contains(Modifier.Static) && this.actualImplicitObject == null) {
77  ErrorManager.Instance.NotifyError(new InstanceMethodCallFromStaticMethodError(caller.FullName, this.methodAnalyzed.FullName, this.location));
78  return null;
79  }
80 
81  // * Is Unification necessary?
82  if (caller.MemberInfo.Class.HasTypeVariables() || caller.HasTypeVariables())
83  return MethodType.methodCall(this.actualImplicitObject, caller, this.arguments, this.methodAnalyzed,this.activeSortOfUnification, this.location);
84  // h Otherwise...
85  // Check the argument number
86  if (this.arguments.GetLength(0) != caller.ParameterListCount) {
87  ErrorManager.Instance.NotifyError(new ArgumentNumberError(caller.MemberInfo.MemberIdentifier, this.arguments.GetLength(0), this.location));
88  return null;
89  }
90  // Check the argument type
91  for (int i = 0; i < caller.ParameterListCount; i++)
92  this.arguments[i].AcceptOperation(PromotionOperation.Create(caller.getParam(i), this.methodAnalyzed, this.location), arg);
93  // * Returns the return type
94  return caller.Return;
95  }
96 
97  #endregion
98 
99  #region TypeVariable ()
100  public override object Exec(TypeVariable caller, object arg) {
101  if (caller.Substitution != null) {
102  DynVarOptions.Instance.AssignDynamism(caller.Substitution, caller.IsDynamic);
103  return caller.Substitution.AcceptOperation(this, arg);
104  }
105  if (this.methodAnalyzed != null) {
106  // * A method invocation constraint is added to the method analyzed
107  ParenthesisConstraint constraint = new ParenthesisConstraint(caller, this.actualImplicitObject, this.arguments, this.activeSortOfUnification, this.location);
108  this.methodAnalyzed.AddConstraint(constraint);
109  return constraint.ReturnType;
110  }
111  return ReportError(caller);
112  }
113  #endregion
114 
115  #region Union ()
116  public override object Exec(UnionType caller, object arg) {
117  // * If all the types in typeset generate a constraint, we simply generate one constraint using the whole union type
118  if (caller.IsFreshVariable() && this.methodAnalyzed != null) {
119  // * A constraint is added to the method analyzed
120  ParenthesisConstraint constraint = new ParenthesisConstraint(caller, this.actualImplicitObject, this.arguments, this.activeSortOfUnification, this.location);
121  this.methodAnalyzed.AddConstraint(constraint);
122  return constraint.ReturnType;
123  }
124  TypeExpression returnType = null;
125  foreach (TypeExpression type in caller.TypeSet) {
126  TypeExpression ret = (TypeExpression)type.AcceptOperation(this, arg);
127  if (ret == null && caller.IsDynamic)
128  return null;
129  returnType = UnionType.collect(returnType, ret);
130  }
131  return returnType;
132 
133  }
134  #endregion
135 
136  // Errors
137  #region ReportError
138  public override object ReportError(TypeExpression caller) {
139 
140  ErrorManager.Instance.NotifyError(new OperationNotAllowedError("()", caller.FullName, this.location));
141  return null;
142  }
143  #endregion
144  }
145 }
146 
147 
148 
override object Exec(UnionType caller, object arg)
Representa a union type.
Definition: UnionType.cs:36
Represents a error produced when tries to make an operation not allowed for the specified 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.
Definition: Location.cs:24
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
string Name
Class identifier;
Definition: UserType.cs:141
Represents a error produced when an instance method is called from a static one, whithout using an ob...
It represents constraints of the form: ret := op1(implicitObj, param*) where op1 is a method...
Represents a error produced when the argument and parameter number is different.
override object ReportError(TypeExpression caller)
AccessModifier MemberInfo
Gets or sets the attribute information of method type
Definition: MethodType.cs:118
override bool HasTypeVariables()
To know if the type expression has some type variables and requieres unification The default implemen...
Definition: UserType.cs:232
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...
static PromotionOperation Create(TypeExpression type, MethodType methodAnalyzed, Location location)
virtual string FullName
Gets the full name of the type Note: WriteType expression is the longest recursive representation of ...
ParenthesisOperation(TypeExpression actualImplicitObject, TypeExpression[] arguments, MethodType methodAnalyzed, SortOfUnification activeSortOfUnification, Location location)
Implements a factory method pattern. Virtual constructor. Role: factory Implements a double dispatche...
Definition: DotOperation.cs:11
override object Exec(ClassType caller, object arg)
static DotOperation Create(string memberName, IList< TypeExpression > previousDot)
Definition: DotOperation.cs:20
override object Exec(IntersectionType caller, object arg)
AccessModifier Constructors
Gets the constructor list
Definition: IBCLUserType.cs:37
virtual bool IsDynamic
Indicates if the type has been set as dynamic
override object Exec(TypeVariable caller, object arg)
Modifier
Indicates differents modifiers to use in class (only public, internal or static), fields or methods...
Implements Double Dispatch Pattern Role:
override bool IsFreshVariable()
To know if it is a type variable with no substitution
Definition: UnionType.cs:630
UserType Class
Gets or sets the class type reference
Representa a method type.
Definition: MethodType.cs:37
override object Exec(BCLClassType caller, object arg)
List< Modifier > Modifiers
Gets the modifiers of the element
TypeExpression Substitution
Gets the substitution; null if it does not exist
override object Exec(ClassTypeProxy caller, object arg)
override object Exec(MethodType caller, object arg)
Represents a class type.
Definition: ClassType.cs:35
override object AcceptOperation(TypeSystemOperation op, object arg)
Definition: ClassType.cs:177
Representa an intersection type.
virtual object AcceptOperation(TypeSystemOperation op, object arg)