未验证 提交 9582b3a2 编写于 作者: C Charles Stoner 提交者: GitHub

Merge pull request #23199 from cston/embedded

Merge misc. changes for embedded attributes from 7a0467ec
...@@ -1998,10 +1998,10 @@ private IEnumerable<Diagnostic> FreezeDeclarationDiagnostics() ...@@ -1998,10 +1998,10 @@ private IEnumerable<Diagnostic> FreezeDeclarationDiagnostics()
{ {
_declarationDiagnosticsFrozen = true; _declarationDiagnosticsFrozen = true;
// Also freeze generated attribute flags by observing them // Also freeze generated attribute flags.
// symbols bound after getting the declaration diagnostics shouldn't need to modify the flags // Symbols bound after getting the declaration
_needsGeneratedIsReadOnlyAttribute_IsFrozen = true; // diagnostics shouldn't need to modify the flags.
_needsGeneratedIsByRefLikeAttribute_IsFrozen = true; _needsGeneratedAttributes_IsFrozen = true;
var result = _lazyDeclarationDiagnostics?.AsEnumerable() ?? Enumerable.Empty<Diagnostic>(); var result = _lazyDeclarationDiagnostics?.AsEnumerable() ?? Enumerable.Empty<Diagnostic>();
return result; return result;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
using System.Threading;
using Microsoft.Cci;
using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.Emit; using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.PooledObjects;
...@@ -165,15 +162,11 @@ protected override void AddEmbeddedResourcesFromAddedModules(ArrayBuilder<Cci.Ma ...@@ -165,15 +162,11 @@ protected override void AddEmbeddedResourcesFromAddedModules(ArrayBuilder<Cci.Ma
internal override SynthesizedAttributeData SynthesizeEmbeddedAttribute() internal override SynthesizedAttributeData SynthesizeEmbeddedAttribute()
{ {
if ((object)_lazyEmbeddedAttribute != null) // _lazyEmbeddedAttribute should have been created before calling this method.
{ return new SynthesizedAttributeData(
return new SynthesizedAttributeData( _lazyEmbeddedAttribute.Constructor,
_lazyEmbeddedAttribute.Constructor, ImmutableArray<TypedConstant>.Empty,
ImmutableArray<TypedConstant>.Empty, ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
}
return base.SynthesizeEmbeddedAttribute();
} }
protected override SynthesizedAttributeData TrySynthesizeIsReadOnlyAttribute() protected override SynthesizedAttributeData TrySynthesizeIsReadOnlyAttribute()
......
...@@ -43,7 +43,7 @@ public override NoPia.EmbeddedTypesManager EmbeddedTypesManagerOpt ...@@ -43,7 +43,7 @@ public override NoPia.EmbeddedTypesManager EmbeddedTypesManagerOpt
private bool _needsGeneratedIsReadOnlyAttribute_Value; private bool _needsGeneratedIsReadOnlyAttribute_Value;
private bool _needsGeneratedIsReadOnlyAttribute_IsFrozen; private bool _needsGeneratedAttributes_IsFrozen;
/// <summary> /// <summary>
/// Returns a value indicating whether this builder has a symbol that needs IsReadOnlyAttribute to be generated during emit phase. /// Returns a value indicating whether this builder has a symbol that needs IsReadOnlyAttribute to be generated during emit phase.
...@@ -54,7 +54,7 @@ internal bool NeedsGeneratedIsReadOnlyAttribute ...@@ -54,7 +54,7 @@ internal bool NeedsGeneratedIsReadOnlyAttribute
{ {
get get
{ {
_needsGeneratedIsReadOnlyAttribute_IsFrozen = true; _needsGeneratedAttributes_IsFrozen = true;
return Compilation.NeedsGeneratedIsReadOnlyAttribute || _needsGeneratedIsReadOnlyAttribute_Value; return Compilation.NeedsGeneratedIsReadOnlyAttribute || _needsGeneratedIsReadOnlyAttribute_Value;
} }
} }
...@@ -1427,11 +1427,7 @@ protected override Cci.IMethodDefinition CreatePrivateImplementationDetailsStati ...@@ -1427,11 +1427,7 @@ protected override Cci.IMethodDefinition CreatePrivateImplementationDetailsStati
return new SynthesizedPrivateImplementationDetailsStaticConstructor(SourceModule, details, GetUntranslatedSpecialType(SpecialType.System_Void, syntaxOpt, diagnostics)); return new SynthesizedPrivateImplementationDetailsStaticConstructor(SourceModule, details, GetUntranslatedSpecialType(SpecialType.System_Void, syntaxOpt, diagnostics));
} }
internal virtual SynthesizedAttributeData SynthesizeEmbeddedAttribute() internal abstract SynthesizedAttributeData SynthesizeEmbeddedAttribute();
{
// Embedded attributes should never be synthesized in modules.
throw ExceptionUtilities.Unreachable;
}
internal SynthesizedAttributeData SynthesizeIsReadOnlyAttribute(Symbol symbol) internal SynthesizedAttributeData SynthesizeIsReadOnlyAttribute(Symbol symbol)
{ {
...@@ -1469,6 +1465,8 @@ protected virtual SynthesizedAttributeData TrySynthesizeIsByRefLikeAttribute() ...@@ -1469,6 +1465,8 @@ protected virtual SynthesizedAttributeData TrySynthesizeIsByRefLikeAttribute()
internal void EnsureIsReadOnlyAttributeExists() internal void EnsureIsReadOnlyAttributeExists()
{ {
Debug.Assert(!_needsGeneratedAttributes_IsFrozen);
if (_needsGeneratedIsReadOnlyAttribute_Value || Compilation.NeedsGeneratedIsReadOnlyAttribute) if (_needsGeneratedIsReadOnlyAttribute_Value || Compilation.NeedsGeneratedIsReadOnlyAttribute)
{ {
return; return;
...@@ -1477,7 +1475,6 @@ internal void EnsureIsReadOnlyAttributeExists() ...@@ -1477,7 +1475,6 @@ internal void EnsureIsReadOnlyAttributeExists()
// Don't report any errors. They should be reported during binding. // Don't report any errors. They should be reported during binding.
if (Compilation.CheckIfIsReadOnlyAttributeShouldBeEmbedded(diagnosticsOpt: null, locationOpt: null)) if (Compilation.CheckIfIsReadOnlyAttributeShouldBeEmbedded(diagnosticsOpt: null, locationOpt: null))
{ {
Debug.Assert(!_needsGeneratedIsReadOnlyAttribute_IsFrozen);
_needsGeneratedIsReadOnlyAttribute_Value = true; _needsGeneratedIsReadOnlyAttribute_Value = true;
} }
} }
......
...@@ -25,6 +25,12 @@ protected override void AddEmbeddedResourcesFromAddedModules(ArrayBuilder<Cci.Ma ...@@ -25,6 +25,12 @@ protected override void AddEmbeddedResourcesFromAddedModules(ArrayBuilder<Cci.Ma
throw ExceptionUtilities.Unreachable; throw ExceptionUtilities.Unreachable;
} }
internal override SynthesizedAttributeData SynthesizeEmbeddedAttribute()
{
// Embedded attributes should never be synthesized in modules.
throw ExceptionUtilities.Unreachable;
}
public override int CurrentGenerationOrdinal => 0; public override int CurrentGenerationOrdinal => 0;
public override IEnumerable<Cci.IFileReference> GetFiles(EmitContext context) => SpecializedCollections.EmptyEnumerable<Cci.IFileReference>(); public override IEnumerable<Cci.IFileReference> GetFiles(EmitContext context) => SpecializedCollections.EmptyEnumerable<Cci.IFileReference>();
public override ISourceAssemblySymbolInternal SourceAssemblyOpt => null; public override ISourceAssemblySymbolInternal SourceAssemblyOpt => null;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis.CodeGen; using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.CSharp.Emit; using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Symbols;
...@@ -587,25 +588,8 @@ internal static bool WouldBeAssignableIfUsedAsMethodReceiver(BoundExpression rec ...@@ -587,25 +588,8 @@ internal static bool WouldBeAssignableIfUsedAsMethodReceiver(BoundExpression rec
private void CheckRefReadOnlySymbols(MethodSymbol symbol) private void CheckRefReadOnlySymbols(MethodSymbol symbol)
{ {
var foundRefReadOnly = false; if (symbol.ReturnsByRefReadonly ||
symbol.Parameters.Any(p => p.RefKind == RefKind.In))
if (symbol.ReturnsByRefReadonly)
{
foundRefReadOnly = true;
}
else
{
foreach (var parameter in symbol.Parameters)
{
if (parameter.RefKind == RefKind.In)
{
foundRefReadOnly = true;
break;
}
}
}
if (foundRefReadOnly)
{ {
_factory.CompilationState.ModuleBuilderOpt?.EnsureIsReadOnlyAttributeExists(); _factory.CompilationState.ModuleBuilderOpt?.EnsureIsReadOnlyAttributeExists();
} }
......
...@@ -35,8 +35,7 @@ public partial class CSharpCompilation ...@@ -35,8 +35,7 @@ public partial class CSharpCompilation
private bool _needsGeneratedIsReadOnlyAttribute_Value; private bool _needsGeneratedIsReadOnlyAttribute_Value;
private bool _needsGeneratedIsByRefLikeAttribute_Value; private bool _needsGeneratedIsByRefLikeAttribute_Value;
private bool _needsGeneratedIsReadOnlyAttribute_IsFrozen; private bool _needsGeneratedAttributes_IsFrozen;
private bool _needsGeneratedIsByRefLikeAttribute_IsFrozen;
/// <summary> /// <summary>
/// Returns a value indicating whether this compilation has a member that needs IsReadOnlyAttribute to be generated during emit phase. /// Returns a value indicating whether this compilation has a member that needs IsReadOnlyAttribute to be generated during emit phase.
...@@ -47,7 +46,7 @@ internal bool NeedsGeneratedIsReadOnlyAttribute ...@@ -47,7 +46,7 @@ internal bool NeedsGeneratedIsReadOnlyAttribute
{ {
get get
{ {
_needsGeneratedIsReadOnlyAttribute_IsFrozen = true; _needsGeneratedAttributes_IsFrozen = true;
return _needsGeneratedIsReadOnlyAttribute_Value; return _needsGeneratedIsReadOnlyAttribute_Value;
} }
} }
...@@ -61,7 +60,7 @@ internal bool NeedsGeneratedIsByRefLikeAttribute ...@@ -61,7 +60,7 @@ internal bool NeedsGeneratedIsByRefLikeAttribute
{ {
get get
{ {
_needsGeneratedIsByRefLikeAttribute_IsFrozen = true; _needsGeneratedAttributes_IsFrozen = true;
return _needsGeneratedIsByRefLikeAttribute_Value; return _needsGeneratedIsByRefLikeAttribute_Value;
} }
} }
...@@ -463,7 +462,7 @@ internal SynthesizedAttributeData SynthesizeDebuggerStepThroughAttribute() ...@@ -463,7 +462,7 @@ internal SynthesizedAttributeData SynthesizeDebuggerStepThroughAttribute()
internal void EnsureIsReadOnlyAttributeExists(DiagnosticBag diagnostics, Location location, bool modifyCompilationForRefReadOnly) internal void EnsureIsReadOnlyAttributeExists(DiagnosticBag diagnostics, Location location, bool modifyCompilationForRefReadOnly)
{ {
Debug.Assert(!modifyCompilationForRefReadOnly || !_needsGeneratedIsReadOnlyAttribute_IsFrozen); Debug.Assert(!modifyCompilationForRefReadOnly || !_needsGeneratedAttributes_IsFrozen);
var isNeeded = CheckIfIsReadOnlyAttributeShouldBeEmbedded(diagnostics, location); var isNeeded = CheckIfIsReadOnlyAttributeShouldBeEmbedded(diagnostics, location);
...@@ -475,7 +474,7 @@ internal void EnsureIsReadOnlyAttributeExists(DiagnosticBag diagnostics, Locatio ...@@ -475,7 +474,7 @@ internal void EnsureIsReadOnlyAttributeExists(DiagnosticBag diagnostics, Locatio
internal void EnsureIsByRefLikeAttributeExists(DiagnosticBag diagnostics, Location location, bool modifyCompilationForIsByRefLike) internal void EnsureIsByRefLikeAttributeExists(DiagnosticBag diagnostics, Location location, bool modifyCompilationForIsByRefLike)
{ {
Debug.Assert(!modifyCompilationForIsByRefLike || !_needsGeneratedIsByRefLikeAttribute_IsFrozen); Debug.Assert(!modifyCompilationForIsByRefLike || !_needsGeneratedAttributes_IsFrozen);
var isNeeded = CheckIfIsByRefLikeAttributeShouldBeEmbedded(diagnostics, location); var isNeeded = CheckIfIsByRefLikeAttributeShouldBeEmbedded(diagnostics, location);
......
...@@ -1121,6 +1121,16 @@ internal override OverriddenOrHiddenMembersResult OverriddenOrHiddenMembers ...@@ -1121,6 +1121,16 @@ internal override OverriddenOrHiddenMembersResult OverriddenOrHiddenMembers
} }
} }
internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)
{
throw ExceptionUtilities.Unreachable;
}
internal override void AddSynthesizedReturnTypeAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)
{
throw ExceptionUtilities.Unreachable;
}
// perf, not correctness // perf, not correctness
internal override CSharpCompilation DeclaringCompilation => null; internal override CSharpCompilation DeclaringCompilation => null;
......
...@@ -1159,6 +1159,19 @@ internal virtual void AddSynthesizedReturnTypeAttributes(PEModuleBuilder moduleB ...@@ -1159,6 +1159,19 @@ internal virtual void AddSynthesizedReturnTypeAttributes(PEModuleBuilder moduleB
{ {
AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeIsReadOnlyAttribute(this)); AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeIsReadOnlyAttribute(this));
} }
var compilation = this.DeclaringCompilation;
var type = this.ReturnType;
if (type.ContainsDynamic() && compilation.HasDynamicEmitAttributes())
{
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(type, this.ReturnTypeCustomModifiers.Length + this.RefCustomModifiers.Length, this.RefKind));
}
if (type.ContainsTupleNames() && compilation.HasTupleNamesAttributes)
{
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeTupleNamesAttribute(type));
}
} }
IMethodSymbol IMethodSymbol.Construct(params ITypeSymbol[] arguments) IMethodSymbol IMethodSymbol.Construct(params ITypeSymbol[] arguments)
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
using System; using System;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.PooledObjects;
namespace Microsoft.CodeAnalysis.CSharp.Symbols namespace Microsoft.CodeAnalysis.CSharp.Symbols
{ {
...@@ -158,16 +156,6 @@ internal override bool IsCallerMemberName ...@@ -158,16 +156,6 @@ internal override bool IsCallerMemberName
get { return _originalParam.IsCallerMemberName; } get { return _originalParam.IsCallerMemberName; }
} }
internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)
{
base.AddSynthesizedAttributes(moduleBuilder, ref attributes);
if (this.RefKind == RefKind.RefReadOnly)
{
AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeIsReadOnlyAttribute(this));
}
}
#endregion #endregion
} }
} }
...@@ -964,23 +964,6 @@ public sealed override ImmutableArray<CSharpAttributeData> GetReturnTypeAttribut ...@@ -964,23 +964,6 @@ public sealed override ImmutableArray<CSharpAttributeData> GetReturnTypeAttribut
return this.GetReturnTypeAttributesBag().Attributes; return this.GetReturnTypeAttributesBag().Attributes;
} }
internal override void AddSynthesizedReturnTypeAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)
{
base.AddSynthesizedReturnTypeAttributes(moduleBuilder, ref attributes);
if (this.ReturnType.ContainsDynamic())
{
var compilation = this.DeclaringCompilation;
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.ReturnType, this.ReturnTypeCustomModifiers.Length + this.RefCustomModifiers.Length, this.RefKind));
}
if (ReturnType.ContainsTupleNames())
{
AddSynthesizedAttribute(ref attributes,
DeclaringCompilation.SynthesizeTupleNamesAttribute(ReturnType));
}
}
internal override CSharpAttributeData EarlyDecodeWellKnownAttribute(ref EarlyDecodeWellKnownAttributeArguments<EarlyWellKnownAttributeBinder, NamedTypeSymbol, AttributeSyntax, AttributeLocation> arguments) internal override CSharpAttributeData EarlyDecodeWellKnownAttribute(ref EarlyDecodeWellKnownAttributeArguments<EarlyWellKnownAttributeBinder, NamedTypeSymbol, AttributeSyntax, AttributeLocation> arguments)
{ {
Debug.Assert(arguments.SymbolPart == AttributeLocation.None || arguments.SymbolPart == AttributeLocation.Return); Debug.Assert(arguments.SymbolPart == AttributeLocation.None || arguments.SymbolPart == AttributeLocation.Return);
......
...@@ -3,10 +3,7 @@ ...@@ -3,10 +3,7 @@
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.PooledObjects;
namespace Microsoft.CodeAnalysis.CSharp.Symbols namespace Microsoft.CodeAnalysis.CSharp.Symbols
{ {
...@@ -253,16 +250,6 @@ public override bool IsImplicitlyDeclared ...@@ -253,16 +250,6 @@ public override bool IsImplicitlyDeclared
} }
} }
internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)
{
base.AddSynthesizedAttributes(moduleBuilder, ref attributes);
if (this.RefKind == RefKind.In)
{
AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeIsReadOnlyAttribute(this));
}
}
internal override bool IsMetadataIn => RefKind == RefKind.In; internal override bool IsMetadataIn => RefKind == RefKind.In;
internal override bool IsMetadataOut => RefKind == RefKind.Out; internal override bool IsMetadataOut => RefKind == RefKind.Out;
......
...@@ -88,6 +88,11 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r ...@@ -88,6 +88,11 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r
AddSynthesizedAttribute(ref attributes, AddSynthesizedAttribute(ref attributes,
compilation.SynthesizeTupleNamesAttribute(Type)); compilation.SynthesizeTupleNamesAttribute(Type));
} }
if (this.RefKind == RefKind.RefReadOnly)
{
AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeIsReadOnlyAttribute(this));
}
} }
internal abstract ParameterSymbol WithCustomModifiersAndParams(TypeSymbol newType, ImmutableArray<CustomModifier> newCustomModifiers, ImmutableArray<CustomModifier> newRefCustomModifiers, bool newIsParams); internal abstract ParameterSymbol WithCustomModifiersAndParams(TypeSymbol newType, ImmutableArray<CustomModifier> newCustomModifiers, ImmutableArray<CustomModifier> newRefCustomModifiers, bool newIsParams);
......
...@@ -81,25 +81,6 @@ public sealed override ImmutableArray<CustomModifier> RefCustomModifiers ...@@ -81,25 +81,6 @@ public sealed override ImmutableArray<CustomModifier> RefCustomModifiers
#endregion #endregion
internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)
{
base.AddSynthesizedAttributes(moduleBuilder, ref attributes);
var compilation = this.DeclaringCompilation;
if (this.ReturnType.ContainsDynamic() && compilation.HasDynamicEmitAttributes() && compilation.CanEmitBoolean())
{
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.ReturnType, this.ReturnTypeCustomModifiers.Length + this.RefCustomModifiers.Length, this.RefKind));
}
if (ReturnType.ContainsTupleNames() &&
compilation.HasTupleNamesAttributes &&
compilation.CanEmitSpecialType(SpecialType.System_String))
{
AddSynthesizedAttribute(ref attributes,
compilation.SynthesizeTupleNamesAttribute(ReturnType));
}
}
internal sealed override bool GenerateDebugInfo internal sealed override bool GenerateDebugInfo
{ {
get { return _generateDebugInfo; } get { return _generateDebugInfo; }
......
...@@ -683,8 +683,17 @@ public IEnumerable<dynamic> M1() ...@@ -683,8 +683,17 @@ public IEnumerable<dynamic> M1()
break; break;
case SymbolKind.Method: case SymbolKind.Method:
// Dev11 marks return type of GetEnumerator with DynamicAttribute, we don't var attributes = ((MethodSymbol)member).GetReturnTypeAttributes();
Assert.Equal(0, ((MethodSymbol)member).GetReturnTypeAttributes().Length); switch (member.MetadataName)
{
case "System.Collections.Generic.IEnumerator<dynamic>.get_Current":
case "System.Collections.Generic.IEnumerable<dynamic>.GetEnumerator":
Assert.Equal(1, attributes.Length);
break;
default:
Assert.Equal(0, attributes.Length);
break;
}
break; break;
case SymbolKind.Property: case SymbolKind.Property:
......
...@@ -697,24 +697,6 @@ private static TypeSymbol CalculateReturnType(CSharpCompilation compilation, Bou ...@@ -697,24 +697,6 @@ private static TypeSymbol CalculateReturnType(CSharpCompilation compilation, Bou
} }
} }
internal override void AddSynthesizedReturnTypeAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)
{
base.AddSynthesizedReturnTypeAttributes(moduleBuilder, ref attributes);
var compilation = this.DeclaringCompilation;
var returnType = this.ReturnType;
if (returnType.ContainsDynamic() && compilation.HasDynamicEmitAttributes())
{
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(returnType, ReturnTypeCustomModifiers.Length + RefCustomModifiers.Length, RefKind));
}
if (returnType.ContainsTupleNames() && compilation.HasTupleNamesAttributes)
{
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeTupleNamesAttribute(returnType));
}
}
internal override int CalculateLocalSyntaxOffset(int localPosition, SyntaxTree localTree) internal override int CalculateLocalSyntaxOffset(int localPosition, SyntaxTree localTree)
{ {
return localPosition; return localPosition;
......
...@@ -1010,6 +1010,11 @@ internal override IEnumerable<INamespaceTypeDefinition> GetTopLevelTypesCore(Emi ...@@ -1010,6 +1010,11 @@ internal override IEnumerable<INamespaceTypeDefinition> GetTopLevelTypesCore(Emi
} }
} }
internal override SynthesizedAttributeData SynthesizeEmbeddedAttribute()
{
throw new NotImplementedException();
}
public override int CurrentGenerationOrdinal => _builder.CurrentGenerationOrdinal; public override int CurrentGenerationOrdinal => _builder.CurrentGenerationOrdinal;
public override ISourceAssemblySymbolInternal SourceAssemblyOpt => _builder.SourceAssemblyOpt; public override ISourceAssemblySymbolInternal SourceAssemblyOpt => _builder.SourceAssemblyOpt;
......
...@@ -156,8 +156,9 @@ public static StringHandle GetName(this MetadataReader reader, EntityHandle toke ...@@ -156,8 +156,9 @@ public static StringHandle GetName(this MetadataReader reader, EntityHandle toke
switch (token.Kind) switch (token.Kind)
{ {
case HandleKind.TypeReference: case HandleKind.TypeReference:
var typeRef = reader.GetTypeReference((TypeReferenceHandle)token); return reader.GetTypeReference((TypeReferenceHandle)token).Name;
return typeRef.Name; case HandleKind.TypeDefinition:
return reader.GetTypeDefinition((TypeDefinitionHandle)token).Name;
default: default:
throw ExceptionUtilities.UnexpectedValue(token.Kind); throw ExceptionUtilities.UnexpectedValue(token.Kind);
} }
...@@ -172,6 +173,25 @@ public static IEnumerable<CustomAttributeRow> GetCustomAttributeRows(this Metada ...@@ -172,6 +173,25 @@ public static IEnumerable<CustomAttributeRow> GetCustomAttributeRows(this Metada
} }
} }
public static string GetCustomAttributeName(this MetadataReader reader, CustomAttributeRow row)
{
EntityHandle parent;
var token = row.ConstructorToken;
switch (token.Kind)
{
case HandleKind.MemberReference:
parent = reader.GetMemberReference((MemberReferenceHandle)token).Parent;
break;
case HandleKind.MethodDefinition:
parent = reader.GetMethodDefinition((MethodDefinitionHandle)token).GetDeclaringType();
break;
default:
throw ExceptionUtilities.UnexpectedValue(token.Kind);
}
var strHandle = reader.GetName(parent);
return reader.GetString(strHandle);
}
public static bool IsIncluded(this ImmutableArray<byte> metadata, string str) public static bool IsIncluded(this ImmutableArray<byte> metadata, string str)
{ {
var builder = ArrayBuilder<byte>.GetInstance(); var builder = ArrayBuilder<byte>.GetInstance();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册