Allow accessing variables inside a table from the variable symbol

This commit is contained in:
Deukhoofd 2018-11-27 14:15:45 +01:00
parent 8b08aea404
commit dca8773e54
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
3 changed files with 11 additions and 13 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using Upsilon.BaseTypes;
using Upsilon.BaseTypes.Number;
@ -252,7 +253,8 @@ namespace Upsilon.Binder
if (assignment.Type == Type.Table)
{
var tableExpression = (BoundTableExpression) assignment;
variable = new TableVariableSymbol(name, tableExpression.ValueType, isLocal);
variable = new TableVariableSymbol(name, tableExpression.ValueType, isLocal,
tableExpression.Expressions.Values.ToArray());
}
else
{
@ -423,10 +425,7 @@ namespace Upsilon.Binder
var commentData = new List<string>();
if (e.CommentData != null)
{
foreach (var comment in e.CommentData)
{
commentData.Add(comment);
}
commentData.AddRange(e.CommentData);
}
if (!Scope.TryGetVariable(name, !isLocal, out var variable))
@ -483,12 +482,9 @@ namespace Upsilon.Binder
statements.Add(bound);
}
foreach (var variable in Scope.Variables)
{
dictionary.Add(variable.Key, true);
}
var innerVariables = Scope.Variables;
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)

View File

@ -7,7 +7,7 @@ namespace Upsilon.Binder
{
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)
{
KeyType = keyType;
@ -33,7 +33,7 @@ namespace Upsilon.Binder
public Type KeyType { get; }
public Type ValueType { get; }
public Dictionary<string, bool> Expressions { get; }
public Dictionary<string, VariableSymbol> Expressions { get; }
public ImmutableArray<BoundStatement> Statements { get; }
}
}

View File

@ -34,11 +34,13 @@ namespace Upsilon.Binder
public class TableVariableSymbol : VariableSymbol
{
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)
{
OutType = outType;
Variables = variables;
}
}
}