143 lines
4.4 KiB
C#
143 lines
4.4 KiB
C#
using System.Collections.Immutable;
|
|||
|
|
using Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel;
|
||
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||
|
|
using Roslyn.Utilities;
|
||
|
|
|
||
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
||
|
|
|
||
|
|
internal abstract class AliasSymbol : Symbol
|
||
|
|
{
|
||
|
|
private readonly ImmutableArray<Location> _locations;
|
||
|
|
|
||
|
|
private readonly string _aliasName;
|
||
|
|
|
||
|
|
private readonly bool _isExtern;
|
||
|
|
|
||
|
|
private readonly Symbol _containingSymbol;
|
||
|
|
|
||
|
|
public sealed override string Name => _aliasName;
|
||
|
|
|
||
|
|
public override SymbolKind Kind => (SymbolKind)0;
|
||
|
|
|
||
|
|
public abstract NamespaceOrTypeSymbol Target { get; }
|
||
|
|
|
||
|
|
public override ImmutableArray<Location> Locations => _locations;
|
||
|
|
|
||
|
|
public override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
if (!_isExtern)
|
||
|
|
{
|
||
|
|
return Symbol.GetDeclaringSyntaxReferenceHelper<UsingDirectiveSyntax>(_locations);
|
||
|
|
}
|
||
|
|
return Symbol.GetDeclaringSyntaxReferenceHelper<ExternAliasDirectiveSyntax>(_locations);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public sealed override bool IsExtern => _isExtern;
|
||
|
|
|
||
|
|
public override bool IsSealed => false;
|
||
|
|
|
||
|
|
public override bool IsAbstract => false;
|
||
|
|
|
||
|
|
public override bool IsOverride => false;
|
||
|
|
|
||
|
|
public override bool IsVirtual => false;
|
||
|
|
|
||
|
|
public override bool IsStatic => false;
|
||
|
|
|
||
|
|
internal sealed override ObsoleteAttributeData? ObsoleteAttributeData => null;
|
||
|
|
|
||
|
|
public override Accessibility DeclaredAccessibility => (Accessibility)0;
|
||
|
|
|
||
|
|
public sealed override Symbol ContainingSymbol => _containingSymbol;
|
||
|
|
|
||
|
|
internal abstract override bool RequiresCompletion { get; }
|
||
|
|
|
||
|
|
protected AliasSymbol(string aliasName, Symbol containingSymbol, ImmutableArray<Location> locations, bool isExtern)
|
||
|
|
{
|
||
|
|
_locations = locations;
|
||
|
|
_aliasName = aliasName;
|
||
|
|
_isExtern = isExtern;
|
||
|
|
_containingSymbol = containingSymbol;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal static AliasSymbol CreateGlobalNamespaceAlias(NamespaceSymbol globalNamespace)
|
||
|
|
{
|
||
|
|
return new AliasSymbolFromResolvedTarget(globalNamespace, "global", globalNamespace, ImmutableArray<Location>.Empty, isExtern: false);
|
||
|
|
}
|
||
|
|
|
||
|
|
internal static AliasSymbol CreateCustomDebugInfoAlias(NamespaceOrTypeSymbol targetSymbol, SyntaxToken aliasToken, Symbol containingSymbol, bool isExtern)
|
||
|
|
{
|
||
|
|
return new AliasSymbolFromResolvedTarget(targetSymbol, ((SyntaxToken)(ref aliasToken)).ValueText, containingSymbol, ImmutableArray.Create<Location>(((SyntaxToken)(ref aliasToken)).GetLocation()), isExtern);
|
||
|
|
}
|
||
|
|
|
||
|
|
internal AliasSymbol ToNewSubmission(CSharpCompilation compilation)
|
||
|
|
{
|
||
|
|
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_000f: Invalid comparison between Unknown and I4
|
||
|
|
NamespaceOrTypeSymbol target = Target;
|
||
|
|
if ((int)target.Kind != 12)
|
||
|
|
{
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
NamespaceSymbol globalNamespace = compilation.GlobalNamespace;
|
||
|
|
return new AliasSymbolFromResolvedTarget(Imports.ExpandPreviousSubmissionNamespace((NamespaceSymbol)target, globalNamespace), Name, ContainingSymbol, _locations, _isExtern);
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override TResult Accept<TArg, TResult>(CSharpSymbolVisitor<TArg, TResult> visitor, TArg a)
|
||
|
|
{
|
||
|
|
return visitor.VisitAlias(this, a);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void Accept(CSharpSymbolVisitor visitor)
|
||
|
|
{
|
||
|
|
visitor.VisitAlias(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override TResult Accept<TResult>(CSharpSymbolVisitor<TResult> visitor)
|
||
|
|
{
|
||
|
|
return visitor.VisitAlias(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
internal abstract NamespaceOrTypeSymbol GetAliasTarget(ConsList<TypeSymbol>? basesBeingResolved);
|
||
|
|
|
||
|
|
internal void CheckConstraints(BindingDiagnosticBag diagnostics)
|
||
|
|
{
|
||
|
|
if (Target is TypeSymbol type && Locations.Length > 0)
|
||
|
|
{
|
||
|
|
TypeConversions typeConversions = ContainingAssembly.CorLibrary.TypeConversions;
|
||
|
|
type.CheckAllConstraints(DeclaringCompilation, typeConversions, GetFirstLocation(), diagnostics);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public override bool Equals(Symbol? obj, TypeCompareKind compareKind)
|
||
|
|
{
|
||
|
|
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if ((object)this == obj)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if ((object)obj == null)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (obj is AliasSymbol aliasSymbol && object.Equals(TryGetFirstLocation(), aliasSymbol.TryGetFirstLocation()))
|
||
|
|
{
|
||
|
|
return Symbol.Equals(ContainingSymbol, aliasSymbol.ContainingSymbol, compareKind);
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override int GetHashCode()
|
||
|
|
{
|
||
|
|
return ((object)TryGetFirstLocation())?.GetHashCode() ?? Name.GetHashCode();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override ISymbol CreateISymbol()
|
||
|
|
{
|
||
|
|
return (ISymbol)(object)new Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.AliasSymbol(this);
|
||
|
|
}
|
||
|
|
}
|