46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using Upsilon.BaseTypes;
|
|
using Upsilon.Binder.VariableSymbols;
|
|
using Upsilon.Evaluator;
|
|
using Upsilon.Exceptions;
|
|
using Upsilon.Text;
|
|
|
|
namespace Upsilon.Binder
|
|
{
|
|
public class BoundVariableSymbol : BoundExpression
|
|
{
|
|
public BoundVariableSymbol(VariableSymbol variableSymbol, bool isCreation, TextSpan span) : base(span)
|
|
{
|
|
VariableSymbol = variableSymbol;
|
|
IsCreation = isCreation;
|
|
}
|
|
|
|
public VariableSymbol VariableSymbol { get; }
|
|
|
|
public bool IsCreation { get; }
|
|
public override BoundKind Kind => BoundKind.BoundVariableSymbol;
|
|
public override IEnumerable<BoundNode> GetNodeAtPosition(int characterPosition, int i)
|
|
{
|
|
yield return this;
|
|
}
|
|
|
|
public override IEnumerable<BoundNode> GetChildren()
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
public override TypeContainer ValueType => VariableSymbol.TypeContainer;
|
|
|
|
|
|
internal override ScriptType Evaluate(EvaluationScope scope, Diagnostics diagnostics, ref EvaluationState state)
|
|
{
|
|
if (scope.TryGet(VariableSymbol, out var val))
|
|
{
|
|
return val;
|
|
}
|
|
|
|
throw new EvaluationException(state.Script.FileName, $"Cannot find variable: '{VariableSymbol.Name}'",
|
|
Span);
|
|
}
|
|
}
|
|
} |