diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index 4fa6cd40ce..4653b56adc 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -3,6 +3,7 @@ net46 + latest True @@ -62,6 +63,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index 30d62d94d5..d246eed85b 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -224,6 +224,12 @@ public void VariableNamingWithoutSymbols([ValueSource("defaultOptions")] Compile Run(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings { UseDebugSymbols = false }); } + [Test] + public void CS72_PrivateProtected([ValueSource("roslynOnlyOptions")] CompilerOptions cscOptions) + { + Run(cscOptions: cscOptions); + } + void Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null) { var ilFile = Path.Combine(TestCasePath, testName) + Tester.GetSuffix(cscOptions) + ".il"; diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.cs new file mode 100644 index 0000000000..914bd48cd3 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.cs @@ -0,0 +1,31 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty +{ + internal class CS72_PrivateProtected + { + private protected int Property { + get; + } + + private protected void Method() + { + } + } +} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.opt.roslyn.il new file mode 100644 index 0000000000..7f53001054 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.opt.roslyn.il @@ -0,0 +1,83 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly CS72_PrivateProtected +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) + .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module CS72_PrivateProtected.dll +// MVID: {16957694-0DCC-41BA-B992-22F83B96A9D7} +.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) +.imagebase 0x10000000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY +// Image base: 0x031E0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected + extends [mscorlib]System.Object +{ + .field private initonly int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method famandassem hidebysig specialname + instance int32 get_Property() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected::'k__BackingField' + IL_0006: ret + } // end of method CS72_PrivateProtected::get_Property + + .method famandassem hidebysig instance void + Method() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method CS72_PrivateProtected::Method + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method CS72_PrivateProtected::.ctor + + .property instance int32 Property() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected::get_Property() + } // end of property CS72_PrivateProtected::Property +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.roslyn.il new file mode 100644 index 0000000000..03f508c0be --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.roslyn.il @@ -0,0 +1,86 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly CS72_PrivateProtected +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) + .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module CS72_PrivateProtected.dll +// MVID: {056F9D5F-A186-4957-9181-B6C798C15C6C} +.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) +.imagebase 0x10000000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY +// Image base: 0x03A40000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected + extends [mscorlib]System.Object +{ + .field private initonly int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method famandassem hidebysig specialname + instance int32 get_Property() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected::'k__BackingField' + IL_0006: ret + } // end of method CS72_PrivateProtected::get_Property + + .method famandassem hidebysig instance void + Method() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method CS72_PrivateProtected::Method + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method CS72_PrivateProtected::.ctor + + .property instance int32 Property() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected::get_Property() + } // end of property CS72_PrivateProtected::Property +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs b/ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs index d0f6c15fa7..01292b7400 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs @@ -62,7 +62,7 @@ protected internal override bool DoMatch(AstNode other, PatternMatching.Match ma // Not worth using a dictionary for such few elements. // This table is sorted in the order that modifiers should be output when generating code. static readonly Modifiers[] allModifiers = { - Modifiers.Public, Modifiers.Protected, Modifiers.Private, Modifiers.Internal, + Modifiers.Public, Modifiers.Private, Modifiers.Protected, Modifiers.Internal, Modifiers.New, Modifiers.Unsafe, Modifiers.Abstract, Modifiers.Virtual, Modifiers.Sealed, Modifiers.Static, Modifiers.Override, diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs index abf709ad75..b75feb53fc 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs @@ -1057,8 +1057,9 @@ public static Modifiers ModifierFromAccessibility(Accessibility accessibility) case Accessibility.Internal: return Modifiers.Internal; case Accessibility.ProtectedOrInternal: - case Accessibility.ProtectedAndInternal: return Modifiers.Protected | Modifiers.Internal; + case Accessibility.ProtectedAndInternal: + return Modifiers.Private | Modifiers.Protected; default: return Modifiers.None; } diff --git a/ICSharpCode.Decompiler/TypeSystem/Accessibility.cs b/ICSharpCode.Decompiler/TypeSystem/Accessibility.cs index fae4c96733..0122c88834 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Accessibility.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Accessibility.cs @@ -53,7 +53,7 @@ public enum Accessibility : byte /// /// The entity is accessible in derived classes within the same project content. /// - /// C# does not support this accessibility. + /// This corresponds to C# 'private protected'. ProtectedAndInternal, } diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index e685145a94..2650580fce 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -349,6 +349,7 @@ + diff --git a/ILSpy/Images/AccessOverlayIcon.cs b/ILSpy/Images/AccessOverlayIcon.cs index ca11c46c46..5db1d75d39 100644 --- a/ILSpy/Images/AccessOverlayIcon.cs +++ b/ILSpy/Images/AccessOverlayIcon.cs @@ -26,6 +26,7 @@ internal enum AccessOverlayIcon Internal, ProtectedInternal, Private, + PrivateProtected, CompilerControlled } } diff --git a/ILSpy/Images/ILSpyNewIconList.txt b/ILSpy/Images/ILSpyNewIconList.txt index a2a35d8ebc..deeeaf3e2d 100644 --- a/ILSpy/Images/ILSpyNewIconList.txt +++ b/ILSpy/Images/ILSpyNewIconList.txt @@ -39,7 +39,7 @@ OverlayProtected.png new (Fugue derived) OverlayProtectedInternal.png new (Fugue derived) OverlayStatic.png new (Fugue derived) PInvokeMethod.png new (Fugue-Icon-Mashup) -PrivateInternal.png new (Fugue derived) +OverlayPrivateProtected.png new (Fugue derived) Property.png ClassBrowserIcons\Icons.16x16.Property.png ReferenceFolder.Closed.png ProjectBrowserIcons\ReferenceFolder.Closed.png ReferenceFolder.Open.png ProjectBrowserIcons\ReferenceFolder.Open.png diff --git a/ILSpy/Images/Images.cs b/ILSpy/Images/Images.cs index a8376f6469..2bf680b3d2 100644 --- a/ILSpy/Images/Images.cs +++ b/ILSpy/Images/Images.cs @@ -95,6 +95,7 @@ static BitmapImage LoadBitmap(string name) private static readonly BitmapImage OverlayInternal = LoadBitmap("OverlayInternal"); private static readonly BitmapImage OverlayProtectedInternal = LoadBitmap("OverlayProtectedInternal"); private static readonly BitmapImage OverlayPrivate = LoadBitmap("OverlayPrivate"); + private static readonly BitmapImage OverlayPrivateProtected = LoadBitmap("OverlayPrivateProtected"); private static readonly BitmapImage OverlayCompilerControlled = LoadBitmap("OverlayCompilerControlled"); private static readonly BitmapImage OverlayStatic = LoadBitmap("OverlayStatic"); @@ -295,6 +296,9 @@ private static ImageSource GetOverlayImage(AccessOverlayIcon overlay) case AccessOverlayIcon.Private: overlayImage = Images.OverlayPrivate; break; + case AccessOverlayIcon.PrivateProtected: + overlayImage = Images.OverlayPrivateProtected; + break; case AccessOverlayIcon.CompilerControlled: overlayImage = Images.OverlayCompilerControlled; break; diff --git a/ILSpy/Images/OverlayPrivateProtected.png b/ILSpy/Images/OverlayPrivateProtected.png new file mode 100644 index 0000000000..497753285b Binary files /dev/null and b/ILSpy/Images/OverlayPrivateProtected.png differ diff --git a/ILSpy/TreeNodes/EventTreeNode.cs b/ILSpy/TreeNodes/EventTreeNode.cs index 6a9679c331..0094956bc0 100644 --- a/ILSpy/TreeNodes/EventTreeNode.cs +++ b/ILSpy/TreeNodes/EventTreeNode.cs @@ -73,8 +73,9 @@ private static AccessOverlayIcon GetOverlayIcon(MethodAttributes methodAttribute case MethodAttributes.Public: return AccessOverlayIcon.Public; case MethodAttributes.Assembly: - case MethodAttributes.FamANDAssem: return AccessOverlayIcon.Internal; + case MethodAttributes.FamANDAssem: + return AccessOverlayIcon.PrivateProtected; case MethodAttributes.Family: return AccessOverlayIcon.Protected; case MethodAttributes.FamORAssem: diff --git a/ILSpy/TreeNodes/FieldTreeNode.cs b/ILSpy/TreeNodes/FieldTreeNode.cs index e530709194..3e486f8805 100644 --- a/ILSpy/TreeNodes/FieldTreeNode.cs +++ b/ILSpy/TreeNodes/FieldTreeNode.cs @@ -87,8 +87,9 @@ private static AccessOverlayIcon GetOverlayIcon(FieldAttributes fieldAttributes) case FieldAttributes.Public: return AccessOverlayIcon.Public; case FieldAttributes.Assembly: - case FieldAttributes.FamANDAssem: return AccessOverlayIcon.Internal; + case FieldAttributes.FamANDAssem: + return AccessOverlayIcon.PrivateProtected; case FieldAttributes.Family: return AccessOverlayIcon.Protected; case FieldAttributes.FamORAssem: diff --git a/ILSpy/TreeNodes/MethodTreeNode.cs b/ILSpy/TreeNodes/MethodTreeNode.cs index 1ddf59ab17..e0b78440f6 100644 --- a/ILSpy/TreeNodes/MethodTreeNode.cs +++ b/ILSpy/TreeNodes/MethodTreeNode.cs @@ -104,8 +104,9 @@ private static AccessOverlayIcon GetOverlayIcon(MethodAttributes methodAttribute case MethodAttributes.Public: return AccessOverlayIcon.Public; case MethodAttributes.Assembly: - case MethodAttributes.FamANDAssem: return AccessOverlayIcon.Internal; + case MethodAttributes.FamANDAssem: + return AccessOverlayIcon.PrivateProtected; case MethodAttributes.Family: return AccessOverlayIcon.Protected; case MethodAttributes.FamORAssem: diff --git a/ILSpy/TreeNodes/PropertyTreeNode.cs b/ILSpy/TreeNodes/PropertyTreeNode.cs index 07c6cd779c..298731e3a6 100644 --- a/ILSpy/TreeNodes/PropertyTreeNode.cs +++ b/ILSpy/TreeNodes/PropertyTreeNode.cs @@ -101,8 +101,9 @@ private static AccessOverlayIcon GetOverlayIcon(MethodAttributes methodAttribute case MethodAttributes.Public: return AccessOverlayIcon.Public; case MethodAttributes.Assembly: - case MethodAttributes.FamANDAssem: return AccessOverlayIcon.Internal; + case MethodAttributes.FamANDAssem: + return AccessOverlayIcon.PrivateProtected; case MethodAttributes.Family: return AccessOverlayIcon.Protected; case MethodAttributes.FamORAssem: diff --git a/ILSpy/TreeNodes/TypeTreeNode.cs b/ILSpy/TreeNodes/TypeTreeNode.cs index 5f51b0de45..b15aec816a 100644 --- a/ILSpy/TreeNodes/TypeTreeNode.cs +++ b/ILSpy/TreeNodes/TypeTreeNode.cs @@ -147,9 +147,11 @@ private static AccessOverlayIcon GetOverlayIcon(TypeDefinition type) break; case TypeAttributes.NotPublic: case TypeAttributes.NestedAssembly: - case TypeAttributes.NestedFamANDAssem: overlay = AccessOverlayIcon.Internal; break; + case TypeAttributes.NestedFamANDAssem: + overlay = AccessOverlayIcon.PrivateProtected; + break; case TypeAttributes.NestedFamily: case TypeAttributes.NestedFamORAssem: overlay = AccessOverlayIcon.Protected;