453 lines
25 KiB
C#
453 lines
25 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using Microsoft.Cci;
|
|
using Microsoft.CodeAnalysis.CSharp.Emit.NoPia;
|
|
using Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
using Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE;
|
|
using Microsoft.CodeAnalysis.Emit;
|
|
using Microsoft.CodeAnalysis.PooledObjects;
|
|
using Microsoft.CodeAnalysis.Symbols;
|
|
using Roslyn.Utilities;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Emit;
|
|
|
|
internal abstract class PEAssemblyBuilderBase : PEModuleBuilder, IAssemblyReference, IModuleReference, IUnitReference, IReference, INamedEntity
|
|
{
|
|
private readonly SourceAssemblySymbol _sourceAssembly;
|
|
|
|
private readonly ImmutableArray<NamedTypeSymbol> _additionalTypes;
|
|
|
|
private ImmutableArray<IFileReference> _lazyFiles;
|
|
|
|
private ImmutableArray<IFileReference> _lazyFilesWithoutManifestResources;
|
|
|
|
private SynthesizedEmbeddedAttributeSymbol _lazyEmbeddedAttribute;
|
|
|
|
private SynthesizedEmbeddedAttributeSymbol _lazyIsReadOnlyAttribute;
|
|
|
|
private SynthesizedEmbeddedAttributeSymbol _lazyRequiresLocationAttribute;
|
|
|
|
private SynthesizedEmbeddedAttributeSymbol _lazyIsByRefLikeAttribute;
|
|
|
|
private SynthesizedEmbeddedAttributeSymbol _lazyIsUnmanagedAttribute;
|
|
|
|
private SynthesizedEmbeddedNullableAttributeSymbol _lazyNullableAttribute;
|
|
|
|
private SynthesizedEmbeddedNullableContextAttributeSymbol _lazyNullableContextAttribute;
|
|
|
|
private SynthesizedEmbeddedNullablePublicOnlyAttributeSymbol _lazyNullablePublicOnlyAttribute;
|
|
|
|
private SynthesizedEmbeddedNativeIntegerAttributeSymbol _lazyNativeIntegerAttribute;
|
|
|
|
private SynthesizedEmbeddedScopedRefAttributeSymbol _lazyScopedRefAttribute;
|
|
|
|
private SynthesizedEmbeddedRefSafetyRulesAttributeSymbol _lazyRefSafetyRulesAttribute;
|
|
|
|
private readonly string _metadataName;
|
|
|
|
public sealed override ISourceAssemblySymbolInternal SourceAssemblyOpt => (ISourceAssemblySymbolInternal)(object)_sourceAssembly;
|
|
|
|
public override string Name => _metadataName;
|
|
|
|
public AssemblyIdentity Identity => _sourceAssembly.Identity;
|
|
|
|
public Version AssemblyVersionPattern => _sourceAssembly.AssemblyVersionPattern;
|
|
|
|
public PEAssemblyBuilderBase(SourceAssemblySymbol sourceAssembly, EmitOptions emitOptions, OutputKind outputKind, ModulePropertiesForSerialization serializationProperties, IEnumerable<ResourceDescription> manifestResources, ImmutableArray<NamedTypeSymbol> additionalTypes)
|
|
: base((SourceModuleSymbol)sourceAssembly.Modules[0], emitOptions, outputKind, serializationProperties, manifestResources)
|
|
{
|
|
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
|
|
_sourceAssembly = sourceAssembly;
|
|
_additionalTypes = ImmutableArrayExtensions.NullToEmpty<NamedTypeSymbol>(additionalTypes);
|
|
_metadataName = ((emitOptions.OutputNameOverride == null) ? sourceAssembly.MetadataName : FileNameUtilities.ChangeExtension(emitOptions.OutputNameOverride, (string)null));
|
|
ConcurrentDictionaryExtensions.Add<Symbol, IModuleReference>(AssemblyOrModuleSymbolToModuleRefMap, (Symbol)sourceAssembly, (IModuleReference)(object)this);
|
|
}
|
|
|
|
public sealed override ImmutableArray<NamedTypeSymbol> GetAdditionalTopLevelTypes()
|
|
{
|
|
return _additionalTypes;
|
|
}
|
|
|
|
internal sealed override ImmutableArray<NamedTypeSymbol> GetEmbeddedTypes(BindingDiagnosticBag diagnostics)
|
|
{
|
|
ArrayBuilder<NamedTypeSymbol> instance = ArrayBuilder<NamedTypeSymbol>.GetInstance();
|
|
CreateEmbeddedAttributesIfNeeded(diagnostics);
|
|
ArrayBuilderExtensions.AddIfNotNull<NamedTypeSymbol>(instance, (NamedTypeSymbol)_lazyEmbeddedAttribute);
|
|
ArrayBuilderExtensions.AddIfNotNull<NamedTypeSymbol>(instance, (NamedTypeSymbol)_lazyIsReadOnlyAttribute);
|
|
ArrayBuilderExtensions.AddIfNotNull<NamedTypeSymbol>(instance, (NamedTypeSymbol)_lazyRequiresLocationAttribute);
|
|
ArrayBuilderExtensions.AddIfNotNull<NamedTypeSymbol>(instance, (NamedTypeSymbol)_lazyIsUnmanagedAttribute);
|
|
ArrayBuilderExtensions.AddIfNotNull<NamedTypeSymbol>(instance, (NamedTypeSymbol)_lazyIsByRefLikeAttribute);
|
|
ArrayBuilderExtensions.AddIfNotNull<NamedTypeSymbol>(instance, (NamedTypeSymbol)_lazyNullableAttribute);
|
|
ArrayBuilderExtensions.AddIfNotNull<NamedTypeSymbol>(instance, (NamedTypeSymbol)_lazyNullableContextAttribute);
|
|
ArrayBuilderExtensions.AddIfNotNull<NamedTypeSymbol>(instance, (NamedTypeSymbol)_lazyNullablePublicOnlyAttribute);
|
|
ArrayBuilderExtensions.AddIfNotNull<NamedTypeSymbol>(instance, (NamedTypeSymbol)_lazyNativeIntegerAttribute);
|
|
ArrayBuilderExtensions.AddIfNotNull<NamedTypeSymbol>(instance, (NamedTypeSymbol)_lazyScopedRefAttribute);
|
|
ArrayBuilderExtensions.AddIfNotNull<NamedTypeSymbol>(instance, (NamedTypeSymbol)_lazyRefSafetyRulesAttribute);
|
|
return instance.ToImmutableAndFree();
|
|
}
|
|
|
|
public sealed override IEnumerable<IFileReference> GetFiles(EmitContext context)
|
|
{
|
|
//IL_000a: 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)
|
|
if (!((EmitContext)(ref context)).IsRefAssembly)
|
|
{
|
|
return getFiles(ref _lazyFiles);
|
|
}
|
|
return getFiles(ref _lazyFilesWithoutManifestResources);
|
|
ImmutableArray<IFileReference> getFiles(ref ImmutableArray<IFileReference> lazyFiles)
|
|
{
|
|
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0045: Expected O, but got Unknown
|
|
if (lazyFiles.IsDefault)
|
|
{
|
|
ArrayBuilder<IFileReference> instance = ArrayBuilder<IFileReference>.GetInstance();
|
|
try
|
|
{
|
|
ImmutableArray<ModuleSymbol> modules = _sourceAssembly.Modules;
|
|
for (int i = 1; i < modules.Length; i++)
|
|
{
|
|
instance.Add((IFileReference)Translate(modules[i], context.Diagnostics));
|
|
}
|
|
if (!((EmitContext)(ref context)).IsRefAssembly)
|
|
{
|
|
foreach (ResourceDescription manifestResource in ((CommonPEModuleBuilder)this).ManifestResources)
|
|
{
|
|
if (!manifestResource.IsEmbedded)
|
|
{
|
|
instance.Add((IFileReference)(object)manifestResource);
|
|
}
|
|
}
|
|
}
|
|
if (ImmutableInterlocked.InterlockedInitialize(ref lazyFiles, instance.ToImmutable()) && lazyFiles.Length > 0 && !CryptographicHashProvider.IsSupportedAlgorithm(_sourceAssembly.HashAlgorithm))
|
|
{
|
|
context.Diagnostics.Add((Diagnostic)(object)new CSDiagnostic((DiagnosticInfo)(object)new CSDiagnosticInfo(ErrorCode.ERR_CryptoHashFailed), NoLocation.Singleton));
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
instance.Free();
|
|
}
|
|
}
|
|
return lazyFiles;
|
|
}
|
|
}
|
|
|
|
protected override void AddEmbeddedResourcesFromAddedModules(ArrayBuilder<ManagedResource> builder, DiagnosticBag diagnostics)
|
|
{
|
|
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0030: Expected O, but got Unknown
|
|
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005e: 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)
|
|
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0084: Expected O, but got Unknown
|
|
ImmutableArray<ModuleSymbol> modules = _sourceAssembly.Modules;
|
|
int length = modules.Length;
|
|
for (int i = 1; i < length; i++)
|
|
{
|
|
IFileReference val = (IFileReference)Translate(modules[i], diagnostics);
|
|
try
|
|
{
|
|
ImmutableArray<EmbeddedResource>.Enumerator enumerator = ((PEModuleSymbol)modules[i]).Module.GetEmbeddedResourcesOrThrow().GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
EmbeddedResource current = enumerator.Current;
|
|
builder.Add(new ManagedResource(current.Name, (current.Attributes & ManifestResourceAttributes.Public) != 0, (Func<Stream>)null, val, current.Offset));
|
|
}
|
|
}
|
|
catch (BadImageFormatException)
|
|
{
|
|
diagnostics.Add((DiagnosticInfo)(object)new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, modules[i]), NoLocation.Singleton);
|
|
}
|
|
}
|
|
}
|
|
|
|
internal override SynthesizedAttributeData SynthesizeEmbeddedAttribute()
|
|
{
|
|
return new SynthesizedAttributeData(_lazyEmbeddedAttribute.Constructors[0], ImmutableArray<TypedConstant>.Empty, ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
|
|
}
|
|
|
|
internal override SynthesizedAttributeData SynthesizeNullableAttribute(WellKnownMember member, ImmutableArray<TypedConstant> arguments)
|
|
{
|
|
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
if ((object)_lazyNullableAttribute != null)
|
|
{
|
|
int index = (((int)member == 390) ? 1 : 0);
|
|
return new SynthesizedAttributeData(_lazyNullableAttribute.Constructors[index], arguments, ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
|
|
}
|
|
return base.SynthesizeNullableAttribute(member, arguments);
|
|
}
|
|
|
|
internal override SynthesizedAttributeData SynthesizeNullableContextAttribute(ImmutableArray<TypedConstant> arguments)
|
|
{
|
|
if ((object)_lazyNullableContextAttribute != null)
|
|
{
|
|
return new SynthesizedAttributeData(_lazyNullableContextAttribute.Constructors[0], arguments, ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
|
|
}
|
|
return base.SynthesizeNullableContextAttribute(arguments);
|
|
}
|
|
|
|
internal override SynthesizedAttributeData SynthesizeNullablePublicOnlyAttribute(ImmutableArray<TypedConstant> arguments)
|
|
{
|
|
if ((object)_lazyNullablePublicOnlyAttribute != null)
|
|
{
|
|
return new SynthesizedAttributeData(_lazyNullablePublicOnlyAttribute.Constructors[0], arguments, ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
|
|
}
|
|
return base.SynthesizeNullablePublicOnlyAttribute(arguments);
|
|
}
|
|
|
|
internal override SynthesizedAttributeData SynthesizeNativeIntegerAttribute(WellKnownMember member, ImmutableArray<TypedConstant> arguments)
|
|
{
|
|
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
if ((object)_lazyNativeIntegerAttribute != null)
|
|
{
|
|
int index = (((int)member == 463) ? 1 : 0);
|
|
return new SynthesizedAttributeData(_lazyNativeIntegerAttribute.Constructors[index], arguments, ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
|
|
}
|
|
return base.SynthesizeNativeIntegerAttribute(member, arguments);
|
|
}
|
|
|
|
internal override SynthesizedAttributeData SynthesizeScopedRefAttribute(WellKnownMember member)
|
|
{
|
|
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
|
|
if ((object)_lazyScopedRefAttribute != null)
|
|
{
|
|
return new SynthesizedAttributeData(_lazyScopedRefAttribute.Constructors[0], ImmutableArray<TypedConstant>.Empty, ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
|
|
}
|
|
return base.SynthesizeScopedRefAttribute(member);
|
|
}
|
|
|
|
internal override SynthesizedAttributeData SynthesizeRefSafetyRulesAttribute(ImmutableArray<TypedConstant> arguments)
|
|
{
|
|
if ((object)_lazyRefSafetyRulesAttribute != null)
|
|
{
|
|
return new SynthesizedAttributeData(_lazyRefSafetyRulesAttribute.Constructors[0], arguments, ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
|
|
}
|
|
return base.SynthesizeRefSafetyRulesAttribute(arguments);
|
|
}
|
|
|
|
protected override SynthesizedAttributeData TrySynthesizeIsReadOnlyAttribute()
|
|
{
|
|
if ((object)_lazyIsReadOnlyAttribute != null)
|
|
{
|
|
return new SynthesizedAttributeData(_lazyIsReadOnlyAttribute.Constructors[0], ImmutableArray<TypedConstant>.Empty, ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
|
|
}
|
|
return base.TrySynthesizeIsReadOnlyAttribute();
|
|
}
|
|
|
|
protected override SynthesizedAttributeData TrySynthesizeRequiresLocationAttribute()
|
|
{
|
|
if ((object)_lazyRequiresLocationAttribute != null)
|
|
{
|
|
return new SynthesizedAttributeData(_lazyRequiresLocationAttribute.Constructors[0], ImmutableArray<TypedConstant>.Empty, ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
|
|
}
|
|
return base.TrySynthesizeRequiresLocationAttribute();
|
|
}
|
|
|
|
protected override SynthesizedAttributeData TrySynthesizeIsUnmanagedAttribute()
|
|
{
|
|
if ((object)_lazyIsUnmanagedAttribute != null)
|
|
{
|
|
return new SynthesizedAttributeData(_lazyIsUnmanagedAttribute.Constructors[0], ImmutableArray<TypedConstant>.Empty, ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
|
|
}
|
|
return base.TrySynthesizeIsUnmanagedAttribute();
|
|
}
|
|
|
|
protected override SynthesizedAttributeData TrySynthesizeIsByRefLikeAttribute()
|
|
{
|
|
if ((object)_lazyIsByRefLikeAttribute != null)
|
|
{
|
|
return new SynthesizedAttributeData(_lazyIsByRefLikeAttribute.Constructors[0], ImmutableArray<TypedConstant>.Empty, ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
|
|
}
|
|
return base.TrySynthesizeIsByRefLikeAttribute();
|
|
}
|
|
|
|
private void CreateEmbeddedAttributesIfNeeded(BindingDiagnosticBag diagnostics)
|
|
{
|
|
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0188: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
|
|
EmbeddableAttributes embeddableAttributes = GetNeedsGeneratedAttributes();
|
|
if (ShouldEmitNullablePublicOnlyAttribute() && ((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)this).Compilation.CheckIfAttributeShouldBeEmbedded(EmbeddableAttributes.NullablePublicOnlyAttribute, diagnostics, Location.None))
|
|
{
|
|
embeddableAttributes |= EmbeddableAttributes.NullablePublicOnlyAttribute;
|
|
}
|
|
if (((SourceModuleSymbol)((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)this).Compilation.SourceModule).RequiresRefSafetyRulesAttribute() && ((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)this).Compilation.CheckIfAttributeShouldBeEmbedded(EmbeddableAttributes.RefSafetyRulesAttribute, diagnostics, Location.None))
|
|
{
|
|
embeddableAttributes |= EmbeddableAttributes.RefSafetyRulesAttribute;
|
|
}
|
|
if (embeddableAttributes != 0)
|
|
{
|
|
Func<string, NamespaceSymbol, BindingDiagnosticBag, SynthesizedEmbeddedAttributeSymbol> factory = CreateParameterlessEmbeddedAttributeSymbol;
|
|
CreateAttributeIfNeeded(ref _lazyEmbeddedAttribute, diagnostics, AttributeDescription.CodeAnalysisEmbeddedAttribute, factory);
|
|
if ((embeddableAttributes & EmbeddableAttributes.IsReadOnlyAttribute) != 0)
|
|
{
|
|
CreateAttributeIfNeeded(ref _lazyIsReadOnlyAttribute, diagnostics, AttributeDescription.IsReadOnlyAttribute, factory);
|
|
}
|
|
if ((embeddableAttributes & EmbeddableAttributes.RequiresLocationAttribute) != 0)
|
|
{
|
|
CreateAttributeIfNeeded(ref _lazyRequiresLocationAttribute, diagnostics, AttributeDescription.RequiresLocationAttribute, factory);
|
|
}
|
|
if ((embeddableAttributes & EmbeddableAttributes.IsByRefLikeAttribute) != 0)
|
|
{
|
|
CreateAttributeIfNeeded(ref _lazyIsByRefLikeAttribute, diagnostics, AttributeDescription.IsByRefLikeAttribute, factory);
|
|
}
|
|
if ((embeddableAttributes & EmbeddableAttributes.IsUnmanagedAttribute) != 0)
|
|
{
|
|
CreateAttributeIfNeeded(ref _lazyIsUnmanagedAttribute, diagnostics, AttributeDescription.IsUnmanagedAttribute, factory);
|
|
}
|
|
if ((embeddableAttributes & EmbeddableAttributes.NullableAttribute) != 0)
|
|
{
|
|
CreateAttributeIfNeeded(ref _lazyNullableAttribute, diagnostics, AttributeDescription.NullableAttribute, CreateNullableAttributeSymbol);
|
|
}
|
|
if ((embeddableAttributes & EmbeddableAttributes.NullableContextAttribute) != 0)
|
|
{
|
|
CreateAttributeIfNeeded(ref _lazyNullableContextAttribute, diagnostics, AttributeDescription.NullableContextAttribute, CreateNullableContextAttributeSymbol);
|
|
}
|
|
if ((embeddableAttributes & EmbeddableAttributes.NullablePublicOnlyAttribute) != 0)
|
|
{
|
|
CreateAttributeIfNeeded(ref _lazyNullablePublicOnlyAttribute, diagnostics, AttributeDescription.NullablePublicOnlyAttribute, CreateNullablePublicOnlyAttributeSymbol);
|
|
}
|
|
if ((embeddableAttributes & EmbeddableAttributes.NativeIntegerAttribute) != 0)
|
|
{
|
|
CreateAttributeIfNeeded(ref _lazyNativeIntegerAttribute, diagnostics, AttributeDescription.NativeIntegerAttribute, CreateNativeIntegerAttributeSymbol);
|
|
}
|
|
if ((embeddableAttributes & EmbeddableAttributes.ScopedRefAttribute) != 0)
|
|
{
|
|
CreateAttributeIfNeeded(ref _lazyScopedRefAttribute, diagnostics, AttributeDescription.ScopedRefAttribute, CreateScopedRefAttributeSymbol);
|
|
}
|
|
if ((embeddableAttributes & EmbeddableAttributes.RefSafetyRulesAttribute) != 0)
|
|
{
|
|
CreateAttributeIfNeeded(ref _lazyRefSafetyRulesAttribute, diagnostics, AttributeDescription.RefSafetyRulesAttribute, CreateRefSafetyRulesAttributeSymbol);
|
|
}
|
|
}
|
|
}
|
|
|
|
private SynthesizedEmbeddedAttributeSymbol CreateParameterlessEmbeddedAttributeSymbol(string name, NamespaceSymbol containingNamespace, BindingDiagnosticBag diagnostics)
|
|
{
|
|
return new SynthesizedEmbeddedAttributeSymbol(name, containingNamespace, ((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)this).SourceModule, GetWellKnownType((WellKnownType)49, diagnostics));
|
|
}
|
|
|
|
private SynthesizedEmbeddedNullableAttributeSymbol CreateNullableAttributeSymbol(string name, NamespaceSymbol containingNamespace, BindingDiagnosticBag diagnostics)
|
|
{
|
|
return new SynthesizedEmbeddedNullableAttributeSymbol(name, containingNamespace, ((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)this).SourceModule, GetWellKnownType((WellKnownType)49, diagnostics), GetSpecialType((SpecialType)10, diagnostics));
|
|
}
|
|
|
|
private SynthesizedEmbeddedNullableContextAttributeSymbol CreateNullableContextAttributeSymbol(string name, NamespaceSymbol containingNamespace, BindingDiagnosticBag diagnostics)
|
|
{
|
|
return new SynthesizedEmbeddedNullableContextAttributeSymbol(name, containingNamespace, ((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)this).SourceModule, GetWellKnownType((WellKnownType)49, diagnostics), GetSpecialType((SpecialType)10, diagnostics));
|
|
}
|
|
|
|
private SynthesizedEmbeddedNullablePublicOnlyAttributeSymbol CreateNullablePublicOnlyAttributeSymbol(string name, NamespaceSymbol containingNamespace, BindingDiagnosticBag diagnostics)
|
|
{
|
|
return new SynthesizedEmbeddedNullablePublicOnlyAttributeSymbol(name, containingNamespace, ((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)this).SourceModule, GetWellKnownType((WellKnownType)49, diagnostics), GetSpecialType((SpecialType)7, diagnostics));
|
|
}
|
|
|
|
private SynthesizedEmbeddedNativeIntegerAttributeSymbol CreateNativeIntegerAttributeSymbol(string name, NamespaceSymbol containingNamespace, BindingDiagnosticBag diagnostics)
|
|
{
|
|
return new SynthesizedEmbeddedNativeIntegerAttributeSymbol(name, containingNamespace, ((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)this).SourceModule, GetWellKnownType((WellKnownType)49, diagnostics), GetSpecialType((SpecialType)7, diagnostics));
|
|
}
|
|
|
|
private SynthesizedEmbeddedScopedRefAttributeSymbol CreateScopedRefAttributeSymbol(string name, NamespaceSymbol containingNamespace, BindingDiagnosticBag diagnostics)
|
|
{
|
|
return new SynthesizedEmbeddedScopedRefAttributeSymbol(name, containingNamespace, ((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)this).SourceModule, GetWellKnownType((WellKnownType)49, diagnostics));
|
|
}
|
|
|
|
private SynthesizedEmbeddedRefSafetyRulesAttributeSymbol CreateRefSafetyRulesAttributeSymbol(string name, NamespaceSymbol containingNamespace, BindingDiagnosticBag diagnostics)
|
|
{
|
|
return new SynthesizedEmbeddedRefSafetyRulesAttributeSymbol(name, containingNamespace, ((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)this).SourceModule, GetWellKnownType((WellKnownType)49, diagnostics), GetSpecialType((SpecialType)13, diagnostics));
|
|
}
|
|
|
|
private void CreateAttributeIfNeeded<T>(ref T symbol, BindingDiagnosticBag diagnostics, AttributeDescription description, Func<string, NamespaceSymbol, BindingDiagnosticBag, T> factory) where T : SynthesizedEmbeddedAttributeSymbolBase
|
|
{
|
|
//IL_000e: 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_0025: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
|
|
if ((object)symbol == null)
|
|
{
|
|
AddDiagnosticsForExistingAttribute(description, diagnostics);
|
|
NamespaceSymbol orSynthesizeNamespace = GetOrSynthesizeNamespace(description.Namespace);
|
|
symbol = factory(description.Name, orSynthesizeNamespace, diagnostics);
|
|
if (symbol.GetAttributeUsageInfo() != AttributeUsageInfo.Default)
|
|
{
|
|
EnsureAttributeUsageAttributeMembersAvailable(diagnostics);
|
|
}
|
|
((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)this).AddSynthesizedDefinition((INamespaceSymbolInternal)(object)orSynthesizeNamespace, (INamespaceOrTypeSymbolInternal)(object)symbol);
|
|
}
|
|
}
|
|
|
|
private void AddDiagnosticsForExistingAttribute(AttributeDescription description, BindingDiagnosticBag diagnostics)
|
|
{
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
|
|
MetadataTypeName emittedName = MetadataTypeName.FromFullName(((AttributeDescription)(ref description)).FullName, false, -1);
|
|
NamedTypeSymbol namedTypeSymbol = _sourceAssembly.SourceModule.LookupTopLevelMetadataType(ref emittedName);
|
|
if ((object)namedTypeSymbol != null)
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_TypeReserved, namedTypeSymbol.GetFirstLocation(), ((AttributeDescription)(ref description)).FullName);
|
|
}
|
|
}
|
|
|
|
private NamespaceSymbol GetOrSynthesizeNamespace(string namespaceFullName)
|
|
{
|
|
NamespaceSymbol namespaceSymbol = ((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)this).SourceModule.GlobalNamespace;
|
|
string[] array = namespaceFullName.Split(new char[1] { '.' });
|
|
foreach (string name in array)
|
|
{
|
|
NamespaceSymbol namespaceSymbol2 = (NamespaceSymbol)namespaceSymbol.GetMembers(name).FirstOrDefault((Symbol m) => (int)m.Kind == 12);
|
|
if (namespaceSymbol2 == null)
|
|
{
|
|
namespaceSymbol2 = new SynthesizedNamespaceSymbol(namespaceSymbol, name);
|
|
((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)this).AddSynthesizedDefinition((INamespaceSymbolInternal)(object)namespaceSymbol, (INamespaceOrTypeSymbolInternal)(object)namespaceSymbol2);
|
|
}
|
|
namespaceSymbol = namespaceSymbol2;
|
|
}
|
|
return namespaceSymbol;
|
|
}
|
|
|
|
private NamedTypeSymbol GetWellKnownType(WellKnownType type, BindingDiagnosticBag diagnostics)
|
|
{
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
NamedTypeSymbol wellKnownType = _sourceAssembly.DeclaringCompilation.GetWellKnownType(type);
|
|
Binder.ReportUseSite(wellKnownType, diagnostics, Location.None);
|
|
return wellKnownType;
|
|
}
|
|
|
|
private NamedTypeSymbol GetSpecialType(SpecialType type, BindingDiagnosticBag diagnostics)
|
|
{
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
NamedTypeSymbol specialType = _sourceAssembly.DeclaringCompilation.GetSpecialType(type);
|
|
Binder.ReportUseSite(specialType, diagnostics, Location.None);
|
|
return specialType;
|
|
}
|
|
|
|
private void EnsureAttributeUsageAttributeMembersAvailable(BindingDiagnosticBag diagnostics)
|
|
{
|
|
CSharpCompilation declaringCompilation = _sourceAssembly.DeclaringCompilation;
|
|
Binder.GetWellKnownTypeMember(declaringCompilation, (WellKnownMember)60, diagnostics, Location.None);
|
|
Binder.GetWellKnownTypeMember(declaringCompilation, (WellKnownMember)61, diagnostics, Location.None);
|
|
Binder.GetWellKnownTypeMember(declaringCompilation, (WellKnownMember)62, diagnostics, Location.None);
|
|
}
|
|
}
|