Beispiel #1
0
        public override QualifiedElement GetQualifiedName()
        {
            var stack = StackPool.Get();

            try
            {
                foreach (var elem in AncestorsAndSelf())
                {
                    elem.AggregateIdentities(stack);
                }
                var ret = new QualifiedElement();

                while (stack.Count != 0)
                {
                    var(scope, category, name) = stack.Pop();
                    _ = new IdentityElement(ret, scope, category, name);
                }

                return(ret);
            }
            finally
            {
                Debug.Assert(stack.Count == 0);
                StackPool.Return(stack);
            }
        }
Beispiel #2
0
        public override QualifiedElement GetQualifiedName()
        {
            var accum = StackPool.Get();

            try
            {
                foreach (var identity in From.Identities.Take(Order).Cast <IdentityElement>().Reverse())
                {
                    identity.AggregateIdentities(accum);
                }

                var ret = new QualifiedElement();

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

                return(ret);
            }
            finally
            {
                Debug.Assert(accum.Count == 0);
                StackPool.Return(accum);
            }
        }
Beispiel #3
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;
        }
Beispiel #4
0
 public IdentityElement(QualifiedElement from, ScopeCategories scope, IdentityCategories category, string name) : base(from)
 {
     if (!category.IsDefined())
     {
         throw new ArgumentException($"{nameof(category)}:{category} is unexpected value");
     }
     if (!scope.IsDefined())
     {
         throw new ArgumentException($"{nameof(scope)}:{scope} is unexpected value.");
     }
     Category = category;
     Name     = name;
     Scope    = scope;
 }
Beispiel #5
0
            static void rec(QualifiedElement q, QualifiedNameSyntax name)
            {
                if (name.Left is QualifiedNameSyntax qs)
                {
                    rec(q, qs);
                }
                else if (name.Left is SimpleNameSyntax sn)
                {
                    _ = new IdentityElement(q, sn.Identifier.Text);
                }
                else
                {
                    throw new InvalidOperationException($"{name.Left.GetType().Name} is unexpected");
                }

                _ = new IdentityElement(q, name.Right.Identifier.Text);
            }
        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();
            }
        }
        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);
            }
        }
Beispiel #8
0
 private static void AttachName(IDiscriminatedElement target, NameSyntax syntax)
 {
     var qualified = new QualifiedElement(target);