Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "private protected" support #1010

Merged
merged 18 commits into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
142c406
Add "private protected" support
pentp Dec 12, 2017
6fcb5d0
Fix highlighting of value keyword in property/event accessors.
siegfriedpammer Dec 13, 2017
ee8841e
Fix #561: Clicking on a node with a deleted file causes a stacktrace …
siegfriedpammer Dec 14, 2017
9adbff2
Set versionName = null (RTM)
siegfriedpammer Dec 16, 2017
5184a9b
Fix NRE in LoadedAssembly.LookupReferencedAssemblyInternal
siegfriedpammer Dec 16, 2017
889b147
Fix NRE in DoDecompile(FieldDefinition) on internal value__ enum fields
siegfriedpammer Dec 16, 2017
454f512
Tests: Set Roslyn language version to latest
siegfriedpammer Dec 17, 2017
70b01e7
Update NuGet packages in Frontends and Xamarin Workbook
christophwille Dec 18, 2017
96c6d5d
Fix Identity of package
christophwille Dec 18, 2017
151fa73
Fix exception in LoadPackageInfos
siegfriedpammer Dec 18, 2017
f493f5e
Fail with null value instead of other exception in case of invalid js…
siegfriedpammer Dec 18, 2017
8bb5551
Go to .3447 Nuget (found .deps.json parsing error on release tests). …
christophwille Dec 18, 2017
8dac53e
Update vsix to 1.7.1 to include update
christophwille Dec 18, 2017
6aefbdf
Merge branch 'master' of https://github.com/icsharpcode/ILSpy
christophwille Dec 18, 2017
1dac21d
Set version to 3.1 alpha1
siegfriedpammer Dec 18, 2017
f764f94
Merge branch 'famandasm' of https://github.com/pentp/ILSpy into pentp…
siegfriedpammer Dec 19, 2017
c848ec4
Add C# 7.2 private protected unit tests
siegfriedpammer Dec 19, 2017
b91cf16
Add overlay icon for private protected.
siegfriedpammer Dec 19, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DecompilerNuGetDemos.workbook
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ platforms:
- DotNetCore
packages:
- id: ICSharpCode.Decompiler
version: 3.0.0.3403-beta4
version: 3.0.0.3447
---

Setup: load the references required to work with the decompiler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.0.1" />
<PackageReference Include="ICSharpCode.Decompiler" Version="3.0.0.3403-beta4" />
<PackageReference Include="ICSharpCode.Decompiler" Version="3.0.0.3447" />

<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
<PackageReference Include="System.Runtime.Handles" Version="4.3.0" />
Expand Down
9 changes: 7 additions & 2 deletions ICSharpCode.Decompiler.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ static int Main(string[] args)
return app.Execute(args);
}

static CSharpDecompiler GetDecompiler(string assemblyFileName)
{
return new CSharpDecompiler(assemblyFileName, new DecompilerSettings() { ThrowOnAssemblyResolveErrors = false });
}

static void ListContent(string assemblyFileName, TextWriter output, ISet<TypeKind> kinds)
{
CSharpDecompiler decompiler = new CSharpDecompiler(assemblyFileName, new DecompilerSettings());
CSharpDecompiler decompiler = GetDecompiler(assemblyFileName);

foreach (var type in decompiler.TypeSystem.Compilation.MainAssembly.GetAllTypeDefinitions()) {
if (!kinds.Contains(type.Kind))
Expand All @@ -95,7 +100,7 @@ static void DecompileAsProject(string assemblyFileName, string outputDirectory)

static void Decompile(string assemblyFileName, TextWriter output, string typeName = null)
{
CSharpDecompiler decompiler = new CSharpDecompiler(assemblyFileName, new DecompilerSettings());
CSharpDecompiler decompiler = GetDecompiler(assemblyFileName);

if (typeName == null) {
output.Write(decompiler.DecompileWholeModuleAsString());
Expand Down
6 changes: 5 additions & 1 deletion ICSharpCode.Decompiler.PowerShell/Demo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ Import-Module $modulePath
$version = Get-DecompilerVersion
Write-Output $version

$decompiler = Get-Decompiler $modulePath
# different test assemblies - it makes a difference wrt .deps.json so there are two netstandard tests here
$asm_netstdWithDepsJson = $basePath + '\bin\Debug\netstandard2.0\ICSharpCode.Decompiler.Powershell.dll'
$asm_netstd = $basePath + '\bin\Debug\netstandard2.0\ICSharpCode.Decompiler.dll'

$decompiler = Get-Decompiler $asm_netstdWithDepsJson

$classes = Get-DecompiledTypes $decompiler -Types class
$classes.Count
Expand Down
4 changes: 3 additions & 1 deletion ICSharpCode.Decompiler.PowerShell/GetDecompilerCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ protected override void ProcessRecord()
string path = GetUnresolvedProviderPathFromPSPath(LiteralPath);

try {
var decompiler = new CSharpDecompiler(path, new DecompilerSettings());
var decompiler = new CSharpDecompiler(path, new DecompilerSettings() {
ThrowOnAssemblyResolveErrors = false
});
WriteObject(decompiler);

} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="PowerShellStandard.Library" Version="3.0.0-preview-01" />
<PackageReference Include="ICSharpCode.Decompiler" Version="3.0.0.3403-beta4" />
<PackageReference Include="ICSharpCode.Decompiler" Version="3.0.0.3447" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static CompilerResults CompileCSharp(string sourceFileName, CompilerOptio
var preprocessorSymbols = GetPreprocessorSymbols(flags);

if (flags.HasFlag(CompilerOptions.UseRoslyn)) {
var parseOptions = new CSharpParseOptions(preprocessorSymbols: preprocessorSymbols.ToArray());
var parseOptions = new CSharpParseOptions(preprocessorSymbols: preprocessorSymbols.ToArray(), languageVersion: LanguageVersion.Latest);
var syntaxTrees = sourceFileNames.Select(f => SyntaxFactory.ParseSyntaxTree(File.ReadAllText(f), parseOptions, path: f));
var compilation = CSharpCompilation.Create(Path.GetFileNameWithoutExtension(sourceFileName),
syntaxTrees, defaultReferences.Value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<PropertyGroup>
<TargetFramework>net46</TargetFramework>
<LangVersion>latest</LangVersion>

<AllowUnsafeBlocks>True</AllowUnsafeBlocks>

Expand Down Expand Up @@ -62,6 +63,7 @@
<Compile Include="TestCases\Correctness\MiniJSON.cs" />
<Compile Include="TestCases\Correctness\FloatingPointArithmetic.cs" />
<Compile Include="TestCases\ILPretty\Issue982.cs" />
<Compile Include="TestCases\Pretty\CS72_PrivateProtected.cs" />
<Compile Include="TestCases\Pretty\ExpressionTrees.cs" />
<Compile Include="TestCases\Pretty\VariableNaming.cs" />
<Compile Include="TestCases\Pretty\VariableNamingWithoutSymbols.cs" />
Expand Down
6 changes: 6 additions & 0 deletions ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -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 '<Property>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::'<Property>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 ***********************
Original file line number Diff line number Diff line change
@@ -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 '<Property>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::'<Property>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 ***********************
4 changes: 2 additions & 2 deletions ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,15 +826,15 @@ EntityDeclaration DoDecompile(FieldDefinition fieldDefinition, IField field, ITy
{
Debug.Assert(decompilationContext.CurrentMember == field);
var typeSystemAstBuilder = CreateAstBuilder(decompilationContext);
if (decompilationContext.CurrentTypeDefinition.Kind == TypeKind.Enum) {
if (decompilationContext.CurrentTypeDefinition.Kind == TypeKind.Enum && field.ConstantValue != null) {
var index = decompilationContext.CurrentTypeDefinition.Members.IndexOf(field);
long previousValue = -1;
if (index > 0) {
var previousMember = (IField)decompilationContext.CurrentTypeDefinition.Members[index - 1];
previousValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, previousMember.ConstantValue, false);
}
long initValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, field.ConstantValue, false);
var enumDec = new EnumMemberDeclaration { Name = field.Name };
long initValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, field.ConstantValue, false);
if (decompilationContext.CurrentTypeDefinition.Attributes.Any(a => a.AttributeType.FullName == "System.FlagsAttribute")) {
enumDec.Initializer = typeSystemAstBuilder.ConvertConstantValue(decompilationContext.CurrentTypeDefinition.EnumUnderlyingType, field.ConstantValue);
if (enumDec.Initializer is PrimitiveExpression primitive && initValue > 9)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ public string TryResolveDotNetCore(AssemblyNameReference name)
static IEnumerable<DotNetCorePackageInfo> LoadPackageInfos(string depsJsonFileName, string targetFramework)
{
var dependencies = JsonReader.Parse(File.ReadAllText(depsJsonFileName));
var runtimeInfos = dependencies["targets"][targetFramework].AsJsonObject;
var runtimeInfos = dependencies["targets"][targetFramework + "/"].AsJsonObject;
var libraries = dependencies["libraries"].AsJsonObject;
if (runtimeInfos == null || libraries == null)
yield break;
foreach (var library in libraries) {
var type = library.Value["type"].AsString;
var path = library.Value["path"].AsString;
var runtimeInfo = runtimeInfos[library.Key]["runtime"].AsJsonObject;
var runtimeInfo = runtimeInfos[library.Key].AsJsonObject?["runtime"].AsJsonObject;
string[] components = new string[runtimeInfo?.Count ?? 0];
if (runtimeInfo != null) {
int i = 0;
Expand Down
2 changes: 1 addition & 1 deletion ICSharpCode.Decompiler/TypeSystem/Accessibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public enum Accessibility : byte
/// <summary>
/// The entity is accessible in derived classes within the same project content.
/// </summary>
/// <remarks>C# does not support this accessibility.</remarks>
/// <remarks>This corresponds to C# 'private protected'.</remarks>
ProtectedAndInternal,
}

Expand Down
4 changes: 2 additions & 2 deletions ILSpy.AddIn/ILSpy.AddIn.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<Company>IC#Code</Company>
<Description>ILSpy</Description>
<NeutralLanguage>en-US</NeutralLanguage>
<Version>1.5.0.0</Version>
<FileVersion>1.5.0.0</FileVersion>
<Version>1.7.1.0</Version>
<FileVersion>1.7.1.0</FileVersion>

<EnableDefaultItems>False</EnableDefaultItems>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
Loading