using System.Linq.Expressions;
using Microsoft.Scripting.Ast;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Dynamic;
using Microsoft.Scripting.Actions;
namespace IronPython.Compiler {
internal class ReducableDynamicExpression : Expression, ILightExceptionAwareExpression {
private readonly Expression _reduction;
public ReducableDynamicExpression(Expression reduction, DynamicMetaObjectBinder binder, IList<Expression> args) {
_reduction = reduction;
Binder = binder;
Args = args;
}
public DynamicMetaObjectBinder Binder { get; }
public IList<Expression> Args { get; }
public override bool CanReduce {
get {
return true;
}
}
public sealed override ExpressionType NodeType {
get { return ExpressionType.Extension; }
}
public sealed override Type Type {
get { return _reduction.Type; }
}
public override Expression Reduce() {
return _reduction;
}
#region ILightExceptionAwareExpression Members
Expression ILightExceptionAwareExpression.ReduceForLightExceptions() {
if (Binder is ILightExceptionBinder binder) {
var lightBinder = binder.GetLightExceptionBinder() as DynamicMetaObjectBinder;
if (lightBinder != binder) {
return DynamicExpression.Dynamic(
lightBinder,
Type,
Args);
}
}
return this;
}
#endregion
}
}