143 lines
6.5 KiB
C#
143 lines
6.5 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 SourceDestructorSymbol : SourceMemberMethodSymbol
|
||
|
|
{
|
||
|
|
private TypeWithAnnotations _lazyReturnType;
|
||
|
|
|
||
|
|
internal override int ParameterCount => 0;
|
||
|
|
|
||
|
|
public override ImmutableArray<ParameterSymbol> Parameters => ImmutableArray<ParameterSymbol>.Empty;
|
||
|
|
|
||
|
|
public override ImmutableArray<TypeParameterSymbol> TypeParameters => ImmutableArray<TypeParameterSymbol>.Empty;
|
||
|
|
|
||
|
|
public override TypeWithAnnotations ReturnTypeWithAnnotations
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
LazyMethodChecks();
|
||
|
|
return _lazyReturnType;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public override string Name => "Finalize";
|
||
|
|
|
||
|
|
internal override bool IsMetadataFinal => false;
|
||
|
|
|
||
|
|
internal override bool GenerateDebugInfo => true;
|
||
|
|
|
||
|
|
internal SourceDestructorSymbol(SourceMemberContainerTypeSymbol containingType, DestructorDeclarationSyntax syntax, bool isNullableAnalysisEnabled, BindingDiagnosticBag diagnostics)
|
||
|
|
: base(containingType, syntax.GetReference(), GetSymbolLocation(syntax, out var location), SyntaxFacts.HasYieldOperations((SyntaxNode?)(object)syntax.Body), MakeModifiersAndFlags(containingType, syntax, isNullableAnalysisEnabled, location, diagnostics, out var modifierErrors))
|
||
|
|
{
|
||
|
|
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
this.CheckUnsafeModifier(DeclarationModifiers, diagnostics);
|
||
|
|
bool flag = syntax.Body != null;
|
||
|
|
bool isExpressionBodied = base.IsExpressionBodied;
|
||
|
|
SyntaxToken identifier = syntax.Identifier;
|
||
|
|
if (((SyntaxToken)(ref identifier)).ValueText != containingType.Name)
|
||
|
|
{
|
||
|
|
identifier = syntax.Identifier;
|
||
|
|
diagnostics.Add(ErrorCode.ERR_BadDestructorName, ((SyntaxToken)(ref identifier)).GetLocation());
|
||
|
|
}
|
||
|
|
if ((flag || isExpressionBodied) && IsExtern)
|
||
|
|
{
|
||
|
|
diagnostics.Add(ErrorCode.ERR_ExternHasBody, location, this);
|
||
|
|
}
|
||
|
|
if (!modifierErrors && !flag && !isExpressionBodied && !IsExtern)
|
||
|
|
{
|
||
|
|
diagnostics.Add(ErrorCode.ERR_ConcreteMissingBody, location, this);
|
||
|
|
}
|
||
|
|
if (containingType.IsStatic)
|
||
|
|
{
|
||
|
|
diagnostics.Add(ErrorCode.ERR_DestructorInStaticClass, location);
|
||
|
|
}
|
||
|
|
else if (!containingType.IsReferenceType)
|
||
|
|
{
|
||
|
|
diagnostics.Add(ErrorCode.ERR_OnlyClassesCanContainDestructors, location);
|
||
|
|
}
|
||
|
|
Symbol.CheckForBlockAndExpressionBody(syntax.Body, syntax.ExpressionBody, syntax, diagnostics);
|
||
|
|
}
|
||
|
|
|
||
|
|
private static (DeclarationModifiers, Flags) MakeModifiersAndFlags(NamedTypeSymbol containingType, DestructorDeclarationSyntax syntax, bool isNullableAnalysisEnabled, Location location, BindingDiagnosticBag diagnostics, out bool modifierErrors)
|
||
|
|
{
|
||
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
DeclarationModifiers declarationModifiers = MakeModifiers(containingType, syntax.Modifiers, location, diagnostics, out modifierErrors);
|
||
|
|
Flags item = SourceMemberMethodSymbol.MakeFlags((MethodKind)4, (RefKind)0, declarationModifiers, returnsVoid: true, returnsVoidIsSet: true, syntax.IsExpressionBodied(), isExtensionMethod: false, isNullableAnalysisEnabled, isVarArg: false, isExplicitInterfaceImplementation: false);
|
||
|
|
return (declarationModifiers, item);
|
||
|
|
}
|
||
|
|
|
||
|
|
private static Location GetSymbolLocation(DestructorDeclarationSyntax syntax, out Location location)
|
||
|
|
{
|
||
|
|
//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)
|
||
|
|
SyntaxToken identifier = syntax.Identifier;
|
||
|
|
location = ((SyntaxToken)(ref identifier)).GetLocation();
|
||
|
|
return location;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override void MethodChecks(BindingDiagnosticBag diagnostics)
|
||
|
|
{
|
||
|
|
DestructorDeclarationSyntax syntax = GetSyntax();
|
||
|
|
Binder binder = DeclaringCompilation.GetBinderFactory(syntaxReferenceOpt.SyntaxTree).GetBinder((SyntaxNode)(object)syntax, syntax, this);
|
||
|
|
_lazyReturnType = TypeWithAnnotations.Create(binder.GetSpecialType((SpecialType)6, diagnostics, (SyntaxNode)(object)syntax));
|
||
|
|
}
|
||
|
|
|
||
|
|
internal DestructorDeclarationSyntax GetSyntax()
|
||
|
|
{
|
||
|
|
return (DestructorDeclarationSyntax)(object)syntaxReferenceOpt.GetSyntax(default(CancellationToken));
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override ExecutableCodeBinder TryGetBodyBinder(BinderFactory binderFactoryOpt = null, bool ignoreAccessibility = false)
|
||
|
|
{
|
||
|
|
return TryGetBodyBinderFromSyntax(binderFactoryOpt, ignoreAccessibility);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override ImmutableArray<ImmutableArray<TypeWithAnnotations>> GetTypeParameterConstraintTypes()
|
||
|
|
{
|
||
|
|
return ImmutableArray<ImmutableArray<TypeWithAnnotations>>.Empty;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override ImmutableArray<TypeParameterConstraintKind> GetTypeParameterConstraintKinds()
|
||
|
|
{
|
||
|
|
return ImmutableArray<TypeParameterConstraintKind>.Empty;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static DeclarationModifiers MakeModifiers(NamedTypeSymbol containingType, SyntaxTokenList modifiers, Location location, BindingDiagnosticBag diagnostics, out bool modifierErrors)
|
||
|
|
{
|
||
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
return (DeclarationModifiers)(((uint)ModifierUtils.MakeAndCheckNonTypeMemberModifiers(isOrdinaryMethod: false, containingType.IsInterface, modifiers, DeclarationModifiers.None, DeclarationModifiers.Extern | DeclarationModifiers.Unsafe, location, diagnostics, out modifierErrors) & 0xFFFFFC0Fu) | 0x20);
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override OneOrMany<SyntaxList<AttributeListSyntax>> GetAttributeDeclarations()
|
||
|
|
{
|
||
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
return OneOrMany.Create<SyntaxList<AttributeListSyntax>>(GetSyntax().AttributeLists);
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override OneOrMany<SyntaxList<AttributeListSyntax>> GetReturnTypeAttributeDeclarations()
|
||
|
|
{
|
||
|
|
//IL_0002: 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_0009: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
return OneOrMany.Create<SyntaxList<AttributeListSyntax>>(default(SyntaxList<AttributeListSyntax>));
|
||
|
|
}
|
||
|
|
|
||
|
|
internal sealed override bool IsMetadataVirtual(bool ignoreInterfaceImplementationChanges = false)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal sealed override bool IsMetadataNewSlot(bool ignoreInterfaceImplementationChanges = false)
|
||
|
|
{
|
||
|
|
return (object)ContainingType.BaseTypeNoUseSiteDiagnostics == null;
|
||
|
|
}
|
||
|
|
}
|