Skip to content

Commit

Permalink
Rewrite AssignVariableNames algorithm to use variable usages instead …
Browse files Browse the repository at this point in the history
…of the list of variables.
  • Loading branch information
siegfriedpammer committed Jul 27, 2024
1 parent c67d086 commit 2ca5b5a
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 150 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,13 @@ private unsafe static void Test(byte[] memory)
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

0 comments on commit 2ca5b5a

Please sign in to comment.