Exemple #1
0
        public InvocableBinding BindInvocation(InvocableBinding[] candidates, Type[] argumentTypes)
        {
            // Get applicable invocables

            // First we check if we can find any candidates if we only allow implicit conversions.
            InvocableBinding[] applicableInvocables = GetApplicableInvocables(candidates, argumentTypes, false);

            if (applicableInvocables == null || applicableInvocables.Length == 0)
            {
                // We could not find any candiate, lets see wether we find candidates
                // if we also allow explicit conversions.
                applicableInvocables = GetApplicableInvocables(candidates, argumentTypes, true);

                if (applicableInvocables == null || applicableInvocables.Length == 0)
                {
                    return(null);
                }
            }

            // Now select the best one

            InvocableBinding bestInvocable            = applicableInvocables[0];
            InvocableBinding lastEquallyGoodInvocable = null;

            for (int i = 1; i < applicableInvocables.Length; i++)
            {
                InvocableBinding invocable = applicableInvocables[i];

                int comparisonResult = CompareFunctions(argumentTypes, bestInvocable.GetParameterTypes(), invocable.GetParameterTypes());

                if (comparisonResult == 0)
                {
                    lastEquallyGoodInvocable = invocable;
                }
                else if (comparisonResult > 0)
                {
                    lastEquallyGoodInvocable = null;
                    bestInvocable            = invocable;
                }
            }

            // Ok, now check that our best function is really the best one

            if (lastEquallyGoodInvocable != null)
            {
                // We have also a function that is equally good. -- The call is ambiguous.
                _errorReporter.AmbiguousInvocation(bestInvocable, lastEquallyGoodInvocable, argumentTypes);

                // Return first to avoid cascading errors.
                return(bestInvocable);
            }

            return(bestInvocable);
        }
        private void AddInvocable(InvocableBinding invocable)
        {
            List <InvocableBinding> functionList;

            if (!_functionsTable.TryGetValue(invocable.Name, out functionList))
            {
                functionList = new List <InvocableBinding>();
                _functionsTable.Add(invocable.Name, functionList);
            }

            functionList.Add(invocable);
        }
Exemple #3
0
 void IErrorReporter.AmbiguousInvocation(InvocableBinding function1, InvocableBinding function2, Type[] argumentTypes)
 {
     if (argumentTypes.Length == 0)
     {
         string message = String.Format(CultureInfo.CurrentCulture, Resources.AmbiguousInvocationNoArgs, function1.GetFullName(), function2.GetFullName());
         HandleError(ErrorId.AmbiguousInvocation, message);
     }
     else
     {
         string message = String.Format(CultureInfo.CurrentCulture, Resources.AmbiguousInvocation, function1.GetFullName(), function2.GetFullName(), FormattingHelpers.FormatTypeList(argumentTypes));
         HandleError(ErrorId.AmbiguousInvocation, message);
     }
 }
        private void AddBufferedFunctions()
        {
            foreach (string functionName in _functionsTable.Keys)
            {
                List <InvocableBinding> functionList = _functionsTable[functionName];
                InvocableBinding        invocable    = functionList[0];

                string description;

                if (invocable is FunctionBinding)
                {
                    if (functionList.Count == 1)
                    {
                        description = String.Format(CultureInfo.CurrentCulture, "<b>{0}</b> : {1}", invocable.Name, invocable.ReturnType.Name);
                    }
                    else
                    {
                        description = String.Format(CultureInfo.CurrentCulture, "<b>{0}</b> : {1} (+ {2} Overloadings)", invocable.Name, invocable.ReturnType.Name, functionList.Count);
                    }
                }
                else
                {
                    MethodBinding method = (MethodBinding)invocable;

                    if (functionList.Count == 1)
                    {
                        description = String.Format(CultureInfo.CurrentCulture, "{0}.<b>{1}</b> : {2}", method.DeclaringType.Name, method.Name, method.ReturnType.Name);
                    }
                    else
                    {
                        description = String.Format(CultureInfo.CurrentCulture, "{0}.<b>{1}</b> : {2} (+ {3} Overloadings)", method.DeclaringType.Name, method.Name, method.ReturnType.Name, functionList.Count);
                    }
                }

                string preText = MaskIdentifier(invocable.Name);

                IntelliPromptMemberListItem item = new IntelliPromptMemberListItem(invocable.Name, FUNCTION_IMG_INDEX, description, preText, String.Empty);
                _members.Add(item);
            }
        }
Exemple #5
0
        private void AddInvocable(InvocableBinding invocableBinding)
        {
            InvokeParameter[] parameters = invocableBinding.GetParameters();

            // Note: Don't use <= otherwise we will never see an IntelliPromt for methods/functions
            //       with no parameters.

            if (parameters.Length < _parameterIndex)
            {
                return;
            }

            StringBuilder sb = new StringBuilder();

            using (StringWriter sw = new StringWriter(sb, CultureInfo.CurrentCulture))
            {
                XmlWriter writer = new XmlTextWriter(sw);

                if (invocableBinding.ReturnType != null)
                {
                    writer.WriteString(invocableBinding.ReturnType.Name);
                    writer.WriteWhitespace(" ");
                }

                MethodBinding methodBinding = invocableBinding as MethodBinding;
                if (methodBinding != null)
                {
                    writer.WriteString(methodBinding.DeclaringType.Name);
                    writer.WriteString(".");
                }

                writer.WriteString(invocableBinding.Name);

                bool highlighParentheses = (_parameterIndex == 0 && parameters.Length == 0);

                if (highlighParentheses)
                {
                    writer.WriteStartElement("b");
                }
                writer.WriteString(" (");
                if (highlighParentheses)
                {
                    writer.WriteEndElement();
                }

                for (int i = 0; i < parameters.Length; i++)
                {
                    if (i > 0)
                    {
                        writer.WriteString(", ");
                    }

                    bool isSelectedParameter = (i == _parameterIndex);

                    if (isSelectedParameter)
                    {
                        writer.WriteStartElement("b");
                    }

                    writer.WriteString(parameters[i].Name);
                    writer.WriteString(": ");
                    writer.WriteString(parameters[i].DataType.Name);

                    if (isSelectedParameter)
                    {
                        writer.WriteEndElement();
                    }
                }

                if (highlighParentheses)
                {
                    writer.WriteStartElement("b");
                }
                writer.WriteString(")");
                if (highlighParentheses)
                {
                    writer.WriteEndElement();
                }
            }

            _infoTip.Info.Add(sb.ToString());
        }