| CODENOTIFIER | HelpYou are not signed inSign in |
Project: IronRuby
Revision: 136
Author: jlam
Date: 21 Aug 2008 10:18:32
Changes:sync to TFS head
Files:| ... | ...@@ -26,7 +26,6 @@ | |
| 26 | 26 | GetMember, |
| 27 | 27 | SetMember, |
| 28 | 28 | DeleteMember, |
| 29 | InvokeMember, | |
| 30 | 29 | Call, |
| 31 | 30 | CreateInstance |
| 32 | 31 | } |
| ... | ...@@ -1,51 +0,0 @@ | |
| 1 | /* **************************************************************************** | |
| 2 | * | |
| 3 | * Copyright (c) Microsoft Corporation. | |
| 4 | * | |
| 5 | * This source code is subject to terms and conditions of the Microsoft Public License. A | |
| 6 | * copy of the license can be found in the License.html file at the root of this distribution. If | |
| 7 | * you cannot locate the Microsoft Public License, please send an email to | |
| 8 | * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound | |
| 9 | * by the terms of the Microsoft Public License. | |
| 10 | * | |
| 11 | * You must not remove this notice, or any other, from this software. | |
| 12 | * | |
| 13 | * | |
| 14 | * ***************************************************************************/ | |
| 15 | ||
| 16 | using System.Scripting.Actions; | |
| 17 | using System.Scripting.Utils; | |
| 18 | ||
| 19 | namespace System.Linq.Expressions { | |
| 20 | /// <summary> | |
| 21 | /// AST node representing dynamic deletion. | |
| 22 | /// | |
| 23 | /// Supported lvalue types: | |
| 24 | /// MemberExpression | |
| 25 | /// (future) BinaryExpression with NodeType == ArrayIndex | |
| 26 | /// (future) IndexedPropertyExpression | |
| 27 | /// </summary> | |
| 28 | public sealed class DeleteExpression : Expression { | |
| 29 | private readonly Expression _expression; | |
| 30 | ||
| 31 | internal DeleteExpression(Annotations annotations, Expression expression, CallSiteBinder bindingInfo) | |
| 32 | : base(ExpressionType.Delete, typeof(object), annotations, bindingInfo) { // TODO: typeof(void) ? | |
| 33 | if (IsBound) { | |
| 34 | RequiresBound(expression, "expression"); | |
| 35 | } | |
| 36 | _expression = expression; | |
| 37 | } | |
| 38 | ||
| 39 | public Expression Expression { | |
| 40 | get { return _expression; } | |
| 41 | } | |
| 42 | } | |
| 43 | ||
| 44 | public partial class Expression { | |
| 45 | public static DeleteExpression DeleteMember(Expression expression, CallSiteBinder binder, Annotations annotations) { | |
| 46 | RequiresCanRead(expression, "expression"); | |
| 47 | ContractUtils.RequiresNotNull(binder, "binder"); | |
| 48 | return new DeleteExpression(annotations, new MemberExpression(expression, null, null, expression.Type, true, false, binder), binder); | |
| 49 | } | |
| 50 | } | |
| 51 | } |
| ... | ...@@ -17,7 +17,7 @@ | |
| 17 | 17 | public sealed class EmptyStatement : Expression { |
| 18 | 18 | |
| 19 | 19 | internal EmptyStatement(Annotations annotations) |
| 20 | : base(ExpressionType.EmptyStatement, typeof(void), annotations, null) { | |
| 20 | : base(ExpressionType.EmptyStatement, typeof(void), annotations) { | |
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | 23 |
| ... | ...@@ -24,7 +24,7 @@ | |
| 24 | 24 | private readonly Expression _false; |
| 25 | 25 | |
| 26 | 26 | internal ConditionalExpression(Annotations annotations, Expression test, Expression ifTrue, Expression ifFalse, Type type) |
| 27 | : base(ExpressionType.Conditional, type, annotations, null) { | |
| 27 | : base(ExpressionType.Conditional, type, annotations) { | |
| 28 | 28 | _test = test; |
| 29 | 29 | _true = ifTrue; |
| 30 | 30 | _false = ifFalse; |
| ... | ...@@ -31,4 +31,8 @@ | |
| 31 | 31 | public delegate void Action<T1, T2, T3, T4, T5, T6, T7>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7); |
| 32 | 32 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes")] |
| 33 | 33 | public delegate void Action<T1, T2, T3, T4, T5, T6, T7, T8>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8); |
| 34 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes")] | |
| 35 | public delegate void Action<T1, T2, T3, T4, T5, T6, T7, T8, T9>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9); | |
| 36 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes")] | |
| 37 | public delegate void Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10); | |
| 34 | 38 | } |
| ... | ...@@ -20,7 +20,7 @@ | |
| 20 | 20 | private readonly Expression _val; |
| 21 | 21 | |
| 22 | 22 | internal ThrowStatement(Annotations annotations, Expression value) |
| 23 | : base(ExpressionType.ThrowStatement, typeof(void), annotations, null) { | |
| 23 | : base(ExpressionType.ThrowStatement, typeof(void), annotations) { | |
| 24 | 24 | _val = value; |
| 25 | 25 | } |
| 26 | 26 |
| ... | ...@@ -26,22 +26,16 @@ | |
| 26 | 26 | /// ParameterExpression |
| 27 | 27 | /// MemberExpression with writable property/field |
| 28 | 28 | /// BinaryExpression with NodeType == ArrayIndex |
| 29 | /// (future) IndexedPropertyExpression | |
| 29 | /// IndexedPropertyExpression | |
| 30 | /// | |
| 31 | /// TODO: merge into BinaryExpression | |
| 30 | 32 | /// </summary> |
| 31 | 33 | public sealed class AssignmentExpression : Expression { |
| 32 | 34 | private readonly Expression _expression; |
| 33 | 35 | private readonly Expression _value; |
| 34 | 36 | |
| 35 | 37 | internal AssignmentExpression(Annotations annotations, Expression expression, Expression value) |
| 36 | : this(annotations, expression, value, expression.Type, null) { | |
| 37 | } | |
| 38 | ||
| 39 | internal AssignmentExpression(Annotations annotations, Expression expression, Expression value, Type result, CallSiteBinder bindingInfo) | |
| 40 | : base(ExpressionType.Assign, result, annotations, bindingInfo) { | |
| 41 | if (IsBound) { | |
| 42 | RequiresBound(expression, "expression"); | |
| 43 | RequiresBound(value, "value"); | |
| 44 | } | |
| 38 | : base(ExpressionType.Assign, expression.Type, annotations) { | |
| 45 | 39 | _expression = expression; |
| 46 | 40 | _value = value; |
| 47 | 41 | } |
| ... | ...@@ -112,36 +106,5 @@ | |
| 112 | 106 | public static AssignmentExpression AssignArrayIndex(Expression array, Expression index, Expression value) { |
| 113 | 107 | return Assign(ArrayIndex(array, index), value); |
| 114 | 108 | } |
| 115 | ||
| 116 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] | |
| 117 | public static AssignmentExpression AssignArrayIndex(Expression array, Expression index, Expression value, Type result, CallSiteBinder bindingInfo, Annotations annotations) { | |
| 118 | RequiresCanRead(array, "array"); | |
| 119 | RequiresCanRead(index, "index"); | |
| 120 | RequiresCanRead(value, "value"); | |
| 121 | ContractUtils.RequiresNotNull(bindingInfo, "bindingInfo"); | |
| 122 | ||
| 123 | // TODO: don't pass bindinginfo to nested MemberExpression | |
| 124 | return new AssignmentExpression( | |
| 125 | annotations, | |
| 126 | new BinaryExpression(Annotations.Empty, ExpressionType.ArrayIndex, array, index, result, bindingInfo), | |
| 127 | value, | |
| 128 | result, | |
| 129 | bindingInfo | |
| 130 | ); | |
| 131 | } | |
| 132 | ||
| 133 | public static AssignmentExpression SetMember(Expression expression, Type result, SetMemberAction bindingInfo, Expression value) { | |
| 134 | return SetMember(expression, result, bindingInfo, value, Annotations.Empty); | |
| 135 | } | |
| 136 | ||
| 137 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] | |
| 138 | public static AssignmentExpression SetMember(Expression expression, Type result, SetMemberAction binder, Expression value, Annotations annotations) { | |
| 139 | RequiresCanRead(expression, "expression"); | |
| 140 | ContractUtils.RequiresNotNull(binder, "binder"); | |
| 141 | RequiresCanRead(value, "value"); | |
| 142 | ||
| 143 | // TODO: don't pass bindinginfo to nested MemberExpression | |
| 144 | return new AssignmentExpression(annotations, new MemberExpression(expression, null, null, expression.Type, true, false, binder), value, result, binder); | |
| 145 | } | |
| 146 | 109 | } |
| 147 | 110 | } |
| ... | ...@@ -36,47 +36,47 @@ | |
| 36 | 36 | // |
| 37 | 37 | |
| 38 | 38 | [Obsolete("used by generated code", true)] |
| 39 | public static object CallHelper1(CallSite<DynamicSiteTarget<object, object>> site, object[] args) { | |
| 39 | public static object CallHelper1(CallSite<Func<CallSite, object, object>> site, object[] args) { | |
| 40 | 40 | return site.Target(site, args[0]); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | [Obsolete("used by generated code", true)] |
| 44 | public static object CallHelper2(CallSite<DynamicSiteTarget<object, object, object>> site, object[] args) { | |
| 44 | public static object CallHelper2(CallSite<Func<CallSite, object, object, object>> site, object[] args) { | |
| 45 | 45 | return site.Target(site, args[0], args[1]); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | [Obsolete("used by generated code", true)] |
| 49 | public static object CallHelper3(CallSite<DynamicSiteTarget<object, object, object, object>> site, object[] args) { | |
| 49 | public static object CallHelper3(CallSite<Func<CallSite, object, object, object, object>> site, object[] args) { | |
| 50 | 50 | return site.Target(site, args[0], args[1], args[2]); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | [Obsolete("used by generated code", true)] |
| 54 | public static object CallHelper4(CallSite<DynamicSiteTarget<object, object, object, object, object>> site, object[] args) { | |
| 54 | public static object CallHelper4(CallSite<Func<CallSite, object, object, object, object, object>> site, object[] args) { | |
| 55 | 55 | return site.Target(site, args[0], args[1], args[2], args[3]); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | [Obsolete("used by generated code", true)] |
| 59 | public static object CallHelper5(CallSite<DynamicSiteTarget<object, object, object, object, object, object>> site, object[] args) { | |
| 59 | public static object CallHelper5(CallSite<Func<CallSite, object, object, object, object, object, object>> site, object[] args) { | |
| 60 | 60 | return site.Target(site, args[0], args[1], args[2], args[3], args[4]); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | [Obsolete("used by generated code", true)] |
| 64 | public static object CallHelper6(CallSite<DynamicSiteTarget<object, object, object, object, object, object, object>> site, object[] args) { | |
| 64 | public static object CallHelper6(CallSite<Func<CallSite, object, object, object, object, object, object, object>> site, object[] args) { | |
| 65 | 65 | return site.Target(site, args[0], args[1], args[2], args[3], args[4], args[5]); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | [Obsolete("used by generated code", true)] |
| 69 | public static object CallHelper7(CallSite<DynamicSiteTarget<object, object, object, object, object, object, object, object>> site, object[] args) { | |
| 69 | public static object CallHelper7(CallSite<Func<CallSite, object, object, object, object, object, object, object, object>> site, object[] args) { | |
| 70 | 70 | return site.Target(site, args[0], args[1], args[2], args[3], args[4], args[5], args[6]); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | [Obsolete("used by generated code", true)] |
| 74 | public static object CallHelper8(CallSite<DynamicSiteTarget<object, object, object, object, object, object, object, object, object>> site, object[] args) { | |
| 74 | public static object CallHelper8(CallSite<Func<CallSite, object, object, object, object, object, object, object, object, object>> site, object[] args) { | |
| 75 | 75 | return site.Target(site, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | [Obsolete("used by generated code", true)] |
| 79 | public static object CallHelper9(CallSite<DynamicSiteTarget<object, object, object, object, object, object, object, object, object, object>> site, object[] args) { | |
| 79 | public static object CallHelper9(CallSite<Func<CallSite, object, object, object, object, object, object, object, object, object, object>> site, object[] args) { | |
| 80 | 80 | return site.Target(site, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]); |
| 81 | 81 | } |
| 82 | 82 |
| ... | ...@@ -26,18 +26,17 @@ | |
| 26 | 26 | private readonly ReadOnlyCollection<Expression> _arguments; |
| 27 | 27 | private readonly Expression _lambda; |
| 28 | 28 | |
| 29 | internal InvocationExpression(Annotations annotations, Expression lambda, Type returnType, CallSiteBinder bindingInfo, ReadOnlyCollection<Expression> arguments) | |
| 30 | : base(ExpressionType.Invoke, returnType, annotations, bindingInfo) { | |
| 31 | if (IsBound) { | |
| 32 | RequiresBound(lambda, "lambda"); | |
| 33 | RequiresBoundItems(arguments, "arguments"); | |
| 34 | } | |
| 29 | internal InvocationExpression(Expression lambda, Annotations annotations, ReadOnlyCollection<Expression> arguments, Type returnType) | |
| 30 | : base(ExpressionType.Invoke, returnType, annotations) { | |
| 31 | ||
| 35 | 32 | _lambda = lambda; |
| 36 | 33 | _arguments = arguments; |
| 37 | 34 | } |
| 35 | ||
| 38 | 36 | public Expression Expression { |
| 39 | 37 | get { return _lambda; } |
| 40 | 38 | } |
| 39 | ||
| 41 | 40 | public ReadOnlyCollection<Expression> Arguments { |
| 42 | 41 | get { return _arguments; } |
| 43 | 42 | } |
| ... | ...@@ -84,81 +83,11 @@ | |
| 84 | 83 | } |
| 85 | 84 | delegateType = exprType.GetGenericArguments()[0]; |
| 86 | 85 | } |
| 87 | MethodInfo mi = delegateType.GetMethod("Invoke"); | |
| 88 | ParameterInfo[] pis = mi.GetParameters(); | |
| 89 | ||
| 90 | ReadOnlyCollection<Expression> argList = arguments.ToReadOnly(); | |
| 91 | if (argList.Count != pis.Length) { | |
| 92 | throw Error.IncorrectNumberOfLambdaArguments(); | |
| 93 | } | |
| 94 | ||
| 95 | Expression[] newArgs = null; | |
| 96 | for (int i = 0, n = argList.Count; i < n; i++) { | |
| 97 | Expression arg = argList[i]; | |
| 98 | ParameterInfo p = pis[i]; | |
| 99 | RequiresCanRead(arg, "arguments"); | |
| 100 | Type pType = p.ParameterType; | |
| 101 | if (pType.IsByRef) { | |
| 102 | pType = pType.GetElementType(); | |
| 103 | } | |
| 104 | if (!TypeUtils.AreReferenceAssignable(pType, arg.Type)) { | |
| 105 | if (TypeUtils.IsSameOrSubclass(typeof(Expression), pType) && TypeUtils.AreAssignable(pType, arg.GetType())) { | |
| 106 | arg = Expression.Quote(arg); | |
| 107 | } else { | |
| 108 | throw Error.ExpressionTypeDoesNotMatchParameter(arg.Type, pType); | |
| 109 | } | |
| 110 | } | |
| 111 | if (newArgs == null && arg != argList[i]) { | |
| 112 | newArgs = new Expression[argList.Count]; | |
| 113 | for (int j = 0; j < i; j++) { | |
| 114 | newArgs[j] = argList[j]; | |
| 115 | } | |
| 116 | } | |
| 117 | if (newArgs != null) { | |
| 118 | newArgs[i] = arg; | |
| 119 | } | |
| 120 | } | |
| 121 | if (newArgs != null) { | |
| 122 | argList = new ReadOnlyCollection<Expression>(newArgs); | |
| 123 | } | |
| 124 | ||
| 125 | return new InvocationExpression(annotations, expression, mi.ReturnType, null, argList); | |
| 126 | } | |
| 127 | 86 | |
| 128 | /// <summary> | |
| 129 | /// A dynamic or unbound invoke | |
| 130 | /// </summary> | |
| 131 | /// <param name="annotations">annotations for the node</param> | |
| 132 | /// <param name="returnType">the type that the method returns, or null for an unbound node</param> | |
| 133 | /// <param name="expression">the callable object to call; must be non-null</param> | |
| 134 | /// <param name="bindingInfo">invoke binding information (method name, named arguments, etc)</param> | |
| 135 | /// <param name="arguments">the arguments to the call</param> | |
| 136 | /// <returns></returns> | |
| 137 | public static InvocationExpression Invoke(Annotations annotations, Type returnType, Expression expression, InvokeAction bindingInfo, params Expression[] arguments) { | |
| 138 | RequiresCanRead(expression, "expression"); | |
| 139 | ContractUtils.RequiresNotNull(bindingInfo, "bindingInfo"); | |
| 140 | ||
| 141 | RequiresCanRead(arguments, "arguments"); | |
| 87 | var mi = delegateType.GetMethod("Invoke"); | |
| 142 | 88 | var args = arguments.ToReadOnly(); |
| 143 | ||
| 144 | // Validate ArgumentInfos. For now, excludes the target expression. | |
| 145 | // This needs to be reconciled with MethodCallExpression | |
| 146 | if (bindingInfo.Arguments.Count > 0 && bindingInfo.Arguments.Count != args.Count) { | |
| 147 | throw Error.ArgumentCountMustMatchBinding( | |
| 148 | args.Count + 1, | |
| 149 | bindingInfo.Arguments.Count | |
| 150 | ); | |
| 151 | } | |
| 152 | ||
| 153 | return new InvocationExpression(annotations, expression, returnType, bindingInfo, arguments.ToReadOnly()); | |
| 154 | } | |
| 155 | ||
| 156 | public static InvocationExpression Invoke(Annotations annotations, Type returnType, Expression expression, CallSiteBinder binder, params Expression[] arguments) { | |
| 157 | RequiresCanRead(expression, "expression"); | |
| 158 | ContractUtils.RequiresNotNull(binder, "binder"); | |
| 159 | RequiresCanRead(arguments, "arguments"); | |
| 160 | ||
| 161 | return new InvocationExpression(annotations, expression, returnType, binder, arguments.ToReadOnly()); | |
| 89 | ValidateArgumentTypes(mi, ExpressionType.Invoke, ref args); | |
| 90 | return new InvocationExpression(expression, annotations, args, mi.ReturnType); | |
| 162 | 91 | } |
| 163 | 92 | } |
| 164 | 93 | } |
| ... | ...@@ -1,59 +0,0 @@ | |
| 1 | /* **************************************************************************** | |
| 2 | * | |
| 3 | * Copyright (c) Microsoft Corporation. | |
| 4 | * | |
| 5 | * This source code is subject to terms and conditions of the Microsoft Public License. A | |
| 6 | * copy of the license can be found in the License.html file at the root of this distribution. If | |
| 7 | * you cannot locate the Microsoft Public License, please send an email to | |
| 8 | * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound | |
| 9 | * by the terms of the Microsoft Public License. | |
| 10 | * | |
| 11 | * You must not remove this notice, or any other, from this software. | |
| 12 | * | |
| 13 | * | |
| 14 | * ***************************************************************************/ | |
| 15 | ||
| 16 | using System; | |
| 17 | using System.Linq.Expressions; | |
| 18 | using Microsoft.Scripting.Utils; | |
| 19 | using Microsoft.Scripting.Runtime; | |
| 20 | ||
| 21 | namespace Microsoft.Scripting.Actions { | |
| 22 | using Ast = System.Linq.Expressions.Expression; | |
| 23 | using AstUtils = Microsoft.Scripting.Ast.Utils; | |
| 24 | ||
| 25 | public class InvokeMemberBinderHelper<T> : BinderHelper<T, OldInvokeMemberAction> where T : class { | |
| 26 | public InvokeMemberBinderHelper(CodeContext context, OldInvokeMemberAction action, object[] args) | |
| 27 | : base(context, action) { | |
| 28 | ContractUtils.RequiresNotNull(args, "args"); | |
| 29 | if (args.Length < 1) throw new ArgumentException("Must receive at least one argument, the target to call", "args"); | |
| 30 | } | |
| 31 | ||
| 32 | public virtual RuleBuilder<T> MakeRule() { | |
| 33 | OldCallAction callAction = OldCallAction.Make(Binder, Action.Signature); | |
| 34 | ||
| 35 | // TODO: First try to make a rule for get-member and see if we get back a constant method to call | |
| 36 | //GetMemberAction getAction = GetMemberAction.Make(Action.Name); | |
| 37 | //RuleBuilder<T> getRule = Binder.GetRule<T>(Context, getAction, new object[] { _args[0] }); | |
| 38 | ||
| 39 | // otherwise, make a generic rule with embedded dynamic sites | |
| 40 | RuleBuilder<T> rule = new RuleBuilder<T>(); | |
| 41 | rule.Test = Ast.True(); | |
| 42 | Expression getExpr = AstUtils.GetMember(Binder, SymbolTable.IdToString(Action.Name), typeof(object), rule.Context, rule.Parameters[0]); | |
| 43 | ||
| 44 | Expression[] callArgs = new Expression[rule.ParameterCount + 1]; | |
| 45 | callArgs[0] = rule.Context; | |
| 46 | callArgs[1] = getExpr; | |
| 47 | for (int i = 2; i < callArgs.Length; i++) { | |
| 48 | callArgs[i] = rule.Parameters[i - 1]; | |
| 49 | } | |
| 50 | ||
| 51 | //TODO support non-object return types | |
| 52 | Expression callExpr = AstUtils.Call(callAction, typeof(object), callArgs); | |
| 53 | ||
| 54 | rule.Target = rule.MakeReturn(Binder, callExpr); | |
| 55 | ||
| 56 | return rule; | |
| 57 | } | |
| 58 | } | |
| 59 | } |
| ... | ...@@ -33,7 +33,7 @@ | |
| 33 | 33 | string name, |
| 34 | 34 | Annotations annotations, |
| 35 | 35 | ReadOnlyCollection<VariableExpression> variables) |
| 36 | : base(ExpressionType.Scope, body.Type, annotations, null) { | |
| 36 | : base(ExpressionType.Scope, body.Type, annotations) { | |
| 37 | 37 | |
| 38 | 38 | _body = body; |
| 39 | 39 | _name = name; |
| ... | ...@@ -23,10 +23,6 @@ | |
| 23 | 23 | private void EmitExpression(Expression node, bool emitDebugMarkers) { |
| 24 | 24 | Debug.Assert(node != null); |
| 25 | 25 | |
| 26 | if (node.IsDynamic) { | |
| 27 | throw Error.DynamicNotReduced(); | |
| 28 | } | |
| 29 | ||
| 30 | 26 | bool startEmitted = emitDebugMarkers && EmitExpressionStart(node); |
| 31 | 27 | |
| 32 | 28 | switch (node.NodeType) { |
| ... | ...@@ -219,10 +215,6 @@ | |
| 219 | 215 | case ExpressionType.TypeIs: |
| 220 | 216 | EmitTypeBinaryExpression(this, node); |
| 221 | 217 | break; |
| 222 | // ActionExpression | |
| 223 | case ExpressionType.ActionExpression: | |
| 224 | EmitActionExpression(this, node); | |
| 225 | break; | |
| 226 | 218 | // Assign |
| 227 | 219 | case ExpressionType.Assign: |
| 228 | 220 | EmitAssignmentExpression(this, node); |
| ... | ...@@ -243,14 +235,14 @@ | |
| 243 | 235 | case ExpressionType.ContinueStatement: |
| 244 | 236 | EmitContinueStatement(this, node); |
| 245 | 237 | break; |
| 246 | // Delete | |
| 247 | case ExpressionType.Delete: | |
| 248 | EmitDeleteExpression(this, node); | |
| 249 | break; | |
| 250 | 238 | // DoStatement |
| 251 | 239 | case ExpressionType.DoStatement: |
| 252 | 240 | EmitDoStatement(this, node); |
| 253 | 241 | break; |
| 242 | // Dynamic | |
| 243 | case ExpressionType.Dynamic: | |
| 244 | EmitDynamicExpression(this, node); | |
| 245 | break; | |
| 254 | 246 | // EmptyStatement |
| 255 | 247 | case ExpressionType.EmptyStatement: |
| 256 | 248 | EmitEmptyStatement(this, node); |
| ... | ...@@ -1,4 +1,4 @@ | |
| 1 | /* **************************************************************************** | |
| 1 | /* **************************************************************************** | |
| 2 | 2 | * |
| 3 | 3 | * Copyright (c) Microsoft Corporation. |
| 4 | 4 | * |
| ... | ...@@ -590,6 +590,24 @@ | |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | /// <summary> |
| 593 | /// A string like "Type must be derived from System.Delegate" | |
| 594 | /// </summary> | |
| 595 | internal static string TypeMustBeDerivedFromSystemDelegate { | |
| 596 | get { | |
| 597 | return "Type must be derived from System.Delegate"; | |
| 598 | } | |
| 599 | } | |
| 600 | ||
| 601 | /// <summary> | |
| 602 | /// A string like "Argument type cannot be void" | |
| 603 | /// </summary> | |
| 604 | internal static string ArgumentTypeCannotBeVoid { | |
| 605 | get { | |
| 606 | return "Argument type cannot be void"; | |
| 607 | } | |
| 608 | } | |
| 609 | ||
| 610 | /// <summary> | |
| 593 | 611 | /// A string like "type or bindingInfo must be non-null" |
| 594 | 612 | /// </summary> |
| 595 | 613 | internal static string TypeOrBindingInfoMustBeNonNull { |
| ... | ...@@ -1239,11 +1257,11 @@ | |
| 1239 | 1257 | } |
| 1240 | 1258 | |
| 1241 | 1259 | /// <summary> |
| 1242 | /// A string like "RuleBuilder can only be used with delegates whose first argument is CallSite." | |
| 1260 | /// A string like "First argument of delegate must be CallSite" | |
| 1243 | 1261 | /// </summary> |
| 1244 | 1262 | internal static string FirstArgumentMustBeCallSite { |
| 1245 | 1263 | get { |
| 1246 | return "RuleBuilder can only be used with delegates whose first argument is CallSite."; | |
| 1264 | return "First argument of delegate must be CallSite"; | |
| 1247 | 1265 | } |
| 1248 | 1266 | } |
| 1249 | 1267 | |
| ... | ...@@ -2338,10 +2356,10 @@ | |
| 2338 | 2356 | } |
| 2339 | 2357 | |
| 2340 | 2358 | /// <summary> |
| 2341 | /// InvalidOperationException with message like "RuleBuilder can only be used with delegates whose first argument is CallSite." | |
| 2359 | /// ArgumentException with message like "First argument of delegate must be CallSite" | |
| 2342 | 2360 | /// </summary> |
| 2343 | 2361 | internal static Exception FirstArgumentMustBeCallSite() { |
| 2344 | return new InvalidOperationException(Strings.FirstArgumentMustBeCallSite); | |
| 2362 | return new ArgumentException(Strings.FirstArgumentMustBeCallSite); | |
| 2345 | 2363 | } |
| 2346 | 2364 | |
| 2347 | 2365 | /// <summary> |
| ... | ...@@ -168,9 +168,6 @@ | |
| 168 | 168 | // TypeIs |
| 169 | 169 | case ExpressionType.TypeIs: |
| 170 | 170 | return DefaultVisitTypeBinaryExpression(node); |
| 171 | // ActionExpression | |
| 172 | case ExpressionType.ActionExpression: | |
| 173 | return DefaultVisitActionExpression(node); | |
| 174 | 171 | // Assign |
| 175 | 172 | case ExpressionType.Assign: |
| 176 | 173 | return DefaultVisitAssignmentExpression(node); |
| ... | ...@@ -186,12 +183,12 @@ | |
| 186 | 183 | // ContinueStatement |
| 187 | 184 | case ExpressionType.ContinueStatement: |
| 188 | 185 | return DefaultVisitContinueStatement(node); |
| 189 | // Delete | |
| 190 | case ExpressionType.Delete: | |
| 191 | return DefaultVisitDeleteExpression(node); | |
| 192 | 186 | // DoStatement |
| 193 | 187 | case ExpressionType.DoStatement: |
| 194 | 188 | return DefaultVisitDoStatement(node); |
| 189 | // Dynamic | |
| 190 | case ExpressionType.Dynamic: | |
| 191 | return DefaultVisitDynamicExpression(node); | |
| 195 | 192 | // EmptyStatement |
| 196 | 193 | case ExpressionType.EmptyStatement: |
| 197 | 194 | return DefaultVisitEmptyStatement(node); |
| ... | ...@@ -252,11 +249,6 @@ | |
| 252 | 249 | // *** BEGIN GENERATED CODE *** |
| 253 | 250 | // generated by function: gen_visitor_methods from: generate_tree.py |
| 254 | 251 | |
| 255 | // ActionExpression | |
| 256 | private Expression DefaultVisitActionExpression(Expression node) { | |
| 257 | return Visit((ActionExpression)node); | |
| 258 | } | |
| 259 | ||
| 260 | 252 | // AssignmentExpression |
| 261 | 253 | private Expression DefaultVisitAssignmentExpression(Expression node) { |
| 262 | 254 | return Visit((AssignmentExpression)node); |
| ... | ...@@ -292,16 +284,16 @@ | |
| 292 | 284 | return Visit((ContinueStatement)node); |
| 293 | 285 | } |
| 294 | 286 | |
| 295 | // DeleteExpression | |
| 296 | private Expression DefaultVisitDeleteExpression(Expression node) { | |
| 297 | return Visit((DeleteExpression)node); | |
| 298 | } | |
| 299 | ||
| 300 | 287 | // DoStatement |
| 301 | 288 | private Expression DefaultVisitDoStatement(Expression node) { |
| 302 | 289 | return Visit((DoStatement)node); |
| 303 | 290 | } |
| 304 | 291 | |
| 292 | // DynamicExpression | |
| 293 | private Expression DefaultVisitDynamicExpression(Expression node) { | |
| 294 | return Visit((DynamicExpression)node); | |
| 295 | } | |
| 296 | ||
| 305 | 297 | // EmptyStatement |
| 306 | 298 | private Expression DefaultVisitEmptyStatement(Expression node) { |
| 307 | 299 | return Visit((EmptyStatement)node); |
| ... | ...@@ -485,8 +485,8 @@ | |
| 485 | 485 | |
| 486 | 486 | CodeContext context = new CodeContext(new Scope(), this); |
| 487 | 487 | |
| 488 | CallSite<DynamicSiteTarget<CodeContext, object, object>> site = | |
| 489 | CallSite<DynamicSiteTarget<CodeContext, object, object>>.Create(OldConvertToAction.Make(Binder, typeof(int), ConversionResultKind.ExplicitTry)); | |
| 488 | CallSite<Func<CallSite, CodeContext, object, object>> site = | |
| 489 | CallSite<Func<CallSite, CodeContext, object, object>>.Create(OldConvertToAction.Make(Binder, typeof(int), ConversionResultKind.ExplicitTry)); | |
| 490 | 490 | |
| 491 | 491 | object exitCode = site.Target(site, context, returnValue); |
| 492 | 492 | return (exitCode != null) ? (int)exitCode : 0; |
| ... | ...@@ -119,6 +119,30 @@ | |
| 119 | 119 | return new List<T>(enumerable).ToArray(); |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | internal static bool Any<T>(this IEnumerable<T> source) { | |
| 123 | using (IEnumerator<T> e = source.GetEnumerator()) { | |
| 124 | return e.MoveNext(); | |
| 125 | } | |
| 126 | } | |
| 127 | ||
| 128 | internal static bool Any<T>(this IEnumerable<T> source, Func<T, bool> predicate) { | |
| 129 | foreach (T element in source) { | |
| 130 | if (predicate(element)) { | |
| 131 | return true; | |
| 132 | } | |
| 133 | } | |
| 134 | return false; | |
| 135 | } | |
| 136 | ||
| 137 | internal static bool All<T>(this IEnumerable<T> source, Func<T, bool> predicate) { | |
| 138 | foreach (T element in source) { | |
| 139 | if (!predicate(element)) { | |
| 140 | return false; | |
| 141 | } | |
| 142 | } | |
| 143 | return true; | |
| 144 | } | |
| 145 | ||
| 122 | 146 | #if !SILVERLIGHT // ICloneable |
| 123 | 147 | internal static T Copy<T>(this T obj) where T : ICloneable { |
| 124 | 148 | return (T)obj.Clone(); |
| ... | ...@@ -13,21 +13,25 @@ | |
| 13 | 13 | * |
| 14 | 14 | * ***************************************************************************/ |
| 15 | 15 | |
| 16 | using System; | |
| 16 | 17 | using System.Collections.Generic; |
| 17 | 18 | using System.Diagnostics; |
| 18 | 19 | using System.Linq.Expressions; |
| 20 | using System.Reflection; | |
| 21 | using System.Reflection.Emit; | |
| 19 | 22 | using System.Scripting.Actions; |
| 20 | 23 | using Microsoft.Scripting.Runtime; |
| 24 | using Microsoft.Scripting.Utils; | |
| 21 | 25 | |
| 22 | 26 | namespace Microsoft.Scripting.Generation { |
| 23 | 27 | |
| 24 | 28 | /// <summary> |
| 25 | 29 | /// Serializes constants and dynamic sites so the code can be saved to disk |
| 26 | 30 | /// </summary> |
| 27 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1501:AvoidExcessiveInheritance")] | |
| 28 | 31 | internal sealed class ToDiskRewriter : GlobalArrayRewriter { |
| 29 | 32 | private List<Expression> _constants; |
| 30 | 33 | private VariableExpression _constantPool; |
| 34 | private Dictionary<Type, Type> _delegateTypes; | |
| 31 | 35 | private int _depth; |
| 32 | 36 | |
| 33 | 37 | internal ToDiskRewriter(TypeGen typeGen) { |
| ... | ...@@ -78,10 +82,10 @@ | |
| 78 | 82 | protected override Expression VisitExtension(Expression node) { |
| 79 | 83 | Expression res = base.VisitExtension(node); |
| 80 | 84 | |
| 81 | if (node.IsDynamic) { | |
| 85 | if (node.NodeType == ExpressionType.Dynamic) { | |
| 82 | 86 | // the node was dynamic, the dynamic nodes were removed, |
| 83 | 87 | // we now need to rewrite any call sites. |
| 84 | return VisitNode(res); | |