57 lines
3.1 KiB
C#
57 lines
3.1 KiB
C#
using System;
|
|||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Collections.Immutable;
|
||
|
|
using System.Linq;
|
||
|
|
using Microsoft.CodeAnalysis.PooledObjects;
|
||
|
|
|
||
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
||
|
|
|
||
|
|
internal sealed class SynthesizedEmbeddedNativeIntegerAttributeSymbol : SynthesizedEmbeddedAttributeSymbolBase
|
||
|
|
{
|
||
|
|
private readonly ImmutableArray<FieldSymbol> _fields;
|
||
|
|
|
||
|
|
private readonly ImmutableArray<MethodSymbol> _constructors;
|
||
|
|
|
||
|
|
private readonly TypeSymbol _boolType;
|
||
|
|
|
||
|
|
private const string FieldName = "TransformFlags";
|
||
|
|
|
||
|
|
public override ImmutableArray<MethodSymbol> Constructors => _constructors;
|
||
|
|
|
||
|
|
public SynthesizedEmbeddedNativeIntegerAttributeSymbol(string name, NamespaceSymbol containingNamespace, ModuleSymbol containingModule, NamedTypeSymbol systemAttributeType, TypeSymbol boolType)
|
||
|
|
: base(name, containingNamespace, containingModule, systemAttributeType)
|
||
|
|
{
|
||
|
|
_boolType = boolType;
|
||
|
|
TypeWithAnnotations boolArrayType = TypeWithAnnotations.Create(ArrayTypeSymbol.CreateSZArray(boolType.ContainingAssembly, TypeWithAnnotations.Create(boolType)));
|
||
|
|
_fields = ImmutableArray.Create((FieldSymbol)new SynthesizedFieldSymbol(this, boolArrayType.Type, "TransformFlags", isPublic: true, isReadOnly: true));
|
||
|
|
_constructors = ImmutableArray.Create((MethodSymbol)new SynthesizedEmbeddedAttributeConstructorWithBodySymbol(this, (MethodSymbol m) => ImmutableArray<ParameterSymbol>.Empty, delegate(SyntheticBoundNodeFactory f, ArrayBuilder<BoundStatement> s, ImmutableArray<ParameterSymbol> p)
|
||
|
|
{
|
||
|
|
GenerateParameterlessConstructorBody(f, s);
|
||
|
|
}), (MethodSymbol)new SynthesizedEmbeddedAttributeConstructorWithBodySymbol(this, (MethodSymbol m) => ImmutableArray.Create(SynthesizedParameterSymbol.Create(m, boolArrayType, 0, (RefKind)0, "", (ScopedKind)0)), delegate(SyntheticBoundNodeFactory f, ArrayBuilder<BoundStatement> s, ImmutableArray<ParameterSymbol> p)
|
||
|
|
{
|
||
|
|
GenerateBoolArrayConstructorBody(f, s, p);
|
||
|
|
}));
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override IEnumerable<FieldSymbol> GetFieldsToEmit()
|
||
|
|
{
|
||
|
|
return _fields;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override AttributeUsageInfo GetAttributeUsageInfo()
|
||
|
|
{
|
||
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
return new AttributeUsageInfo(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, false, false);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void GenerateParameterlessConstructorBody(SyntheticBoundNodeFactory factory, ArrayBuilder<BoundStatement> statements)
|
||
|
|
{
|
||
|
|
statements.Add((BoundStatement)factory.ExpressionStatement(factory.AssignmentExpression(factory.Field(factory.This(), _fields.Single()), factory.Array(_boolType, ImmutableArray.Create((BoundExpression)factory.Literal(value: true))))));
|
||
|
|
}
|
||
|
|
|
||
|
|
private void GenerateBoolArrayConstructorBody(SyntheticBoundNodeFactory factory, ArrayBuilder<BoundStatement> statements, ImmutableArray<ParameterSymbol> parameters)
|
||
|
|
{
|
||
|
|
statements.Add((BoundStatement)factory.ExpressionStatement(factory.AssignmentExpression(factory.Field(factory.This(), _fields.Single()), factory.Parameter(parameters.Single()))));
|
||
|
|
}
|
||
|
|
}
|