Class LvalExpressionVisitor
Expression visitor with tracking of "left values" (lval
s) to guarantee
rewrite safety.
Inherited Members
Namespace: System.Linq.Expressions
Assembly: Nuqleon.Linq.Expressions.Optimizers.dll
Syntax
public class LvalExpressionVisitor : SafeExpressionVisitor
Remarks
Nodes of type System.Linq.Expressions.IndexExpression, System.Linq.Expressions.MemberExpression, and System.Linq.Expressions.ParameterExpression can be used as assignment targets and will be visited using specialized VisitIndex(IndexExpression, Boolean), VisitMember(MemberExpression, Boolean), and VisitParameter(ParameterExpression, Boolean) methods.
Constructors
LvalExpressionVisitor()
Declaration
public LvalExpressionVisitor()
Methods
GetInvokeMethod(Expression)
Gets the delegate invocation method of the specified expression that represents an invocation target.
Declaration
protected static MethodInfo GetInvokeMethod(Expression expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | expression | The invocation target expression. |
Returns
Type | Description |
---|---|
System.Reflection.MethodInfo | The method representing the delegate invocation method of the invocation target expression. |
IsAssignment(ExpressionType)
Checks if the specified node type represents an assignment expression node.
Declaration
protected static bool IsAssignment(ExpressionType nodeType)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.ExpressionType | nodeType | The node type to check. |
Returns
Type | Description |
---|---|
System.Boolean | true if the specified node type represents an assignment expression node; otherwise, false. |
VisitArgument(Expression, ParameterInfo)
Visits the expression argument
using the corresponding parameter
to determine whether the argument is assigned to a ref
or out
parameter. An argument that
is passed by reference gets visited using VisitLval(Expression).
Declaration
protected virtual Expression VisitArgument(Expression argument, ParameterInfo parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | argument | The argument expression to visit. |
System.Reflection.ParameterInfo | parameter | The parameter corresponding to the argument. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the expression arguments. |
VisitArguments(ReadOnlyCollection<Expression>, ParameterInfo[])
Visits the expression arguments using the corresponding parameters to determine whether each
argument is assigned to a ref
or out
parameter. Arguments that are passed by
reference get visited using VisitLval(Expression).
Declaration
protected ReadOnlyCollection<Expression> VisitArguments(ReadOnlyCollection<Expression> arguments, ParameterInfo[] parameters)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.ObjectModel.ReadOnlyCollection<System.Linq.Expressions.Expression> | arguments | The argument expressions to visit. |
System.Reflection.ParameterInfo[] | parameters | The parameters corresponding to the arguments. |
Returns
Type | Description |
---|---|
System.Collections.ObjectModel.ReadOnlyCollection<System.Linq.Expressions.Expression> | The result of visiting the expression arguments. |
VisitArguments(ReadOnlyCollection<Expression>, ParameterInfo[], Int32)
Visits the expression arguments
using the corresponding parameters
to determine whether each argument is assigned to a ref
or out
parameter. Arguments that are
passed by reference get visited using VisitLval(Expression).
Declaration
protected virtual ReadOnlyCollection<Expression> VisitArguments(ReadOnlyCollection<Expression> arguments, ParameterInfo[] parameters, int skip)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.ObjectModel.ReadOnlyCollection<System.Linq.Expressions.Expression> | arguments | The argument expressions to visit. |
System.Reflection.ParameterInfo[] | parameters | The parameters corresponding to the arguments. |
System.Int32 | skip | The number of parameters to skip when pairing them with corresponding arguments. |
Returns
Type | Description |
---|---|
System.Collections.ObjectModel.ReadOnlyCollection<System.Linq.Expressions.Expression> | The result of visiting the expression arguments. |
VisitBinaryWithConversion(BinaryExpression)
Visits a binary expression that has a System.Linq.Expressions.BinaryExpression.Conversion, determines whether it is an assignment expression, and calls VisitBinaryWithConversion(BinaryExpression, Boolean).
Declaration
protected override sealed Expression VisitBinaryWithConversion(BinaryExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.BinaryExpression | node | The binary expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the binary expression. |
Overrides
VisitBinaryWithConversion(BinaryExpression, Boolean)
Visits a binary expression that has a System.Linq.Expressions.BinaryExpression.Conversion using the specified assignment behavior. If the node represents an assignment, the System.Linq.Expressions.BinaryExpression.Left node is visited using VisitLval(Expression).
Declaration
protected virtual Expression VisitBinaryWithConversion(BinaryExpression node, bool isAssignment)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.BinaryExpression | node | The binary expression to visit. |
System.Boolean | isAssignment | Indicates if the node represents an assignment. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the binary expression. |
VisitBinaryWithoutConversion(BinaryExpression)
Visits a binary expression that has no System.Linq.Expressions.BinaryExpression.Conversion, determines whether it is an assignment expression, and calls VisitBinaryWithoutConversion(BinaryExpression, Boolean).
Declaration
protected override sealed Expression VisitBinaryWithoutConversion(BinaryExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.BinaryExpression | node | The binary expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the binary expression. |
Overrides
VisitBinaryWithoutConversion(BinaryExpression, Boolean)
Visits a binary expression that has no System.Linq.Expressions.BinaryExpression.Conversion using the specified assignment behavior. If the node represents an assignment, the System.Linq.Expressions.BinaryExpression.Left node is visited using VisitLval(Expression).
Declaration
protected virtual Expression VisitBinaryWithoutConversion(BinaryExpression node, bool isAssignment)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.BinaryExpression | node | The binary expression to visit. |
System.Boolean | isAssignment | Indicates if the node represents an assignment. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the binary expression. |
VisitDynamic(DynamicExpression)
Visits a dynamic expression and visits System.Linq.Expressions.DynamicExpression.Arguments that are passed
to ref
or out
parameters using VisitLval(Expression).
Declaration
protected override sealed Expression VisitDynamic(DynamicExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.DynamicExpression | node | The dynamic expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the dynamic expression. |
Remarks
This method is sealed in order to guarantee proper assignment target tracking. In order to guarantee assignment target tracking, override VisitDynamicCore(DynamicExpression) instead.
VisitDynamicCore(DynamicExpression)
Visits a dynamic expression and visits System.Linq.Expressions.DynamicExpression.Arguments that are passed
to ref
or out
parameters using VisitLval(Expression).
Declaration
protected virtual Expression VisitDynamicCore(DynamicExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.DynamicExpression | node | The dynamic expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the dynamic expression. |
VisitIndex(IndexExpression)
Visits an index expression and visits the System.Linq.Expressions.IndexExpression.Object of a value type
using VisitLval(Expression) and System.Linq.Expressions.IndexExpression.Arguments that are passed to
ref
or out
parameters using VisitLval(Expression). It is assumed that the index
expression is not the target of an assignment itself.
Declaration
protected override sealed Expression VisitIndex(IndexExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.IndexExpression | node | The index expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the index expression. |
VisitIndex(IndexExpression, Boolean)
Visits an index expression with the specified isLval
behavior.
See VisitIndex(IndexExpression) for more information about visitor behavior.
Declaration
protected virtual Expression VisitIndex(IndexExpression node, bool isLval)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.IndexExpression | node | The index expression to visit. |
System.Boolean | isLval | Indicates whether the index expression occurs in an assignment target position. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the index expression. |
VisitInvocation(InvocationExpression)
Visits an invocation expression and visits System.Linq.Expressions.InvocationExpression.Arguments that are passed
to ref
or out
parameters using VisitLval(Expression).
Declaration
protected override sealed Expression VisitInvocation(InvocationExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.InvocationExpression | node | The invocation expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the invocation expression. |
Remarks
This method is sealed in order to guarantee proper assignment target tracking. In order to guarantee assignment target tracking, override VisitInvocationCore(InvocationExpression) instead.
VisitInvocationCore(InvocationExpression)
Visits an invocation expression and visits System.Linq.Expressions.InvocationExpression.Arguments that are passed
to ref
or out
parameters using VisitLval(Expression).
Declaration
protected virtual Expression VisitInvocationCore(InvocationExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.InvocationExpression | node | The invocation expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the invocation expression. |
VisitLval(Expression)
Visits an expression that occurs in an assignment target position.
Declaration
protected virtual Expression VisitLval(Expression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | node | The expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the expression. |
VisitMember(MemberExpression)
Visits a member expression and visits the System.Linq.Expressions.MemberExpression.Expression of a value type using VisitLval(Expression). It is assumed that the member expression is not the target of an assignment itself.
Declaration
protected override sealed Expression VisitMember(MemberExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.MemberExpression | node | The member expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the member expression. |
VisitMember(MemberExpression, Boolean)
Visits a member expression with the specified isLval
behavior.
See VisitMember(MemberExpression) for more information about visitor behavior.
Declaration
protected virtual Expression VisitMember(MemberExpression node, bool isLval)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.MemberExpression | node | The member expression to visit. |
System.Boolean | isLval | Indicates whether the member expression occurs in an assignment target position. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the member expression. |
VisitMethodCall(MethodCallExpression)
Visits a method call expression and visits the System.Linq.Expressions.MethodCallExpression.Object of a value
type using VisitLval(Expression) and System.Linq.Expressions.MethodCallExpression.Arguments that are passed
to ref
or out
parameters using VisitLval(Expression).
Declaration
protected override sealed Expression VisitMethodCall(MethodCallExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.MethodCallExpression | node | The method call expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the method call expression. |
Remarks
This method is sealed in order to guarantee proper assignment target tracking. In order to guarantee assignment target tracking, override VisitMethodCallCore(MethodCallExpression) instead.
VisitMethodCallCore(MethodCallExpression)
Visits a method call expression and visits the System.Linq.Expressions.MethodCallExpression.Object of a value
type using VisitLval(Expression) and System.Linq.Expressions.MethodCallExpression.Arguments that are passed
to ref
or out
parameters using VisitLval(Expression).
Declaration
protected virtual Expression VisitMethodCallCore(MethodCallExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.MethodCallExpression | node | The method call expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the method call expression. |
VisitNew(NewExpression)
Visits a new expression and visits System.Linq.Expressions.NewExpression.Arguments that are passed to ref
or out
parameters using VisitLval(Expression).
Declaration
protected override sealed Expression VisitNew(NewExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.NewExpression | node | The new expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the new expression. |
VisitNewCore(NewExpression)
Visits a new expression and visits System.Linq.Expressions.NewExpression.Arguments that are passed to ref
or out
parameters using VisitLval(Expression).
Declaration
protected virtual Expression VisitNewCore(NewExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.NewExpression | node | The new expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the new expression. |
VisitParameter(ParameterExpression)
Visits a parameter expression that does not occur as the target of an assignment.
Declaration
protected override sealed Expression VisitParameter(ParameterExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.ParameterExpression | node | The parameter expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the parameter expression. |
VisitParameter(ParameterExpression, Boolean)
Visits a parameter expression with the specified isLval
behavior.
Declaration
protected virtual Expression VisitParameter(ParameterExpression node, bool isLval)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.ParameterExpression | node | The parameter expression to visit. |
System.Boolean | isLval | Indicates whether the parameter expression occurs in an assignment target position. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the parameter expression. |
VisitRuntimeVariable(ParameterExpression)
Visits a runtime variable expression assuming it may get assigned to.
Declaration
protected override ParameterExpression VisitRuntimeVariable(ParameterExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.ParameterExpression | node | The runtime variable expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.ParameterExpression | The result of visiting the runtime variable expression. |
Overrides
VisitUnaryNonQuote(UnaryExpression)
Visits a unary expression that's not a System.Linq.Expressions.ExpressionType.Quote, determines whether it is an assignment expression, and calls VisitUnaryNonQuote(UnaryExpression, Boolean).
Declaration
protected override sealed Expression VisitUnaryNonQuote(UnaryExpression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.UnaryExpression | node | The unary expression to visit. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the unary expression. |
Overrides
VisitUnaryNonQuote(UnaryExpression, Boolean)
Visits a unary expression that's not a System.Linq.Expressions.ExpressionType.Quote using the specified assignment behavior. If the node represents an assignment, the System.Linq.Expressions.UnaryExpression.Operand is visited using VisitLval(Expression).
Declaration
protected virtual Expression VisitUnaryNonQuote(UnaryExpression node, bool isAssignment)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.UnaryExpression | node | The unary expression to visit. |
System.Boolean | isAssignment | Indicates if the node represents an assignment. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of visiting the unary expression. |