Exemplo n.º 1
0
        internal static bool BuildConversion(MetaObjectBuilder /*!*/ metaBuilder, DynamicMetaObject /*!*/ target, Expression /*!*/ contextExpression,
                                             Type /*!*/ toType, bool defaultFallback)
        {
            Expression expr = TryImplicitConversion(target, toType);

            if (expr != null)
            {
                metaBuilder.Result = expr;
                metaBuilder.AddObjectTypeRestriction(target.Value, target.Expression);
                return(true);
            }

            if (defaultFallback)
            {
                metaBuilder.AddObjectTypeRestriction(target.Value, target.Expression);

                metaBuilder.SetError(Methods.MakeTypeConversionError.OpCall(
                                         contextExpression,
                                         AstUtils.Convert(target.Expression, typeof(object)),
                                         Ast.Constant(toType, typeof(Type))
                                         ));
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        private void BuildCall(MetaObjectBuilder /*!*/ metaBuilder, CallArguments /*!*/ args, string /*!*/ name)
        {
            var actualArgs = RubyOverloadResolver.NormalizeArguments(metaBuilder, args, 0, Int32.MaxValue);

            if (metaBuilder.Error)
            {
                return;
            }

            metaBuilder.AddRestriction(
                Ast.Equal(
                    Ast.Property(Ast.Convert(args.TargetExpression, typeof(Win32API)), VersionProperty),
                    Ast.Constant(_version)
                    )
                );

            if (_function == IntPtr.Zero)
            {
                metaBuilder.SetError(Ast.Throw(new Func <Exception>(UninitializedFunctionError).Method.OpCall(), typeof(object)));
                return;
            }

            if (_signature.Length != actualArgs.Count)
            {
                metaBuilder.SetError(Ast.Throw(new Func <int, int, Exception>(InvalidParameterCountError).Method.OpCall(
                                                   Ast.Constant(_signature.Length), Ast.Constant(actualArgs.Count)), typeof(object)
                                               ));
                return;
            }

            var calliArgs = new AstExpressions();

            calliArgs.Add(Ast.Property(Ast.Convert(args.TargetExpression, typeof(Win32API)), FunctionProperty));
            for (int i = 0; i < actualArgs.Count; i++)
            {
                calliArgs.Add(MarshalArgument(metaBuilder, actualArgs[i], _signature[i]));
            }

            metaBuilder.Result = Ast.Call(EmitCalliStub(), calliArgs);

            // MRI returns 0 if void return type is given:
            if (_returnType == ArgType.None)
            {
                metaBuilder.Result = Ast.Block(metaBuilder.Result, AstUtils.Constant(0));
            }
        }
Exemplo n.º 3
0
        internal protected override bool TryImplicitConversion(MetaObjectBuilder /*!*/ metaBuilder, CallArguments /*!*/ args)
        {
            object target = args.Target;

            if (target == null)
            {
                metaBuilder.SetError(Methods.CreateTypeConversionError.OpCall(AstUtils.Constant("nil"), AstUtils.Constant(TargetTypeName)));
                return(true);
            }

            return((metaBuilder.Result = Convert(ReturnType, args)) != null);
        }
Exemplo n.º 4
0
        internal protected override bool TryImplicitConversion(MetaObjectBuilder /*!*/ metaBuilder, CallArguments /*!*/ args)
        {
            if (args.Target == null)
            {
                metaBuilder.SetError(Methods.CreateTypeConversionError.OpCall(AstUtils.Constant("nil"), AstUtils.Constant(TargetTypeName)));
                return(true);
            }

            metaBuilder.Result =
                ImplicitConvert(typeof(int), args) ??
                ImplicitConvert(typeof(BigInteger), args);

            return(metaBuilder.Result != null);
        }
Exemplo n.º 5
0
 protected virtual void SetError(MetaObjectBuilder /*!*/ metaBuilder, CallArguments /*!*/ args, Expression /*!*/ targetClassNameConstant, Type /*!*/ resultType)
 {
     metaBuilder.SetError(Methods.CreateTypeConversionError.OpCall(targetClassNameConstant, AstUtils.Constant(TargetTypeName)));
 }