Ejemplo n.º 1
0
        MethodBase[] ResolveMethods(CallSiteContext bound, string name, string nameOpt)
        {
            var routine = bound.CurrentContext.GetDeclaredFunction(name) ?? ((nameOpt != null) ? bound.CurrentContext.GetDeclaredFunction(nameOpt) : null);

            if (routine == null)
            {
                return(null);
            }

            if (routine is PhpRoutineInfo || routine is DelegateRoutineInfo)
            {
                Debug.Assert(routine.Index != 0);

                // restriction: ctx.CheckFunctionDeclared(index, routine.GetHashCode())
                var checkExpr = Expression.Call(
                    bound.Context,
                    typeof(Context).GetMethod("CheckFunctionDeclared", typeof(int), typeof(int)),
                    Expression.Constant(routine.Index), Expression.Constant(routine.GetHashCode()));

                bound.AddRestriction(checkExpr);
            }
            else if (routine is ClrRoutineInfo)
            {
                // CLR routines persist across whole app, no restriction needed
            }

            //
            var targetInstance = routine.Target;

            if (targetInstance != null)
            {
                bound.TargetInstance = Expression.Constant(targetInstance);
            }

            if (bound.TypeArguments != null && bound.TypeArguments.Length != 0)
            {
                // global functions cannot be (should not be) generic!
                throw new InvalidOperationException();  // NS
            }

            //
            return(routine.Methods);
        }
Ejemplo n.º 2
0
 void ISpecialParamHolder.Process(CallSiteContext info, Expression valueExpr)
 {
     info.AddRestriction(Expression.Call(valueExpr, Cache.Operators.RuntimeTypeHandle_Equals_RuntimeTypeHandle, Expression.Constant(Value)));
     info.ClassContext = Type.GetTypeFromHandle(Value);
 }
Ejemplo n.º 3
0
 void ISpecialParamHolder.Process(CallSiteContext info, Expression valueExpr)
 {
     info.AddRestriction(BindingRestrictions.GetInstanceRestriction(valueExpr, Value));
     info.TargetType = Value;
 }
Ejemplo n.º 4
0
        MethodBase[] ResolveMethods(CallSiteContext bound, string name, string nameOpt)
        {
            var routine = bound.CurrentContext.GetDeclaredFunction(name) ?? ((nameOpt != null) ? bound.CurrentContext.GetDeclaredFunction(nameOpt) : null);

            if (routine == null)
            {
                // add restriction // https://github.com/iolevel/wpdotnet-sdk/issues/92

                // restriction: ctx.GetDeclaredFunction(name) == null
                var checkExpr = Expression.ReferenceEqual(
                    Expression.Call(bound.Context, Cache.Operators.GetDeclaredFunction_Context_String, Expression.Constant(name)),
                    Cache.Expressions.Null);

                bound.AddRestriction(checkExpr);

                if (nameOpt != null)
                {
                    // restriction: ctx.GetDeclaredFunction(nameOpt) == null
                    checkExpr = Expression.ReferenceEqual(
                        Expression.Call(bound.Context, Cache.Operators.GetDeclaredFunction_Context_String, Expression.Constant(nameOpt)),
                        Cache.Expressions.Null);

                    bound.AddRestriction(checkExpr);
                }

                return(null);
            }

            if (routine is PhpRoutineInfo || routine is DelegateRoutineInfo)
            {
                Debug.Assert(routine.Index != 0);

                // restriction: CheckFunctionDeclared(ctx, index, routine.GetHashCode())
                var checkExpr = Expression.Call(
                    Cache.Operators.CheckFunctionDeclared_Context_Int_Int,
                    bound.Context, Expression.Constant(routine.Index), Expression.Constant(routine.GetHashCode()));

                bound.AddRestriction(checkExpr);
            }
            else if (routine is ClrRoutineInfo)
            {
                // CLR routines persist across whole app, no restriction needed
            }

            //
            var targetInstance = routine.Target;

            if (targetInstance != null)
            {
                bound.TargetInstance = Expression.Constant(targetInstance);
            }

            if (bound.TypeArguments != null && bound.TypeArguments.Length != 0)
            {
                // global functions cannot be (should not be) generic!
                throw new InvalidOperationException();  // NS
            }

            //
            return(routine.Methods);
        }