More fixes for function binding
This commit is contained in:
parent
87a533ac2b
commit
faaca91265
|
@ -88,6 +88,7 @@ namespace Upsilon.BaseTypes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
internal class IgnoredUserDataTypeContainer : TypeContainer
|
internal class IgnoredUserDataTypeContainer : TypeContainer
|
||||||
{
|
{
|
||||||
public IgnoredUserDataTypeContainer() : base(BaseTypes.Type.Unknown)
|
public IgnoredUserDataTypeContainer() : base(BaseTypes.Type.Unknown)
|
||||||
|
@ -98,7 +99,7 @@ namespace Upsilon.BaseTypes
|
||||||
public IgnoredUserDataTypeContainer(string userData) : base(userData)
|
public IgnoredUserDataTypeContainer(string userData) : base(userData)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public class UndefinedUserDataTypeContainer : TypeContainer
|
public class UndefinedUserDataTypeContainer : TypeContainer
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Upsilon.BoundTypes;
|
||||||
using Upsilon.Evaluator;
|
using Upsilon.Evaluator;
|
||||||
using Upsilon.Text;
|
using Upsilon.Text;
|
||||||
|
|
||||||
|
@ -8,9 +9,12 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
public GenericUserData(object obj)
|
public GenericUserData(object obj)
|
||||||
{
|
{
|
||||||
Value = obj;
|
Value = obj;
|
||||||
_typeInfo = UserDataTypeHandler.GetTypeInfo(obj.GetType());
|
var type = obj.GetType();
|
||||||
|
_typeInfo = UserDataTypeHandler.GetTypeInfo(type);
|
||||||
|
Type = new TypeContainer(_typeInfo.BoundTypeName);
|
||||||
|
|
||||||
}
|
}
|
||||||
public override TypeContainer Type { get; } = new IgnoredUserDataTypeContainer();
|
public override TypeContainer Type { get; }
|
||||||
|
|
||||||
private object Value { get; }
|
private object Value { get; }
|
||||||
private readonly UserDataType _typeInfo;
|
private readonly UserDataType _typeInfo;
|
||||||
|
|
|
@ -304,19 +304,14 @@ namespace Upsilon.Binder
|
||||||
{
|
{
|
||||||
returnType = internalFunction.GetResultType(parameters.ToArray());
|
returnType = internalFunction.GetResultType(parameters.ToArray());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
//returnType = function.ResultType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (isValid, error, wrongParameter) = function.ValidateParameters(parameters.ToImmutable());
|
var isValid = function.ValidateParameters(parameters.ToImmutable());
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
{
|
{
|
||||||
var span = e.Span;
|
_diagnostics.LogError(
|
||||||
if (wrongParameter != null)
|
$"No valid function with name '{function.Name}' and parameter types {string.Join(", ", parameters.Select(x => $"'{x.Type}'"))} found",
|
||||||
span = wrongParameter.Span;
|
expression.Span);
|
||||||
_diagnostics.LogError(error, span);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (resolved is UserDataVariableSymbol udSymbol)
|
else if (resolved is UserDataVariableSymbol udSymbol)
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Upsilon.Binder.VariableSymbols
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract (bool IsValid, string Error, BoundExpression WrongParameter) ValidateParameters(
|
public abstract bool ValidateParameters(
|
||||||
ImmutableArray<BoundExpression> callingParameters);
|
ImmutableArray<BoundExpression> callingParameters);
|
||||||
|
|
||||||
public FunctionVariableSymbolOption GetFirstValid(TypeContainer[] types)
|
public FunctionVariableSymbolOption GetFirstValid(TypeContainer[] types)
|
||||||
|
|
|
@ -23,8 +23,7 @@ namespace Upsilon.Binder.VariableSymbols
|
||||||
FunctionOption = options;
|
FunctionOption = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override (bool IsValid, string Error,
|
public override bool ValidateParameters(ImmutableArray<BoundExpression> callingParameters)
|
||||||
BoundExpression WrongParameter) ValidateParameters(ImmutableArray<BoundExpression> callingParameters)
|
|
||||||
{
|
{
|
||||||
foreach (var functionVariableSymbolOption in FunctionOption)
|
foreach (var functionVariableSymbolOption in FunctionOption)
|
||||||
{
|
{
|
||||||
|
@ -67,12 +66,10 @@ namespace Upsilon.Binder.VariableSymbols
|
||||||
}
|
}
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
continue;
|
continue;
|
||||||
return (true, null, null);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (false,
|
return false;
|
||||||
$"No valid function with name '{Name}' and variables of type {string.Join(", ", callingParameters.Select(x => $"'{x.Type}'"))} found",
|
|
||||||
null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeContainer GetResultType(BoundExpression[] parameters)
|
public TypeContainer GetResultType(BoundExpression[] parameters)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Upsilon.BaseTypes;
|
using Upsilon.BaseTypes;
|
||||||
|
using Upsilon.BoundTypes;
|
||||||
|
|
||||||
namespace Upsilon.Binder.VariableSymbols
|
namespace Upsilon.Binder.VariableSymbols
|
||||||
{
|
{
|
||||||
|
@ -12,7 +13,7 @@ namespace Upsilon.Binder.VariableSymbols
|
||||||
FunctionOption.Add(new ScriptFunctionVariableOption(resultType, parameters));
|
FunctionOption.Add(new ScriptFunctionVariableOption(resultType, parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override (bool IsValid, string Error, BoundExpression WrongParameter) ValidateParameters(ImmutableArray<BoundExpression> callingParameters)
|
public override bool ValidateParameters(ImmutableArray<BoundExpression> callingParameters)
|
||||||
{
|
{
|
||||||
foreach (var functionVariableSymbolOption in FunctionOption)
|
foreach (var functionVariableSymbolOption in FunctionOption)
|
||||||
{
|
{
|
||||||
|
@ -25,23 +26,37 @@ namespace Upsilon.Binder.VariableSymbols
|
||||||
{
|
{
|
||||||
var functionParameter = option.Parameters[i];
|
var functionParameter = option.Parameters[i];
|
||||||
var callingParameter = callingParameters[i];
|
var callingParameter = callingParameters[i];
|
||||||
if (functionParameter.TypeContainer != BaseTypes.Type.Unknown &&
|
if (functionParameter.TypeContainer == Type.Unknown ||
|
||||||
callingParameter.Type != BaseTypes.Type.Unknown &&
|
callingParameter.Type == Type.Unknown ||
|
||||||
callingParameter.Type != BaseTypes.Type.Nil)
|
callingParameter.Type == Type.Nil)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!functionParameter.TypeContainer.Type.HasFlag(callingParameter.Type))
|
||||||
{
|
{
|
||||||
if (callingParameter.Type != functionParameter.TypeContainer)
|
isValid = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (functionParameter.TypeContainer.Type.HasFlag(Type.UserData))
|
||||||
|
{
|
||||||
|
var variable = Binder.ResolveVariable(callingParameter, null);
|
||||||
|
if (variable != null && variable.TypeContainer == Type.UserData)
|
||||||
|
{
|
||||||
|
if (!string.Equals(functionParameter.TypeContainer.UserData,
|
||||||
|
callingParameter.Type.UserData))
|
||||||
{
|
{
|
||||||
isValid = false;
|
isValid = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
continue;
|
continue;
|
||||||
return (true, null, null);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (false, null, null);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue