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

32 lines
2.3 KiB
C#

using System.Collections.Immutable;
using Microsoft.CodeAnalysis.CodeGen;
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
internal sealed class SynthesizedInlineArrayAsReadOnlySpanMethod : SynthesizedGlobalMethodSymbol
{
internal SynthesizedInlineArrayAsReadOnlySpanMethod(SourceModuleSymbol containingModule, PrivateImplementationDetails privateImplType, string synthesizedMethodName, NamedTypeSymbol spanType, NamedTypeSymbol intType)
: base(containingModule, privateImplType, synthesizedMethodName)
{
SetTypeParameters(ImmutableArray.Create((TypeParameterSymbol)new SynthesizedSimpleMethodTypeParameterSymbol(this, 0, "TBuffer"), (TypeParameterSymbol)new SynthesizedSimpleMethodTypeParameterSymbol(this, 1, "TElement")));
SetReturnType(spanType.Construct(TypeParameters[1]));
SetParameters(ImmutableArray.Create(SynthesizedParameterSymbol.Create(this, TypeWithAnnotations.Create(TypeParameters[0]), 0, (RefKind)3, "buffer", (ScopedKind)0), SynthesizedParameterSymbol.Create(this, TypeWithAnnotations.Create(intType), 1, (RefKind)0, "length", (ScopedKind)0)));
}
internal override void GenerateMethodBody(TypeCompilationState compilationState, BindingDiagnosticBag diagnostics)
{
SyntheticBoundNodeFactory syntheticBoundNodeFactory = new SyntheticBoundNodeFactory(this, (SyntaxNode)(object)this.GetNonNullSyntaxNode(), compilationState, diagnostics);
syntheticBoundNodeFactory.CurrentFunction = this;
try
{
BoundReturnStatement body = syntheticBoundNodeFactory.Return(syntheticBoundNodeFactory.Call(null, syntheticBoundNodeFactory.WellKnownMethod((WellKnownMember)100).Construct(TypeParameters[1]), syntheticBoundNodeFactory.Call(null, syntheticBoundNodeFactory.WellKnownMethod((WellKnownMember)130).Construct(ImmutableArray<TypeSymbol>.CastUp(TypeParameters)), syntheticBoundNodeFactory.Call(null, syntheticBoundNodeFactory.WellKnownMethod((WellKnownMember)131).Construct(TypeParameters[0]), syntheticBoundNodeFactory.Parameter(Parameters[0]))), syntheticBoundNodeFactory.Parameter(Parameters[1])));
syntheticBoundNodeFactory.CloseMethod(body);
}
catch (SyntheticBoundNodeFactory.MissingPredefinedMember missingPredefinedMember)
{
((BindingDiagnosticBag)diagnostics).Add(missingPredefinedMember.Diagnostic);
syntheticBoundNodeFactory.CloseMethod(syntheticBoundNodeFactory.ThrowNull());
}
}
}