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

94 lines
5.1 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 SourceUserDefinedOperatorSymbol : SourceUserDefinedOperatorSymbolBase
{
protected override Location ReturnTypeLocation => ((SyntaxNode)GetSyntax().ReturnType).Location;
internal override bool GenerateDebugInfo => true;
public static SourceUserDefinedOperatorSymbol CreateUserDefinedOperatorSymbol(SourceMemberContainerTypeSymbol containingType, Binder bodyBinder, OperatorDeclarationSyntax syntax, bool isNullableAnalysisEnabled, BindingDiagnosticBag diagnostics)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: 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)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
SyntaxToken val = syntax.OperatorToken;
Location location = ((SyntaxToken)(ref val)).GetLocation();
string text = OperatorFacts.OperatorNameFromDeclaration(syntax);
if (SyntaxFacts.IsCheckedOperator(text))
{
MessageID.IDS_FeatureCheckedUserDefinedOperators.CheckFeatureAvailability(diagnostics, syntax.CheckedKeyword);
}
else
{
val = syntax.OperatorToken;
if (!((SyntaxToken)(ref val)).IsMissing && syntax.CheckedKeyword.IsKind(SyntaxKind.CheckedKeyword))
{
val = syntax.CheckedKeyword;
diagnostics.Add(ErrorCode.ERR_OperatorCantBeChecked, ((SyntaxToken)(ref val)).GetLocation(), SyntaxFacts.GetText(SyntaxFacts.GetOperatorKind(text)));
}
}
if (text == "op_UnsignedRightShift")
{
MessageID.IDS_FeatureUnsignedRightShift.CheckFeatureAvailability(diagnostics, syntax.OperatorToken);
}
ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier = syntax.ExplicitInterfaceSpecifier;
text = ExplicitInterfaceHelpers.GetMemberNameAndInterfaceSymbol(bodyBinder, explicitInterfaceSpecifier, text, diagnostics, out var explicitInterfaceTypeOpt, out var _);
return new SourceUserDefinedOperatorSymbol((MethodKind)((explicitInterfaceSpecifier == null) ? 9 : 8), containingType, explicitInterfaceTypeOpt, text, location, syntax, isNullableAnalysisEnabled, diagnostics);
}
private SourceUserDefinedOperatorSymbol(MethodKind methodKind, SourceMemberContainerTypeSymbol containingType, TypeSymbol explicitInterfaceType, string name, Location location, OperatorDeclarationSyntax syntax, bool isNullableAnalysisEnabled, BindingDiagnosticBag diagnostics)
: base(methodKind, explicitInterfaceType, name, containingType, location, syntax, SourceUserDefinedOperatorSymbolBase.MakeDeclarationModifiers(methodKind, containingType.IsInterface, syntax, location, diagnostics), syntax.HasAnyBody(), syntax.IsExpressionBodied(), SyntaxFacts.HasYieldOperations((SyntaxNode?)(object)syntax.Body), isNullableAnalysisEnabled, diagnostics)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
Symbol.CheckForBlockAndExpressionBody(syntax.Body, syntax.ExpressionBody, syntax, diagnostics);
if (IsAbstract || IsVirtual || (name != "op_Equality" && name != "op_Inequality"))
{
CheckFeatureAvailabilityAndRuntimeSupport((SyntaxNode)(object)syntax, location, syntax.Body != null || syntax.ExpressionBody != null, diagnostics);
}
if (syntax.ExplicitInterfaceSpecifier != null)
{
MessageID.IDS_FeatureStaticAbstractMembersInInterfaces.CheckFeatureAvailability(diagnostics, (SyntaxNode)(object)syntax.ExplicitInterfaceSpecifier);
}
}
internal OperatorDeclarationSyntax GetSyntax()
{
return (OperatorDeclarationSyntax)(object)syntaxReferenceOpt.GetSyntax(default(CancellationToken));
}
internal override ExecutableCodeBinder TryGetBodyBinder(BinderFactory binderFactoryOpt = null, bool ignoreAccessibility = false)
{
return TryGetBodyBinderFromSyntax(binderFactoryOpt, ignoreAccessibility);
}
protected override int GetParameterCountFromSyntax()
{
return GetSyntax().ParameterList.ParameterCount;
}
internal sealed 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);
}
protected override (TypeWithAnnotations ReturnType, ImmutableArray<ParameterSymbol> Parameters) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics)
{
OperatorDeclarationSyntax syntax = GetSyntax();
return MakeParametersAndBindReturnType(syntax, syntax.ReturnType, diagnostics);
}
}