Show / Hide Table of Contents

Class CpsRewriterBase<TContinuationState>

Base class for expression tree rewriters to turn expressions into a Continuation Passing Style (CPS).

Inheritance
System.Object
CpsRewriterBase<TContinuationState>
ClassicCpsRewriter
ClassicCpsRewriterWithErrorPropagation
Namespace: System.Linq.CompilerServices
Assembly: Nuqleon.Linq.CompilerServices.dll
Syntax
public abstract class CpsRewriterBase<TContinuationState> : Object
Type Parameters
Name Description
TContinuationState

Type of the state object threaded through the CPS transformation.

Constructors

CpsRewriterBase()

Declaration
protected CpsRewriterBase()

Methods

CheckAsyncMethod(MethodInfo, MethodInfo)

Checks whether the discovered asynchronous method matches the specified synchronous method.

Declaration
protected virtual void CheckAsyncMethod(MethodInfo synchronousMethod, MethodInfo asynchronousMethod)
Parameters
Type Name Description
System.Reflection.MethodInfo synchronousMethod

Synchronous method to match.

System.Reflection.MethodInfo asynchronousMethod

Asynchronous method; null if not found.

FindAsyncMethod(MethodInfo)

Finds the asynchronous method to rewrite the given method to. The specified method has the UseAsyncMethodAttribute applied, but resolution of the method can be overridden by subclasses. By default, the GetContinuationParameters method is used to supply additional parameters that appear on the asynchronous method, used to find the right overload of a method with the same name as the synchronous one.

Declaration
protected virtual MethodInfo FindAsyncMethod(MethodInfo method)
Parameters
Type Name Description
System.Reflection.MethodInfo method

Method to find the target asynchronous method for.

Returns
Type Description
System.Reflection.MethodInfo

Asynchronous method to rewrite the call site for the specified method.

GetAsyncMethodName(MethodInfo)

Gets the asynchronous method name for the given synchronous method. By default, the name is the same as the synchronous method. The GetContinuationParameters method will be called to find additional parameters that designate the asynchronous method overload to look for.

Declaration
protected virtual string GetAsyncMethodName(MethodInfo method)
Parameters
Type Name Description
System.Reflection.MethodInfo method

Method to find the name of the corresponding asynchronous method for.

Returns
Type Description
System.String

Name of the asynchronous method to search for.

GetContinuationParameters(MethodInfo)

Gets the continuation parameter types that are used during method overload resolution by appending those to the parameters type of the synchronous method.

Declaration
protected abstract IEnumerable<Type> GetContinuationParameters(MethodInfo method)
Parameters
Type Name Description
System.Reflection.MethodInfo method

Method to find continuation parameters for, e.g. by inspecting its return type and creating the corresponding callback parameter type.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Type>

Continuation parameter types to check for when searching for an asynchronous method overload.

InvokeContinuation(TContinuationState, Expression)

Creates an invocation of the given continuation.

Declaration
protected abstract Expression InvokeContinuation(TContinuationState continuation, Expression argument)
Parameters
Type Name Description
TContinuationState continuation

Continuation to invoke.

System.Linq.Expressions.Expression argument

Argument to pass to the continuation's invocation.

Returns
Type Description
System.Linq.Expressions.Expression

Expression representing the invocation of the continuation.

MakeAsyncMethodCall(Expression, MethodInfo, IEnumerable<Expression>, TContinuationState)

Creates an asynchronous method call with the given continuation.

Declaration
protected abstract Expression MakeAsyncMethodCall(Expression instance, MethodInfo method, IEnumerable<Expression> arguments, TContinuationState continuation)
Parameters
Type Name Description
System.Linq.Expressions.Expression instance

Instance of the method call.

System.Reflection.MethodInfo method

Method to call.

System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments

Arguments of the method call.

TContinuationState continuation

Continuation to supply to the asynchronous method.

Returns
Type Description
System.Linq.Expressions.Expression

Expression representing an asynchronous method call with the given continuation.

MakeContinuation(Expression, ParameterExpression, TContinuationState)

Creates a new continuation with the given result parameter to run the specified remainder computation.

Declaration
protected abstract TContinuationState MakeContinuation(Expression remainder, ParameterExpression resultParameter, TContinuationState currentContinuation)
Parameters
Type Name Description
System.Linq.Expressions.Expression remainder

Remainder of the expression to evaluate upon invocation of the continuation.

System.Linq.Expressions.ParameterExpression resultParameter

Parameter with the result of the expression evaluation preceding the invocation of the continuation.

TContinuationState currentContinuation

Current continuation being processed upon requesting a new continuation.

Returns
Type Description
TContinuationState

Continuation object that will execute the remainder computation, given the specified result parameter.

RewriteCore(Expression, TContinuationState)

Rewrites the given expression into a CPS-based expression using the specified initial CPS rewrite state.

Declaration
protected Expression RewriteCore(Expression expression, TContinuationState initialState)
Parameters
Type Name Description
System.Linq.Expressions.Expression expression

Expression to rewrite to a CPS-based expression.

TContinuationState initialState

Initial CPS rewrite state.

Returns
Type Description
System.Linq.Expressions.Expression

Rewritten expression in CPS style.

RewriteCore(Expression, TContinuationState, Boolean)

Rewrites the given expression into a CPS-based expression using the specified initial CPS rewrite state.

Declaration
protected Expression RewriteCore(Expression expression, TContinuationState initialState, bool inline)
Parameters
Type Name Description
System.Linq.Expressions.Expression expression

Expression to rewrite to a CPS-based expression.

TContinuationState initialState

Initial CPS rewrite state.

System.Boolean inline

Indicates whether or not to inline invocations when possible. This optimization may defeat evaluation order for specific subclasses, so it can be disabled.

Returns
Type Description
System.Linq.Expressions.Expression

Rewritten expression in CPS style.

In This Article
Back to top Generated by DocFX