Lots of work on type binding

This commit is contained in:
2018-11-11 18:12:42 +01:00
parent 699377cdfc
commit 3561979ded
23 changed files with 530 additions and 142 deletions

View File

@@ -0,0 +1,51 @@
using System.Collections.Generic;
namespace Upsilon.Binder
{
public class BoundScope
{
private readonly BoundScope _parentScope;
private readonly Dictionary<string, VariableSymbol> _variables;
public BoundScope(BoundScope parentScope)
{
_parentScope = parentScope;
_variables = new Dictionary<string, VariableSymbol>();
}
public void SetVariable(VariableSymbol var)
{
if (_variables.ContainsKey(var.Name))
_variables[var.Name] = var;
else
_variables.Add(var.Name, var);
}
public void SetGlobalVariable(VariableSymbol var)
{
if (_parentScope == null)
{
SetVariable(var);
}
else
{
_parentScope.SetGlobalVariable(var);
}
}
public bool TryGetVariable(string key, out VariableSymbol result)
{
if (_variables.TryGetValue(key, out result))
{
return true;
}
if (_parentScope != null)
{
return _parentScope.TryGetVariable(key, out result);
}
return false;
}
}
}