Example #1
0
        /// <summary>
        /// Searches through this scopes local variables for the inputted variable.
        /// If specified, this search will continue recursively up the nesting tree until we reach global scope.
        /// </summary>
        /// <param name="variableName"></param>
        /// <returns></returns>
        internal bool VariableExists(string variableName, ScopeSearchOption searchOption = ScopeSearchOption.kThisScope)
        {
            bool result = LocalVariables.ContainsKey(variableName);

            if (result || searchOption == ScopeSearchOption.kThisScope || ParentScope == null)
            {
                return(result);
            }

            // Search the parent - this will recurse upwards
            return(ParentScope.VariableExists(variableName, searchOption));
        }
Example #2
0
        internal Variable GetLocalVariable(string variableName, ScopeSearchOption searchOption = ScopeSearchOption.kUpwardsRecursive)
        {
            Debug.Assert(VariableExists(variableName, searchOption));

            Variable variable;

            if (LocalVariables.TryGetValue(variableName, out variable))
            {
                return(variable);
            }
            else if (ParentScope != null)
            {
                return(ParentScope.GetLocalVariable(variableName));
            }
            else
            {
                return(null);
            }
        }