49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
using Upsilon.BaseTypes;
|
|
|
|
namespace Upsilon.Binder.VariableSymbols
|
|
{
|
|
public abstract class FunctionVariableSymbol : VariableSymbol
|
|
{
|
|
public List<FunctionVariableSymbolOption> FunctionOption { get; protected set; } = new List<FunctionVariableSymbolOption>();
|
|
|
|
public FunctionVariableSymbol(string name, bool local, Type resultType)
|
|
: base(name, Type.Function, local)
|
|
{
|
|
}
|
|
|
|
public abstract bool ValidateParameters(
|
|
ImmutableArray<BoundExpression> callingParameters);
|
|
|
|
public FunctionVariableSymbolOption GetFirstValid(TypeContainer[] types)
|
|
{
|
|
return FunctionOption.FirstOrDefault(x =>
|
|
{
|
|
var parTypes = x.GetParameterTypes();
|
|
for (var i = 0; i < parTypes.Length; i++)
|
|
{
|
|
var parType = parTypes[i];
|
|
var givenType = types[i];
|
|
if (parType == Type.Unknown || givenType == Type.Unknown)
|
|
continue;
|
|
if (!parType.Type.HasFlag(givenType))
|
|
return false;
|
|
}
|
|
return true;
|
|
});
|
|
}
|
|
}
|
|
|
|
public abstract class FunctionVariableSymbolOption
|
|
{
|
|
public FunctionVariableSymbolOption(TypeContainer resultType)
|
|
{
|
|
ResultType = resultType;
|
|
}
|
|
|
|
public abstract TypeContainer[] GetParameterTypes();
|
|
public TypeContainer ResultType { get; internal set; }
|
|
}
|
|
} |