Skip to content

Commit 91050e0

Browse files
authored
Merge branch 'master' into use-type-hint-in-pointer-arithmetic
2 parents f1a1750 + d2d76ec commit 91050e0

File tree

61 files changed

+1199
-525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1199
-525
lines changed

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
<PackageVersion Include="K4os.Compression.LZ4" Version="1.3.8" />
1616
<PackageVersion Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" />
1717
<PackageVersion Include="McMaster.Extensions.Hosting.CommandLine" Version="4.1.1" />
18-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
19-
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic" Version="4.12.0" />
18+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" />
19+
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic" Version="4.13.0" />
2020
<PackageVersion Include="Microsoft.DiaSymReader.Converter.Xml" Version="1.1.0-beta2-22171-02" />
2121
<PackageVersion Include="Microsoft.DiaSymReader" Version="1.4.0" />
2222
<PackageVersion Include="Microsoft.DiaSymReader.Native" Version="17.0.0-beta1.21524.1" />
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Management.Automation;
2+
3+
using ICSharpCode.Decompiler.CSharp;
4+
using ICSharpCode.Decompiler.Metadata;
5+
6+
namespace ICSharpCode.Decompiler.PowerShell
7+
{
8+
[Cmdlet(VerbsCommon.Get, "TargetFramework")]
9+
[OutputType(typeof(string))]
10+
public class GetTargetFramework : PSCmdlet
11+
{
12+
[Parameter(Position = 0, Mandatory = true)]
13+
public CSharpDecompiler Decompiler { get; set; }
14+
15+
protected override void ProcessRecord()
16+
{
17+
MetadataFile module = Decompiler.TypeSystem.MainModule.MetadataFile;
18+
WriteObject(module.Metadata.DetectTargetFrameworkId());
19+
}
20+
}
21+
}

ICSharpCode.Decompiler.PowerShell/manifest.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
'Get-DecompiledSource',
6969
'Get-DecompiledTypes',
7070
'Get-Decompiler',
71-
'Get-DecompilerVersion'
71+
'Get-DecompilerVersion',
72+
'Get-TargetFramework'
7273
)
7374

7475
# Variables to export from this module

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
<None Include="TestCases\ILPretty\Issue1922.il" />
105105
<None Include="TestCases\ILPretty\Issue1918.il" />
106106
<None Include="TestCases\ILPretty\Issue2104.il" />
107+
<None Include="TestCases\ILPretty\Issue3421.il" />
107108
<None Include="TestCases\ILPretty\WeirdEnums.il" />
108109
<None Include="TestCases\ILPretty\ConstantBlobs.il" />
109110
<None Include="TestCases\ILPretty\CS1xSwitch_Debug.il" />
@@ -129,9 +130,11 @@
129130
<Compile Include="Output\InsertParenthesesVisitorTests.cs" />
130131
<Compile Include="ProjectDecompiler\TargetFrameworkTests.cs" />
131132
<Compile Include="TestAssemblyResolver.cs" />
133+
<Compile Include="TestCases\ILPretty\Issue3421.cs" />
132134
<Compile Include="TestCases\ILPretty\MonoFixed.cs" />
133135
<Compile Include="TestCases\Pretty\Comparisons.cs" />
134136
<Compile Include="TestCases\Pretty\PointerArithmetic.cs" />
137+
<Compile Include="TestCases\Pretty\Issue3439.cs" />
135138
<None Include="TestCases\VBPretty\VBAutomaticEvents.vb" />
136139
<Compile Include="TestCases\VBPretty\VBAutomaticEvents.cs" />
137140
<Compile Include="TestCases\VBPretty\VBNonGenericForEach.cs" />

ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ public async Task Issue2443()
207207
await Run();
208208
}
209209

210+
[Test]
211+
public async Task Issue3421()
212+
{
213+
await Run();
214+
}
215+
210216
[Test]
211217
public async Task Issue2260SwitchString()
212218
{

ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,21 @@ public async Task CustomShortCircuitOperators([ValueSource(nameof(defaultOptions
233233
[Test]
234234
public async Task ExceptionHandling([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
235235
{
236-
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings {
237-
NullPropagation = false,
236+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => {
237+
settings.NullPropagation = false;
238238
// legacy csc generates a dead store in debug builds
239-
RemoveDeadStores = (cscOptions == CompilerOptions.None),
240-
FileScopedNamespaces = false,
239+
settings.RemoveDeadStores = (cscOptions == CompilerOptions.None);
240+
settings.FileScopedNamespaces = false;
241241
});
242242
}
243243

244244
[Test]
245245
public async Task Switch([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
246246
{
247-
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings {
247+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => {
248248
// legacy csc generates a dead store in debug builds
249-
RemoveDeadStores = (cscOptions == CompilerOptions.None),
250-
SwitchExpressions = false,
251-
FileScopedNamespaces = false,
249+
settings.RemoveDeadStores = (cscOptions == CompilerOptions.None);
250+
settings.SwitchExpressions = false;
252251
});
253252
}
254253

@@ -267,7 +266,10 @@ public async Task ReduceNesting([ValueSource(nameof(defaultOptions))] CompilerOp
267266
[Test]
268267
public async Task DelegateConstruction([ValueSource(nameof(defaultOptionsWithMcs))] CompilerOptions cscOptions)
269268
{
270-
await RunForLibrary(cscOptions: cscOptions);
269+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => {
270+
settings.QueryExpressions = false;
271+
settings.NullableReferenceTypes = false;
272+
});
271273
}
272274

273275
[Test]
@@ -293,9 +295,9 @@ public async Task Using([ValueSource(nameof(defaultOptions))] CompilerOptions cs
293295
{
294296
await RunForLibrary(
295297
cscOptions: cscOptions,
296-
decompilerSettings: new DecompilerSettings {
297-
UseEnhancedUsing = false,
298-
FileScopedNamespaces = false,
298+
configureDecompiler: settings => {
299+
settings.UseEnhancedUsing = false;
300+
settings.FileScopedNamespaces = false;
299301
}
300302
);
301303
}
@@ -327,11 +329,11 @@ public async Task Generics([ValueSource(nameof(defaultOptions))] CompilerOptions
327329
[Test]
328330
public async Task Loops([ValueSource(nameof(defaultOptionsWithMcs))] CompilerOptions cscOptions)
329331
{
330-
DecompilerSettings settings = Tester.GetSettings(cscOptions);
331-
// legacy csc generates a dead store in debug builds
332-
settings.RemoveDeadStores = (cscOptions == CompilerOptions.None);
333-
settings.UseExpressionBodyForCalculatedGetterOnlyProperties = false;
334-
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: settings);
332+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => {
333+
// legacy csc generates a dead store in debug builds
334+
settings.RemoveDeadStores = (cscOptions == CompilerOptions.None);
335+
settings.UseExpressionBodyForCalculatedGetterOnlyProperties = false;
336+
});
335337
}
336338

337339
[Test]
@@ -440,9 +442,7 @@ public async Task VariableNaming([ValueSource(nameof(defaultOptions))] CompilerO
440442
[Test]
441443
public async Task VariableNamingWithoutSymbols([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
442444
{
443-
var settings = Tester.GetSettings(cscOptions);
444-
settings.UseDebugSymbols = false;
445-
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: settings);
445+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => settings.UseDebugSymbols = false);
446446
}
447447

448448
[Test]
@@ -474,7 +474,7 @@ public async Task AsyncUsing([ValueSource(nameof(roslyn3OrNewerOptions))] Compil
474474
{
475475
await RunForLibrary(
476476
cscOptions: cscOptions,
477-
decompilerSettings: new DecompilerSettings { UseEnhancedUsing = false, FileScopedNamespaces = false }
477+
configureDecompiler: settings => { settings.UseEnhancedUsing = false; }
478478
);
479479
}
480480

@@ -499,7 +499,7 @@ public async Task NativeInts([ValueSource(nameof(roslyn3OrNewerWithNet40Options)
499499
[Test]
500500
public async Task FileScopedNamespaces([ValueSource(nameof(roslyn4OrNewerOptions))] CompilerOptions cscOptions)
501501
{
502-
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings());
502+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => settings.FileScopedNamespaces = true);
503503
}
504504

505505
[Test]
@@ -601,7 +601,13 @@ public async Task ConstantsTests([ValueSource(nameof(defaultOptions))] CompilerO
601601
[Test]
602602
public async Task Issue1080([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions)
603603
{
604-
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings(CSharp.LanguageVersion.CSharp6));
604+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => settings.SetLanguageVersion(CSharp.LanguageVersion.CSharp6));
605+
}
606+
607+
[Test]
608+
public async Task Issue3439([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
609+
{
610+
await RunForLibrary(cscOptions: cscOptions);
605611
}
606612

607613
[Test]
@@ -718,12 +724,12 @@ public async Task PointerArithmetic([ValueSource(nameof(defaultOptions))] Compil
718724
await RunForLibrary(cscOptions: cscOptions);
719725
}
720726

721-
async Task RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null)
727+
async Task RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, Action<DecompilerSettings> configureDecompiler = null)
722728
{
723-
await Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CompilerOptions.Library, decompilerSettings);
729+
await Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CompilerOptions.Library, configureDecompiler);
724730
}
725731

726-
async Task Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null)
732+
async Task Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, Action<DecompilerSettings> configureDecompiler = null)
727733
{
728734
var csFile = Path.Combine(TestCasePath, testName + ".cs");
729735
var exeFile = TestsAssemblyOutput.GetFilePath(TestCasePath, testName, Tester.GetSuffix(cscOptions) + ".exe");
@@ -745,7 +751,9 @@ async Task Run([CallerMemberName] string testName = null, AssemblerOptions asmOp
745751
}
746752

747753
// 2. Decompile
748-
var decompiled = await Tester.DecompileCSharp(exeFile, decompilerSettings ?? Tester.GetSettings(cscOptions)).ConfigureAwait(false);
754+
var settings = Tester.GetSettings(cscOptions);
755+
configureDecompiler?.Invoke(settings);
756+
var decompiled = await Tester.DecompileCSharp(exeFile, settings).ConfigureAwait(false);
749757

750758
// 3. Compile
751759
CodeAssert.FilesAreEqual(csFile, decompiled, Tester.GetPreprocessorSymbols(cscOptions).Append("EXPECTED_OUTPUT").ToArray());

ICSharpCode.Decompiler.Tests/TestCases/ILPretty/GuessAccessors.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public void MethodUnknownClass()
1515
//IL_0007: Expected O, but got Unknown
1616
UnknownClass val = new UnknownClass();
1717
int? unknownProperty = val.UnknownProperty;
18-
int? num2 = (val.UnknownProperty = unknownProperty.GetValueOrDefault());
19-
int? num3 = num2;
18+
int? num = (val.UnknownProperty = unknownProperty.GetValueOrDefault());
19+
int? num3 = num;
2020
List<object> list = new List<object> {
2121
val[unknownProperty.Value] ?? "",
2222
val.NotProperty,
@@ -50,9 +50,9 @@ public void MethodUnknownGenericClass()
5050
//IL_00e1: Expected O, but got Unknown
5151
//IL_00e1: Expected O, but got Unknown
5252
UnknownGenericClass<UnknownEventArgs> val = new UnknownGenericClass<UnknownEventArgs>();
53-
UnknownEventArgs val2 = (val.UnknownProperty = val.UnknownProperty);
53+
UnknownEventArgs e = (val.UnknownProperty = val.UnknownProperty);
5454
List<object> list = new List<object> {
55-
val[((object)val2).GetHashCode()] ?? "",
55+
val[((object)e).GetHashCode()] ?? "",
5656
val.NotProperty,
5757
val.get_NotPropertyWithGeneric<string>(42),
5858
val[42],
@@ -61,10 +61,10 @@ public void MethodUnknownGenericClass()
6161
};
6262
val.OnEvent += Instance_OnEvent;
6363
val.OnEvent -= Instance_OnEvent;
64-
UnknownEventArgs val3 = val[(UnknownEventArgs)null];
65-
val[new UnknownEventArgs()] = val3;
66-
UnknownEventArgs val4 = val[new UnknownEventArgs(), new UnknownEventArgs()];
67-
val[new UnknownEventArgs(), new UnknownEventArgs()] = val4;
64+
UnknownEventArgs e2 = val[(UnknownEventArgs)null];
65+
val[new UnknownEventArgs()] = e2;
66+
UnknownEventArgs e3 = val[new UnknownEventArgs(), new UnknownEventArgs()];
67+
val[new UnknownEventArgs(), new UnknownEventArgs()] = e3;
6868
}
6969

7070
public void MethodUnknownStatic()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
internal class Issue3421
2+
{
3+
private string name;
4+
private object value;
5+
6+
public virtual void SetValue(object value)
7+
{
8+
switch (name)
9+
{
10+
case "##Name##":
11+
return;
12+
case "##Value##":
13+
this.value = value;
14+
return;
15+
case "##InnerText##":
16+
this.value = value.ToString();
17+
return;
18+
case null:
19+
return;
20+
}
21+
if (this.value == null)
22+
{
23+
this.value = "";
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)