private OverloadResolutionResult <IndexerSymbolSignature> LookupIndexer(TypeSymbol type, ImmutableArray <TypeSymbol> argumentTypes)
        {
            var signatures = from m in LookupIndexer(type)
                             select new IndexerSymbolSignature(m);

            return(OverloadResolution.Perform(signatures, argumentTypes));
        }
        private OverloadResolutionResult <FunctionSymbolSignature> LookupFunction(SyntaxToken name, ImmutableArray <TypeSymbol> argumentTypes)
        {
            var signatures = from f in LookupSymbols <FunctionSymbol>(name)
                             where name.Text == f.Name
                             select new FunctionSymbolSignature(f);

            return(OverloadResolution.Perform(signatures, argumentTypes));
        }
        private static OverloadResolutionResult <BinaryOperatorSignature> ResolveOverloads(BinaryOperatorKind kind, TypeSymbol leftOperandType, TypeSymbol rightOperandType)
        {
            var builtInSignatures = GetBuiltInSignatures(kind);

            if (BothTypesBuiltIn(leftOperandType, rightOperandType))
            {
                return(OverloadResolution.Perform(builtInSignatures, leftOperandType, rightOperandType));
            }

            return(OverloadResolutionResult <BinaryOperatorSignature> .None);
        }
        private static OverloadResolutionResult <UnaryOperatorSignature> ResolveOverloads(UnaryOperatorKind kind, TypeSymbol operandType)
        {
            var builtInSignatures = GetBuiltInSignatures(kind);

            if (TypeBuiltIn(operandType))
            {
                return(OverloadResolution.Perform(builtInSignatures, operandType));
            }

            return(OverloadResolutionResult <UnaryOperatorSignature> .None);
        }
        private OverloadResolutionResult <FunctionSymbolSignature> LookupMethod(TypeSymbol type, SyntaxToken name, ImmutableArray <TypeSymbol> argumentTypes)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            var signatures = from m in LookupMethod(type, name)
                             select new FunctionSymbolSignature(m);

            return(OverloadResolution.Perform(signatures, argumentTypes));
        }
        private OverloadResolutionResult <FunctionSymbolSignature> LookupNumericConstructor(TypeSymbol type, ImmutableArray <TypeSymbol> argumentTypes)
        {
            var signatures = IntrinsicNumericConstructors.AllFunctions
                             .Where(x => x.ReturnType.Equals(type))
                             .Select(x => new FunctionSymbolSignature(x));

            var resolutionResult = OverloadResolution.Perform(signatures, argumentTypes);

            if (type.Kind == SymbolKind.IntrinsicMatrixType && resolutionResult.Selected == null)
            {
                // If no existing signatures for matrix constructor, then as long as we have the correct arguments, create a new function symbol on-the-fly.
                // This is to handle the MANY overloads of matrix constructor functions, which are too many to create and store statically.

                if (argumentTypes.All(x => x is IntrinsicNumericTypeSymbol))
                {
                    var matrixType = (IntrinsicMatrixTypeSymbol)type;

                    var totalScalars = matrixType.Rows * matrixType.Cols;

                    var numericArgumentTypes = argumentTypes
                                               .Cast <IntrinsicNumericTypeSymbol>()
                                               .ToImmutableArray();

                    var totalScalarsInArgs = numericArgumentTypes
                                             .Sum(x => x.GetNumElements());

                    if (totalScalars == totalScalarsInArgs)
                    {
                        signatures = new[]
                        {
                            new FunctionSymbol(matrixType.Name, string.Empty, null, matrixType,
                                               f => numericArgumentTypes.Select((t, i) => new ParameterSymbol($"arg{i}", string.Empty, f, t.GetNumericTypeWithScalarType(matrixType.ScalarType))).ToArray(),
                                               isNumericConstructor: true)
                        }.Select(x => new FunctionSymbolSignature(x));

                        resolutionResult = OverloadResolution.Perform(signatures, argumentTypes);
                    }
                }
            }

            return(resolutionResult);
        }