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); }
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); } }
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; }
void IErrorReporter.InvocationRequiresParentheses(SourceRange sourceRange, InvocableBinding[] invocableGroup) { string message = String.Format(CultureInfo.CurrentCulture, Resources.InvocationRequiresParentheses, invocableGroup[0].GetFullName()); HandleError(sourceRange, ErrorId.InvocationRequiresParentheses, message); }
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()); }