public override DynamicMetaObject FallbackGetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject errorSuggestion) { if (argumentInfo.Count != indexes.Length + 1) { if (errorSuggestion == null) { throw new NotImplementedException(); } return(errorSuggestion); } var ctx = DynamicContext.Create(); var expr = ctx.CreateCompilerExpression(argumentInfo [0], target); var args = ctx.CreateCompilerArguments(argumentInfo.Skip(1), indexes); expr = new Compiler.ElementAccess(expr, args, Compiler.Location.Null); expr = new Compiler.Cast(new Compiler.TypeExpression(ctx.ImportType(ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); var binder = new CSharpBinder(this, expr, errorSuggestion); binder.AddRestrictions(target); binder.AddRestrictions(indexes); return(binder.Bind(ctx, callingContext)); }
public override DynamicMetaObject FallbackConvert(DynamicMetaObject target, DynamicMetaObject errorSuggestion) { var ctx = DynamicContext.Create(); var expr = ctx.CreateCompilerExpression(null, target); if (Explicit) { expr = new Compiler.Cast(new Compiler.TypeExpression(ctx.ImportType(Type), Compiler.Location.Null), expr, Compiler.Location.Null); } else { expr = new Compiler.ImplicitCast(expr, ctx.ImportType(Type), (flags & CSharpBinderFlags.ConvertArrayIndex) != 0); } if ((flags & CSharpBinderFlags.CheckedContext) != 0) { expr = new Compiler.CheckedExpr(expr, Compiler.Location.Null); } var binder = new CSharpBinder(this, expr, errorSuggestion); binder.AddRestrictions(target); return(binder.Bind(ctx, context)); }
public override DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion) { var ctx = DynamicContext.Create(); var c_args = ctx.CreateCompilerArguments(argumentInfo.Skip(1), args); var t_args = typeArguments == null ? null : new Compiler.TypeArguments(typeArguments.Select(l => new Compiler.TypeExpression(ctx.ImportType(l), Compiler.Location.Null)).ToArray()); var expr = ctx.CreateCompilerExpression(argumentInfo[0], target); // // Simple name invocation is actually member access invocation // to capture original this argument. This brings problem when // simple name is resolved as a static invocation and member access // has to be reduced back to simple name without reporting an error // if ((flags & CSharpBinderFlags.InvokeSimpleName) != 0) { var value = expr as Compiler.RuntimeValueExpression; if (value != null) { value.IsSuggestionOnly = true; } } expr = new Compiler.MemberAccess(expr, Name, t_args, Compiler.Location.Null); expr = new Invocation(expr, c_args, this); if ((flags & CSharpBinderFlags.ResultDiscarded) == 0) { expr = new Compiler.Cast(new Compiler.TypeExpression(ctx.ImportType(ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); } else { expr = new Compiler.DynamicResultCast(ctx.ImportType(ReturnType), expr); } var binder = new CSharpBinder(this, expr, errorSuggestion); binder.AddRestrictions(target); binder.AddRestrictions(args); if ((flags & CSharpBinderFlags.InvokeSpecialName) != 0) { binder.ResolveOptions |= Compiler.ResolveContext.Options.InvokeSpecialName; } return(binder.Bind(ctx, callingContext)); }
public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion) { var ctx = DynamicContext.Create(); var expr = ctx.CreateCompilerExpression(argumentInfo [0], target); expr = new Compiler.MemberAccess(expr, Name); expr = new Compiler.Cast(new Compiler.TypeExpression(ctx.ImportType(ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); var binder = new CSharpBinder(this, expr, errorSuggestion); binder.AddRestrictions(target); return(binder.Bind(ctx, callingContext)); }
public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) { var ctx = DynamicContext.Create(); var context_type = ctx.ImportType(callingContext); var queried_type = ctx.ImportType(target.LimitType); var rc = new Compiler.ResolveContext(new RuntimeBinderContext(ctx, context_type), 0); var expr = Compiler.Expression.MemberLookup(rc, false, queried_type, name, 0, Compiler.Expression.MemberLookupRestrictions.ExactArity, Compiler.Location.Null); var binder = new CSharpBinder( this, new Compiler.BoolConstant(ctx.CompilerContext.BuiltinTypes, expr is Compiler.EventExpr, Compiler.Location.Null), null); binder.AddRestrictions(target); return(binder.Bind(ctx, callingContext)); }
public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) { var ctx = DynamicContext.Create(); var type = ctx.CreateCompilerExpression(argumentInfo [0], target); target_return_type = type.Type.GetMetaInfo(); var c_args = ctx.CreateCompilerArguments(argumentInfo.Skip(1), args); var binder = new CSharpBinder( this, new Compiler.New(type, c_args, Compiler.Location.Null), null); binder.AddRestrictions(target); binder.AddRestrictions(args); return(binder.Bind(ctx, callingContext)); }
public override DynamicMetaObject FallbackSetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion) { if (argumentInfo.Count != indexes.Length + 2) { if (errorSuggestion == null) { throw new NotImplementedException(); } return(errorSuggestion); } var ctx = DynamicContext.Create(); var expr = ctx.CreateCompilerExpression(argumentInfo [0], target); var args = ctx.CreateCompilerArguments(argumentInfo.Skip(1), indexes); expr = new Compiler.ElementAccess(expr, args, Compiler.Location.Null); var source = ctx.CreateCompilerExpression(argumentInfo [indexes.Length + 1], value); // Same conversion as in SetMemberBinder if ((flags & CSharpBinderFlags.ValueFromCompoundAssignment) != 0) { expr = new Compiler.RuntimeExplicitAssign(expr, source); } else { expr = new Compiler.SimpleAssign(expr, source); } expr = new Compiler.Cast(new Compiler.TypeExpression(ctx.ImportType(ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); if ((flags & CSharpBinderFlags.CheckedContext) != 0) { expr = new Compiler.CheckedExpr(expr, Compiler.Location.Null); } var binder = new CSharpBinder(this, expr, errorSuggestion); binder.AddRestrictions(target); binder.AddRestrictions(value); binder.AddRestrictions(indexes); return(binder.Bind(ctx, callingContext)); }
public override DynamicMetaObject FallbackUnaryOperation(DynamicMetaObject target, DynamicMetaObject errorSuggestion) { var ctx = DynamicContext.Create(); var expr = ctx.CreateCompilerExpression(argumentInfo [0], target); if (Operation == ExpressionType.IsTrue) { expr = new Compiler.BooleanExpression(expr); } else if (Operation == ExpressionType.IsFalse) { expr = new Compiler.BooleanExpressionFalse(expr); } else { if (Operation == ExpressionType.Increment) { expr = new Compiler.UnaryMutator(Compiler.UnaryMutator.Mode.PreIncrement, expr, Compiler.Location.Null); } else if (Operation == ExpressionType.Decrement) { expr = new Compiler.UnaryMutator(Compiler.UnaryMutator.Mode.PreDecrement, expr, Compiler.Location.Null); } else { expr = new Compiler.Unary(GetOperator(), expr, Compiler.Location.Null); } expr = new Compiler.Cast(new Compiler.TypeExpression(ctx.ImportType(ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); if ((flags & CSharpBinderFlags.CheckedContext) != 0) { expr = new Compiler.CheckedExpr(expr, Compiler.Location.Null); } } var binder = new CSharpBinder(this, expr, errorSuggestion); binder.AddRestrictions(target); return(binder.Bind(ctx, context)); }
public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion) { var ctx = DynamicContext.Create(); var expr = ctx.CreateCompilerExpression(argumentInfo [0], target); var c_args = ctx.CreateCompilerArguments(argumentInfo.Skip(1), args); expr = new Compiler.Invocation(expr, c_args); if ((flags & CSharpBinderFlags.ResultDiscarded) == 0) { expr = new Compiler.Cast(new Compiler.TypeExpression(ctx.ImportType(ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); } else { expr = new Compiler.DynamicResultCast(ctx.ImportType(ReturnType), expr); } var binder = new CSharpBinder(this, expr, errorSuggestion); binder.AddRestrictions(target); binder.AddRestrictions(args); return(binder.Bind(ctx, callingContext)); }
public override DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion) { var ctx = DynamicContext.Create(); var source = ctx.CreateCompilerExpression(argumentInfo [1], value); var expr = ctx.CreateCompilerExpression(argumentInfo [0], target); // Field assignment expr = new Compiler.MemberAccess(expr, Name); // Compound assignment under dynamic context does not convert result // expression but when setting member type we need to do explicit // conversion to ensure type match between member type and dynamic // expression type if ((flags & CSharpBinderFlags.ValueFromCompoundAssignment) != 0) { expr = new Compiler.RuntimeExplicitAssign(expr, source); } else { expr = new Compiler.SimpleAssign(expr, source); } expr = new Compiler.Cast(new Compiler.TypeExpression(ctx.ImportType(ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); if ((flags & CSharpBinderFlags.CheckedContext) != 0) { expr = new Compiler.CheckedExpr(expr, Compiler.Location.Null); } var binder = new CSharpBinder(this, expr, errorSuggestion); binder.AddRestrictions(target); binder.AddRestrictions(value); return(binder.Bind(ctx, callingContext)); }