Пример #1
0
        public IdentityElement(QualifiedElement parent, string name) : base(parent)
        {
            var piv = parent.Parent;

            (ScopeCategories scope, IdentityCategories category)? attr = default;

            while (!(piv is ImaginaryRoot))
            {
                attr = piv switch
                {
                    NameSpaceElement _ => (ScopeCategories.Public, IdentityCategories.Namespace),
                    ClassElement cls => (cls.Scope, IdentityCategories.Class),
                    StructElement str => (str.Scope, IdentityCategories.Struct),
                    InterfaceElement iface => (iface.Scope, IdentityCategories.Interface),
                    EnumElement e => (e.Scope, IdentityCategories.Enum),
                    DelegateElement d => (d.Scope, IdentityCategories.Delegate),
                    _ => null
                };

                piv = piv.Parent;

                if (attr is null)
                {
                    continue;
                }
                break;
            }

            Name     = name;
            Category = attr?.category ?? throw new CategoryNotFoundException(name);
            Scope    = attr.Value.scope;
        }
        public NameSpaceElement Build(CompilationUnitSyntax syntax, IPhysicalStorage storage)
        {
            try
            {
                var global = new NameSpaceElement(storage);
                _ = new QualifiedElement(global);

                _parentStack.Push(global);
                Visit(syntax);
                Debug.Assert(_parentStack.Count == 1);
                return((NameSpaceElement)_parentStack.Pop());
            }
            finally
            {
                _parentStack.Clear();
            }
        }
Пример #3
0
        public override QualifiedElement GetQualifiedName()
        {
            var accum = StackPool.Get();

            try
            {
                AggregateIdentities(accum);

                var piv = Parent switch
                {
                    NameSpaceElement ns => ns.Parent,
                    _ => Parent
                };

                if (!(piv is ImaginaryRoot))
                {
                    foreach (var element in piv.AncestorsAndSelf())
                    {
                        element.AggregateIdentities(accum);
                    }
                }

                var ret = new QualifiedElement();

                while (accum.Count != 0)
                {
                    var(scope, cat, nme) = accum.Pop();
                    _ = new IdentityElement(ret, scope, cat, nme);
                }

                return(ret);
            }
            finally
            {
                Debug.Assert(accum.Count == 0);
                StackPool.Return(accum);
            }
        }