Example #1
0
        private readonly NarrowingLevel _maxLevel;                  // the maximum narrowing level allowed

        public CallBinderHelper(CodeContext context, TAction action, object[] args, RuleBuilder rule)
            : base(context, action)
        {
            ContractUtils.RequiresNotEmpty(args, "args");

            _maxLevel = NarrowingLevel.All;
            _args     = RemoveExplicitInstanceArgument(action, args);
            _rule     = rule;
            _test     = _rule.MakeTypeTest(CompilerHelpers.GetType(Callable), 0);
        }
Example #2
0
        public void MakeRule()
        {
            Type toType    = Action.ToType;
            Type knownType = CompilerHelpers.GetVisibleType(_rule.Parameters[0].Type);

            // check for conversion to object first...
            if (TryConvertToObject(toType, knownType))
            {
                _rule.AddTest(Ast.Constant(true));
                return;
            }

            // do checks that aren't based upon strongly knowing the object's type (and don't require tests)
            if (TryAllConversions(toType, knownType))
            {
                _rule.AddTest(Ast.Constant(true));
                return;
            }

            // try again w/ a test for the known-type
            Type type = CompilerHelpers.GetType(_arg);

            _rule.AddTest(_rule.MakeTypeTest(type, 0));

            if (TryAllConversions(toType, type))
            {
                return;
            }

            // finally try conversions that aren't based upon the incoming type at all but
            // are last chance conversions based on the destination type
            if (TryExtraConversions(toType))
            {
                return;
            }

            // no conversion is available, make an error rule.
            MakeErrorTarget();
        }