The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
SimplePromotionOperation.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 
5 using AST;
6 using ErrorManagement;
7 using Tools;
8 using TypeSystem.Operations;
9 using DynVarManagement;
10 using TypeSystem.Constraints;
11 namespace TypeSystem.Operations {
12  internal class SimplePromotionOperation : PromotionOperation {
13  #region Fields
14  protected TypeExpression to;
15  protected MethodType methodAnalyzed;
16  protected Location location;
17  #endregion
18 
19  #region Constructor
20  internal SimplePromotionOperation(TypeExpression to, MethodType methodAnalyzed, Location location) {
21  this.to = to;
22  this.methodAnalyzed = methodAnalyzed;
23  this.location = location;
24  }
25  #endregion
26 
27  public override KindOfPromotion KindOfPromotion {
28  get { return KindOfPromotion.Simple; }
29  }
30 
31  #region ClassTypeProxy -->...
32  public override object Exec(FieldType from, object arg) {
33  if (from.FieldTypeExpression != null)
34  return from.FieldTypeExpression.AcceptOperation(this, arg);
35  return null;
36  }
37  #endregion
38 
39  #region TypeExpression-->...
40  public override object Exec(TypeExpression from, object arg) {
41  if ((int)from.AcceptOperation(new PromotionLevelOperation(this.to), arg) == -1) {
42  return ReportError(from);
43  }
44  return to;
45  }
46  #endregion
47 
48  #region UnionType-->
49  public override object Exec(UnionType from, object arg) {
50  return from.AcceptOperation(PromotionOperation.Create(this.to, AssignmentOperator.Assign, this.methodAnalyzed, this.location), arg);
51  }
52  #endregion
53 
54  #region Promotion
55  public override object Exec(TypeVariable from, object arg) {
56  if (from.Substitution != null) {
57  DynVarOptions.Instance.AssignDynamism(from.Substitution, from.IsDynamic);
58  return from.Substitution.AcceptOperation(this, arg);
59  }
60  if (methodAnalyzed != null) {
61  // * A constraint is added to the method analyzed
62  PromotionConstraint constraint = new PromotionConstraint(from, this.to, this.location);
63  this.methodAnalyzed.AddConstraint(constraint);
64  return constraint.ReturnType;
65  }
66  return ReportError(from);
67  }
68 
69  #endregion
70 
71  #region Report Errors
72  public override object ReportError(TypeExpression from) {
73  ErrorManager.Instance.NotifyError(new TypePromotionError(from.FullName, this.to.FullName, this.location));
74  return null;
75  }
76  #endregion
77  }
78 }
It represents constraints of the form op1 <= op2 (op1 is a subtype of op2)
Its operation AcceptOperation() returns an integer value that indicates a promotion level between two...
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
Represents a error produced when the type promotion can not be applied to specified expressions...
KindOfPromotion
This class implements factory method pattern ( virtual constructor). Role: Factory ...