internal static DynamicExpression Make(Type returnType, Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1, Expression arg2, Expression arg3) { if (returnType == typeof(object)) { return new DynamicExpression4(delegateType, binder, arg0, arg1, arg2, arg3); } else { return new TypedDynamicExpression4(returnType, delegateType, binder, arg0, arg1, arg2, arg3); } }
public void SetCurrentLine(string line) { lineNumber++; currentLine = line; Value = null; if(currentLine.Count() > 0){ localExpression = new Expression(currentLine); if (localExpression.NumericalEvaluation != null) { Value = localExpression.NumericalEvaluation; OutputString = localExpression.OutputString; } else { OutputString = "\""+line+"\" " + localExpression.OutputString; } } }
public void ExpressionConstructorTest() { Expression target = new Expression("3+4*334 - te 33z 34.3.4,() || ,"); Tokens tokens = new Tokens(new System.Collections.Generic.List<Token>(){ new Token("3", TokenType.numberLiteral), new Token("+", TokenType.operatorOrPunctuation), new Token("+4", TokenType.numberLiteral), new Token("*", TokenType.operatorOrPunctuation), new Token("334", TokenType.numberLiteral), new Token("-", TokenType.atomicOperatorOrPunctuation), new Token("te", TokenType.identifier), new Token("33z", TokenType.identifier), new Token("34.3.4", TokenType.numberLiteral), new Token(",", TokenType.operatorOrPunctuation), new Token("(", TokenType.atomicOperatorOrPunctuation), new Token(")", TokenType.atomicOperatorOrPunctuation), new Token("||", TokenType.operatorOrPunctuation), new Token(",", TokenType.operatorOrPunctuation) }); for(int i=0; i < tokens.AsList().Count; i++){ Assert.AreEqual<string>(tokens.AsList()[i].TokenString, target.Tokens.AsList()[i].TokenString); Assert.AreEqual<TokenType>(tokens.AsList()[i].TokenType, target.Tokens.AsList()[i].TokenType); } }
internal TypedDynamicExpression1(Type retType, Type delegateType, CallSiteBinder binder, Expression arg0) : base(delegateType, binder, arg0) { _retType = retType; }
internal override DynamicExpression Rewrite(Expression[] args) { Debug.Assert(args.Length == ((IArgumentProvider)this).ArgumentCount); return Expression.MakeDynamic(DelegateType, Binder, args); }
private object _arg0; // storage for the 1st argument or a readonly collection. See IArgumentProvider for more info. internal DynamicExpression1(Type delegateType, CallSiteBinder binder, Expression arg0) : base(delegateType, binder) { _arg0 = arg0; }
Expression IDynamicExpression.Rewrite(Expression[] args) { return this.Rewrite(args); }
/// <summary> /// Makes a copy of this node replacing the args with the provided values. The /// number of the args needs to match the number of the current block. /// /// This helper is provided to allow re-writing of nodes to not depend on the specific optimized /// subclass of DynamicExpression which is being used. /// </summary> internal virtual DynamicExpression Rewrite(Expression[] args) { throw ContractUtils.Unreachable; }
internal override DynamicExpression Rewrite(Expression[] args) { Debug.Assert(args.Length == 4); return Expression.MakeDynamic(DelegateType, Binder, args[0], args[1], args[2], args[3]); }
public Opera_nd_tor(Expression expression) { this.expression = expression; }
public Expression Reduce() { int level = 0; while (list.Count > 1) { Require.True(level <= precedence.highestLevel); // needs to be a for loop, the list gets modified in action //forward Opera_nd_tor item; for (int j = 0; j < 2; ++j) { bool leftToRight = j == 0; int i; if (leftToRight) i = -1; else i = list.Count; while (true) { if (leftToRight) { i++; if (i == list.Count) break; } else { if (i == 0) break; i--; } item = list[i]; if (item.IsOperator && (item.Precedence == level) && (item.LeftToRight == leftToRight)) { switch (item.Kind) { case OperatorKind.Infix: { i = i - 1; Expression left = list[i].Expression; Expression right = list[i + 2].Expression; list.RemoveRange(i, 3); list.Insert(i, item.ReduceInfix(left, right)); break; } case OperatorKind.Prefix: { Expression right = list[i + 1].Expression; list.RemoveRange(i, 2); list.Insert(i, item.ReducePrefix(right)); break; } case OperatorKind.Postfix: { i = i - 1; Expression left = list[i].Expression; list.RemoveRange(i, 2); list.Insert(i, item.ReducePostFix(left)); break; } default: { Require.NotCalled(); break; } } } } } level++; } Expression result = list[0].Expression; list.Clear(); return result; }
/// <summary> /// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" /> and four arguments. /// </summary> /// <param name="delegateType">The type of the delegate used by the <see cref="CallSite" />.</param> /// <param name="binder">The runtime binder for the dynamic operation.</param> /// <param name="arg0">The first argument to the dynamic operation.</param> /// <param name="arg1">The second argument to the dynamic operation.</param> /// <param name="arg2">The third argument to the dynamic operation.</param> /// <param name="arg3">The fourth argument to the dynamic operation.</param> /// <returns> /// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to /// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the /// <see cref="DynamicExpression.DelegateType">DelegateType</see>, /// <see cref="DynamicExpression.Binder">Binder</see>, and /// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values. /// </returns> public static DynamicExpression MakeDynamic(Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1, Expression arg2, Expression arg3) { ContractUtils.RequiresNotNull(delegateType, "delegateType"); ContractUtils.RequiresNotNull(binder, "binder"); if (!delegateType.IsSubclassOf(typeof(MulticastDelegate))) throw Error.TypeMustBeDerivedFromSystemDelegate(); var method = GetValidMethodForDynamic(delegateType); var parameters = method.GetParametersCached(); ValidateArgumentCount(method, ExpressionType.Dynamic, 5, parameters); ValidateDynamicArgument(arg0); ValidateOneArgument(method, ExpressionType.Dynamic, arg0, parameters[1]); ValidateDynamicArgument(arg1); ValidateOneArgument(method, ExpressionType.Dynamic, arg1, parameters[2]); ValidateDynamicArgument(arg2); ValidateOneArgument(method, ExpressionType.Dynamic, arg2, parameters[3]); ValidateDynamicArgument(arg3); ValidateOneArgument(method, ExpressionType.Dynamic, arg3, parameters[4]); return DynamicExpression.Make(method.GetReturnType(), delegateType, binder, arg0, arg1, arg2, arg3); }
public void AddOperator(string token, Expression expression, OperatorKind kind) { list.Add(new Opera_nd_tor(precedence.precedence[ExpressionPrecedence.operatorName(kind, token)], expression)); }
public void AddOperand(Expression expression) { list.Add(new Opera_nd_tor(expression)); }
public Opera_nd_tor ReducePostFix(Expression left) { return new Opera_nd_tor(operatorDef.Handler(null, left, postfixExpression)); }
public Opera_nd_tor ReducePrefix(Expression right) { return new Opera_nd_tor(operatorDef.Handler(token, null, right)); }
public Opera_nd_tor ReduceInfix(Expression left, Expression right) { return new Opera_nd_tor(operatorDef.Handler(token, left, right)); }
private readonly Expression _arg1; // storage for the 2nd argument internal DynamicExpression2(Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1) : base(delegateType, binder) { _arg0 = arg0; _arg1 = arg1; }
/// <summary> /// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" /> and one argument. /// </summary> /// <param name="delegateType">The type of the delegate used by the <see cref="CallSite" />.</param> /// <param name="binder">The runtime binder for the dynamic operation.</param> /// <param name="arg0">The argument to the dynamic operation.</param> /// <returns> /// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to /// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the /// <see cref="DynamicExpression.DelegateType">DelegateType</see>, /// <see cref="DynamicExpression.Binder">Binder</see>, and /// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values. /// </returns> public static DynamicExpression MakeDynamic(Type delegateType, CallSiteBinder binder, Expression arg0) { ContractUtils.RequiresNotNull(delegateType, "delegatType"); ContractUtils.RequiresNotNull(binder, "binder"); ContractUtils.Requires(delegateType.IsSubclassOf(typeof(Delegate)), "delegateType", Strings.TypeMustBeDerivedFromSystemDelegate); var method = GetValidMethodForDynamic(delegateType); var parameters = method.GetParametersCached(); ValidateArgumentCount(method, ExpressionType.Dynamic, 2, parameters); ValidateDynamicArgument(arg0); ValidateOneArgument(method, ExpressionType.Dynamic, arg0, parameters[1]); return DynamicExpression.Make(method.GetReturnType(), delegateType, binder, arg0); }
private readonly Expression _arg1, _arg2, _arg3; // storage for the 2nd - 4th arguments internal DynamicExpression4(Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1, Expression arg2, Expression arg3) : base(delegateType, binder) { _arg0 = arg0; _arg1 = arg1; _arg2 = arg2; _arg3 = arg3; }
public void ExpressionConstructorTest1() { string textOfCurrentLine = "4+-1(3)(-3)3--3"; Expression target = new Expression(textOfCurrentLine); //Assert.AreEqual(target.OutputString, "34"); }
internal TypedDynamicExpression4(Type retType, Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1, Expression arg2, Expression arg3) : base(delegateType, binder, arg0, arg1, arg2, arg3) { _retType = retType; }
public Opera_nd_tor(OperatorDefinition operatorDef, Expression expression) { Require.Assigned(operatorDef); this.operatorDef = operatorDef; this.postfixExpression = expression; }
/// <summary> /// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" />. /// </summary> /// <param name="binder">The runtime binder for the dynamic operation.</param> /// <param name="returnType">The result type of the dynamic expression.</param> /// <param name="arg0">The first argument to the dynamic operation.</param> /// <param name="arg1">The second argument to the dynamic operation.</param> /// <param name="arg2">The third argument to the dynamic operation.</param> /// <param name="arg3">The fourth argument to the dynamic operation.</param> /// <returns> /// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to /// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the /// <see cref="DynamicExpression.Binder">Binder</see> and /// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values. /// </returns> /// <remarks> /// The <see cref="DynamicExpression.DelegateType">DelegateType</see> property of the /// result will be inferred from the types of the arguments and the specified return type. /// </remarks> public static DynamicExpression Dynamic(CallSiteBinder binder, Type returnType, Expression arg0, Expression arg1, Expression arg2, Expression arg3) { ContractUtils.RequiresNotNull(binder, "binder"); ValidateDynamicArgument(arg0); ValidateDynamicArgument(arg1); ValidateDynamicArgument(arg2); ValidateDynamicArgument(arg3); DelegateHelpers.TypeInfo info = DelegateHelpers.GetNextTypeInfo( returnType, DelegateHelpers.GetNextTypeInfo( arg3.Type, DelegateHelpers.GetNextTypeInfo( arg2.Type, DelegateHelpers.GetNextTypeInfo( arg1.Type, DelegateHelpers.GetNextTypeInfo( arg0.Type, DelegateHelpers.NextTypeInfo(typeof(CallSite)) ) ) ) ) ); Type delegateType = info.DelegateType; if (delegateType == null) { delegateType = info.MakeDelegateType(returnType, arg0, arg1, arg2, arg3); } return DynamicExpression.Make(returnType, delegateType, binder, arg0, arg1, arg2, arg3); }
/// <summary> /// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" />. /// </summary> /// <param name="binder">The runtime binder for the dynamic operation.</param> /// <param name="returnType">The result type of the dynamic expression.</param> /// <param name="arg0">The first argument to the dynamic operation.</param> /// <param name="arg1">The second argument to the dynamic operation.</param> /// <param name="arg2">The third argument to the dynamic operation.</param> /// <param name="arg3">The fourth argument to the dynamic operation.</param> /// <returns> /// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to /// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the /// <see cref="DynamicExpression.Binder">Binder</see> and /// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values. /// </returns> /// <remarks> /// The <see cref="DynamicExpression.DelegateType">DelegateType</see> property of the /// result will be inferred from the types of the arguments and the specified return type. /// </remarks> public static new DynamicExpression Dynamic(CallSiteBinder binder, Type returnType, Expression arg0, Expression arg1, Expression arg2, Expression arg3) { return Expression.Dynamic(binder, returnType, arg0, arg1, arg2, arg3); }
private static void ValidateDynamicArgument(Expression arg) { RequiresCanRead(arg, "arguments"); var type = arg.Type; ContractUtils.RequiresNotNull(type, "type"); TypeUtils.ValidateType(type); if (type == typeof(void)) throw Error.ArgumentTypeCannotBeVoid(); }
/// <summary> /// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" /> and four arguments. /// </summary> /// <param name="delegateType">The type of the delegate used by the <see cref="CallSite" />.</param> /// <param name="binder">The runtime binder for the dynamic operation.</param> /// <param name="arg0">The first argument to the dynamic operation.</param> /// <param name="arg1">The second argument to the dynamic operation.</param> /// <param name="arg2">The third argument to the dynamic operation.</param> /// <param name="arg3">The fourth argument to the dynamic operation.</param> /// <returns> /// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to /// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the /// <see cref="DynamicExpression.DelegateType">DelegateType</see>, /// <see cref="DynamicExpression.Binder">Binder</see>, and /// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values. /// </returns> public static new DynamicExpression MakeDynamic(Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1, Expression arg2, Expression arg3) { return Expression.MakeDynamic(delegateType, binder, arg0, arg1, arg2, arg3); }