コード例 #1
0
ファイル: Scope.cs プロジェクト: mortend/uno
        string GetUnique(UXIL.Node n, string baseId, Node pathOrigin)
        {
            var id = baseId;

            if ((n.InstanceType == InstanceType.Local || n.InstanceType == InstanceType.None) && !DocumentScope.ContainsNode(n) && (pathOrigin != null))
            {
                var ps = pathOrigin.ParentScope;

                if (n == ps && ps is TemplateNode)
                {
                    return("__parentInstance");
                }

                var prefix = "__parent";

                while (ps != null)
                {
                    if (n == ps)
                    {
                        return(prefix);
                    }

                    if (ps.ContainsNode(n))
                    {
                        return(prefix + "." + id);
                    }

                    ps     = ps.ParentScope;
                    prefix = prefix + ".__parent";
                }

                throw new Exception(id + " cannot be accessed from this scope");
            }

            var c = 0;

            while (true)
            {
                if (!_identifiers.ContainsIdentifier(id) &&
                    !reservedWords.Contains(id) &&
                    (id != DocumentScope.GeneratedClassName.Surname))
                {
                    if (_identifiers.ContainsNode(n))
                    {
                        return(_identifiers.Get(n));
                    }

                    _identifiers.Add(n, id);

                    return(id);
                }

                c++;
                id = baseId + c;
            }
        }