Made ResolveVariableOrConstant less hacky.
This commit is contained in:
parent
c4532d85e7
commit
102f623cd1
1 changed files with 15 additions and 14 deletions
|
@ -212,23 +212,24 @@ 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 = ResolveVariable(node);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
{
|
||||||
variableInfo = null;
|
variableInfo = null;
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
constInfo = ResolveConstant(node);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
constInfo = null;
|
constInfo = null;
|
||||||
|
// walk the stack backwards to resolve to the latest declaration
|
||||||
|
for (int i = Scopes.Count - 1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
var variable = Scopes[i].ResolveVariable(node.Value);
|
||||||
|
if (variable != null)
|
||||||
|
{
|
||||||
|
variableInfo = variable;
|
||||||
}
|
}
|
||||||
|
var constant = Scopes[i].ResolveConstant(node.Value);
|
||||||
|
if (constant != null)
|
||||||
|
{
|
||||||
|
constInfo = constant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new sunUndeclaredVariableException(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteHeader()
|
void WriteHeader()
|
||||||
|
|
Loading…
Reference in a new issue