Skip to content

Commit 4ed1531

Browse files
Merge pull request #1010 from pentp/famandasm
Add "private protected" support
2 parents 37eda57 + b91cf16 commit 4ed1531

18 files changed

+230
-9
lines changed

ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<PropertyGroup>
55
<TargetFramework>net46</TargetFramework>
6+
<LangVersion>latest</LangVersion>
67

78
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
89

@@ -62,6 +63,7 @@
6263
<Compile Include="TestCases\Correctness\MiniJSON.cs" />
6364
<Compile Include="TestCases\Correctness\FloatingPointArithmetic.cs" />
6465
<Compile Include="TestCases\ILPretty\Issue982.cs" />
66+
<Compile Include="TestCases\Pretty\CS72_PrivateProtected.cs" />
6567
<Compile Include="TestCases\Pretty\ExpressionTrees.cs" />
6668
<Compile Include="TestCases\Pretty\VariableNaming.cs" />
6769
<Compile Include="TestCases\Pretty\VariableNamingWithoutSymbols.cs" />

ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ public void VariableNamingWithoutSymbols([ValueSource("defaultOptions")] Compile
224224
Run(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings { UseDebugSymbols = false });
225225
}
226226

227+
[Test]
228+
public void CS72_PrivateProtected([ValueSource("roslynOnlyOptions")] CompilerOptions cscOptions)
229+
{
230+
Run(cscOptions: cscOptions);
231+
}
232+
227233
void Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null)
228234
{
229235
var ilFile = Path.Combine(TestCasePath, testName) + Tester.GetSuffix(cscOptions) + ".il";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
20+
{
21+
internal class CS72_PrivateProtected
22+
{
23+
private protected int Property {
24+
get;
25+
}
26+
27+
private protected void Method()
28+
{
29+
}
30+
}
31+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
3+
// Copyright (c) Microsoft Corporation. All rights reserved.
4+
5+
6+
7+
// Metadata version: v4.0.30319
8+
.assembly extern mscorlib
9+
{
10+
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
11+
.ver 4:0:0:0
12+
}
13+
.assembly CS72_PrivateProtected
14+
{
15+
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
16+
.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
17+
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
18+
19+
// --- The following custom attribute is added automatically, do not uncomment -------
20+
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 )
21+
22+
.permissionset reqmin
23+
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
24+
.hash algorithm 0x00008004
25+
.ver 0:0:0:0
26+
}
27+
.module CS72_PrivateProtected.dll
28+
// MVID: {16957694-0DCC-41BA-B992-22F83B96A9D7}
29+
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
30+
.imagebase 0x10000000
31+
.file alignment 0x00000200
32+
.stackreserve 0x00100000
33+
.subsystem 0x0003 // WINDOWS_CUI
34+
.corflags 0x00000001 // ILONLY
35+
// Image base: 0x031E0000
36+
37+
38+
// =============== CLASS MEMBERS DECLARATION ===================
39+
40+
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected
41+
extends [mscorlib]System.Object
42+
{
43+
.field private initonly int32 '<Property>k__BackingField'
44+
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
45+
.method famandassem hidebysig specialname
46+
instance int32 get_Property() cil managed
47+
{
48+
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
49+
// Code size 7 (0x7)
50+
.maxstack 8
51+
IL_0000: ldarg.0
52+
IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected::'<Property>k__BackingField'
53+
IL_0006: ret
54+
} // end of method CS72_PrivateProtected::get_Property
55+
56+
.method famandassem hidebysig instance void
57+
Method() cil managed
58+
{
59+
// Code size 1 (0x1)
60+
.maxstack 8
61+
IL_0000: ret
62+
} // end of method CS72_PrivateProtected::Method
63+
64+
.method public hidebysig specialname rtspecialname
65+
instance void .ctor() cil managed
66+
{
67+
// Code size 7 (0x7)
68+
.maxstack 8
69+
IL_0000: ldarg.0
70+
IL_0001: call instance void [mscorlib]System.Object::.ctor()
71+
IL_0006: ret
72+
} // end of method CS72_PrivateProtected::.ctor
73+
74+
.property instance int32 Property()
75+
{
76+
.get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected::get_Property()
77+
} // end of property CS72_PrivateProtected::Property
78+
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected
79+
80+
81+
// =============================================================
82+
83+
// *********** DISASSEMBLY COMPLETE ***********************
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
3+
// Copyright (c) Microsoft Corporation. All rights reserved.
4+
5+
6+
7+
// Metadata version: v4.0.30319
8+
.assembly extern mscorlib
9+
{
10+
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
11+
.ver 4:0:0:0
12+
}
13+
.assembly CS72_PrivateProtected
14+
{
15+
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
16+
.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
17+
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
18+
19+
// --- The following custom attribute is added automatically, do not uncomment -------
20+
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 )
21+
22+
.permissionset reqmin
23+
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
24+
.hash algorithm 0x00008004
25+
.ver 0:0:0:0
26+
}
27+
.module CS72_PrivateProtected.dll
28+
// MVID: {056F9D5F-A186-4957-9181-B6C798C15C6C}
29+
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
30+
.imagebase 0x10000000
31+
.file alignment 0x00000200
32+
.stackreserve 0x00100000
33+
.subsystem 0x0003 // WINDOWS_CUI
34+
.corflags 0x00000001 // ILONLY
35+
// Image base: 0x03A40000
36+
37+
38+
// =============== CLASS MEMBERS DECLARATION ===================
39+
40+
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected
41+
extends [mscorlib]System.Object
42+
{
43+
.field private initonly int32 '<Property>k__BackingField'
44+
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
45+
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
46+
.method famandassem hidebysig specialname
47+
instance int32 get_Property() cil managed
48+
{
49+
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
50+
// Code size 7 (0x7)
51+
.maxstack 8
52+
IL_0000: ldarg.0
53+
IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected::'<Property>k__BackingField'
54+
IL_0006: ret
55+
} // end of method CS72_PrivateProtected::get_Property
56+
57+
.method famandassem hidebysig instance void
58+
Method() cil managed
59+
{
60+
// Code size 2 (0x2)
61+
.maxstack 8
62+
IL_0000: nop
63+
IL_0001: ret
64+
} // end of method CS72_PrivateProtected::Method
65+
66+
.method public hidebysig specialname rtspecialname
67+
instance void .ctor() cil managed
68+
{
69+
// Code size 8 (0x8)
70+
.maxstack 8
71+
IL_0000: ldarg.0
72+
IL_0001: call instance void [mscorlib]System.Object::.ctor()
73+
IL_0006: nop
74+
IL_0007: ret
75+
} // end of method CS72_PrivateProtected::.ctor
76+
77+
.property instance int32 Property()
78+
{
79+
.get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected::get_Property()
80+
} // end of property CS72_PrivateProtected::Property
81+
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected
82+
83+
84+
// =============================================================
85+
86+
// *********** DISASSEMBLY COMPLETE ***********************

ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected internal override bool DoMatch(AstNode other, PatternMatching.Match ma
6262
// Not worth using a dictionary for such few elements.
6363
// This table is sorted in the order that modifiers should be output when generating code.
6464
static readonly Modifiers[] allModifiers = {
65-
Modifiers.Public, Modifiers.Protected, Modifiers.Private, Modifiers.Internal,
65+
Modifiers.Public, Modifiers.Private, Modifiers.Protected, Modifiers.Internal,
6666
Modifiers.New,
6767
Modifiers.Unsafe,
6868
Modifiers.Abstract, Modifiers.Virtual, Modifiers.Sealed, Modifiers.Static, Modifiers.Override,

ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,8 +1057,9 @@ public static Modifiers ModifierFromAccessibility(Accessibility accessibility)
10571057
case Accessibility.Internal:
10581058
return Modifiers.Internal;
10591059
case Accessibility.ProtectedOrInternal:
1060-
case Accessibility.ProtectedAndInternal:
10611060
return Modifiers.Protected | Modifiers.Internal;
1061+
case Accessibility.ProtectedAndInternal:
1062+
return Modifiers.Private | Modifiers.Protected;
10621063
default:
10631064
return Modifiers.None;
10641065
}

ICSharpCode.Decompiler/TypeSystem/Accessibility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public enum Accessibility : byte
5353
/// <summary>
5454
/// The entity is accessible in derived classes within the same project content.
5555
/// </summary>
56-
/// <remarks>C# does not support this accessibility.</remarks>
56+
/// <remarks>This corresponds to C# 'private protected'.</remarks>
5757
ProtectedAndInternal,
5858
}
5959

ILSpy/ILSpy.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@
349349
<Resource Include="Images\FieldReadOnly.png" />
350350
<Resource Include="Images\OverlayInternal.png" />
351351
<Resource Include="Images\OverlayPrivate.png" />
352+
<Resource Include="Images\OverlayPrivateProtected.png" />
352353
<Resource Include="Images\OverlayProtected.png" />
353354
<Resource Include="Images\OverlayProtectedInternal.png" />
354355
<Resource Include="Images\OverlayCompilerControlled.png" />

ILSpy/Images/AccessOverlayIcon.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal enum AccessOverlayIcon
2626
Internal,
2727
ProtectedInternal,
2828
Private,
29+
PrivateProtected,
2930
CompilerControlled
3031
}
3132
}

0 commit comments

Comments
 (0)