private BinaryNode( BinaryExpression binaryExpression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions, string binaryOperationMethodName) { if (binaryExpression == null) { throw new ArgumentNullException("binaryExpression"); } if (constExpressions == null) { throw new ArgumentNullException("constExpressions"); } if (parameterExpressions == null) { throw new ArgumentNullException("parameterExpressions"); } this.binaryExpression = binaryExpression; this.leftNode = AotCompiler.Compile(binaryExpression.Left, constExpressions, parameterExpressions); this.rightNode = AotCompiler.Compile(binaryExpression.Right, constExpressions, parameterExpressions); this.operation = Intrinsic.WrapBinaryOperation(binaryExpression.Method) ?? (binaryOperationMethodName == null ? null : Intrinsic.WrapBinaryOperation(binaryExpression.Left.Type, binaryOperationMethodName)); this.isNullable = IsNullable(binaryExpression.Left) || IsNullable(binaryExpression.Right); this.shortcutLeftValue = binaryExpression.NodeType == ExpressionType.OrElse ? Constants.TrueObject : binaryExpression.NodeType == ExpressionType.AndAlso ? Constants.FalseObject : null; }
public ArrayIndexNode(Expression expression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions) { if (expression == null) { throw new ArgumentNullException("expression"); } if (constExpressions == null) { throw new ArgumentNullException("constExpressions"); } if (parameterExpressions == null) { throw new ArgumentNullException("parameterExpressions"); } var binaryExpression = expression as BinaryExpression; var methodCallExpression = expression as MethodCallExpression; if (binaryExpression != null) { this.targetNode = AotCompiler.Compile(binaryExpression.Left, constExpressions, parameterExpressions); this.indexNode = AotCompiler.Compile(binaryExpression.Right, constExpressions, parameterExpressions); } else { this.methodCallNode = new CallNode(methodCallExpression, constExpressions, parameterExpressions); } this.expression = expression; }
public CallNode(MethodCallExpression methodCallExpression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions) { if (methodCallExpression == null) { throw new ArgumentNullException("methodCallExpression"); } if (constExpressions == null) { throw new ArgumentNullException("constExpressions"); } if (parameterExpressions == null) { throw new ArgumentNullException("parameterExpressions"); } this.methodCallExpression = methodCallExpression; this.targetNode = AotCompiler.Compile(methodCallExpression.Object, constExpressions, parameterExpressions); this.argumentNodes = new ExecutionNode[methodCallExpression.Arguments.Count]; for (var i = 0; i < this.argumentNodes.Length; i++) { this.argumentNodes[i] = AotCompiler.Compile(methodCallExpression.Arguments[i], constExpressions, parameterExpressions); } this.fastCallInvoker = FastCall.TryCreate(methodCallExpression.Method); this.isStatic = this.methodCallExpression.Method.IsStatic; }
private UnaryNode( UnaryExpression unaryExpression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions, string unaryOperationMethodName) { this.unaryExpression = unaryExpression; if (unaryExpression == null) { throw new ArgumentNullException("unaryExpression"); } if (constExpressions == null) { throw new ArgumentNullException("constExpressions"); } if (parameterExpressions == null) { throw new ArgumentNullException("parameterExpressions"); } this.operandNode = AotCompiler.Compile(unaryExpression.Operand, constExpressions, parameterExpressions); this.isNullable = IsNullable(unaryExpression.Operand); this.operation = Intrinsic.WrapUnaryOperation(unaryExpression.Method) ?? (unaryOperationMethodName == null ? null : Intrinsic.WrapUnaryOperation(unaryExpression.Operand.Type, unaryOperationMethodName)); }
public TypeAsNode(UnaryExpression typeAsExpression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions) { if (typeAsExpression == null) { throw new ArgumentNullException("typeAsExpression"); } if (constExpressions == null) { throw new ArgumentNullException("constExpressions"); } if (parameterExpressions == null) { throw new ArgumentNullException("parameterExpressions"); } this.typeAsExpression = typeAsExpression; this.targetType = TypeDescription.GetTypeDescription(typeAsExpression.Type); if (this.targetType.IsValueType) { this.convertNode = new ConvertNode(typeAsExpression, constExpressions, parameterExpressions); } else { this.targetNode = AotCompiler.Compile(typeAsExpression.Operand, constExpressions, parameterExpressions); } }
public MemberAccessNode(MemberExpression memberExpression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions) { if (memberExpression == null) { throw new ArgumentNullException("memberExpression"); } if (constExpressions == null) { throw new ArgumentNullException("constExpressions"); } if (parameterExpressions == null) { throw new ArgumentNullException("parameterExpressions"); } this.memberExpression = memberExpression; this.targetNode = AotCompiler.Compile(memberExpression.Expression, constExpressions, parameterExpressions); var member = this.memberExpression.Member; this.fieldInfo = member as FieldInfo; var properFieldInfo = member as PropertyInfo; if (properFieldInfo != null) { this.propertyGetter = properFieldInfo.GetGetMethod(nonPublic: true); } this.isStatic = this.fieldInfo != null ? this.fieldInfo.IsStatic : this.propertyGetter != null && this.propertyGetter.IsStatic; }
public ListInitNode(ListInitExpression listInitExpression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions) { if (listInitExpression == null) { throw new ArgumentNullException("listInitExpression"); } if (constExpressions == null) { throw new ArgumentNullException("constExpressions"); } if (parameterExpressions == null) { throw new ArgumentNullException("parameterExpressions"); } this.listInitExpression = listInitExpression; this.newNode = new NewNode(listInitExpression.NewExpression, constExpressions, parameterExpressions); this.initializationNodes = new KeyValuePair <MethodInfo, ExecutionNode[]> [listInitExpression.Initializers.Count]; for (var i = 0; i < this.initializationNodes.Length; i++) { var initialization = listInitExpression.Initializers[i]; var argumentNodes = new ExecutionNode[initialization.Arguments.Count]; for (var a = 0; a < initialization.Arguments.Count; a++) { argumentNodes[a] = AotCompiler.Compile(initialization.Arguments[a], constExpressions, parameterExpressions); } this.initializationNodes[i] = new KeyValuePair <MethodInfo, ExecutionNode[]>(initialization.AddMethod, argumentNodes); } }
public ConvertNode(UnaryExpression convertExpression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions) { this.convertExpression = convertExpression; this.operandNode = AotCompiler.Compile(convertExpression.Operand, constExpressions, parameterExpressions); this.sourceType = TypeDescription.GetTypeDescription(convertExpression.Operand.Type); this.targetType = TypeDescription.GetTypeDescription(convertExpression.Type); if (this.sourceType.IsNullable) { this.sourceType = this.sourceType.UnderlyingType; this.isSourceTypeNullable = true; } if (this.targetType.IsNullable) { this.targetType = this.targetType.UnderlyingType; this.isTargetTypeNullable = true; } this.operation = Intrinsic.WrapUnaryOperation(convertExpression.Method) ?? Intrinsic.WrapUnaryOperation ( this.targetType.ExplicitConvertFrom.FindConversion(this.sourceType, this.targetType) ?? this.targetType.ImplicitConvertFrom.FindConversion(this.sourceType, this.targetType) ?? this.sourceType.ExplicitConvertTo.FindConversion(this.sourceType, this.targetType) ?? this.sourceType.ImplicitConvertTo.FindConversion(this.sourceType, this.targetType) ); }
public ConvertNode(UnaryExpression convertExpression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions) { this.convertExpression = convertExpression; this.operandNode = AotCompiler.Compile(convertExpression.Operand, constExpressions, parameterExpressions); this.operation = Intrinsic.WrapUnaryOperation(convertExpression.Method) ?? Intrinsic.WrapUnaryOperation( convertExpression.Type .GetMethods(BindingFlags.Public | BindingFlags.Static) .FirstOrDefault(m => (string.Equals(m.Name, "op_Explicit", StringComparison.Ordinal) || string.Equals(m.Name, "op_Implicit", StringComparison.Ordinal)) && m.ReturnType == convertExpression.Type && m.GetParameters().Length == 1 && m.GetParameters()[0].ParameterType == convertExpression.Operand.Type) ); this.targetType = Nullable.GetUnderlyingType(convertExpression.Type) ?? convertExpression.Type; this.isTargetTypeNullable = IsNullable(convertExpression.Type); this.sourceType = Nullable.GetUnderlyingType(convertExpression.Operand.Type) ?? convertExpression.Operand.Type; this.isSourceTypeNullable = IsNullable(convertExpression.Operand); }
public ArrayLengthNode(UnaryExpression unaryExpression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions) { this.unaryExpression = unaryExpression; if (unaryExpression == null) { throw new ArgumentNullException("unaryExpression"); } if (constExpressions == null) { throw new ArgumentNullException("constExpressions"); } if (parameterExpressions == null) { throw new ArgumentNullException("parameterExpressions"); } this.targetNode = AotCompiler.Compile(unaryExpression.Operand, constExpressions, parameterExpressions); }
public TypeIsNode(TypeBinaryExpression typeBinaryExpression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions) { if (typeBinaryExpression == null) { throw new ArgumentNullException("typeBinaryExpression"); } if (constExpressions == null) { throw new ArgumentNullException("constExpressions"); } if (parameterExpressions == null) { throw new ArgumentNullException("parameterExpressions"); } this.typeBinaryExpression = typeBinaryExpression; this.targetNode = AotCompiler.Compile(typeBinaryExpression.Expression, constExpressions, parameterExpressions); }
public CoalesceNode(BinaryExpression binaryExpression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions) { if (binaryExpression == null) { throw new ArgumentNullException("binaryExpression"); } if (constExpressions == null) { throw new ArgumentNullException("constExpressions"); } if (parameterExpressions == null) { throw new ArgumentNullException("parameterExpressions"); } this.binaryExpression = binaryExpression; this.leftNode = AotCompiler.Compile(binaryExpression.Left, constExpressions, parameterExpressions); this.rightNode = AotCompiler.Compile(binaryExpression.Right, constExpressions, parameterExpressions); }
public ConditionalNode(ConditionalExpression conditionalExpression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions) { if (conditionalExpression == null) { throw new ArgumentNullException("conditionalExpression"); } if (constExpressions == null) { throw new ArgumentNullException("constExpressions"); } if (parameterExpressions == null) { throw new ArgumentNullException("parameterExpressions"); } this.conditionalExpression = conditionalExpression; this.trueBranchNode = AotCompiler.Compile(conditionalExpression.IfTrue, constExpressions, parameterExpressions); this.falseBranchNode = AotCompiler.Compile(conditionalExpression.IfFalse, constExpressions, parameterExpressions); this.conditionTestNode = AotCompiler.Compile(conditionalExpression.Test, constExpressions, parameterExpressions); }
public MemberListBindingsNode(ReadOnlyCollection <MemberBinding> bindings, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions) { if (bindings == null) { throw new ArgumentNullException("bindings"); } if (constExpressions == null) { throw new ArgumentNullException("constExpressions"); } if (parameterExpressions == null) { throw new ArgumentNullException("parameterExpressions"); } var listBindings = new PreparedListBinding[bindings.Sum(b => b is MemberListBinding ? ((MemberListBinding)b).Initializers.Count : 0)]; var i = 0; foreach (var binding in bindings) { var memberListBinding = binding as MemberListBinding; if (memberListBinding == null) { continue; } foreach (var elementInitializer in memberListBinding.Initializers) { var arguments = new ExecutionNode[elementInitializer.Arguments.Count]; for (var a = 0; a < arguments.Length; a++) { arguments[a] = AotCompiler.Compile(elementInitializer.Arguments[a], constExpressions, parameterExpressions); } listBindings[i++] = new PreparedListBinding(memberListBinding.Member, elementInitializer.AddMethod, arguments); } } this.bindingsByMember = listBindings.ToLookup(b => b.Member); }
public InvocationNode(InvocationExpression invocationExpression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions) { if (invocationExpression == null) { throw new ArgumentNullException("invocationExpression"); } if (constExpressions == null) { throw new ArgumentNullException("constExpressions"); } if (parameterExpressions == null) { throw new ArgumentNullException("parameterExpressions"); } this.invocationExpression = invocationExpression; this.target = AotCompiler.Compile(invocationExpression.Expression, constExpressions, parameterExpressions); this.argumentNodes = new ExecutionNode[invocationExpression.Arguments.Count]; for (var i = 0; i < this.argumentNodes.Length; i++) { this.argumentNodes[i] = AotCompiler.Compile(invocationExpression.Arguments[i], constExpressions, parameterExpressions); } }
public PreparedMemberAssignment(MemberInfo member, ExecutionNode valueNode) { this.Member = member; this.ValueNode = valueNode; }