138 lines
6.7 KiB
C#
138 lines
6.7 KiB
C#
using System.Collections.Immutable;
|
|
using System.Threading;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
using Roslyn.Utilities;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
|
|
internal sealed class AliasSymbolFromSyntax : AliasSymbol
|
|
{
|
|
private readonly SyntaxReference _directive;
|
|
|
|
private SymbolCompletionState _state;
|
|
|
|
private NamespaceOrTypeSymbol? _aliasTarget;
|
|
|
|
private BindingDiagnosticBag? _aliasTargetDiagnostics;
|
|
|
|
public override NamespaceOrTypeSymbol Target => GetAliasTarget(null);
|
|
|
|
internal BindingDiagnosticBag AliasTargetDiagnostics
|
|
{
|
|
get
|
|
{
|
|
GetAliasTarget(null);
|
|
return _aliasTargetDiagnostics;
|
|
}
|
|
}
|
|
|
|
internal override bool RequiresCompletion => true;
|
|
|
|
internal AliasSymbolFromSyntax(SourceNamespaceSymbol containingSymbol, UsingDirectiveSyntax syntax)
|
|
{
|
|
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
|
|
SyntaxToken identifier = syntax.Alias.Name.Identifier;
|
|
string valueText = ((SyntaxToken)(ref identifier)).ValueText;
|
|
identifier = syntax.Alias.Name.Identifier;
|
|
base._002Ector(valueText, containingSymbol, ImmutableArray.Create<Location>(((SyntaxToken)(ref identifier)).GetLocation()), isExtern: false);
|
|
_directive = syntax.GetReference();
|
|
}
|
|
|
|
internal AliasSymbolFromSyntax(SourceNamespaceSymbol containingSymbol, ExternAliasDirectiveSyntax syntax)
|
|
{
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
|
|
SyntaxToken identifier = syntax.Identifier;
|
|
string valueText = ((SyntaxToken)(ref identifier)).ValueText;
|
|
identifier = syntax.Identifier;
|
|
base._002Ector(valueText, containingSymbol, ImmutableArray.Create<Location>(((SyntaxToken)(ref identifier)).GetLocation()), isExtern: true);
|
|
_directive = syntax.GetReference();
|
|
}
|
|
|
|
internal override NamespaceOrTypeSymbol GetAliasTarget(ConsList<TypeSymbol>? basesBeingResolved)
|
|
{
|
|
if (!_state.HasComplete(CompletionPart.StartBaseType))
|
|
{
|
|
BindingDiagnosticBag instance = BindingDiagnosticBag.GetInstance();
|
|
NamespaceOrTypeSymbol value = (IsExtern ? ResolveExternAliasTarget(instance) : ResolveAliasTarget((UsingDirectiveSyntax)(object)_directive.GetSyntax(default(CancellationToken)), instance, basesBeingResolved));
|
|
if ((object)Interlocked.CompareExchange(ref _aliasTarget, value, null) == null)
|
|
{
|
|
Interlocked.Exchange(ref _aliasTargetDiagnostics, instance);
|
|
_state.NotePartComplete(CompletionPart.StartBaseType);
|
|
}
|
|
else
|
|
{
|
|
((BindingDiagnosticBag<AssemblySymbol>)(object)instance).Free();
|
|
_state.SpinWaitComplete(CompletionPart.StartBaseType, default(CancellationToken));
|
|
}
|
|
}
|
|
return _aliasTarget;
|
|
}
|
|
|
|
private NamespaceSymbol ResolveExternAliasTarget(BindingDiagnosticBag diagnostics)
|
|
{
|
|
if (!ContainingSymbol.DeclaringCompilation.GetExternAliasTarget(Name, out NamespaceSymbol @namespace))
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_BadExternAlias, GetFirstLocation(), Name);
|
|
}
|
|
return @namespace;
|
|
}
|
|
|
|
private NamespaceOrTypeSymbol ResolveAliasTarget(UsingDirectiveSyntax usingDirective, BindingDiagnosticBag diagnostics, ConsList<TypeSymbol>? basesBeingResolved)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0063: 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)
|
|
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
|
|
SyntaxToken unsafeKeyword = usingDirective.UnsafeKeyword;
|
|
SyntaxToken val = default(SyntaxToken);
|
|
if (unsafeKeyword != val)
|
|
{
|
|
MessageID.IDS_FeatureUsingTypeAlias.CheckFeatureAvailability(diagnostics, usingDirective.UnsafeKeyword);
|
|
}
|
|
else if (!(usingDirective.NamespaceOrType is NameSyntax))
|
|
{
|
|
MessageID.IDS_FeatureUsingTypeAlias.CheckFeatureAvailability(diagnostics, (SyntaxNode)(object)usingDirective.NamespaceOrType);
|
|
}
|
|
TypeSyntax namespaceOrType = usingDirective.NamespaceOrType;
|
|
BinderFlags binderFlags = BinderFlags.SuppressConstraintChecks | BinderFlags.SuppressObsoleteChecks;
|
|
SyntaxToken unsafeKeyword2 = usingDirective.UnsafeKeyword;
|
|
val = default(SyntaxToken);
|
|
if (unsafeKeyword2 != val)
|
|
{
|
|
val = usingDirective.UnsafeKeyword;
|
|
this.CheckUnsafeModifier(DeclarationModifiers.Unsafe, ((SyntaxToken)(ref val)).GetLocation(), diagnostics);
|
|
binderFlags |= BinderFlags.UnsafeRegion;
|
|
}
|
|
else if (!DeclaringCompilation.IsFeatureEnabled(MessageID.IDS_FeatureUsingTypeAlias))
|
|
{
|
|
binderFlags |= BinderFlags.UnsafeRegion;
|
|
}
|
|
Binder.NamespaceOrTypeOrAliasSymbolWithAnnotations namespaceOrTypeOrAliasSymbolWithAnnotations = ContainingSymbol.DeclaringCompilation.GetBinderFactory(namespaceOrType.SyntaxTree).GetBinder((SyntaxNode)(object)namespaceOrType).WithAdditionalFlags(binderFlags)
|
|
.BindNamespaceOrTypeSymbol(namespaceOrType, diagnostics, basesBeingResolved);
|
|
if (usingDirective.NamespaceOrType is NullableTypeSyntax nullableTypeSyntax && namespaceOrTypeOrAliasSymbolWithAnnotations.TypeWithAnnotations.NullableAnnotation == NullableAnnotation.Annotated && (namespaceOrTypeOrAliasSymbolWithAnnotations.TypeWithAnnotations.Type?.IsReferenceType ?? false))
|
|
{
|
|
val = nullableTypeSyntax.QuestionToken;
|
|
diagnostics.Add(ErrorCode.ERR_BadNullableReferenceTypeInUsingAlias, ((SyntaxToken)(ref val)).GetLocation());
|
|
}
|
|
NamespaceOrTypeSymbol namespaceOrTypeSymbol = namespaceOrTypeOrAliasSymbolWithAnnotations.NamespaceOrTypeSymbol;
|
|
if (namespaceOrTypeSymbol is TypeSymbol { IsNativeIntegerWrapperType: not false } && (usingDirective.NamespaceOrType.IsNint || usingDirective.NamespaceOrType.IsNuint))
|
|
{
|
|
MessageID.IDS_FeatureUsingTypeAlias.CheckFeatureAvailability(diagnostics, (SyntaxNode)(object)usingDirective.NamespaceOrType);
|
|
}
|
|
return namespaceOrTypeSymbol;
|
|
}
|
|
}
|