235 lines
7.0 KiB
C#
235 lines
7.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using Microsoft.Cci;
|
|
using Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
using Microsoft.CodeAnalysis.PooledObjects;
|
|
using Microsoft.CodeAnalysis.Symbols;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
|
|
internal abstract class NamespaceSymbol : NamespaceOrTypeSymbol, INamespace, INamedEntity, INamespaceSymbolInternal, INamespaceOrTypeSymbolInternal, ISymbolInternal
|
|
{
|
|
private ImmutableArray<NamedTypeSymbol> _lazyTypesMightContainExtensionMethods;
|
|
|
|
private string _lazyQualifiedName;
|
|
|
|
INamespace INamespace.ContainingNamespace => (INamespace)(object)AdaptedNamespaceSymbol.ContainingNamespace?.GetCciAdapter();
|
|
|
|
string INamedEntity.Name => AdaptedNamespaceSymbol.MetadataName;
|
|
|
|
internal NamespaceSymbol AdaptedNamespaceSymbol => this;
|
|
|
|
public virtual bool IsGlobalNamespace => (object)ContainingNamespace == null;
|
|
|
|
internal abstract NamespaceExtent Extent { get; }
|
|
|
|
public NamespaceKind NamespaceKind => Extent.Kind;
|
|
|
|
public CSharpCompilation ContainingCompilation
|
|
{
|
|
get
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Invalid comparison between Unknown and I4
|
|
if ((int)NamespaceKind != 3)
|
|
{
|
|
return null;
|
|
}
|
|
return Extent.Compilation;
|
|
}
|
|
}
|
|
|
|
public virtual ImmutableArray<NamespaceSymbol> ConstituentNamespaces => ImmutableArray.Create(this);
|
|
|
|
public sealed override NamedTypeSymbol ContainingType => null;
|
|
|
|
public abstract override AssemblySymbol ContainingAssembly { get; }
|
|
|
|
internal override ModuleSymbol ContainingModule
|
|
{
|
|
get
|
|
{
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000f: Invalid comparison between Unknown and I4
|
|
NamespaceExtent extent = Extent;
|
|
if ((int)extent.Kind == 1)
|
|
{
|
|
return extent.Module;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public sealed override SymbolKind Kind => (SymbolKind)12;
|
|
|
|
public sealed override bool IsImplicitlyDeclared => IsGlobalNamespace;
|
|
|
|
public sealed override Accessibility DeclaredAccessibility => (Accessibility)6;
|
|
|
|
public sealed override bool IsStatic => true;
|
|
|
|
public sealed override bool IsAbstract => false;
|
|
|
|
public sealed override bool IsSealed => false;
|
|
|
|
internal sealed override ObsoleteAttributeData ObsoleteAttributeData => null;
|
|
|
|
internal NamedTypeSymbol ImplicitType
|
|
{
|
|
get
|
|
{
|
|
ImmutableArray<NamedTypeSymbol> typeMembers = GetTypeMembers("<invalid-global-code>");
|
|
if (typeMembers.Length == 0)
|
|
{
|
|
return null;
|
|
}
|
|
return typeMembers[0];
|
|
}
|
|
}
|
|
|
|
private ImmutableArray<NamedTypeSymbol> TypesMightContainExtensionMethods
|
|
{
|
|
get
|
|
{
|
|
ImmutableArray<NamedTypeSymbol> lazyTypesMightContainExtensionMethods = _lazyTypesMightContainExtensionMethods;
|
|
if (lazyTypesMightContainExtensionMethods.IsDefault)
|
|
{
|
|
_lazyTypesMightContainExtensionMethods = ImmutableArrayExtensions.WhereAsArray<NamedTypeSymbol>(GetTypeMembersUnordered(), (Func<NamedTypeSymbol, bool>)((NamedTypeSymbol t) => t.MightContainExtensionMethods));
|
|
lazyTypesMightContainExtensionMethods = _lazyTypesMightContainExtensionMethods;
|
|
}
|
|
return lazyTypesMightContainExtensionMethods;
|
|
}
|
|
}
|
|
|
|
internal string QualifiedName => _lazyQualifiedName ?? (_lazyQualifiedName = ToDisplayString(SymbolDisplayFormat.QualifiedNameOnlyFormat));
|
|
|
|
bool INamespaceSymbolInternal.IsGlobalNamespace => IsGlobalNamespace;
|
|
|
|
INamespaceSymbolInternal INamespace.GetInternalSymbol()
|
|
{
|
|
return (INamespaceSymbolInternal)(object)AdaptedNamespaceSymbol;
|
|
}
|
|
|
|
internal new NamespaceSymbol GetCciAdapter()
|
|
{
|
|
return this;
|
|
}
|
|
|
|
public IEnumerable<NamespaceSymbol> GetNamespaceMembers()
|
|
{
|
|
return GetMembers().OfType<NamespaceSymbol>();
|
|
}
|
|
|
|
internal override TResult Accept<TArgument, TResult>(CSharpSymbolVisitor<TArgument, TResult> visitor, TArgument argument)
|
|
{
|
|
return visitor.VisitNamespace(this, argument);
|
|
}
|
|
|
|
public override void Accept(CSharpSymbolVisitor visitor)
|
|
{
|
|
visitor.VisitNamespace(this);
|
|
}
|
|
|
|
public override TResult Accept<TResult>(CSharpSymbolVisitor<TResult> visitor)
|
|
{
|
|
return visitor.VisitNamespace(this);
|
|
}
|
|
|
|
internal NamespaceSymbol()
|
|
{
|
|
}
|
|
|
|
internal NamespaceSymbol LookupNestedNamespace(ImmutableArray<ReadOnlyMemory<char>> names)
|
|
{
|
|
NamespaceSymbol namespaceSymbol = this;
|
|
ImmutableArray<ReadOnlyMemory<char>>.Enumerator enumerator = names.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
ReadOnlyMemory<char> current = enumerator.Current;
|
|
namespaceSymbol = namespaceSymbol.GetNestedNamespace(current);
|
|
if ((object)namespaceSymbol == null)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
return namespaceSymbol;
|
|
}
|
|
|
|
internal NamespaceSymbol GetNestedNamespace(string name)
|
|
{
|
|
return GetNestedNamespace(name.AsMemory());
|
|
}
|
|
|
|
internal NamespaceSymbol GetNestedNamespace(ReadOnlyMemory<char> name)
|
|
{
|
|
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0022: Invalid comparison between Unknown and I4
|
|
ImmutableArray<Symbol>.Enumerator enumerator = GetMembers(name).GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
Symbol current = enumerator.Current;
|
|
if ((int)current.Kind == 12)
|
|
{
|
|
return (NamespaceSymbol)current;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public abstract ImmutableArray<Symbol> GetMembers(ReadOnlyMemory<char> name);
|
|
|
|
public sealed override ImmutableArray<Symbol> GetMembers(string name)
|
|
{
|
|
return GetMembers(name.AsMemory());
|
|
}
|
|
|
|
internal NamespaceSymbol GetNestedNamespace(NameSyntax name)
|
|
{
|
|
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
|
|
SyntaxToken identifier;
|
|
switch (name.Kind())
|
|
{
|
|
case SyntaxKind.IdentifierName:
|
|
case SyntaxKind.GenericName:
|
|
identifier = ((SimpleNameSyntax)name).Identifier;
|
|
return GetNestedNamespace(((SyntaxToken)(ref identifier)).ValueText);
|
|
case SyntaxKind.QualifiedName:
|
|
{
|
|
QualifiedNameSyntax qualifiedNameSyntax = (QualifiedNameSyntax)name;
|
|
NamespaceSymbol nestedNamespace = GetNestedNamespace(qualifiedNameSyntax.Left);
|
|
if ((object)nestedNamespace != null)
|
|
{
|
|
return nestedNamespace.GetNestedNamespace(qualifiedNameSyntax.Right);
|
|
}
|
|
break;
|
|
}
|
|
case SyntaxKind.AliasQualifiedName:
|
|
identifier = name.GetUnqualifiedName().Identifier;
|
|
return GetNestedNamespace(((SyntaxToken)(ref identifier)).ValueText);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
internal virtual void GetExtensionMethods(ArrayBuilder<MethodSymbol> methods, string nameOpt, int arity, LookupOptions options)
|
|
{
|
|
if (ContainingAssembly.MightContainExtensionMethods)
|
|
{
|
|
ImmutableArray<NamedTypeSymbol>.Enumerator enumerator = TypesMightContainExtensionMethods.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
enumerator.Current.DoGetExtensionMethods(methods, nameOpt, arity, options);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected sealed override ISymbol CreateISymbol()
|
|
{
|
|
return (ISymbol)(object)new Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.NamespaceSymbol(this);
|
|
}
|
|
}
|