The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CGVisitDefinitionNodeOperation.cs
Go to the documentation of this file.
1 using TypeSystem.Operations;
2 using TypeSystem;
3 using ErrorManagement;
4 using AST;
5 using Tools;
6 using System.Collections.Generic;
7 using CodeGeneration.ExceptionManagement;
8 using AST.Operations;
9 namespace CodeGeneration.Operations {
13  internal class CGVisitDefinitionNodeOperation<T> : AstOperation where T : ILCodeGenerator {
14 
18  private T codeGenerator;
22  private int indent;
23 
24  private Definition node;
25 
26  private object argument;
27  private VisitorILCodeGeneration<T> visitor;
35 
36  public CGVisitDefinitionNodeOperation(VisitorILCodeGeneration<T> visitor, Definition node, T codeGenerator, int indent, object argument) {
37  this.node = node;
38  this.codeGenerator = codeGenerator;
39  this.indent = indent;
40  this.visitor = visitor;
41  this.argument = argument;
42  }
43 
44  public override object Exec(InvocationExpression invocationExpression, object arg) {
45  this.BeginOfOperation();
46  MethodType methodType = invocationExpression.ActualMethodCalled as MethodType;
47  if (methodType != null) {
48  // Both elements of condition must be the same, but it is not true, the promotion is different.
49  if (this.node.Init.ILTypeExpression.IsValueType() && !methodType.Return.IsValueType())
50  this.codeGenerator.Promotion(this.indent, methodType.Return, methodType.Return, this.node.TypeExpr, this.node.ILTypeExpression, true, this.visitor.CheckMakeAnUnbox(this.node.Init));
51  else
52  this.codeGenerator.Promotion(this.indent, this.node.Init.ExpressionType, this.node.Init.ILTypeExpression, this.node.TypeExpr, this.node.ILTypeExpression, true, this.visitor.CheckMakeAnUnbox(this.node.Init));
53  }
54  return this.EndOfOperation();
55  }
56  public override object Exec(AstNode exp, object arg) {
57  this.BeginOfOperation();
58  this.codeGenerator.Promotion(this.indent, this.node.Init.ExpressionType, this.node.Init.ILTypeExpression, this.node.TypeExpr, this.node.ILTypeExpression, true, this.visitor.CheckMakeAnUnbox(this.node.Init));
59  return this.EndOfOperation();
60  }
61  protected virtual object EndOfOperation() {
62  this.codeGenerator.stloc(this.indent, this.node.ILName);
63  this.codeGenerator.WriteLine();
64  return null;
65  }
66  protected virtual void BeginOfOperation() {
67  this.node.Init.Accept(this.visitor, this.argument);
68  }
69  }
70 }
Encapsulates a invocation expression.
Encapsulates a definition.
Definition: Definition.cs:36
This class represent the entry wnen sending a message to an operation object. derived from AstNode ...
Abstract class for all nodes that compounds the abstract syntax tree.
Definition: AstNode.cs:33
Representa a method type.
Definition: MethodType.cs:37