66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using Upsilon.BaseTypes;
|
|
using Upsilon.Binder.VariableSymbols;
|
|
using Upsilon.Text;
|
|
using Type = Upsilon.BaseTypes.Type;
|
|
|
|
namespace Upsilon.Binder
|
|
{
|
|
public class BoundTableExpression : BoundExpression, IBoundNodeScopeOwner
|
|
{
|
|
public BoundTableExpression(Dictionary<string, VariableSymbol> expressions,
|
|
ImmutableArray<BoundStatement> statements, TextSpan span, BoundScope scope) : base(span)
|
|
{
|
|
Expressions = expressions;
|
|
Statements = statements;
|
|
Scope = scope;
|
|
}
|
|
|
|
public override BoundKind Kind => BoundKind.BoundTableExpression;
|
|
|
|
public override IEnumerable<BoundNode> GetChildren()
|
|
{
|
|
return Statements;
|
|
}
|
|
|
|
public override TypeContainer Type
|
|
{
|
|
get
|
|
{
|
|
TypeContainer valueType = null;
|
|
foreach (var statement in Statements)
|
|
{
|
|
if (!(statement is BoundExpressionStatement exp))
|
|
{
|
|
valueType = BaseTypes.Type.Unknown;
|
|
break;
|
|
}
|
|
if (valueType == null)
|
|
{
|
|
valueType = exp.Expression.Type;
|
|
continue;
|
|
}
|
|
if (valueType == exp.Expression.Type) continue;
|
|
valueType = BaseTypes.Type.Unknown;
|
|
break;
|
|
}
|
|
|
|
TypeContainer valueRealType = BaseTypes.Type.Unknown;
|
|
if (valueType != null)
|
|
valueRealType = valueType;
|
|
|
|
var arr = new TypeContainer[] {BaseTypes.Type.String, valueRealType};
|
|
return new CompositeTypeContainer()
|
|
{
|
|
Types = arr.ToImmutableArray()
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
public Dictionary<string, VariableSymbol> Expressions { get; }
|
|
public ImmutableArray<BoundStatement> Statements { get; }
|
|
public BoundScope Scope { get; set; }
|
|
}
|
|
} |