Made resolvevariable in binder public static so VS Code extension can use it
This commit is contained in:
parent
a4cdaa5b05
commit
e741e9c355
|
@ -12,7 +12,7 @@ using Type = Upsilon.BaseTypes.Type;
|
|||
|
||||
namespace Upsilon.Binder
|
||||
{
|
||||
internal class Binder : IDisposable
|
||||
public class Binder : IDisposable
|
||||
{
|
||||
private Diagnostics _diagnostics;
|
||||
public BoundScope Scope { get; private set; }
|
||||
|
@ -216,7 +216,11 @@ namespace Upsilon.Binder
|
|||
}
|
||||
|
||||
var returnType = Type.Unknown;
|
||||
var resolved = ResolveVariable(expression);
|
||||
var resolved = ResolveVariable(expression, _diagnostics);
|
||||
if (resolved == null)
|
||||
{
|
||||
_diagnostics.LogError("Can't resolve variable", expression.Span);
|
||||
}
|
||||
if (resolved is FunctionVariableSymbol function)
|
||||
{
|
||||
if (function is ScriptFunctionVariableSymbol scriptFunction)
|
||||
|
@ -294,7 +298,7 @@ namespace Upsilon.Binder
|
|||
return new BoundFunctionCallExpression(expression, parameters.ToImmutable(), e.Span, returnType);
|
||||
}
|
||||
|
||||
private VariableSymbol ResolveVariable(BoundExpression expression)
|
||||
public static VariableSymbol ResolveVariable(BoundExpression expression, Diagnostics diagnostics)
|
||||
{
|
||||
if (expression.Kind == BoundKind.VariableExpression)
|
||||
{
|
||||
|
@ -305,20 +309,27 @@ namespace Upsilon.Binder
|
|||
{
|
||||
var fullStopIndexExpression = (BoundFullStopIndexExpression) expression;
|
||||
var indexerExpression = fullStopIndexExpression.Expression;
|
||||
var indexerVariable = ResolveVariable(indexerExpression);
|
||||
if (indexerVariable.Type == Type.Table)
|
||||
var indexerVariable = ResolveVariable(indexerExpression, diagnostics);
|
||||
if (indexerVariable == null)
|
||||
{
|
||||
diagnostics?.LogError("Can't resolve variable", expression.Span);
|
||||
}
|
||||
else if (indexerVariable.Type == Type.Table)
|
||||
{
|
||||
return ((TableVariableSymbol)indexerVariable).Variables[fullStopIndexExpression.Index];
|
||||
}
|
||||
if (indexerVariable.Type == Type.UserData)
|
||||
else if (indexerVariable.Type == Type.UserData)
|
||||
{
|
||||
var parent =
|
||||
(UserDataBoundTypeDefinition) ((UserDataVariableSymbol) indexerVariable).BoundTypeDefinition;
|
||||
var bDefProperty = parent.Properties[fullStopIndexExpression.Index.ToLowerInvariant()];
|
||||
var boundDef = BoundTypeHandler.GetTypeDefinition(bDefProperty.ActualType);
|
||||
if (boundDef != null)
|
||||
if (parent.Properties.TryGetValue(fullStopIndexExpression.Index.ToLowerInvariant(),
|
||||
out var bDefProperty))
|
||||
{
|
||||
return new UserDataVariableSymbol(fullStopIndexExpression.Index, boundDef, parent);
|
||||
var boundDef = BoundTypeHandler.GetTypeDefinition(bDefProperty.ActualType);
|
||||
if (boundDef != null)
|
||||
{
|
||||
return new UserDataVariableSymbol(fullStopIndexExpression.Index, boundDef, parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (indexerVariable.Type == Type.Unknown)
|
||||
|
@ -341,7 +352,6 @@ namespace Upsilon.Binder
|
|||
{
|
||||
return new VariableSymbol("", expression.Type, true);
|
||||
}
|
||||
_diagnostics.LogError("Can't resolve variable", expression.Span);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -773,8 +783,12 @@ namespace Upsilon.Binder
|
|||
return new BoundFullStopIndexExpression(expression, index, Type.Unknown, e.Span);
|
||||
}
|
||||
|
||||
var variableSymbol = ResolveVariable(expression);
|
||||
if (variableSymbol != null)
|
||||
var variableSymbol = ResolveVariable(expression, _diagnostics);
|
||||
if (variableSymbol == null)
|
||||
{
|
||||
_diagnostics.LogError("Can't resolve variable", expression.Span);
|
||||
}
|
||||
else
|
||||
{
|
||||
var functionParameter = (UserDataVariableSymbol) variableSymbol;
|
||||
var udBoundDef = (UserDataBoundTypeDefinition)functionParameter.BoundTypeDefinition;
|
||||
|
|
Loading…
Reference in New Issue