Beispiel #1
0
        public sealed override ImmutableArray <Symbol> GetMembers(string name)
        {
            EnsureAllMembersLoaded();

            PENestedNamespaceSymbol            ns = null;
            ImmutableArray <PENamedTypeSymbol> t;

            if (lazyNamespaces.TryGetValue(name, out ns))
            {
                if (lazyTypes.TryGetValue(name, out t))
                {
                    // TODO - Eliminate the copy by storing all members and type members instead of non-type and type members?
                    return(StaticCast <Symbol> .From(t).Add(ns));
                }
                else
                {
                    return(ImmutableArray.Create <Symbol>(ns));
                }
            }
            else if (lazyTypes.TryGetValue(name, out t))
            {
                return(StaticCast <Symbol> .From(t));
            }

            return(ImmutableArray <Symbol> .Empty);
        }
        public sealed override ImmutableArray <Symbol> GetMembers(string name)
        {
            EnsureAllMembersLoaded();

            PENestedNamespaceSymbol            ns = null;
            ImmutableArray <PENamedTypeSymbol> t;

#if XSHARP
            // When we have siblings then collect all members from all siblings
            if (!siblings.IsEmpty)
            {
                var builder = ArrayBuilder <Symbol> .GetInstance();

                foreach (var sib in siblings)
                {
                    sib.EnsureAllMembersLoaded();
                    if (sib.lazyNamespaces.TryGetValue(name, out ns))
                    {
                        builder.AddRange(ns);
                    }
                    if (sib.lazyTypes.TryGetValue(name, out t))
                    {
                        builder.AddRange(t);
                    }
                }
                return(builder.ToImmutableAndFree());
            }
#endif

            if (lazyNamespaces.TryGetValue(name, out ns))
            {
                if (lazyTypes.TryGetValue(name, out t))
                {
                    // TODO - Eliminate the copy by storing all members and type members instead of non-type and type members?
                    return(StaticCast <Symbol> .From(t).Add(ns));
                }
                else
                {
                    return(ImmutableArray.Create <Symbol>(ns));
                }
            }
            else if (lazyTypes.TryGetValue(name, out t))
            {
                return(StaticCast <Symbol> .From(t));
            }

            return(ImmutableArray <Symbol> .Empty);
        }
Beispiel #3
0
        /// <summary>
        /// Create symbols for nested namespaces and initialize namespaces map.
        /// </summary>
        private void LazyInitializeNamespaces(
            IEnumerable <KeyValuePair <string, IEnumerable <IGrouping <string, TypeDefinitionHandle> > > > childNamespaces)
        {
            if (this.lazyNamespaces == null)
            {
                var namespaces = new Dictionary <string, PENestedNamespaceSymbol>(StringOrdinalComparer.Instance);

                foreach (var child in childNamespaces)
                {
                    var c = new PENestedNamespaceSymbol(child.Key, this, child.Value);
                    namespaces.Add(c.Name, c);
                }

                Interlocked.CompareExchange(ref this.lazyNamespaces, namespaces, null);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Create symbols for nested namespaces and initialize namespaces map.
        /// </summary>
        private void LazyInitializeNamespaces(
            IEnumerable<KeyValuePair<string, IEnumerable<IGrouping<string, TypeDefinitionHandle>>>> childNamespaces)
        {
            if (this.lazyNamespaces == null)
            {
                var namespaces = new Dictionary<string, PENestedNamespaceSymbol>(StringOrdinalComparer.Instance);

                foreach (var child in childNamespaces)
                {
                    var c = new PENestedNamespaceSymbol(child.Key, this, child.Value);
                    namespaces.Add(c.Name, c);
                }

                Interlocked.CompareExchange(ref this.lazyNamespaces, namespaces, null);
            }
        }
        /// <summary>
        /// Create symbols for nested namespaces and initialize namespaces map.
        /// </summary>
        private void LazyInitializeNamespaces(
            IEnumerable <KeyValuePair <string, IEnumerable <IGrouping <string, TypeDefinitionHandle> > > > childNamespaces)
        {
            if (this.lazyNamespaces == null)
            {
#if XSHARP
                // Keep track of namespaces that only differ in casing.
                // we link these namespaces with eachother so the type
                // lookup or member lookup on one returns the elements of all
                var namespaces = new Dictionary <string, PENestedNamespaceSymbol>(XSharpString.Comparer);
                var duplicates = new Dictionary <string, List <PENestedNamespaceSymbol> >(XSharpString.Comparer);
                var list       = new List <PENestedNamespaceSymbol>();
#else
                var namespaces = new Dictionary <string, PENestedNamespaceSymbol>(StringOrdinalComparer.Instance);
#endif

                foreach (var child in childNamespaces)
                {
                    var c = new PENestedNamespaceSymbol(child.Key, this, child.Value);
#if XSHARP
                    if (!namespaces.ContainsKey(c.Name))
                    {
                        namespaces.Add(c.Name, c);
                    }
                    else
                    {
                        List <PENestedNamespaceSymbol> dups;
                        if (!duplicates.ContainsKey(c.Name))
                        {
                            dups = new List <PENestedNamespaceSymbol>()
                            {
                                namespaces[c.Name]
                            };
                            duplicates.Add(c.Name, dups);
                        }
                        else
                        {
                            dups = duplicates[c.Name];
                        }
                        dups.Add(c);
                    }
                    list.Add(c);
#else
                    namespaces.Add(c.Name, c);
#endif
                }

                Interlocked.CompareExchange(ref this.lazyNamespaces, namespaces, null);
#if XSHARP
                // link the duplicate children with eachother
                foreach (var dup in duplicates)
                {
                    foreach (var ns in dup.Value)
                    {
                        ns.siblings = dup.Value.ToImmutableArray();
                    }
                }
                Interlocked.CompareExchange(ref this.lazyNamespacesList, list, null);
#endif
            }
        }