19 using System.Collections.Generic;
23 using CodeGeneration.Operations;
25 namespace CodeGeneration {
34 class VisitorCLRCodeGeneration<T> : VisitorILCodeGeneration<T> where T :
CLRCodeGenerator {
36 public VisitorCLRCodeGeneration(
string moduleName, T codeGenerator)
43 : base(moduleName, codeGenerator) { }
46 #region Visit(InvocationExpression node, Object obj)
48 #region Pattern: runtime check union methods
78 if ( actualMethodCalled != null )
81 return node.Identifier.AcceptOperation(
new CGILInvocationExpressionOperation<T>(this.indent,
this, this.codeGenerator, node, ia, objInv, objArgs), null);
87 for (
int j = 0; j < node.Arguments.ExpressionCount; j++) {
88 node.Arguments.GetExpressionElement(j).Accept(
this, objArgs);
134 #region runtimeCheckTypeExpression()
161 #region IntrospectiveInvocation()
162 internal void IntrospectiveInvocation(
InvocationExpression node, Object obj, Object inheritedAttributes,
string memberName) {
167 InheritedAttributes ia = (InheritedAttributes)obj;
168 ia.IsParentNodeAnInvocation =
true;
169 Object o = node.Identifier.Accept(
this, ia);
170 this.IntrospectiveGetMethod(node, ia, memberName);
171 node.Identifier.Accept(
this, ia);
172 this.codeGenerator.ldci4(this.indent, node.Arguments.ExpressionCount);
173 this.codeGenerator.newarr(this.indent,
"[mscorlib]System.Object");
174 for (
int i = 0; i < node.Arguments.ExpressionCount; i++)
175 IntrospectiveInvocationMakeReadyArgument(node, ia, i);
176 this.codeGenerator.CallVirt(this.indent,
"instance",
"object",
"[mscorlib]System.Reflection.MethodBase",
"Invoke",
new string[] {
"object",
"object[]" });
179 private void IntrospectiveGetMethod(
InvocationExpression node, InheritedAttributes ia, String memberName)
181 String end = this.codeGenerator.NewLabel;
182 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Type",
"[mscorlib]System.Object",
"GetType", null);
183 this.codeGenerator.ldstr(this.indent, memberName);
184 this.codeGenerator.ldci4(this.indent, node.Arguments.ExpressionCount);
185 this.codeGenerator.newarr(this.indent,
"[mscorlib]System.Type");
186 for (
int i = 0; i < node.Arguments.ExpressionCount; i++)
188 TypeExpression argType = node.Arguments.GetExpressionElement(i).ILTypeExpression;
189 this.IntropectiveInvocationLoadArgument(i, argType);
191 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Reflection.MethodInfo",
"[mscorlib]System.Type",
"GetMethod",
new string[] {
"string",
"class [mscorlib]System.Type[]" });
192 this.codeGenerator.dup(this.indent);
193 this.codeGenerator.brtrue(this.indent,end);
194 this.codeGenerator.pop(this.indent);
195 node.Identifier.Accept(
this, ia);
196 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Type",
"[mscorlib]System.Object",
"GetType", null);
197 this.codeGenerator.ldstr(this.indent, memberName);
198 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Reflection.MethodInfo",
"[mscorlib]System.Type",
"GetMethod",
new string[] {
"string" });
199 this.codeGenerator.WriteLabel(this.indent, end);
208 private void IntrospectiveInvocationMakeReadyArgument(
InvocationExpression node, Object inheritedAttributes,
int i) {
209 TypeExpression argType = node.Arguments.GetExpressionElement(i).ILTypeExpression;
210 this.codeGenerator.dup(this.indent);
211 this.codeGenerator.ldci4(this.indent, i);
212 node.Arguments.GetExpressionElement(i).Accept(
this, inheritedAttributes);
213 this.codeGenerator.BoxIfNeeded(this.indent, argType);
214 this.codeGenerator.stelemRef(this.indent);
221 private void IntropectiveInvocationLoadArgument(
int index,
TypeExpression argType) {
222 this.codeGenerator.dup(this.indent);
223 this.codeGenerator.ldci4(this.indent, index);
224 this.codeGenerator.ldtoken(this.indent, TypeMapping.Instance.GetBCLName(argType.ILType(),
true));
225 this.codeGenerator.Call(this.indent,
"class",
"[mscorlib]System.Type",
"[mscorlib]System.Type",
"GetTypeFromHandle",
new string[] {
"valuetype [mscorlib]System.RuntimeTypeHandle" });
226 this.codeGenerator.stelemRef(this.indent);
Encapsulates a invocation expression.
MethodType ActualMethodCalled
Gets or sets the type expression of the current invocation expression. If not exists, their value is null.
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.
This class encapsulates the IL CLR code generator IL.
Expression Reference
Gets or sets the reference of a concrete identifier.
It typechecks the runtime arguments, embeded in a method call, with the parametes of this method...
override Object Visit(InvocationExpression node, Object obj)
This class encapsulates several inherited attributes used in code generation process.
bool Assignment
Gets or sets true if assignment expression found. Otherwise, gets or sets false.
Representa a method type.