Esempio n. 1
0
        public static void ReportUndeclaredFunction(this ICollection <Diagnostic> diagnostics, FunctionInvocationExpressionSyntax node, IEnumerable <TypeSymbol> argumentTypes)
        {
            var name             = node.Name.ToStringIgnoringMacroReferences();
            var argumentTypeList = string.Join(@", ", argumentTypes.Select(t => t.ToDisplayName()));

            diagnostics.Report(node.GetTextSpanSafe(), DiagnosticId.UndeclaredFunction, name, argumentTypeList);
        }
Esempio n. 2
0
        private BoundExpression BindFunctionInvocationExpression(FunctionInvocationExpressionSyntax syntax)
        {
            // Don't try to bind CompileShader function calls, for now.
            if ((syntax.Name.Kind == SyntaxKind.IdentifierName) && ((IdentifierNameSyntax)syntax.Name).Name.ContextualKind == SyntaxKind.CompileShaderKeyword)
            {
                return(new BoundFunctionInvocationExpression(syntax,
                                                             syntax.ArgumentList.Arguments.Select(x => (BoundExpression) new BoundErrorExpression()).ToImmutableArray(),
                                                             OverloadResolutionResult <FunctionSymbolSignature> .None));
            }

            var name           = syntax.Name;
            var boundArguments = BindArgumentList(syntax.ArgumentList);
            var argumentTypes  = boundArguments.Select(a => a.Type).ToImmutableArray();

            var anyErrorsInArguments = argumentTypes.Any(a => a.IsError());

            if (anyErrorsInArguments)
            {
                return(new BoundFunctionInvocationExpression(syntax, boundArguments, OverloadResolutionResult <FunctionSymbolSignature> .None));
            }

            ContainerSymbol containerSymbol;
            SyntaxToken     actualName;

            switch (name.Kind)
            {
            case SyntaxKind.IdentifierName:
                containerSymbol = null;
                actualName      = ((IdentifierNameSyntax)name).Name;
                break;

            case SyntaxKind.QualifiedName:
                containerSymbol = LookupContainer(((QualifiedNameSyntax)syntax.Name).Left);
                actualName      = ((QualifiedNameSyntax)name).Right.Name;
                break;

            default:
                throw new InvalidOperationException();
            }

            var result = (containerSymbol?.Binder ?? this).LookupFunction(actualName, argumentTypes);

            if (result.Best == null)
            {
                if (result.Selected == null)
                {
                    Diagnostics.ReportUndeclaredFunction(syntax, argumentTypes);
                    return(new BoundErrorExpression());
                }

                var symbol1 = result.Selected.Signature.Symbol;
                var symbol2 = result.Candidates.First(c => !c.Signature.Symbol.Equals(symbol1)).Signature.Symbol;
                Diagnostics.ReportAmbiguousInvocation(syntax.GetTextSpanSafe(), symbol1, symbol2, argumentTypes);
            }

            var convertedArguments = boundArguments.Select((a, i) => BindArgument(a, result, i, syntax.ArgumentList.Arguments[i].GetTextSpanSafe())).ToImmutableArray();

            return(new BoundFunctionInvocationExpression(syntax, convertedArguments, result));
        }
Esempio n. 3
0
 public static void ReportUndeclaredFunction(this ICollection<Diagnostic> diagnostics, FunctionInvocationExpressionSyntax node, IEnumerable<TypeSymbol> argumentTypes)
 {
     var name = node.Name.ToStringIgnoringMacroReferences();
     var argumentTypeList = string.Join(@", ", argumentTypes.Select(t => t.ToDisplayName()));
     diagnostics.Report(node.GetTextSpanSafe(), DiagnosticId.UndeclaredFunction, name, argumentTypeList);
 }