2019-01-20 14:01:18 +00:00
|
|
|
using System.Collections.Generic;
|
2018-11-30 14:28:36 +00:00
|
|
|
using System.Collections.Immutable;
|
2019-01-20 14:01:18 +00:00
|
|
|
using System.Linq;
|
2018-11-30 14:28:36 +00:00
|
|
|
using Upsilon.BaseTypes;
|
|
|
|
|
|
|
|
namespace Upsilon.Binder.VariableSymbols
|
|
|
|
{
|
2019-02-13 17:10:39 +00:00
|
|
|
public abstract class FunctionVariableSymbol : VariableSymbol
|
2018-11-30 14:28:36 +00:00
|
|
|
{
|
2019-01-20 20:00:01 +00:00
|
|
|
public List<FunctionVariableSymbolOption> FunctionOption { get; protected set; } = new List<FunctionVariableSymbolOption>();
|
2019-02-13 17:10:39 +00:00
|
|
|
public bool IsCoroutine { get; }
|
2018-11-30 14:28:36 +00:00
|
|
|
|
2019-02-13 17:10:39 +00:00
|
|
|
public FunctionVariableSymbol(string name, bool local, bool isCoroutine)
|
2019-01-20 20:00:01 +00:00
|
|
|
: base(name, Type.Function, local)
|
2018-11-30 14:28:36 +00:00
|
|
|
{
|
2019-02-13 17:10:39 +00:00
|
|
|
IsCoroutine = isCoroutine;
|
2018-11-30 14:28:36 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 12:15:19 +00:00
|
|
|
public abstract bool ValidateParameters(
|
2018-11-30 14:28:36 +00:00
|
|
|
ImmutableArray<BoundExpression> callingParameters);
|
2019-01-20 14:01:18 +00:00
|
|
|
|
|
|
|
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; }
|
2018-11-30 14:28:36 +00:00
|
|
|
}
|
|
|
|
}
|