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 FunctionOption { get; protected set; } = new List(); public bool IsCoroutine { get; } public FunctionVariableSymbol(string name, bool local, bool isCoroutine) : base(name, Type.Function, local) { IsCoroutine = isCoroutine; } public abstract bool ValidateParameters( ImmutableArray 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; } } }