32 lines
2.1 KiB
C#
32 lines
2.1 KiB
C#
using System.Collections.Immutable;
|
|
using Microsoft.CodeAnalysis.CodeGen;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
|
|
internal sealed class SynthesizedInlineArrayAsSpanMethod : SynthesizedGlobalMethodSymbol
|
|
{
|
|
internal SynthesizedInlineArrayAsSpanMethod(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)1, "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)99).Construct(TypeParameters[1]), syntheticBoundNodeFactory.Call(null, syntheticBoundNodeFactory.WellKnownMethod((WellKnownMember)130).Construct(ImmutableArray<TypeSymbol>.CastUp(TypeParameters)), syntheticBoundNodeFactory.Parameter(Parameters[0])), syntheticBoundNodeFactory.Parameter(Parameters[1])));
|
|
syntheticBoundNodeFactory.CloseMethod(body);
|
|
}
|
|
catch (SyntheticBoundNodeFactory.MissingPredefinedMember missingPredefinedMember)
|
|
{
|
|
((BindingDiagnosticBag)diagnostics).Add(missingPredefinedMember.Diagnostic);
|
|
syntheticBoundNodeFactory.CloseMethod(syntheticBoundNodeFactory.ThrowNull());
|
|
}
|
|
}
|
|
}
|