3 using TypeSystem.Constraints;
4 using DynVarManagement;
5 namespace TypeSystem.Operations {
10 internal class VerbosePromotionOperation : PromotionOperation {
13 private TypeExpression to;
15 private MethodType methodAnalyzed;
20 internal VerbosePromotionOperation (TypeExpression to, Enum op, MethodType methodAnalyzed,
Location location) {
23 this.methodAnalyzed = methodAnalyzed;
24 this.location = location;
27 #region Kind of promotion information
29 get {
return KindOfPromotion.Verbose; }
32 #region ClassTypeProxy --> ...
33 public override object Exec(ClassTypeProxy from,
object arg) {
34 return from.RealType.AcceptOperation(
this, arg);
38 #region FieldType --> ...
40 public override object Exec(FieldType from,
object arg) {
41 if (from.FieldTypeExpression != null) {
42 return from.FieldTypeExpression.AcceptOperation(
this, arg);
49 public override object Exec(TypeExpression from,
object arg) {
50 if ((
int)from.AcceptOperation (
new PromotionLevelOperation(this.to), arg) == -1) {
51 return ReportError(from);
57 public override object Exec(UnionType from,
object arg) {
58 return this.InternalPromotion(from, arg);
60 #region InternalPromotion
61 private TypeExpression InternalPromotion(UnionType from,
object arg) {
62 if (from.IsFreshVariable() && this.methodAnalyzed != null) {
65 this.methodAnalyzed.AddConstraint(constraint);
71 UnionType dynamicUnionType =
new UnionType();
72 dynamicUnionType.IsDynamic =
true;
73 foreach (TypeExpression subType
in from.TypeSet) {
76 if (subType.IsFreshVariable())
77 dynamicUnionType.AddType(subType);
79 aux = (int) subType.AcceptOperation(
new PromotionLevelOperation(this.to), arg);
84 aux = (int)subType.AcceptOperation(
new PromotionLevelOperation(this.to), arg);
86 return (TypeExpression)ReportError(from);
89 if (dynamicUnionType.Count != 0) {
91 this.methodAnalyzed.AddConstraint(constraint);
94 if (from.IsDynamic && aux == -1) {
96 return (TypeExpression)ReportError(from);
103 public override object Exec(TypeVariable from,
object arg) {
104 if (from.Substitution != null) {
105 DynVarOptions.Instance.AssignDynamism(from.Substitution, from.IsDynamic);
106 return from.Substitution.AcceptOperation(
this, arg);
108 if (this.methodAnalyzed != null) {
111 this.methodAnalyzed.AddConstraint(constraint);
112 return constraint.ReturnType;
114 return ReportError(from);
118 public override object ReportError(TypeExpression from) {
119 ErrorManager.Instance.NotifyError(
new TypePromotionError(from.fullName,
this.to.FullName,
this.op.ToString(), this.location));
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.
KindOfPromotion
This class implements factory method pattern ( virtual constructor). Role: Factory ...