コード例 #1
0
        private static bool CheckVariableNameInUse(VariableExpression expression, string variableName)
        {
            if (expression == null)
                return false;

            var scripts = new List<LuatScript>();

            var bs = expression.FindAncestor<BlockStatement>();
            while (bs != null)
            {
                foreach (var i in bs.Locals.Entries)
                {
                    LuatTable table = i.Value;

                    if (!scripts.Contains(i.Key))
                        scripts.Add(i.Key);

                    foreach (var v in table.Children)
                    {
                        string name = v.Key;
                        if (name == variableName)
                            return true;
                    }
                }

                bs = bs.FindAncestor<BlockStatement>();
            }

            foreach (LuatScript script in scripts)
            {
                var visited = new HashSet<LuatValue>();
                IEnumerable<KeyValuePair<string, LuatValue>> children = script.Table.GetChildren(ref visited);

                foreach (KeyValuePair<string, LuatValue> child in children)
                {
                    if (child.Key == variableName)
                        return true;
                }
            }

            return false;
        }