Made ResolveVariableOrConstant less hacky.

This commit is contained in:
arookas 2015-12-23 20:28:03 -05:00
parent c4532d85e7
commit 102f623cd1

View file

@ -213,22 +213,23 @@ namespace arookas
public void ResolveVariableOrConstant(sunIdentifier node, out sunVariableSymbol variableInfo, out sunConstInfo constInfo) public void ResolveVariableOrConstant(sunIdentifier node, out sunVariableSymbol variableInfo, out sunConstInfo constInfo)
{ {
try variableInfo = null;
constInfo = null;
// walk the stack backwards to resolve to the latest declaration
for (int i = Scopes.Count - 1; i >= 0; --i)
{ {
variableInfo = ResolveVariable(node); var variable = Scopes[i].ResolveVariable(node.Value);
} if (variable != null)
catch {
{ variableInfo = variable;
variableInfo = null; }
} var constant = Scopes[i].ResolveConstant(node.Value);
try if (constant != null)
{ {
constInfo = ResolveConstant(node); constInfo = constant;
} }
catch
{
constInfo = null;
} }
throw new sunUndeclaredVariableException(node);
} }
void WriteHeader() void WriteHeader()