Allow accessing variables inside a table from the variable symbol
This commit is contained in:
parent
8b08aea404
commit
dca8773e54
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Upsilon.BaseTypes;
|
using Upsilon.BaseTypes;
|
||||||
using Upsilon.BaseTypes.Number;
|
using Upsilon.BaseTypes.Number;
|
||||||
|
@ -252,7 +253,8 @@ namespace Upsilon.Binder
|
||||||
if (assignment.Type == Type.Table)
|
if (assignment.Type == Type.Table)
|
||||||
{
|
{
|
||||||
var tableExpression = (BoundTableExpression) assignment;
|
var tableExpression = (BoundTableExpression) assignment;
|
||||||
variable = new TableVariableSymbol(name, tableExpression.ValueType, isLocal);
|
variable = new TableVariableSymbol(name, tableExpression.ValueType, isLocal,
|
||||||
|
tableExpression.Expressions.Values.ToArray());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -423,10 +425,7 @@ namespace Upsilon.Binder
|
||||||
var commentData = new List<string>();
|
var commentData = new List<string>();
|
||||||
if (e.CommentData != null)
|
if (e.CommentData != null)
|
||||||
{
|
{
|
||||||
foreach (var comment in e.CommentData)
|
commentData.AddRange(e.CommentData);
|
||||||
{
|
|
||||||
commentData.Add(comment);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Scope.TryGetVariable(name, !isLocal, out var variable))
|
if (!Scope.TryGetVariable(name, !isLocal, out var variable))
|
||||||
|
@ -483,12 +482,9 @@ namespace Upsilon.Binder
|
||||||
statements.Add(bound);
|
statements.Add(bound);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var variable in Scope.Variables)
|
var innerVariables = Scope.Variables;
|
||||||
{
|
|
||||||
dictionary.Add(variable.Key, true);
|
|
||||||
}
|
|
||||||
Scope = s;
|
Scope = s;
|
||||||
return new BoundTableExpression(keyType, valueType, dictionary, statements.ToImmutable(), e.Span);
|
return new BoundTableExpression(keyType, valueType, innerVariables, statements.ToImmutable(), e.Span);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BoundExpression BindIndexExpression(IndexExpressionSyntax e)
|
private BoundExpression BindIndexExpression(IndexExpressionSyntax e)
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace Upsilon.Binder
|
||||||
{
|
{
|
||||||
public class BoundTableExpression : BoundExpression
|
public class BoundTableExpression : BoundExpression
|
||||||
{
|
{
|
||||||
public BoundTableExpression(Type keyType, Type valueType, Dictionary<string, bool> expressions,
|
public BoundTableExpression(Type keyType, Type valueType, Dictionary<string, VariableSymbol> expressions,
|
||||||
ImmutableArray<BoundStatement> statements, TextSpan span) : base(span)
|
ImmutableArray<BoundStatement> statements, TextSpan span) : base(span)
|
||||||
{
|
{
|
||||||
KeyType = keyType;
|
KeyType = keyType;
|
||||||
|
@ -33,7 +33,7 @@ namespace Upsilon.Binder
|
||||||
public Type KeyType { get; }
|
public Type KeyType { get; }
|
||||||
public Type ValueType { get; }
|
public Type ValueType { get; }
|
||||||
|
|
||||||
public Dictionary<string, bool> Expressions { get; }
|
public Dictionary<string, VariableSymbol> Expressions { get; }
|
||||||
public ImmutableArray<BoundStatement> Statements { get; }
|
public ImmutableArray<BoundStatement> Statements { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -34,11 +34,13 @@ namespace Upsilon.Binder
|
||||||
public class TableVariableSymbol : VariableSymbol
|
public class TableVariableSymbol : VariableSymbol
|
||||||
{
|
{
|
||||||
public Type OutType { get; }
|
public Type OutType { get; }
|
||||||
|
public VariableSymbol[] Variables { get; }
|
||||||
|
|
||||||
public TableVariableSymbol(string name, Type outType, bool local)
|
public TableVariableSymbol(string name, Type outType, bool local, VariableSymbol[] variables)
|
||||||
:base (name, Type.Table, local)
|
:base (name, Type.Table, local)
|
||||||
{
|
{
|
||||||
OutType = outType;
|
OutType = outType;
|
||||||
|
Variables = variables;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue