The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CGILInvocationExpressionOperation.cs
Go to the documentation of this file.
1 
2  using AST;
3 using TypeSystem;
4 using AST.Operations;
5 using System;
6 namespace CodeGeneration.Operations {
9  internal class CGILInvocationExpressionOperation<T> : AstOperation where T : CLRCodeGenerator {
10 
14  private T codeGenerator;
18 
19  private VisitorCLRCodeGeneration<T> visitor;
23  private int indent;
28 
29  InheritedAttributes inheritedAttributes;
30 
31  InheritedAttributes objInv;
32 
33  Object objArgs;
34 
35  public CGILInvocationExpressionOperation(int indent, VisitorCLRCodeGeneration<T> visitor,
36  T codeGenerator, InvocationExpression node,
37  InheritedAttributes inheritedAttributes, InheritedAttributes objInv, object objArgs) {
38  this.indent = indent;
39  this.visitor = visitor;
40  this.codeGenerator = codeGenerator;
41  this.node = node;
42  this.inheritedAttributes = inheritedAttributes; // ia simple alias for briefing
43  this.objInv = objInv;
44  this.objArgs = objArgs;
45 
46  }
47  public override object Exec(FieldAccessExpression f, object arg) {
48  // * 1. A message has been sent with the syntax "obj.method(...)"
49  TypeExpression caller = this.node.ActualMethodCalled;
50  if (caller != null)
51  return caller.AcceptOperation(new CGILMethodInvocationOperation<T>(
52  this.indent, this.visitor, this.codeGenerator, this.node,
53  this.inheritedAttributes, this.objArgs, this.objInv), arg);
54 
55  throw new FieldAccessException();
56  }
57 
58  public override object Exec(SingleIdentifierExpression s, object arg) {
59  // * 2. A message is sent with without the implicit object "method(...)"
61  MethodType actualMethodCalled = TypeExpression.As<MethodType>(node.ActualMethodCalled);
62  if ( ( ( (MethodType)node.ActualMethodCalled ).MemberInfo.ModifierMask & Modifier.Static ) == 0 )
63  this.codeGenerator.ldarg(this.indent, 0);
64  this.node.Arguments.Accept(this.visitor, this.objArgs);
65  this.codeGenerator.Call(this.indent, actualMethodCalled, actualMethodCalled.MemberInfo.Class, s.Identifier);
66  //If the actualMethodCalled returns a TypeVariable and the InvocationExpression returns a ValueType an unboxing is needed, becasue there is not auto-unboxing from object to a ValueType.
67  if (actualMethodCalled.Return is TypeVariable && actualMethodCalled.Return.IsFreshVariable() && node.ExpressionType.IsValueType())
68  this.codeGenerator.UnboxAny(this.indent, node.ExpressionType);
69  return null;
70 
71  }
72 
73  public override object Exec(BaseExpression b, object arg) {
74  // * 2.2 A constructor is called
75  MethodType actualMethodCalled = TypeExpression.As<MethodType>(node.ActualMethodCalled);
76  this.node.Arguments.Accept(this.visitor, this.objArgs);
77  this.codeGenerator.constructorCall(this.indent, actualMethodCalled, b.ExpressionType, ".ctor");
78 
79  return null;
80  }
81 
82  public override object Exec(AstNode a, object arg) {
83  this.codeGenerator.WriteLine(this.indent, "//entro por AstNode");
84  return null;
85  }
86 
87 
88  }
89 }
90 
Encapsulates a &#39;base&#39; expression.
Encapsulates the expression to access a field.
Encapsulates a invocation expression.
override bool IsFreshVariable()
To know if it is a type variable with no substitution
This class represent the entry wnen sending a message to an operation object. derived from AstNode ...
Abstract class that represents all different types.
Represents a generic type expression
Definition: TypeVariable.cs:36
Encapsulates a identifier expression of our programming language.
Abstract class for all nodes that compounds the abstract syntax tree.
Definition: AstNode.cs:33
Modifier
Indicates differents modifiers to use in class (only public, internal or static), fields or methods...
Representa a method type.
Definition: MethodType.cs:37