Browse Source

Rename lifetime annotation to `ScopedRef`

pull/2992/head
Daniel Grunwald 2 years ago
parent
commit
3dc2f3d5b6
  1. 4
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  2. 19
      ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs
  3. 2
      ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs
  4. 22
      ICSharpCode.Decompiler/DecompilerSettings.cs
  5. 10
      ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs
  6. 8
      ICSharpCode.Decompiler/TypeSystem/IParameter.cs
  7. 2
      ICSharpCode.Decompiler/TypeSystem/Implementation/AttributeListBuilder.cs
  8. 4
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataParameter.cs
  9. 18
      ILSpy/Properties/Resources.Designer.cs
  10. 6
      ILSpy/Properties/Resources.resx

4
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -2565,9 +2565,9 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -2565,9 +2565,9 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
WriteKeyword(ParameterDeclaration.ThisModifierRole);
Space();
}
if (parameterDeclaration.IsRefScoped)
if (parameterDeclaration.IsScopedRef)
{
WriteKeyword(ParameterDeclaration.RefScopedRole);
WriteKeyword(ParameterDeclaration.ScopedRefRole);
Space();
}
switch (parameterDeclaration.ParameterModifier)

19
ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs

@ -44,7 +44,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -44,7 +44,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{
public static readonly Role<AttributeSection> AttributeRole = EntityDeclaration.AttributeRole;
public static readonly TokenRole ThisModifierRole = new TokenRole("this");
public static readonly TokenRole RefScopedRole = new TokenRole("scoped");
public static readonly TokenRole ScopedRefRole = new TokenRole("scoped");
[Obsolete("Renamed to ScopedRefRole")]
public static readonly TokenRole RefScopedRole = ScopedRefRole;
public static readonly TokenRole RefModifierRole = new TokenRole("ref");
public static readonly TokenRole OutModifierRole = new TokenRole("out");
public static readonly TokenRole InModifierRole = new TokenRole("in");
@ -105,7 +107,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -105,7 +107,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
}
bool hasThisModifier;
bool isRefScoped;
bool isScopedRef;
public CSharpTokenNode ThisKeyword {
get {
@ -125,11 +127,20 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -125,11 +127,20 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
}
}
public bool IsScopedRef {
get { return isScopedRef; }
set {
ThrowIfFrozen();
isScopedRef = value;
}
}
[Obsolete("Renamed to IsScopedRef")]
public bool IsRefScoped {
get { return isRefScoped; }
get { return isScopedRef; }
set {
ThrowIfFrozen();
isRefScoped = value;
isScopedRef = value;
}
}

2
ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

@ -1654,7 +1654,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -1654,7 +1654,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{
decl.ParameterModifier = ParameterModifier.Params;
}
decl.IsRefScoped = parameter.Lifetime.RefScoped;
decl.IsScopedRef = parameter.Lifetime.ScopedRef;
if (ShowAttributes)
{
decl.Attributes.AddRange(ConvertAttributes(parameter.GetAttributes()));

22
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -150,7 +150,7 @@ namespace ICSharpCode.Decompiler @@ -150,7 +150,7 @@ namespace ICSharpCode.Decompiler
if (languageVersion < CSharp.LanguageVersion.CSharp11_0)
{
parameterNullCheck = false;
lifetimeAnnotations = false;
scopedRef = false;
requiredMembers = false;
numericIntPtr = false;
utf8StringLiterals = false;
@ -159,7 +159,7 @@ namespace ICSharpCode.Decompiler @@ -159,7 +159,7 @@ namespace ICSharpCode.Decompiler
public CSharp.LanguageVersion GetMinimumRequiredVersion()
{
if (parameterNullCheck || lifetimeAnnotations || requiredMembers || numericIntPtr || utf8StringLiterals)
if (parameterNullCheck || scopedRef || requiredMembers || numericIntPtr || utf8StringLiterals)
return CSharp.LanguageVersion.CSharp11_0;
if (fileScopedNamespaces || recordStructs)
return CSharp.LanguageVersion.CSharp10_0;
@ -358,24 +358,30 @@ namespace ICSharpCode.Decompiler @@ -358,24 +358,30 @@ namespace ICSharpCode.Decompiler
}
}
bool lifetimeAnnotations = true;
bool scopedRef = true;
/// <summary>
/// Use C# 11 <c>scoped</c> modifier.
/// </summary>
[Category("C# 11.0 / VS 2022.4")]
[Description("DecompilerSettings.LifetimeAnnotations")]
public bool LifetimeAnnotations {
get { return lifetimeAnnotations; }
[Description("DecompilerSettings.ScopedRef")]
public bool ScopedRef {
get { return scopedRef; }
set {
if (lifetimeAnnotations != value)
if (scopedRef != value)
{
lifetimeAnnotations = value;
scopedRef = value;
OnPropertyChanged();
}
}
}
[Obsolete("Renamed to ScopedRef. This property will be removed in a future version of the decompiler.")]
public bool LifetimeAnnotations {
get { return ScopedRef; }
set { ScopedRef = value; }
}
bool requiredMembers = true;
/// <summary>

10
ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs

@ -123,7 +123,9 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -123,7 +123,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// Allow C# 11 scoped annotation. If this option is not enabled, ScopedRefAttribute
/// will be reported as custom attribute.
/// </summary>
LifetimeAnnotations = 0x4000,
ScopedRef = 0x4000,
[Obsolete("Use ScopedRef instead")]
LifetimeAnnotations = ScopedRef,
/// <summary>
/// Replace 'IntPtr' types with the 'nint' type even in absence of [NativeIntegerAttribute].
/// Note: DecompilerTypeSystem constructor removes this setting from the options if
@ -135,7 +137,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -135,7 +137,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// </summary>
Default = Dynamic | Tuple | ExtensionMethods | DecimalConstants | ReadOnlyStructsAndParameters
| RefStructs | UnmanagedConstraints | NullabilityAnnotations | ReadOnlyMethods
| NativeIntegers | FunctionPointers | LifetimeAnnotations | NativeIntegersWithoutAttribute
| NativeIntegers | FunctionPointers | ScopedRef | NativeIntegersWithoutAttribute
}
/// <summary>
@ -171,8 +173,8 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -171,8 +173,8 @@ namespace ICSharpCode.Decompiler.TypeSystem
typeSystemOptions |= TypeSystemOptions.NativeIntegers;
if (settings.FunctionPointers)
typeSystemOptions |= TypeSystemOptions.FunctionPointers;
if (settings.LifetimeAnnotations)
typeSystemOptions |= TypeSystemOptions.LifetimeAnnotations;
if (settings.ScopedRef)
typeSystemOptions |= TypeSystemOptions.ScopedRef;
if (settings.NumericIntPtr)
typeSystemOptions |= TypeSystemOptions.NativeIntegersWithoutAttribute;
return typeSystemOptions;

8
ICSharpCode.Decompiler/TypeSystem/IParameter.cs

@ -40,6 +40,14 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -40,6 +40,14 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <summary>
/// C# 11 scoped annotation: "scoped ref" (ScopedRefAttribute)
/// </summary>
public bool ScopedRef {
#pragma warning disable 618
get { return RefScoped; }
set { RefScoped = value; }
#pragma warning restore 618
}
[Obsolete("Use ScopedRef property instead of directly accessing this field")]
public bool RefScoped;
[Obsolete("C# 11 preview: \"ref scoped\" no longer supported")]

2
ICSharpCode.Decompiler/TypeSystem/Implementation/AttributeListBuilder.cs

@ -253,7 +253,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -253,7 +253,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
return (options & TypeSystemOptions.NullabilityAnnotations) != 0
&& (target == SymbolKind.TypeDefinition || IsMethodLike(target));
case "ScopedRefAttribute":
return (options & TypeSystemOptions.LifetimeAnnotations) != 0
return (options & TypeSystemOptions.ScopedRef) != 0
&& (target == SymbolKind.Parameter);
default:
return false;

4
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataParameter.cs

@ -117,7 +117,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -117,7 +117,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public LifetimeAnnotation Lifetime {
get {
if ((module.TypeSystemOptions & TypeSystemOptions.LifetimeAnnotations) == 0)
if ((module.TypeSystemOptions & TypeSystemOptions.ScopedRef) == 0)
{
return default;
}
@ -126,7 +126,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -126,7 +126,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
var parameterDef = metadata.GetParameter(handle);
if (parameterDef.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.ScopedRef))
{
return new LifetimeAnnotation { RefScoped = true };
return new LifetimeAnnotation { ScopedRef = true };
}
return default;
}

18
ILSpy/Properties/Resources.Designer.cs generated

@ -1073,15 +1073,6 @@ namespace ICSharpCode.ILSpy.Properties { @@ -1073,15 +1073,6 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to &apos;scoped&apos; lifetime annotation.
/// </summary>
public static string DecompilerSettings_LifetimeAnnotations {
get {
return ResourceManager.GetString("DecompilerSettings.LifetimeAnnotations", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Use nint/nuint types.
/// </summary>
@ -1235,6 +1226,15 @@ namespace ICSharpCode.ILSpy.Properties { @@ -1235,6 +1226,15 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to &apos;scoped&apos; lifetime annotation.
/// </summary>
public static string DecompilerSettings_ScopedRef {
get {
return ResourceManager.GetString("DecompilerSettings.ScopedRef", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Separate local variable declarations and initializers (int x = 5; -&gt; int x; x = 5;), if possible.
/// </summary>

6
ILSpy/Properties/Resources.resx

@ -381,9 +381,6 @@ Are you sure you want to continue?</value> @@ -381,9 +381,6 @@ Are you sure you want to continue?</value>
<data name="DecompilerSettings.IsUnmanagedAttributeOnTypeParametersShouldBeReplacedWithUnmanagedConstraints" xml:space="preserve">
<value>IsUnmanagedAttribute on type parameters should be replaced with 'unmanaged' constraints</value>
</data>
<data name="DecompilerSettings.LifetimeAnnotations" xml:space="preserve">
<value>'scoped' lifetime annotation</value>
</data>
<data name="DecompilerSettings.NativeIntegers" xml:space="preserve">
<value>Use nint/nuint types</value>
</data>
@ -435,6 +432,9 @@ Are you sure you want to continue?</value> @@ -435,6 +432,9 @@ Are you sure you want to continue?</value>
<data name="DecompilerSettings.RequiredMembers" xml:space="preserve">
<value>Required members</value>
</data>
<data name="DecompilerSettings.ScopedRef" xml:space="preserve">
<value>'scoped' lifetime annotation</value>
</data>
<data name="DecompilerSettings.SeparateLocalVariableDeclarations" xml:space="preserve">
<value>Separate local variable declarations and initializers (int x = 5; -&gt; int x; x = 5;), if possible</value>
</data>

Loading…
Cancel
Save