Files
2026-08-27 10:56:38 -06:00

129 lines
4.9 KiB
C#

using System;
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
internal sealed class SourceLabelSymbol : LabelSymbol
{
private readonly MethodSymbol _containingMethod;
private readonly SyntaxNodeOrToken _identifierNodeOrToken;
private readonly ConstantValue? _switchCaseLabelConstant;
private string? _lazyName;
public override string Name => _lazyName ?? (_lazyName = MakeLabelName());
public override ImmutableArray<Location> Locations
{
get
{
if (!((SyntaxNodeOrToken)(ref _identifierNodeOrToken)).IsToken || ((SyntaxNodeOrToken)(ref _identifierNodeOrToken)).Parent != null)
{
return ImmutableArray.Create<Location>(((SyntaxNodeOrToken)(ref _identifierNodeOrToken)).GetLocation());
}
return ImmutableArray<Location>.Empty;
}
}
public override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences
{
get
{
CSharpSyntaxNode cSharpSyntaxNode = null;
if (((SyntaxNodeOrToken)(ref _identifierNodeOrToken)).IsToken)
{
if (((SyntaxNodeOrToken)(ref _identifierNodeOrToken)).Parent != null)
{
cSharpSyntaxNode = ((SyntaxNodeOrToken)(ref _identifierNodeOrToken)).Parent.FirstAncestorOrSelf<LabeledStatementSyntax>((Func<LabeledStatementSyntax, bool>)null, true);
}
}
else
{
cSharpSyntaxNode = ((SyntaxNodeOrToken)(ref _identifierNodeOrToken)).AsNode().FirstAncestorOrSelf<SwitchLabelSyntax>((Func<SwitchLabelSyntax, bool>)null, true);
}
if (cSharpSyntaxNode != null)
{
return ImmutableArray.Create<SyntaxReference>(cSharpSyntaxNode.GetReference());
}
return ImmutableArray<SyntaxReference>.Empty;
}
}
public override MethodSymbol ContainingMethod => _containingMethod;
public override Symbol ContainingSymbol => _containingMethod;
internal override SyntaxNodeOrToken IdentifierNodeOrToken => _identifierNodeOrToken;
public ConstantValue? SwitchCaseLabelConstant => _switchCaseLabelConstant;
public SourceLabelSymbol(MethodSymbol containingMethod, SyntaxNodeOrToken identifierNodeOrToken, ConstantValue? switchCaseLabelConstant = null)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
_containingMethod = containingMethod;
_identifierNodeOrToken = identifierNodeOrToken;
_switchCaseLabelConstant = switchCaseLabelConstant;
}
private string MakeLabelName()
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
SyntaxNode val = ((SyntaxNodeOrToken)(ref _identifierNodeOrToken)).AsNode();
if (val != null)
{
if (val.Kind() == SyntaxKind.DefaultSwitchLabel)
{
return ((object)((DefaultSwitchLabelSyntax)(object)val).Keyword/*cast due to constrained. prefix*/).ToString();
}
return ((object)val).ToString();
}
SyntaxToken token = ((SyntaxNodeOrToken)(ref _identifierNodeOrToken)).AsToken();
if (token.Kind() != SyntaxKind.None)
{
return ((SyntaxToken)(ref token)).ValueText;
}
return ((object)_switchCaseLabelConstant)?.ToString() ?? "";
}
public SourceLabelSymbol(MethodSymbol containingMethod, ConstantValue switchCaseLabelConstant)
{
//IL_0010: 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)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
_containingMethod = containingMethod;
_identifierNodeOrToken = SyntaxNodeOrToken.op_Implicit(default(SyntaxToken));
_switchCaseLabelConstant = switchCaseLabelConstant;
}
public override bool Equals(Symbol? obj, TypeCompareKind compareKind)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
if ((object)obj == this)
{
return true;
}
if (obj is SourceLabelSymbol sourceLabelSymbol && sourceLabelSymbol._identifierNodeOrToken.Kind() != SyntaxKind.None && ((SyntaxNodeOrToken)(ref sourceLabelSymbol._identifierNodeOrToken)).Equals(_identifierNodeOrToken))
{
return sourceLabelSymbol._containingMethod.Equals(_containingMethod, compareKind);
}
return false;
}
public override int GetHashCode()
{
return ((object)Unsafe.As<SyntaxNodeOrToken, SyntaxNodeOrToken>(ref _identifierNodeOrToken)/*cast due to constrained. prefix*/).GetHashCode();
}
}