From 102f623cd169044f0ab540b17bc4ff12ed12b520 Mon Sep 17 00:00:00 2001 From: arookas Date: Wed, 23 Dec 2015 20:28:03 -0500 Subject: [PATCH] Made ResolveVariableOrConstant less hacky. --- ssc/context.cs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/ssc/context.cs b/ssc/context.cs index 965da76..6101e96 100644 --- a/ssc/context.cs +++ b/ssc/context.cs @@ -213,22 +213,23 @@ namespace arookas 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); - } - catch - { - variableInfo = null; - } - try - { - constInfo = ResolveConstant(node); - } - catch - { - constInfo = null; + 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()