Exemple #1
0
        public OverloadableOperation(Operator op, params Operand[] operands)
        {
            this.op       = op;
            this.operands = operands;

            List <ApplicableFunction> candidates = null;

            foreach (Operand operand in operands)
            {
                if ((object)operand != null && !operand.Type.IsPrimitive)
                {
                    // try overloads
                    candidates = op.FindUserCandidates(operands);
                    break;
                }
            }

            if (candidates == null)
            {
                candidates = OverloadResolver.FindApplicable(op.GetStandardCandidates(operands), operands);
            }

            if (candidates == null)
            {
                throw new InvalidOperationException(string.Format(null, "Cannot apply operator '{0}' to operands of type '{1}', op.methodName",
                                                                  string.Join(", ", Array.ConvertAll <Operand, string>(operands, Operand.GetTypeName))));
            }

            af = OverloadResolver.FindBest(candidates);

            if (af == null)
            {
                throw new AmbiguousMatchException("Ambiguous binding");
            }
        }
        void PrepareAfNormally(ITypeMapper typeMapper, Operand[] afOperands)
        {
            List <ApplicableFunction> candidates = null;

            foreach (Operand operand in afOperands)
            {
                if ((object)operand != null && !operand.GetReturnType(typeMapper).IsPrimitive)
                {
                    // try overloads
                    candidates = _op.FindUserCandidates(typeMapper, afOperands);
                    break;
                }
            }

            if (candidates == null)
            {
                candidates = OverloadResolver.FindApplicable(_op.GetStandardCandidates(typeMapper, afOperands), typeMapper, afOperands);
            }

            if (candidates == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              null,
                              Properties.Messages.ErrInvalidOperation,
                              _op.MethodName,
                              string.Join(", ", ConvertAll <Operand, string>(afOperands, op => op.GetReturnType(typeMapper).FullName))));
            }

            _af = OverloadResolver.FindBest(candidates, typeMapper);
        }
Exemple #3
0
        void PrepareAf(ITypeMapper typeMapper)
        {
            if (_af != null)
            {
                return;
            }
            List <ApplicableFunction> candidates = null;

            foreach (Operand operand in _operands)
            {
                if ((object)operand != null && !operand.GetReturnType(typeMapper).IsPrimitive)
                {
                    // try overloads
                    candidates = _op.FindUserCandidates(typeMapper, _operands);
                    break;
                }
            }

            if (candidates == null)
            {
                candidates = OverloadResolver.FindApplicable(_op.GetStandardCandidates(typeMapper, _operands), typeMapper, _operands);
            }

            if (candidates == null)
            {
                throw new InvalidOperationException(string.Format(null, Messages.ErrInvalidOperation, _op.MethodName,
                                                                  string.Join(", ", Array.ConvertAll <Operand, string>(_operands, op => op.GetReturnType(typeMapper).FullName))));
            }

            _af = OverloadResolver.FindBest(candidates, typeMapper);

            if (_af == null)
            {
                throw new AmbiguousMatchException(Messages.ErrAmbiguousBinding);
            }
        }