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
WriteKeyword(ParameterDeclaration.ThisModifierRole); WriteKeyword(ParameterDeclaration.ThisModifierRole);
Space(); Space();
} }
if (parameterDeclaration.IsRefScoped) if (parameterDeclaration.IsScopedRef)
{ {
WriteKeyword(ParameterDeclaration.RefScopedRole); WriteKeyword(ParameterDeclaration.ScopedRefRole);
Space(); Space();
} }
switch (parameterDeclaration.ParameterModifier) switch (parameterDeclaration.ParameterModifier)

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

@ -44,7 +44,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{ {
public static readonly Role<AttributeSection> AttributeRole = EntityDeclaration.AttributeRole; public static readonly Role<AttributeSection> AttributeRole = EntityDeclaration.AttributeRole;
public static readonly TokenRole ThisModifierRole = new TokenRole("this"); 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 RefModifierRole = new TokenRole("ref");
public static readonly TokenRole OutModifierRole = new TokenRole("out"); public static readonly TokenRole OutModifierRole = new TokenRole("out");
public static readonly TokenRole InModifierRole = new TokenRole("in"); public static readonly TokenRole InModifierRole = new TokenRole("in");
@ -105,7 +107,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
} }
bool hasThisModifier; bool hasThisModifier;
bool isRefScoped; bool isScopedRef;
public CSharpTokenNode ThisKeyword { public CSharpTokenNode ThisKeyword {
get { get {
@ -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 { public bool IsRefScoped {
get { return isRefScoped; } get { return isScopedRef; }
set { set {
ThrowIfFrozen(); ThrowIfFrozen();
isRefScoped = value; isScopedRef = value;
} }
} }

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

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

22
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -150,7 +150,7 @@ namespace ICSharpCode.Decompiler
if (languageVersion < CSharp.LanguageVersion.CSharp11_0) if (languageVersion < CSharp.LanguageVersion.CSharp11_0)
{ {
parameterNullCheck = false; parameterNullCheck = false;
lifetimeAnnotations = false; scopedRef = false;
requiredMembers = false; requiredMembers = false;
numericIntPtr = false; numericIntPtr = false;
utf8StringLiterals = false; utf8StringLiterals = false;
@ -159,7 +159,7 @@ namespace ICSharpCode.Decompiler
public CSharp.LanguageVersion GetMinimumRequiredVersion() public CSharp.LanguageVersion GetMinimumRequiredVersion()
{ {
if (parameterNullCheck || lifetimeAnnotations || requiredMembers || numericIntPtr || utf8StringLiterals) if (parameterNullCheck || scopedRef || requiredMembers || numericIntPtr || utf8StringLiterals)
return CSharp.LanguageVersion.CSharp11_0; return CSharp.LanguageVersion.CSharp11_0;
if (fileScopedNamespaces || recordStructs) if (fileScopedNamespaces || recordStructs)
return CSharp.LanguageVersion.CSharp10_0; return CSharp.LanguageVersion.CSharp10_0;
@ -358,24 +358,30 @@ namespace ICSharpCode.Decompiler
} }
} }
bool lifetimeAnnotations = true; bool scopedRef = true;
/// <summary> /// <summary>
/// Use C# 11 <c>scoped</c> modifier. /// Use C# 11 <c>scoped</c> modifier.
/// </summary> /// </summary>
[Category("C# 11.0 / VS 2022.4")] [Category("C# 11.0 / VS 2022.4")]
[Description("DecompilerSettings.LifetimeAnnotations")] [Description("DecompilerSettings.ScopedRef")]
public bool LifetimeAnnotations { public bool ScopedRef {
get { return lifetimeAnnotations; } get { return scopedRef; }
set { set {
if (lifetimeAnnotations != value) if (scopedRef != value)
{ {
lifetimeAnnotations = value; scopedRef = value;
OnPropertyChanged(); 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; bool requiredMembers = true;
/// <summary> /// <summary>

10
ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs

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

8
ICSharpCode.Decompiler/TypeSystem/IParameter.cs

@ -40,6 +40,14 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <summary> /// <summary>
/// C# 11 scoped annotation: "scoped ref" (ScopedRefAttribute) /// C# 11 scoped annotation: "scoped ref" (ScopedRefAttribute)
/// </summary> /// </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; public bool RefScoped;
[Obsolete("C# 11 preview: \"ref scoped\" no longer supported")] [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
return (options & TypeSystemOptions.NullabilityAnnotations) != 0 return (options & TypeSystemOptions.NullabilityAnnotations) != 0
&& (target == SymbolKind.TypeDefinition || IsMethodLike(target)); && (target == SymbolKind.TypeDefinition || IsMethodLike(target));
case "ScopedRefAttribute": case "ScopedRefAttribute":
return (options & TypeSystemOptions.LifetimeAnnotations) != 0 return (options & TypeSystemOptions.ScopedRef) != 0
&& (target == SymbolKind.Parameter); && (target == SymbolKind.Parameter);
default: default:
return false; return false;

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

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

18
ILSpy/Properties/Resources.Designer.cs generated

@ -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> /// <summary>
/// Looks up a localized string similar to Use nint/nuint types. /// Looks up a localized string similar to Use nint/nuint types.
/// </summary> /// </summary>
@ -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> /// <summary>
/// Looks up a localized string similar to Separate local variable declarations and initializers (int x = 5; -&gt; int x; x = 5;), if possible. /// Looks up a localized string similar to Separate local variable declarations and initializers (int x = 5; -&gt; int x; x = 5;), if possible.
/// </summary> /// </summary>

6
ILSpy/Properties/Resources.resx

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

Loading…
Cancel
Save