提交 6a688b0f 编写于 作者: O Omar Tawfik 提交者: vsadov

Replace IsConst modreq with InAttribute

Fixes #19950
上级 2401959c
......@@ -304,9 +304,9 @@ private sealed class PEParameterSymbolWithCustomModifiers : PEParameterSymbol
_customModifiers = CSharpCustomModifier.Convert(customModifiers);
_refCustomModifiers = CSharpCustomModifier.Convert(refCustomModifiers);
if (this.RefKind != RefKind.RefReadOnly && _refCustomModifiers.Any(modifier => !modifier.IsOptional && modifier.Modifier.IsWellKnownTypeIsConst()))
if (this.RefKind != RefKind.RefReadOnly && _refCustomModifiers.Any(modifier => !modifier.IsOptional && modifier.Modifier.IsWellKnownTypeInAttribute()))
{
// IsConst modreq is only accepted on RefReadOnly symbols
// The modreq is only accepted on RefReadOnly symbols
isBad = true;
}
......
......@@ -742,8 +742,8 @@ private sealed class PEPropertySymbolWithCustomModifiers : PEPropertySymbol
_typeCustomModifiers = CSharpCustomModifier.Convert(returnInfo.CustomModifiers);
_refCustomModifiers = CSharpCustomModifier.Convert(returnInfo.RefCustomModifiers);
// IsConst modreq is only accepted on RefReadOnly symbols
isBad = this.RefKind != RefKind.RefReadOnly && _refCustomModifiers.Any(modifier => !modifier.IsOptional && modifier.Modifier.IsWellKnownTypeIsConst());
// The modreq is only accepted on RefReadOnly symbols
isBad = this.RefKind != RefKind.RefReadOnly && _refCustomModifiers.Any(modifier => !modifier.IsOptional && modifier.Modifier.IsWellKnownTypeInAttribute());
}
public override ImmutableArray<CustomModifier> TypeCustomModifiers
......
......@@ -57,9 +57,9 @@ internal override bool IsAcceptedVolatileModifierType(PEModuleSymbol moduleSymbo
return type.SpecialType == SpecialType.System_Runtime_CompilerServices_IsVolatile;
}
internal override bool IsAcceptedIsConstModifierType(TypeSymbol type)
internal override bool IsAcceptedInAttributeModifierType(TypeSymbol type)
{
return type.IsWellKnownTypeIsConst();
return type.IsWellKnownTypeInAttribute();
}
internal override TypeSymbol GetSZArrayTypeSymbol(PEModuleSymbol moduleSymbol, TypeSymbol elementType, ImmutableArray<ModifierInfo<TypeSymbol>> customModifiers)
......
......@@ -161,7 +161,7 @@ private void ComputeParameters()
arglistToken: out arglistToken,
allowRefOrOut: true,
allowThis: true,
addIsConstModifier: false,
addRefReadOnlyModifier: false,
diagnostics: diagnostics);
ParameterHelpers.EnsureIsReadOnlyAttributeExists(parameters, diagnostics, modifyCompilationForRefReadOnly: false);
......
......@@ -22,7 +22,7 @@ internal static class ParameterHelpers
DiagnosticBag diagnostics,
bool allowRefOrOut,
bool allowThis,
bool addIsConstModifier)
bool addRefReadOnlyModifier)
{
arglistToken = default(SyntaxToken);
......@@ -92,7 +92,7 @@ internal static class ParameterHelpers
parameterIndex,
(paramsKeyword.Kind() != SyntaxKind.None),
parameterIndex == 0 && thisKeyword.Kind() != SyntaxKind.None,
addIsConstModifier,
addRefReadOnlyModifier,
diagnostics);
ReportParameterErrors(owner, parameterSyntax, parameter, thisKeyword, paramsKeyword, firstDefault, diagnostics);
......
......@@ -83,7 +83,7 @@ protected override void MethodChecks(DiagnosticBag diagnostics)
bodyBinder, this, parameterList, out arglistToken,
allowRefOrOut: true,
allowThis: false,
addIsConstModifier: false,
addRefReadOnlyModifier: false,
diagnostics: diagnostics);
_lazyIsVararg = (arglistToken.Kind() == SyntaxKind.ArgListKeyword);
......
......@@ -251,7 +251,7 @@ private sealed class InvokeMethod : SourceDelegateMethodSymbol
binder, this, syntax.ParameterList, out arglistToken,
allowRefOrOut: true,
allowThis: false,
addIsConstModifier: true,
addRefReadOnlyModifier: true,
diagnostics: diagnostics);
if (arglistToken.Kind() == SyntaxKind.ArgListKeyword)
......@@ -264,8 +264,8 @@ private sealed class InvokeMethod : SourceDelegateMethodSymbol
if (_refKind == RefKind.RefReadOnly)
{
var isConstType = binder.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsConst, diagnostics, syntax.ReturnType);
_refCustomModifiers = ImmutableArray.Create(CSharpCustomModifier.CreateRequired(isConstType));
var modifierType = binder.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_InAttribute, diagnostics, syntax.ReturnType);
_refCustomModifiers = ImmutableArray.Create(CSharpCustomModifier.CreateRequired(modifierType));
}
else
{
......
......@@ -168,7 +168,7 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB
signatureBinder, this, syntax.ParameterList, out arglistToken,
allowRefOrOut: true,
allowThis: true,
addIsConstModifier: IsVirtual || IsAbstract,
addRefReadOnlyModifier: IsVirtual || IsAbstract,
diagnostics: diagnostics);
_lazyIsVararg = (arglistToken.Kind() == SyntaxKind.ArgListKeyword);
......@@ -338,11 +338,11 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB
}
else if (_refKind == RefKind.RefReadOnly)
{
var isConstType = withTypeParamsBinder.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsConst, diagnostics, syntax.ReturnType);
var modifierType = withTypeParamsBinder.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_InAttribute, diagnostics, syntax.ReturnType);
_lazyCustomModifiers = CustomModifiersTuple.Create(
typeCustomModifiers: ImmutableArray<CustomModifier>.Empty,
refCustomModifiers: ImmutableArray.Create(CSharpCustomModifier.CreateRequired(isConstType)));
refCustomModifiers: ImmutableArray.Create(CSharpCustomModifier.CreateRequired(modifierType)));
}
}
else if ((object)_explicitInterfaceType != null)
......
......@@ -35,7 +35,7 @@ internal abstract class SourceParameterSymbol : SourceParameterSymbolBase
int ordinal,
bool isParams,
bool isExtensionMethodThis,
bool addIsConstModifier,
bool addRefReadOnlyModifier,
DiagnosticBag declarationDiagnostics)
{
var name = identifier.ValueText;
......@@ -50,9 +50,9 @@ internal abstract class SourceParameterSymbol : SourceParameterSymbolBase
identifier.Parent.GetLocation());
}
if (addIsConstModifier && refKind == RefKind.RefReadOnly)
if (addRefReadOnlyModifier && refKind == RefKind.RefReadOnly)
{
var isConstType = context.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsConst, declarationDiagnostics, syntax);
var modifierType = context.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_InAttribute, declarationDiagnostics, syntax);
return new SourceComplexParameterSymbolWithCustomModifiers(
owner,
......@@ -60,7 +60,7 @@ internal abstract class SourceParameterSymbol : SourceParameterSymbolBase
parameterType,
refKind,
ImmutableArray<CustomModifier>.Empty,
ImmutableArray.Create(CSharpCustomModifier.CreateRequired(isConstType)),
ImmutableArray.Create(CSharpCustomModifier.CreateRequired(modifierType)),
name,
locations,
syntax.GetReference(),
......
......@@ -281,11 +281,11 @@ internal sealed class SourcePropertySymbol : PropertySymbol, IAttributeTargetSym
}
else if (_refKind == RefKind.RefReadOnly)
{
var isConstType = bodyBinder.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsConst, diagnostics, syntax.Type);
var modifierType = bodyBinder.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_InAttribute, diagnostics, syntax.Type);
_customModifiers = CustomModifiersTuple.Create(
ImmutableArray<CustomModifier>.Empty,
ImmutableArray.Create(CSharpCustomModifier.CreateRequired(isConstType)));
ImmutableArray.Create(CSharpCustomModifier.CreateRequired(modifierType)));
}
if (!hasAccessorList)
......@@ -789,7 +789,7 @@ private DeclarationModifiers MakeModifiers(SyntaxTokenList modifiers, bool isExp
}
private static ImmutableArray<ParameterSymbol> MakeParameters(
Binder binder, SourcePropertySymbol owner, BaseParameterListSyntax parameterSyntaxOpt, DiagnosticBag diagnostics, bool addIsConstModifier)
Binder binder, SourcePropertySymbol owner, BaseParameterListSyntax parameterSyntaxOpt, DiagnosticBag diagnostics, bool addRefReadOnlyModifier)
{
if (parameterSyntaxOpt == null)
{
......@@ -806,7 +806,7 @@ private DeclarationModifiers MakeModifiers(SyntaxTokenList modifiers, bool isExp
binder, owner, parameterSyntaxOpt, out arglistToken,
allowRefOrOut: false,
allowThis: false,
addIsConstModifier: addIsConstModifier,
addRefReadOnlyModifier: addRefReadOnlyModifier,
diagnostics: diagnostics);
if (arglistToken.Kind() != SyntaxKind.None)
......@@ -1408,7 +1408,7 @@ private TypeSymbol ComputeType(Binder binder, BasePropertyDeclarationSyntax synt
private ImmutableArray<ParameterSymbol> ComputeParameters(Binder binder, BasePropertyDeclarationSyntax syntax, DiagnosticBag diagnostics)
{
var parameterSyntaxOpt = GetParameterListSyntax(syntax);
var parameters = MakeParameters(binder, this, parameterSyntaxOpt, diagnostics, addIsConstModifier: IsVirtual || IsAbstract);
var parameters = MakeParameters(binder, this, parameterSyntaxOpt, diagnostics, addRefReadOnlyModifier: IsVirtual || IsAbstract);
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
foreach (ParameterSymbol param in parameters)
......
......@@ -131,7 +131,7 @@ protected override void MethodChecks(DiagnosticBag diagnostics)
out arglistToken,
allowRefOrOut: true,
allowThis: false,
addIsConstModifier: false,
addRefReadOnlyModifier: false,
diagnostics: diagnostics);
if (arglistToken.Kind() == SyntaxKind.ArgListKeyword)
......
......@@ -1529,20 +1529,20 @@ private static bool NormalizeTaskTypesInPointer(CSharpCompilation compilation, r
return new Cci.TypeReferenceWithAttributes(typeRef);
}
internal static bool IsWellKnownTypeIsConst(this ITypeSymbol typeSymbol)
internal static bool IsWellKnownTypeInAttribute(this ITypeSymbol typeSymbol)
{
if (typeSymbol.Name != "IsConst" || typeSymbol.ContainingType != null)
if (typeSymbol.Name != "InAttribute" || typeSymbol.ContainingType != null)
{
return false;
}
var compilerServicesNamespace = typeSymbol.ContainingNamespace;
if (compilerServicesNamespace?.Name != "CompilerServices")
var interopServicesNamespace = typeSymbol.ContainingNamespace;
if (interopServicesNamespace?.Name != "InteropServices")
{
return false;
}
var runtimeNamespace = compilerServicesNamespace.ContainingNamespace;
var runtimeNamespace = interopServicesNamespace.ContainingNamespace;
if (runtimeNamespace?.Name != "Runtime")
{
return false;
......
......@@ -161,7 +161,7 @@
<Compile Include="Emit\EntryPointTests.cs" />
<Compile Include="Emit\NoPiaEmbedTypes.cs" />
<Compile Include="Emit\OptionalArgumentsTests.cs" />
<Compile Include="Emit\IsConstModifierTests.cs" />
<Compile Include="Emit\InAttributeModifierTests.cs" />
<Compile Include="Emit\ResourceTests.cs" />
<Compile Include="CodeGen\CodeGenScriptTests.cs" />
<Compile Include="PDB\CheckSumTest.cs" />
......
......@@ -708,8 +708,8 @@ private TypeSymbol GetTypeOfTypeDef(TypeDefinitionHandle typeDef, out bool isNoP
switch (allowedRequiredModifierType)
{
case AllowedRequiredModifierType.System_Runtime_CompilerServices_IsConst:
isAllowed = IsAcceptedIsConstModifierType(type);
case AllowedRequiredModifierType.System_Runtime_InteropServices_InAttribute:
isAllowed = IsAcceptedInAttributeModifierType(type);
break;
case AllowedRequiredModifierType.System_Runtime_CompilerServices_Volatile:
isAllowed = IsAcceptedVolatileModifierType(type);
......@@ -1130,9 +1130,9 @@ private void DecodeParameterOrThrow(ref BlobReader signatureReader, /*out*/ ref
{
info.CustomModifiers = DecodeModifiersOrThrow(
ref signatureReader,
AllowedRequiredModifierType.System_Runtime_CompilerServices_IsConst,
AllowedRequiredModifierType.System_Runtime_InteropServices_InAttribute,
out SignatureTypeCode typeCode,
out bool isConstFound);
out bool inAttributeFound);
if (typeCode == SignatureTypeCode.ByReference)
{
......@@ -1140,7 +1140,7 @@ private void DecodeParameterOrThrow(ref BlobReader signatureReader, /*out*/ ref
info.RefCustomModifiers = info.CustomModifiers;
info.CustomModifiers = DecodeModifiersOrThrow(ref signatureReader, AllowedRequiredModifierType.None, out typeCode, out _);
}
else if (isConstFound)
else if (inAttributeFound)
{
// This cannot be placed on CustomModifiers, just RefCustomModifiers
throw new UnsupportedSignatureContent();
......@@ -2412,7 +2412,7 @@ private enum AllowedRequiredModifierType
{
None,
System_Runtime_CompilerServices_Volatile,
System_Runtime_CompilerServices_IsConst,
System_Runtime_InteropServices_InAttribute,
}
}
}
......@@ -41,7 +41,7 @@ internal abstract class SymbolFactory<ModuleSymbol, TypeSymbol>
internal abstract TypeSymbol GetEnumUnderlyingType(ModuleSymbol moduleSymbol, TypeSymbol type);
internal abstract bool IsAcceptedVolatileModifierType(ModuleSymbol moduleSymbol, TypeSymbol type);
internal abstract bool IsAcceptedIsConstModifierType(TypeSymbol type);
internal abstract bool IsAcceptedInAttributeModifierType(TypeSymbol type);
internal abstract Cci.PrimitiveTypeCode GetPrimitiveTypeCode(ModuleSymbol moduleSymbol, TypeSymbol type);
}
}
......@@ -93,9 +93,9 @@ protected bool IsAcceptedVolatileModifierType(TypeSymbol type)
return _factory.IsAcceptedVolatileModifierType(this.moduleSymbol, type);
}
protected bool IsAcceptedIsConstModifierType(TypeSymbol type)
protected bool IsAcceptedInAttributeModifierType(TypeSymbol type)
{
return _factory.IsAcceptedIsConstModifierType(type);
return _factory.IsAcceptedInAttributeModifierType(type);
}
protected Microsoft.Cci.PrimitiveTypeCode GetPrimitiveTypeCode(TypeSymbol type)
......
......@@ -267,7 +267,7 @@ internal enum WellKnownType
System_Runtime_CompilerServices_IsReadOnlyAttribute,
System_Runtime_CompilerServices_IsByRefLikeAttribute,
System_Runtime_CompilerServices_IsConst,
System_Runtime_InteropServices_InAttribute,
System_ObsoleteAttribute,
NextAvailable,
......@@ -531,7 +531,7 @@ internal static class WellKnownTypes
"System.Runtime.CompilerServices.IsReadOnlyAttribute",
"System.Runtime.CompilerServices.IsByRefLikeAttribute",
"System.Runtime.CompilerServices.IsConst",
"System.Runtime.InteropServices.InAttribute",
"System.ObsoleteAttribute",
};
......
......@@ -49,7 +49,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE
Return False
End Function
Friend Overrides Function IsAcceptedIsConstModifierType(type As TypeSymbol) As Boolean
Friend Overrides Function IsAcceptedInAttributeModifierType(type As TypeSymbol) As Boolean
' VB doesn't deal with ref-readonly parameters or return-types.
Return False
End Function
......
......@@ -89,7 +89,7 @@
<Compile Include="SymbolsTests\AnonymousTypes\AnonymousTypesEmittedSymbolsTests.vb" />
<Compile Include="SymbolsTests\AnonymousTypes\AnonymousTypesSemanticsTests.vb" />
<Compile Include="SymbolsTests\CustomModifiersTests.vb" />
<Compile Include="SymbolsTests\Metadata\PE\IsConstModifierTests.vb" />
<Compile Include="SymbolsTests\Metadata\PE\InAttributeModifierTests.vb" />
<Compile Include="SymbolsTests\WellKnownTypeValidationTests.vb" />
<Compile Include="SymbolsTests\AssemblyAndNamespaceTests.vb" />
<Compile Include="SymbolsTests\CompilationCreationTests.vb" />
......
......@@ -5,7 +5,7 @@ Imports Microsoft.CodeAnalysis.Test.Utilities
Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Symbols.Metadata
Public Class IsConstModifierTests
Public Class InAttributeModifierTests
Inherits BasicTestBase
<Fact>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册