/// <summary> /// 计算器 /// </summary> /// <param name="type"></param> /// <param name="left"></param> /// <param name="right"></param> /// <returns></returns> private static object calculateChar(System.Linq.Expressions.ExpressionType type, object left, object right) { switch (type) { case System.Linq.Expressions.ExpressionType.Add: return((char)left + (char)right); case System.Linq.Expressions.ExpressionType.AddChecked: checked { return((char)left + (char)right); } case System.Linq.Expressions.ExpressionType.Subtract: return((char)left - (char)right); case System.Linq.Expressions.ExpressionType.SubtractChecked: checked { return((char)left - (char)right); } case System.Linq.Expressions.ExpressionType.Multiply: return((char)left * (char)right); case System.Linq.Expressions.ExpressionType.MultiplyChecked: checked { return((char)left * (char)right); } case System.Linq.Expressions.ExpressionType.Divide: return((char)left / (char)right); case System.Linq.Expressions.ExpressionType.Modulo: return((char)left % (char)right); case System.Linq.Expressions.ExpressionType.Or: return((char)left | (char)right); case System.Linq.Expressions.ExpressionType.And: return((char)left & (char)right); case System.Linq.Expressions.ExpressionType.ExclusiveOr: return((char)left ^ (char)right); case System.Linq.Expressions.ExpressionType.LeftShift: return((char)left << (int)right); case System.Linq.Expressions.ExpressionType.RightShift: return((char)left >> (int)right); default: return(null); } }
/// <summary> /// 计算器 /// </summary> /// <param name="type"></param> /// <param name="left"></param> /// <param name="right"></param> /// <returns></returns> private static object /*Type[1]*/ calculateULong/*Type[1]*/ (System.Linq.Expressions.ExpressionType type, object left, object right) { switch (type) { case System.Linq.Expressions.ExpressionType.Add: return((/*Type[0]*/ ulong /*Type[0]*/)left + (/*Type[0]*/ ulong /*Type[0]*/)right); case System.Linq.Expressions.ExpressionType.AddChecked: checked { return((/*Type[0]*/ ulong /*Type[0]*/)left + (/*Type[0]*/ ulong /*Type[0]*/)right); } case System.Linq.Expressions.ExpressionType.Subtract: return((/*Type[0]*/ ulong /*Type[0]*/)left - (/*Type[0]*/ ulong /*Type[0]*/)right); case System.Linq.Expressions.ExpressionType.SubtractChecked: checked { return((/*Type[0]*/ ulong /*Type[0]*/)left - (/*Type[0]*/ ulong /*Type[0]*/)right); } case System.Linq.Expressions.ExpressionType.Multiply: return((/*Type[0]*/ ulong /*Type[0]*/)left * (/*Type[0]*/ ulong /*Type[0]*/)right); case System.Linq.Expressions.ExpressionType.MultiplyChecked: checked { return((/*Type[0]*/ ulong /*Type[0]*/)left * (/*Type[0]*/ ulong /*Type[0]*/)right); } case System.Linq.Expressions.ExpressionType.Divide: return((/*Type[0]*/ ulong /*Type[0]*/)left / (/*Type[0]*/ ulong /*Type[0]*/)right); case System.Linq.Expressions.ExpressionType.Modulo: return((/*Type[0]*/ ulong /*Type[0]*/)left % (/*Type[0]*/ ulong /*Type[0]*/)right); case System.Linq.Expressions.ExpressionType.Or: return((/*Type[0]*/ ulong /*Type[0]*/)left | (/*Type[0]*/ ulong /*Type[0]*/)right); case System.Linq.Expressions.ExpressionType.And: return((/*Type[0]*/ ulong /*Type[0]*/)left & (/*Type[0]*/ ulong /*Type[0]*/)right); case System.Linq.Expressions.ExpressionType.ExclusiveOr: return((/*Type[0]*/ ulong /*Type[0]*/)left ^ (/*Type[0]*/ ulong /*Type[0]*/)right); case System.Linq.Expressions.ExpressionType.LeftShift: return((/*Type[0]*/ ulong /*Type[0]*/)left << (int)right); case System.Linq.Expressions.ExpressionType.RightShift: return((/*Type[0]*/ ulong /*Type[0]*/)left >> (int)right); default: return(null); } }
/// <summary>Visits an unary expression.</summary> /// <param name="expression">Expression to be visited.</param> /// <returns>Expression visited</returns> protected override System.Linq.Expressions.Expression VisitUnary(System.Linq.Expressions.UnaryExpression expression) { MethodNames operatorName; System.Linq.Expressions.ExpressionType expressionType = expression.NodeType; switch (expression.NodeType) { case System.Linq.Expressions.ExpressionType.Convert: case System.Linq.Expressions.ExpressionType.TypeAs: return(Visit(expression.Operand)); default: string methodName = Enum.GetNames(typeof(MethodNames)).Where(item => item == expressionType.ToString()).FirstOrDefault(); if (!System.String.IsNullOrEmpty(methodName)) { operatorName = (MethodNames)Enum.Parse(typeof(MethodNames), methodName); } else { return(base.VisitUnary(expression)); } break; } UnaryOperator unaryOperator = new UnaryOperator(operatorName); HandleComponent(unaryOperator); Visit(expression.Operand); CleanupComponent(_lastComponent); _lastComponent = unaryOperator; return(expression); }
public static object BinaryOpMetamethod(LuaContext context, ExprType op, object left, object right) { ContractUtils.RequiresNotNull(context, "context"); switch (op) { case ExprType.Add: case ExprType.Subtract: case ExprType.Multiply: case ExprType.Divide: case ExprType.Modulo: case ExprType.Power: return NumericMetamethod(context, op, left, right); case ExprType.GreaterThan: case ExprType.GreaterThanOrEqual: case ExprType.LessThan: case ExprType.LessThanOrEqual: return RelationalMetamethod(context, op, left, right); case ExprType.Equal: return EquateMetamethod(context, op, left, right); case ExprType.NotEqual: return Not(EquateMetamethod(context, ExprType.Equal, left, right)); default: throw new ArgumentOutOfRangeException("op"); } }
private static string NodeTypeToString(System.Linq.Expressions.ExpressionType nodeType, bool rightIsNull) { switch (nodeType) { case System.Linq.Expressions.ExpressionType.Add: return("+"); case System.Linq.Expressions.ExpressionType.And: return("&"); case System.Linq.Expressions.ExpressionType.AndAlso: return("AND"); case System.Linq.Expressions.ExpressionType.Divide: return("/"); case System.Linq.Expressions.ExpressionType.Equal: return(rightIsNull ? "IS" : "="); case System.Linq.Expressions.ExpressionType.GreaterThan: return(">"); case System.Linq.Expressions.ExpressionType.GreaterThanOrEqual: return(">="); case System.Linq.Expressions.ExpressionType.LessThan: return("<"); case System.Linq.Expressions.ExpressionType.LessThanOrEqual: return("<="); case System.Linq.Expressions.ExpressionType.Modulo: return("%"); case System.Linq.Expressions.ExpressionType.Multiply: return("*"); case System.Linq.Expressions.ExpressionType.Negate: return("-"); case System.Linq.Expressions.ExpressionType.Not: return("NOT"); case System.Linq.Expressions.ExpressionType.NotEqual: return("<>"); case System.Linq.Expressions.ExpressionType.Or: return("|"); case System.Linq.Expressions.ExpressionType.OrElse: return("OR"); case System.Linq.Expressions.ExpressionType.Subtract: return("-"); default: throw new System.Exception(string.Format("Unsupported node type: {0}", nodeType)); } }
static object GetRelationalMetamethod(Context context, ExprType op, object left, object right) { var methodName = GetMethodName(op); var metamethodLeft = GetMetamethod(context, left, methodName); var metamethodRight = GetMetamethod(context, right, methodName); return(metamethodLeft != metamethodRight ? null : metamethodLeft); }
public static Expr BinaryOp(Expr context, ExprType operation, DynamicMetaObject left, DynamicMetaObject right) { return Expr.Invoke( Expr.Constant((Func<CodeContext, ExprType, object, object, object>)LuaOps.BinaryOpMetamethod), context, Expr.Constant(operation), Expr.Convert(left.Expression, typeof(object)), Expr.Convert(right.Expression, typeof(object))); }
public static Expr BinaryOp(Context context, ExprType operation, DynamicMetaObject left, DynamicMetaObject right) { return(Expr.Invoke( Expr.Constant((Func <Context, ExprType, object, object, object>)LuaOps.BinaryOpMetamethod), Expr.Constant(context, typeof(Context)), Expr.Constant(operation), Expr.Convert(left.Expression, typeof(object)), Expr.Convert(right.Expression, typeof(object)))); }
Expression SetOperationInformations(ResolveContext rc, IType resultType, Expression lhs, BinaryOperatorType op, Expression rhs, bool isLifted = false) { this.isLiftedOperator = isLifted; this.ResolvedType = resultType; this.left = lhs; this.right = rhs; this.operatortype = ResolveContext.GetLinqNodeType(this.oper, rc.checkForOverflow); _resolved = true; return(this); }
/// <summary> /// 计算器 /// </summary> /// <param name="type"></param> /// <param name="value"></param> /// <returns></returns> private static object /*Type[1]*/ calculateLong/*Type[1]*/ (System.Linq.Expressions.ExpressionType type, object value) { switch (type) { case System.Linq.Expressions.ExpressionType.Negate: return(-(/*Type[0]*/ long /*Type[0]*/)value); case System.Linq.Expressions.ExpressionType.NegateChecked: checked { return(-(/*Type[0]*/ long /*Type[0]*/)value); } } return(null); }
/// <summary> /// 计算器 /// </summary> /// <param name="type"></param> /// <param name="value"></param> /// <returns></returns> private static object calculateDouble(System.Linq.Expressions.ExpressionType type, object value) { switch (type) { case System.Linq.Expressions.ExpressionType.Negate: return(-(double)value); case System.Linq.Expressions.ExpressionType.NegateChecked: checked { return(-(double)value); } } return(null); }
/// <summary> /// 比较器 /// </summary> /// <param name="type"></param> /// <param name="left"></param> /// <param name="right"></param> /// <returns></returns> private static LogicType compareDateTime(System.Linq.Expressions.ExpressionType type, object left, object right) { switch (type) { case System.Linq.Expressions.ExpressionType.GreaterThanOrEqual: return(((DateTime)left) >= ((DateTime)right) ? LogicType.True : LogicType.False); case System.Linq.Expressions.ExpressionType.GreaterThan: return(((DateTime)left) > ((DateTime)right) ? LogicType.True : LogicType.False); default: return(LogicType.Unknown); } }
/// <summary> /// 比较器 /// </summary> /// <param name="type"></param> /// <param name="left"></param> /// <param name="right"></param> /// <returns></returns> private static LogicType /*Type[1]*/ compareULong/*Type[1]*/ (System.Linq.Expressions.ExpressionType type, object left, object right) { switch (type) { case System.Linq.Expressions.ExpressionType.GreaterThanOrEqual: return(((/*Type[0]*/ ulong /*Type[0]*/)left) >= ((/*Type[0]*/ ulong /*Type[0]*/)right) ? LogicType.True : LogicType.False); case System.Linq.Expressions.ExpressionType.GreaterThan: return(((/*Type[0]*/ ulong /*Type[0]*/)left) > ((/*Type[0]*/ ulong /*Type[0]*/)right) ? LogicType.True : LogicType.False); default: return(LogicType.Unknown); } }
public static object RelationalMetamethod(Context context, ExprType op, object left, object right) { if (left.GetType() != right.GetType()) { return(false); } // There are no metamethods for 'a > b' and 'a >= b' so they are translated to 'b < a' and 'b <= a' respectively var invert = op == ExprType.GreaterThan || op == ExprType.GreaterThanOrEqual; var metamethod = GetRelationalMetamethod(context, op, left, right); if (metamethod != null) { if (invert) { Context.DynamicCache.GetDynamicCall2()(metamethod, right, left); } else { Context.DynamicCache.GetDynamicCall2()(metamethod, left, right); } } // In the absence of a '<=' metamethod, try '<', 'a <= b' is translated to 'not (b < a)' if (op != ExprType.LessThanOrEqual && op != ExprType.GreaterThanOrEqual) { return(false); } metamethod = GetRelationalMetamethod(context, ExprType.LessThan, left, right); if (metamethod != null) { if (invert) { Not(Context.DynamicCache.GetDynamicCall2()(metamethod, right, left)); } else { Not(Context.DynamicCache.GetDynamicCall2()(metamethod, left, right)); } } var leftTypeName = BaseLibrary.Type(left); var rightTypeName = BaseLibrary.Type(right); if (leftTypeName == rightTypeName) { throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_TWO_ERROR, "compare", leftTypeName); } throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_WITH_ERROR, "compare", leftTypeName, rightTypeName); }
/// <summary> /// 表达式类型计算 /// </summary> /// <param name="type"></param> /// <returns></returns> string ExpressionTypeCast(System.Linq.Expressions.ExpressionType type) { switch (type) { case System.Linq.Expressions.ExpressionType.And: case System.Linq.Expressions.ExpressionType.AndAlso: return(" AND "); case System.Linq.Expressions.ExpressionType.Equal: return(" ="); case System.Linq.Expressions.ExpressionType.GreaterThan: return(" >"); case System.Linq.Expressions.ExpressionType.GreaterThanOrEqual: return(">="); case System.Linq.Expressions.ExpressionType.LessThan: return("<"); case System.Linq.Expressions.ExpressionType.LessThanOrEqual: return("<="); case System.Linq.Expressions.ExpressionType.NotEqual: return("<>"); case System.Linq.Expressions.ExpressionType.Or: case System.Linq.Expressions.ExpressionType.OrElse: return(" Or "); case System.Linq.Expressions.ExpressionType.Add: case System.Linq.Expressions.ExpressionType.AddChecked: return("+"); case System.Linq.Expressions.ExpressionType.Subtract: case System.Linq.Expressions.ExpressionType.SubtractChecked: return("-"); case System.Linq.Expressions.ExpressionType.Divide: return("/"); case System.Linq.Expressions.ExpressionType.Multiply: case System.Linq.Expressions.ExpressionType.MultiplyChecked: return("*"); default: return(null); } }
public static object NumericMetamethod(Context context, ExprType op, object left, object right) { var methodName = GetMethodName(op); var metamethod = GetMetamethod(context, left, methodName) ?? GetMetamethod(context, right, methodName); if (metamethod != null) { return(Context.DynamicCache.GetDynamicCall2()(metamethod, left, right)); } var typeName = BaseLibrary.Type(BaseLibrary.ToNumber(left) == null ? left : right); throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_ERROR, "perform arithmetic on", typeName); }
/// <summary>Visits a binary expression.</summary> /// <param name="expression">Expression to be visited.</param> /// <returns>Expression visited</returns> protected override System.Linq.Expressions.Expression VisitBinary(System.Linq.Expressions.BinaryExpression expression) { MethodNames operatorName; System.Linq.Expressions.ExpressionType expressionType = expression.NodeType; switch (expression.NodeType) { case System.Linq.Expressions.ExpressionType.OrElse: expressionType = System.Linq.Expressions.ExpressionType.Or; goto default; case System.Linq.Expressions.ExpressionType.AndAlso: expressionType = System.Linq.Expressions.ExpressionType.And; goto default; default: string methodName = Enum.GetNames(typeof(MethodNames)).Where(item => item == expressionType.ToString()).FirstOrDefault(); if (!System.String.IsNullOrEmpty(methodName)) { operatorName = (MethodNames)Enum.Parse(typeof(MethodNames), methodName); } else { return(base.VisitBinary(expression)); } break; } BinaryOperator binaryOperator = new BinaryOperator(operatorName); HandleComponent(binaryOperator); Visit(expression.Left); CleanupComponent(_lastComponent); Visit(expression.Right); CleanupComponent(_lastComponent); _lastComponent = binaryOperator; return(expression); }
Expression SetUserDefinedOperationInformations(ResolveContext rc, OverloadResolution r) {//TODO:Is It OK if (r.BestCandidateErrors != OverloadResolutionErrors.None) { rc.Report.Error(0, loc, "Operator `{0}' is ambiguous on operands of type `{1}' and `{2}'", OperName(oper), left.Type.ToString(), right.Type.ToString()); return(r.CreateInvocation(null)); } IMethod method = (IMethod)r.BestCandidate; var operands = r.GetArgumentsWithConversions(); this.operatortype = ResolveContext.GetLinqNodeType(this.oper, rc.checkForOverflow); this.isLiftedOperator = method is OverloadResolution.ILiftedOperator; this.ResolvedType = method.ReturnType; this.left = operands[0]; this.right = operands[1]; this.userDefinedOperatorMethod = method; _resolved = true; return(this); }
public static object BinaryOpMetamethod(Context context, ExprType op, object left, object right) { switch (op) { case ExprType.Add: case ExprType.Subtract: case ExprType.Multiply: case ExprType.Divide: case ExprType.Modulo: case ExprType.Power: return(NumericMetamethod(context, op, left, right)); case ExprType.GreaterThan: case ExprType.GreaterThanOrEqual: case ExprType.LessThan: case ExprType.LessThanOrEqual: return(RelationalMetamethod(context, op, left, right)); default: throw new ArgumentOutOfRangeException("op"); } }
/// <summary> /// 计算器 /// </summary> /// <param name="type"></param> /// <param name="left"></param> /// <param name="right"></param> /// <returns></returns> private static object /*Type[1]*/ calculateDouble/*Type[1]*/ (System.Linq.Expressions.ExpressionType type, object left, object right) { switch (type) { case System.Linq.Expressions.ExpressionType.Add: return((/*Type[0]*/ double /*Type[0]*/)left + (/*Type[0]*/ double /*Type[0]*/)right); case System.Linq.Expressions.ExpressionType.AddChecked: checked { return((/*Type[0]*/ double /*Type[0]*/)left + (/*Type[0]*/ double /*Type[0]*/)right); } case System.Linq.Expressions.ExpressionType.Subtract: return((/*Type[0]*/ double /*Type[0]*/)left - (/*Type[0]*/ double /*Type[0]*/)right); case System.Linq.Expressions.ExpressionType.SubtractChecked: checked { return((/*Type[0]*/ double /*Type[0]*/)left - (/*Type[0]*/ double /*Type[0]*/)right); } case System.Linq.Expressions.ExpressionType.Multiply: return((/*Type[0]*/ double /*Type[0]*/)left * (/*Type[0]*/ double /*Type[0]*/)right); case System.Linq.Expressions.ExpressionType.MultiplyChecked: checked { return((/*Type[0]*/ double /*Type[0]*/)left * (/*Type[0]*/ double /*Type[0]*/)right); } case System.Linq.Expressions.ExpressionType.Divide: return((/*Type[0]*/ double /*Type[0]*/)left / (/*Type[0]*/ double /*Type[0]*/)right); case System.Linq.Expressions.ExpressionType.Modulo: return((/*Type[0]*/ double /*Type[0]*/)left % (/*Type[0]*/ double /*Type[0]*/)right); default: return(null); } }
/// <summary> /// 计算器 /// </summary> /// <param name="type"></param> /// <param name="left"></param> /// <param name="right"></param> /// <returns></returns> private static object calculateDecimal(System.Linq.Expressions.ExpressionType type, object left, object right) { switch (type) { case System.Linq.Expressions.ExpressionType.Add: return((decimal)left + (decimal)right); case System.Linq.Expressions.ExpressionType.AddChecked: checked { return((decimal)left + (decimal)right); } case System.Linq.Expressions.ExpressionType.Subtract: return((decimal)left - (decimal)right); case System.Linq.Expressions.ExpressionType.SubtractChecked: checked { return((decimal)left - (decimal)right); } case System.Linq.Expressions.ExpressionType.Multiply: return((decimal)left * (decimal)right); case System.Linq.Expressions.ExpressionType.MultiplyChecked: checked { return((decimal)left * (decimal)right); } case System.Linq.Expressions.ExpressionType.Divide: return((decimal)left / (decimal)right); case System.Linq.Expressions.ExpressionType.Modulo: return((decimal)left % (decimal)right); default: return(null); } }
private string Visit(System.Linq.Expressions.ExpressionType op) { switch (op) { case System.Linq.Expressions.ExpressionType.Add: return("+"); case System.Linq.Expressions.ExpressionType.AddAssign: return("+="); case System.Linq.Expressions.ExpressionType.AddAssignChecked: break; case System.Linq.Expressions.ExpressionType.AddChecked: break; case System.Linq.Expressions.ExpressionType.And: return("&"); case System.Linq.Expressions.ExpressionType.AndAlso: return("&&"); case System.Linq.Expressions.ExpressionType.AndAssign: return("&="); case System.Linq.Expressions.ExpressionType.ArrayIndex: break; case System.Linq.Expressions.ExpressionType.ArrayLength: break; case System.Linq.Expressions.ExpressionType.Assign: return("="); case System.Linq.Expressions.ExpressionType.Block: break; case System.Linq.Expressions.ExpressionType.Call: break; case System.Linq.Expressions.ExpressionType.Coalesce: return("??"); case System.Linq.Expressions.ExpressionType.Conditional: break; case System.Linq.Expressions.ExpressionType.Constant: break; case System.Linq.Expressions.ExpressionType.Convert: break; case System.Linq.Expressions.ExpressionType.ConvertChecked: break; case System.Linq.Expressions.ExpressionType.DebugInfo: break; case System.Linq.Expressions.ExpressionType.Decrement: break; case System.Linq.Expressions.ExpressionType.Default: break; case System.Linq.Expressions.ExpressionType.Divide: return("/"); case System.Linq.Expressions.ExpressionType.DivideAssign: return("/="); case System.Linq.Expressions.ExpressionType.Dynamic: break; case System.Linq.Expressions.ExpressionType.Equal: return("=="); case System.Linq.Expressions.ExpressionType.ExclusiveOr: return("^"); case System.Linq.Expressions.ExpressionType.ExclusiveOrAssign: return("^="); case System.Linq.Expressions.ExpressionType.Extension: break; case System.Linq.Expressions.ExpressionType.Goto: break; case System.Linq.Expressions.ExpressionType.GreaterThan: return(">"); case System.Linq.Expressions.ExpressionType.GreaterThanOrEqual: return(">="); case System.Linq.Expressions.ExpressionType.Increment: break; case System.Linq.Expressions.ExpressionType.Index: break; case System.Linq.Expressions.ExpressionType.Invoke: break; case System.Linq.Expressions.ExpressionType.IsFalse: break; case System.Linq.Expressions.ExpressionType.IsTrue: break; case System.Linq.Expressions.ExpressionType.Label: break; case System.Linq.Expressions.ExpressionType.Lambda: break; case System.Linq.Expressions.ExpressionType.LeftShift: return("<<"); case System.Linq.Expressions.ExpressionType.LeftShiftAssign: return("<<="); case System.Linq.Expressions.ExpressionType.LessThan: return("<"); case System.Linq.Expressions.ExpressionType.LessThanOrEqual: return("<="); case System.Linq.Expressions.ExpressionType.ListInit: break; case System.Linq.Expressions.ExpressionType.Loop: break; case System.Linq.Expressions.ExpressionType.MemberAccess: break; case System.Linq.Expressions.ExpressionType.MemberInit: break; case System.Linq.Expressions.ExpressionType.Modulo: return("%"); case System.Linq.Expressions.ExpressionType.ModuloAssign: return("%="); case System.Linq.Expressions.ExpressionType.Multiply: return("*"); case System.Linq.Expressions.ExpressionType.MultiplyAssign: return("*="); case System.Linq.Expressions.ExpressionType.MultiplyAssignChecked: break; case System.Linq.Expressions.ExpressionType.MultiplyChecked: break; case System.Linq.Expressions.ExpressionType.Negate: return("-"); case System.Linq.Expressions.ExpressionType.NegateChecked: break; case System.Linq.Expressions.ExpressionType.New: break; case System.Linq.Expressions.ExpressionType.NewArrayBounds: break; case System.Linq.Expressions.ExpressionType.NewArrayInit: break; case System.Linq.Expressions.ExpressionType.Not: return("!"); case System.Linq.Expressions.ExpressionType.NotEqual: return("!="); case System.Linq.Expressions.ExpressionType.OnesComplement: return("~"); case System.Linq.Expressions.ExpressionType.Or: return("|"); case System.Linq.Expressions.ExpressionType.OrAssign: return("|="); case System.Linq.Expressions.ExpressionType.OrElse: return("||"); case System.Linq.Expressions.ExpressionType.Parameter: break; case System.Linq.Expressions.ExpressionType.PostDecrementAssign: return("--"); case System.Linq.Expressions.ExpressionType.PostIncrementAssign: return("++"); case System.Linq.Expressions.ExpressionType.Power: break; case System.Linq.Expressions.ExpressionType.PowerAssign: break; case System.Linq.Expressions.ExpressionType.PreDecrementAssign: return("--"); case System.Linq.Expressions.ExpressionType.PreIncrementAssign: return("++"); case System.Linq.Expressions.ExpressionType.Quote: break; case System.Linq.Expressions.ExpressionType.RightShift: return(">>"); case System.Linq.Expressions.ExpressionType.RightShiftAssign: return(">>="); case System.Linq.Expressions.ExpressionType.RuntimeVariables: break; case System.Linq.Expressions.ExpressionType.Subtract: return("-"); case System.Linq.Expressions.ExpressionType.SubtractAssign: return("-="); case System.Linq.Expressions.ExpressionType.SubtractAssignChecked: break; case System.Linq.Expressions.ExpressionType.SubtractChecked: break; case System.Linq.Expressions.ExpressionType.Switch: break; case System.Linq.Expressions.ExpressionType.Throw: break; case System.Linq.Expressions.ExpressionType.Try: break; case System.Linq.Expressions.ExpressionType.TypeAs: break; case System.Linq.Expressions.ExpressionType.TypeEqual: break; case System.Linq.Expressions.ExpressionType.TypeIs: break; case System.Linq.Expressions.ExpressionType.UnaryPlus: break; case System.Linq.Expressions.ExpressionType.Unbox: break; default: break; } throw new NotImplementedException(op.ToString()); }
public OperationDistributionResult(System.Linq.Expressions.ExpressionType type) : this() { ExpressionType = type; IsStandardOperation = true; }
static string GetMethodName(ExprType op) { string methodName; return(Constant.METAMETHODS.TryGetValue(op, out methodName) ? methodName : null); }
protected UnaryOperationBinder(System.Linq.Expressions.ExpressionType operation) { }
public LuaBinaryOperationBinder(Context context, ExprType op) : base(op) { this.context = context; }
static object GetRelationalMetamethod(Context context, ExprType op, object left, object right) { var methodName = GetMethodName(op); var metamethodLeft = GetMetamethod(context, left, methodName); var metamethodRight = GetMetamethod(context, right, methodName); return metamethodLeft != metamethodRight ? null : metamethodLeft; }
public static object RelationalMetamethod(Context context, ExprType op, object left, object right) { if (left.GetType() != right.GetType()) return false; // There are no metamethods for 'a > b' and 'a >= b' so they are translated to 'b < a' and 'b <= a' respectively var invert = op == ExprType.GreaterThan || op == ExprType.GreaterThanOrEqual; var metamethod = GetRelationalMetamethod(context, op, left, right); if (metamethod != null) { if (invert) Context.DynamicCache.GetDynamicCall2()(metamethod, right, left); else Context.DynamicCache.GetDynamicCall2()(metamethod, left, right); } // In the absence of a '<=' metamethod, try '<', 'a <= b' is translated to 'not (b < a)' if (op != ExprType.LessThanOrEqual && op != ExprType.GreaterThanOrEqual) return false; metamethod = GetRelationalMetamethod(context, ExprType.LessThan, left, right); if (metamethod != null) { if (invert) Not(Context.DynamicCache.GetDynamicCall2()(metamethod, right, left)); else Not(Context.DynamicCache.GetDynamicCall2()(metamethod, left, right)); } var leftTypeName = BaseLibrary.Type(left); var rightTypeName = BaseLibrary.Type(right); if (leftTypeName == rightTypeName) throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_TWO_ERROR, "compare", leftTypeName); throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_WITH_ERROR, "compare", leftTypeName, rightTypeName); }
public static object EquateMetamethod(LuaContext context, ExprType op, object left, object right) { ContractUtils.RequiresNotNull(context, "context"); var leftTypeName = BaseLibrary.Type(left); var rightTypeName = BaseLibrary.Type(right); if (left == null && right == null) return true; var metamethod = GetRelationalMetamethod(context, op, left, right); if (metamethod != null) return context.DynamicCache.GetDynamicCall2()(metamethod, left, right); else return left == null ? right.Equals(left) : left.Equals(right); }
/// <summary> /// Converts a LINQ binary operator into the Infer.NET equivalent. /// </summary> /// <param name="nodeType"></param> /// <returns></returns> private BinaryOperator ConvertBinaryOp(System.Linq.Expressions.ExpressionType nodeType) { if (nodeType == System.Linq.Expressions.ExpressionType.Add) { return(BinaryOperator.Add); } if (nodeType == System.Linq.Expressions.ExpressionType.And) { return(BinaryOperator.BitwiseAnd); } if (nodeType == System.Linq.Expressions.ExpressionType.ExclusiveOr) { return(BinaryOperator.BitwiseExclusiveOr); } if (nodeType == System.Linq.Expressions.ExpressionType.Or) { return(BinaryOperator.BitwiseOr); } if (nodeType == System.Linq.Expressions.ExpressionType.AndAlso) { return(BinaryOperator.BooleanAnd); } if (nodeType == System.Linq.Expressions.ExpressionType.OrElse) { return(BinaryOperator.BooleanOr); } if (nodeType == System.Linq.Expressions.ExpressionType.Divide) { return(BinaryOperator.Divide); } if (nodeType == System.Linq.Expressions.ExpressionType.GreaterThan) { return(BinaryOperator.GreaterThan); } if (nodeType == System.Linq.Expressions.ExpressionType.GreaterThanOrEqual) { return(BinaryOperator.GreaterThanOrEqual); } if (nodeType == System.Linq.Expressions.ExpressionType.Equal) { return(BinaryOperator.ValueEquality); } if (nodeType == System.Linq.Expressions.ExpressionType.NotEqual) { return(BinaryOperator.ValueInequality); } if (nodeType == System.Linq.Expressions.ExpressionType.LessThan) { return(BinaryOperator.LessThan); } if (nodeType == System.Linq.Expressions.ExpressionType.LessThanOrEqual) { return(BinaryOperator.LessThanOrEqual); } if (nodeType == System.Linq.Expressions.ExpressionType.Modulo) { return(BinaryOperator.Modulus); } if (nodeType == System.Linq.Expressions.ExpressionType.Multiply) { return(BinaryOperator.Multiply); } if (nodeType == System.Linq.Expressions.ExpressionType.LeftShift) { return(BinaryOperator.ShiftLeft); } if (nodeType == System.Linq.Expressions.ExpressionType.RightShift) { return(BinaryOperator.ShiftRight); } if (nodeType == System.Linq.Expressions.ExpressionType.Subtract) { return(BinaryOperator.Subtract); } throw new NotImplementedException("Could not convert operator: " + nodeType); }
public static object NumericMetamethod(Context context, ExprType op, object left, object right) { var methodName = GetMethodName(op); var metamethod = GetMetamethod(context, left, methodName) ?? GetMetamethod(context, right, methodName); if (metamethod != null) return Context.DynamicCache.GetDynamicCall2()(metamethod, left, right); var typeName = BaseLibrary.Type(BaseLibrary.ToNumber(left) == null ? left : right); throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_ERROR, "perform arithmetic on", typeName); }
/// <summary> /// 二元运算符表达式 /// </summary> /// <param name="left"></param> /// <param name="right"></param> /// <param name="type"></param> /// <returns></returns> string BinarExpressionProvider(System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Linq.Expressions.ExpressionType type) { string where = "("; //先处理左边 string leftStr = ExpressionRouter(left); //获取实体列的特性 List <EntityPropColumnAttributes> columnAttrList = AttributeHelper.GetEntityColumnAtrributes <TEntity>(); var list = columnAttrList.Where(w => w.propName == leftStr); if (list.Count() > 0) { EntityPropColumnAttributes columnAttribute = list.First(); leftStr = columnAttribute.fieldName; } //节点类型 string typeStr = ExpressionTypeCast(type); //再处理右边 string rightStr = RightExpressionRouter(right).ToStr(); where += leftStr; where += typeStr; if (rightStr == "null") { if (where.EndsWith(" =")) { where = where.Substring(0, where.Length - 2) + " is null"; } else if (where.EndsWith("<>")) { where = where.Substring(0, where.Length - 2) + " is not null"; } } else { //如果左侧包含(则代表左侧非字段 if (leftStr.Contains("(")) { where += rightStr; } else { int num = random.Next(100, 999); where += "@" + leftStr + num; listPara.Add(new SqlParameter("@" + leftStr + num, rightStr)); } } return(where += ")"); }
static string GetMethodName(ExprType op) { string methodName; return Constant.METAMETHODS.TryGetValue(op, out methodName) ? methodName : null; }
public static Expr BinaryOp(CodeContext context, ExprType operation, DynamicMetaObject left, DynamicMetaObject right) { return BinaryOp(Expr.Constant(context, typeof(CodeContext)), operation, left, right); }
public LuaUnaryOperationBinder(Context context, ExprType operation) : base(operation) { this.context = context; }
public static Expr BinaryOp(LuaTable context, ExprType operation, DynamicMetaObject left, DynamicMetaObject right) { return BinaryOp(Expr.Property(Expr.Constant(context, typeof(LuaTable)), "Context"), operation, left, right); }
public static System.Runtime.CompilerServices.CallSiteBinder UnaryOperation(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Linq.Expressions.ExpressionType operation, System.Type context, System.Collections.Generic.IEnumerable <Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo> argumentInfo) { throw null; }
public static OperatorResolveResult Trinary(this ResolveResult first, System.Linq.Expressions.ExpressionType opType, ResolveResult second, ResolveResult third, IType resultType) { return(new OperatorResolveResult(resultType, opType, first, second, third)); }
public LuaUnaryOperationBinder(LuaContext context, ExprType operation) : base(operation) { ContractUtils.RequiresNotNull(context, "context"); this.context = context; }
public static OperatorResolveResult Binary(this ResolveResult left, System.Linq.Expressions.ExpressionType opType, ResolveResult right, IType resultType) { return(new OperatorResolveResult(resultType, opType, left, right)); }