The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
VisitorRrotorCodeGeneration.cs
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
3 // Project rROTOR
4 // --------------------------------------------------------------------------
5 // File: VisitorRrotorCodeGeneration.cs
6 // Author: Francisco Ortin - francisco.ortin@gmail.com
7 // Description:
8 // This class walks the AST to obtain the translation to IL code over
9 // the Reflective extension of the SSCLI (Rrotor).
10 // Inheritance: VisitorCodeGeneration
11 // Implements Visitor pattern [Concrete Visitor].
12 // Implements Factory method [Concrete Product].
13 // --------------------------------------------------------------------------
14 // Create date: 21-08-2007
15 // Modification date: 21-08-2007
17 
18 using System;
19 using System.Collections.Generic;
20 using System.IO;
21 using System.Text;
22 
23 using AST;
24 using Tools;
25 using TypeSystem;
26 using ErrorManagement;
27 
28 namespace CodeGeneration {
38  abstract class VisitorRrotorCodeGeneration<T>: VisitorILCodeGeneration <T> where T: RrotorCodeGenerator{
39 
40 
41 
42  #region Constructor
43  public VisitorRrotorCodeGeneration(string moduleName, T codeGenerator)
50  : base(moduleName, codeGenerator) { }
51 
52  #endregion
53 
54  #region Visit(InvocationExpression node, Object obj)
55 
56  public override Object Visit(InvocationExpression node, Object obj) {
58  Object objArgs = obj;
59  MethodType actualMethodCalled = TypeExpression.As<MethodType>(node.ActualMethodCalled);
60  if (actualMethodCalled != null)
61  objArgs = new InheritedAttributes(ia.CurrentMethod, ia.Assignment, ia.Reference, ia.ArrayAccessFound, actualMethodCalled, ia.IsParentNodeAnInvocation);
62 
63  FieldAccessExpression fieldAccessExpression = node.Identifier as FieldAccessExpression;
64  if (fieldAccessExpression != null) {
65  // * A message has been sent with the syntax "obj.method(...)"
66  Object o = node.Identifier.Accept(this, obj);
67  node.Arguments.Accept(this, objArgs);
68  if ((o is SynthesizedAttributes) && (((SynthesizedAttributes)o).IdentifierExpressionMode == IdentifierMode.Instance)) {
69  TypeExpression klass = null; // * When the implicit object is a fresh var reference
70  if (actualMethodCalled != null)
71  klass = actualMethodCalled.MemberInfo.Class;
72  this.codeGenerator.CallVirt(this.indent, actualMethodCalled, klass, fieldAccessExpression.FieldName.Identifier, node.Arguments);
73  }
74  else
75  this.codeGenerator.Call(this.indent, actualMethodCalled, actualMethodCalled.MemberInfo.Class, actualMethodCalled.MemberInfo.MemberIdentifier);
76  }
77  else {
78  // * A message is sent with without the implicit object "method(...)"
80  if ((((MethodType)node.Identifier.ExpressionType).MemberInfo.ModifierMask & Modifier.Static) == 0)
81  this.codeGenerator.ldarg(this.indent, 0);
82  node.Arguments.Accept(this, objArgs);
83  this.codeGenerator.Call(this.indent, actualMethodCalled, actualMethodCalled.MemberInfo.Class, ((SingleIdentifierExpression)node.Identifier).Identifier);
84  }
85  else {
86  if (node.Identifier is BaseExpression) {
87  node.Arguments.Accept(this, objArgs);
88  this.codeGenerator.constructorCall(this.indent, actualMethodCalled, ((BaseExpression)node.Identifier).ExpressionType, ".ctor");
89  }
90  }
91  }
92  //TODO: OJO AQUÏ: MIRAR DONDE SE CORRESPONDE CON CODEGENERATOR, PORQUE GENERAR UNA LÍNEA DESDE EL VISITOR
93  // ES un poco chapuzaCHAPUZA
94  this.codeGenerator.WriteLine();
95  return null;
96  }
97 
98  #endregion
99 
100  #region AddException
101  public override void AddExceptionCode() {
102  throw new NotImplementedException();
103  }
104  #endregion
105  }
106 }
Encapsulates a &#39;base&#39; expression.
Expression Identifier
Gets the expression to invoke
bool IsParentNodeAnInvocation
Gets or sets true if the parent node is an InvocationExpression. Otherwise, false.
Encapsulates the expression to access a field.
Encapsulates a invocation expression.
This class encapsulates the IL CLR code generator IL.
Abstract class that represents all different types.
bool ArrayAccessFound
Gets or sets true if array access expression found. Otherwise, gets or sets false.
MethodDefinition CurrentMethod
Gets or sets the current method definition node.
Encapsulates a identifier expression of our programming language.
Expression Reference
Gets or sets the reference of a concrete identifier.
override Object Visit(InvocationExpression node, Object obj)
This class encapsulates several inherited attributes used in code generation process.
Modifier
Indicates differents modifiers to use in class (only public, internal or static), fields or methods...
bool Assignment
Gets or sets true if assignment expression found. Otherwise, gets or sets false.
Representa a method type.
Definition: MethodType.cs:37
override void AddExceptionCode()
Adds the intermediate code for exception to include in the file.
This class encapsulates several inherited attributes used in code generation process.