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

Rewrite AssignVariableNames #3243

Merged
merged 3 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<None Include="TestCases\ILPretty\GuessAccessors.cs" />
<None Include="TestCases\ILPretty\GuessAccessors.il" />
<None Include="TestCases\ILPretty\Issue2260SwitchString.il" />
<None Include="TestCases\ILPretty\MonoFixed.il" />
<None Include="TestCases\ILPretty\UnknownTypes.cs" />
<None Include="TestCases\ILPretty\UnknownTypes.il" />
<None Include="TestCases\ILPretty\EvalOrder.cs" />
Expand Down Expand Up @@ -128,6 +129,7 @@
<Compile Include="Output\InsertParenthesesVisitorTests.cs" />
<Compile Include="ProjectDecompiler\TargetFrameworkTests.cs" />
<Compile Include="TestAssemblyResolver.cs" />
<Compile Include="TestCases\ILPretty\MonoFixed.cs" />
<Compile Include="Util\ResourceReaderWriterTests.cs" />
<None Include="TestCases\VBPretty\VBAutomaticEvents.vb" />
<Compile Include="TestCases\VBPretty\VBAutomaticEvents.cs" />
Expand Down
8 changes: 4 additions & 4 deletions ICSharpCode.Decompiler.Tests/TestCases/ILPretty/MonoFixed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ public unsafe void FixMultipleStrings(string text)
{
fixed (char* ptr = text)
{
fixed (char* ptr2 = Environment.UserName)
fixed (char* userName = Environment.UserName)
{
fixed (char* ptr3 = text)
fixed (char* ptr2 = text)
{
*ptr = 'c';
*ptr2 = 'd';
*ptr3 = 'e';
*userName = 'd';
*ptr2 = 'e';
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,35 +250,35 @@ public async Task LoadsToCatch(int i)
{
throw null;
}
catch (Exception ex2) when (i == 0)
catch (Exception ex) when (i == 0)
{
Console.WriteLine("First!");
if (i == 1)
{
throw;
}
await Task.Yield();
Console.WriteLine(ex2.StackTrace);
Console.WriteLine(ex.StackTrace);
}
catch (Exception ex3) when (True())
catch (Exception ex2) when (True())
{
Console.WriteLine("Second!");
if (i == 1)
{
throw;
}
await Task.Yield();
Console.WriteLine(ex3.StackTrace);
Console.WriteLine(ex2.StackTrace);
}
catch (Exception ex)
catch (Exception ex3)
{
Console.WriteLine("Third!");
if (i == 1)
{
throw;
}
await Task.Yield();
Console.WriteLine(ex.StackTrace);
Console.WriteLine(ex3.StackTrace);
}
catch when (i == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,19 @@ public static Action StaticAnonymousMethodNoClosure()

public static void NameConflict()
{
// i is captured variable,
// j is parameter in anonymous method
// i is local in main method,
// j is captured variable,
// k is parameter in anonymous method
// l is local in anonymous method,
// k is local in main method
// Ensure that the decompiler doesn't introduce name conflicts
List<Action<int>> list = new List<Action<int>>();
for (int k = 0; k < 10; k++)
for (int i = 0; i < 10; i++)
{
int i;
for (i = 0; i < 10; i++)
int j;
for (j = 0; j < 10; j++)
{
list.Add(delegate (int j) {
for (int l = 0; l < i; l += j)
list.Add(delegate (int k) {
for (int l = 0; l < j; l += k)
{
Console.WriteLine();
}
Expand Down
28 changes: 14 additions & 14 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/LocalFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public int MixedLocalFunction<T2>() where T2 : ICloneable, IConvertible
#pragma warning disable CS0219
T2 t2 = default(T2);
object z = this;
for (int j = 0; j < 10; j++)
for (int i = 0; i < 10; i++)
{
int i = 0;
i += NonStaticMethod6<object>(0);
int i2 = 0;
i2 += NonStaticMethod6<object>(0);
#if CS90
[My]
[return: My]
Expand All @@ -56,7 +56,7 @@ int NonStaticMethod6<T3>(int unused)
return NonStaticMethod6_1<T1>() + NonStaticMethod6_1<T2>() + z.GetHashCode();
int NonStaticMethod6_1<T4>()
{
return i + l + NonStaticMethod6<T4>(0) + StaticMethod1<decimal>();
return i2 + l + NonStaticMethod6<T4>(0) + StaticMethod1<decimal>();
}
}
}
Expand Down Expand Up @@ -119,18 +119,18 @@ public int MixedLocalFunction2Delegate<T2>() where T2 : ICloneable, IConvertible
{
T2 t2 = default(T2);
object z = this;
for (int j = 0; j < 10; j++)
for (int i = 0; i < 10; i++)
{
int i = 0;
i += StaticInvokeAsFunc(NonStaticMethod6<object>);
int i2 = 0;
i2 += StaticInvokeAsFunc(NonStaticMethod6<object>);
int NonStaticMethod6<T3>()
{
t2 = default(T2);
int l = 0;
return StaticInvokeAsFunc(NonStaticMethod6_1<T1>) + StaticInvokeAsFunc(NonStaticMethod6_1<T2>) + z.GetHashCode();
int NonStaticMethod6_1<T4>()
{
return i + l + StaticInvokeAsFunc(NonStaticMethod6<T4>) + StaticInvokeAsFunc(StaticMethod1<decimal>);
return i2 + l + StaticInvokeAsFunc(NonStaticMethod6<T4>) + StaticInvokeAsFunc(StaticMethod1<decimal>);
}
}
}
Expand Down Expand Up @@ -743,12 +743,12 @@ int ZZZ_0_0()
int ZZZ_1()
{
t0 = 0;
int t = t0;
int t3 = t0;
return new Func<int>(ZZZ_1_0)();
int ZZZ_1_0()
{
t0 = 0;
t = 0;
t3 = 0;
return 0;
}
}
Expand Down Expand Up @@ -779,14 +779,14 @@ int ZZZ_0()
int ZZZ_1()
{
t0 = 0;
int t1 = t0;
int t3 = t0;
#if !OPT
Func<int> func = delegate {
#else
return ((Func<int>)delegate {
#endif
t0 = 0;
t1 = 0;
t3 = 0;
return 0;
#if !OPT
};
Expand Down Expand Up @@ -822,14 +822,14 @@ int ZZZ_0()
int ZZZ_1()
{
t0 = 0;
int t1 = t0;
int t3 = t0;
#if !OPT
Func<int> func = delegate {
#else
return ((Func<int>)delegate {
#endif
t0 = 0;
t1 = 0;
t3 = 0;
return 0;
#if !OPT
};
Expand Down
4 changes: 2 additions & 2 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ public unsafe void UseFixedMemberAsReference(StructWithFixedSizeMembers* m)

public unsafe void PinFixedMember(ref StructWithFixedSizeMembers m)
{
fixed (int* ptr = m.Integers)
fixed (int* integers = m.Integers)
{
UsePointer(ptr);
UsePointer(integers);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
using System;
using System.Collections.Generic;

namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
internal class VariableNamingWithoutSymbols
{
Expand All @@ -25,5 +28,62 @@ private void Test2(string text, C c)
string text2 = c.Text;
#endif
}

private static IDisposable GetData()
{
return null;
}

private static void UseData(IDisposable data)
{

}

private static IEnumerable<int> GetItems()
{
throw null;
}

private static byte[] GetMemory()
{
throw null;
}

private static void Test(int item)
{
foreach (int item2 in GetItems())
{
Console.WriteLine(item2);
}
}

private static void Test(IDisposable data)
{
#if CS80
using IDisposable data2 = GetData();
UseData(data2);
#else
using (IDisposable data2 = GetData())
{
UseData(data2);
}
#endif
}

private unsafe static void Test(byte[] memory)
{
fixed (byte* memory2 = GetMemory())
{
Console.WriteLine(*memory2);
}
}

private static void ForLoopNamingConflict(int i)
{
for (int j = 0; j < i; j++)
{
Console.WriteLine(i + " of " + j);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,25 @@ public void Issue1898(int i)
thisField = this,
field1 = i
};
int field1 = default(int);
string field2 = default(string);
int field5 = default(int);
string field4 = default(string);
DisplayClass field3 = default(DisplayClass);
while (true)
{
switch (Rand())
{
case 1:
field1 = Rand();
field5 = Rand();
continue;
case 2:
field2 = Rand().ToString();
field4 = Rand().ToString();
continue;
case 3:
field3 = displayClass;
continue;
}
Console.WriteLine(field1);
Console.WriteLine(field2);
Console.WriteLine(field5);
Console.WriteLine(field4);
Console.WriteLine(field3);
}
}
Expand Down
Loading
Loading