The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CGConvertToOperation.cs
Go to the documentation of this file.
1 using TypeSystem;
2 using ErrorManagement;
3 using AST;
4 using Tools;
5 using System.Collections.Generic;
6 using CodeGeneration.ExceptionManagement;
7 namespace CodeGeneration.Operations {
14  internal class CGConvertToOperation<T> : CGTypeSystemOperation where T : ILCodeGenerator {
15 
19  private T codeGenerator;
22  private int indent;
23 
24 
25  private TypeExpression secondTypeExpression;
26  public CGConvertToOperation(TypeExpression secondTypeExpression, T codeGenerator, int indent) {
27  this.secondTypeExpression = secondTypeExpression;
28  this.codeGenerator = codeGenerator;
29  this.indent = indent;
30 
31 
32  }
33 
34  public override object Exec(CharType c, object arg) {
35 
36  if ( TypeExpression.Is<DoubleType>(this.secondTypeExpression) )
37  this.codeGenerator.convToDouble(this.indent);
38 
39  if ( TypeExpression.Is<StringType>(this.secondTypeExpression) )
40  return c.AcceptOperation(new CGToStringOperation<ILCodeGenerator>(this.codeGenerator, this.indent), true); // we force a box
41 
42  return null;
43  }
44 
45  public override object Exec(DoubleType d, object arg) {
46 
47  if ( TypeExpression.Is<StringType>(this.secondTypeExpression))
48  return d.AcceptOperation(new CGToStringOperation<ILCodeGenerator>(this.codeGenerator, this.indent), true); // we force a box
49 
50  return null;
51 
52  }
53  public override object Exec(IntType i, object arg) {
54  if ( TypeExpression.Is<StringType>(this.secondTypeExpression) )
55  return i.AcceptOperation(new CGToStringOperation<ILCodeGenerator>(this.codeGenerator, this.indent), true); // we force a box
56 
57 
58  if ( TypeExpression.Is<DoubleType>(this.secondTypeExpression) ) {
59  this.codeGenerator.convToDouble(this.indent);
60  return null;
61  }
62 
63  return null;
64  }
65 
66  // TODO
67  // hay conversiones que no sé hacer
68  public override object Exec(StringType s, object arg) {
69  if ( TypeExpression.Is<StringType>(this.secondTypeExpression) ) {
70  }
71  return null;
72 
73  }
74  public override object Exec(TypeVariable t, object arg) {
75  if ( t.HasFreshVariable() ) {
76  ReportError(string.Format("Cannot make convertions from type {0} to {1}.", t.FullName, this.secondTypeExpression.FullName));
77  return null;
78  }
79  return t.Substitution.AcceptOperation(this, null);
80  }
81  }
82 }
override string FullName
The full name in type variables is calculated just in time
virtual bool HasFreshVariable()
To know if it is a type variable with no substitution
Represent a string type.
Definition: StringType.cs:36
Represent a character type.
Definition: CharType.cs:38
Abstract class that represents all different types.
Represents a generic type expression
Definition: TypeVariable.cs:36
Represent a integer type.
Definition: IntType.cs:37
Represents a double type.
Definition: DoubleType.cs:36
override object AcceptOperation(TypeSystemOperation op, object arg)
Definition: CharType.cs:86