Browse Source

Fix crash in ProxyCallReplacer

pull/1198/head
Daniel Grunwald 7 years ago
parent
commit
96e3b23ab3
  1. 8
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs
  2. 205
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il
  3. 183
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il
  4. 202
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il
  5. 126
      ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs
  6. 2
      ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs

8
ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs

@ -20,6 +20,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty @@ -20,6 +20,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
}
}
internal class B2<T> : A
{
protected internal override async Task<string> Test(string test)
{
return await base.Test(test);
}
}
internal class C
{
protected internal virtual string Test(string test)

205
ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il

@ -308,6 +308,211 @@ @@ -308,6 +308,211 @@
} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<T>
extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A
{
.class auto ansi sealed nested private beforefieldinit '<Test>d__0'<T>
extends [mscorlib]System.ValueType
implements [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field public int32 '<>1__state'
.field public valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> '<>t__builder'
.field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<!T> '<>4__this'
.field public string test
.field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> '<>u__$awaiter1'
.field private object '<>t__stack'
.method private hidebysig newslot virtual final
instance void MoveNext() cil managed
{
.override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext
// Code size 184 (0xb8)
.maxstack 3
.locals init (bool V_0,
string V_1,
class [mscorlib]System.Exception V_2,
int32 V_3,
valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> V_4,
valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> V_5)
.try
{
IL_0000: ldc.i4.1
IL_0001: stloc.0
IL_0002: ldarg.0
IL_0003: ldfld int32 valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_0008: stloc.3
IL_0009: ldloc.3
IL_000a: ldc.i4.0
IL_000b: beq.s IL_000f
IL_000d: br.s IL_0011
IL_000f: br.s IL_0057
IL_0011: br.s IL_0013
IL_0013: nop
IL_0014: ldarg.0
IL_0015: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<!0> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>4__this'
IL_001a: ldarg.0
IL_001b: ldfld string valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::test
IL_0020: call instance class [mscorlib]System.Threading.Tasks.Task`1<string> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<!T>::'<>n__FabricatedMethod2'(string)
IL_0025: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<!0> class [mscorlib]System.Threading.Tasks.Task`1<string>::GetAwaiter()
IL_002a: stloc.s V_4
IL_002c: ldloca.s V_4
IL_002e: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>::get_IsCompleted()
IL_0033: brtrue.s IL_0076
IL_0035: ldarg.0
IL_0036: ldc.i4.0
IL_0037: stfld int32 valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_003c: ldarg.0
IL_003d: ldloc.s V_4
IL_003f: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>u__$awaiter1'
IL_0044: ldarg.0
IL_0045: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_004a: ldloca.s V_4
IL_004c: ldarg.0
IL_004d: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::AwaitUnsafeOnCompleted<valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>,valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!0>>(!!0&,
!!1&)
IL_0052: nop
IL_0053: ldc.i4.0
IL_0054: stloc.0
IL_0055: leave.s IL_00b6
IL_0057: ldarg.0
IL_0058: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>u__$awaiter1'
IL_005d: stloc.s V_4
IL_005f: ldarg.0
IL_0060: ldloca.s V_5
IL_0062: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>
IL_0068: ldloc.s V_5
IL_006a: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>u__$awaiter1'
IL_006f: ldarg.0
IL_0070: ldc.i4.m1
IL_0071: stfld int32 valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_0076: ldloca.s V_4
IL_0078: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>::GetResult()
IL_007d: ldloca.s V_4
IL_007f: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>
IL_0085: stloc.1
IL_0086: leave.s IL_00a0
} // end .try
catch [mscorlib]System.Exception
{
IL_0088: stloc.2
IL_0089: ldarg.0
IL_008a: ldc.i4.s -2
IL_008c: stfld int32 valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_0091: ldarg.0
IL_0092: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_0097: ldloc.2
IL_0098: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::SetException(class [mscorlib]System.Exception)
IL_009d: nop
IL_009e: leave.s IL_00b6
} // end handler
IL_00a0: nop
IL_00a1: ldarg.0
IL_00a2: ldc.i4.s -2
IL_00a4: stfld int32 valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_00a9: ldarg.0
IL_00aa: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_00af: ldloc.1
IL_00b0: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::SetResult(!0)
IL_00b5: nop
IL_00b6: nop
IL_00b7: ret
} // end of method '<Test>d__0'::MoveNext
.method private hidebysig newslot virtual final
instance void SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine param0) cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
.override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::SetStateMachine
// Code size 13 (0xd)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_0006: ldarg.1
IL_0007: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine)
IL_000c: ret
} // end of method '<Test>d__0'::SetStateMachine
} // end of class '<Test>d__0'
.method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1<string>
Test(string test) cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerStepThroughAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 3F 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..?ICSharpCode.D
65 63 6F 6D 70 69 6C 65 72 2E 54 65 73 74 73 2E // ecompiler.Tests.
54 65 73 74 43 61 73 65 73 2E 49 4C 50 72 65 74 // TestCases.ILPret
74 79 2E 42 32 60 31 2B 3C 54 65 73 74 3E 64 5F // ty.B2`1+<Test>d_
5F 30 00 00 ) // _0..
// Code size 70 (0x46)
.maxstack 2
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T> V_0,
class [mscorlib]System.Threading.Tasks.Task`1<string> V_1,
valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> V_2)
IL_0000: ldloca.s V_0
IL_0002: ldarg.0
IL_0003: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<!0> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>4__this'
IL_0008: ldloca.s V_0
IL_000a: ldarg.1
IL_000b: stfld string valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::test
IL_0010: ldloca.s V_0
IL_0012: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!0> valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::Create()
IL_0017: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_001c: ldloca.s V_0
IL_001e: ldc.i4.m1
IL_001f: stfld int32 valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_0024: ldloca.s V_0
IL_0026: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_002b: stloc.2
IL_002c: ldloca.s V_2
IL_002e: ldloca.s V_0
IL_0030: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::Start<valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!0>>(!!0&)
IL_0035: ldloca.s V_0
IL_0037: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_003c: call instance class [mscorlib]System.Threading.Tasks.Task`1<!0> valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::get_Task()
IL_0041: stloc.1
IL_0042: br.s IL_0044
IL_0044: ldloc.1
IL_0045: ret
} // end of method B2`1::Test
.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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A::.ctor()
IL_0006: ret
} // end of method B2`1::.ctor
.method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1<string>
'<>n__FabricatedMethod2'(string A_1) cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 12 (0xc)
.maxstack 2
.locals init (class [mscorlib]System.Threading.Tasks.Task`1<string> V_0)
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: call instance class [mscorlib]System.Threading.Tasks.Task`1<string> ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A::Test(string)
IL_0007: stloc.0
IL_0008: br.s IL_000a
IL_000a: ldloc.0
IL_000b: ret
} // end of method B2`1::'<>n__FabricatedMethod2'
} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C
extends [mscorlib]System.Object
{

183
ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il

@ -275,6 +275,189 @@ @@ -275,6 +275,189 @@
} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<T>
extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A
{
.class auto ansi sealed nested private beforefieldinit '<Test>d__0'<T>
extends [mscorlib]System.ValueType
implements [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field public int32 '<>1__state'
.field public valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> '<>t__builder'
.field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<!T> '<>4__this'
.field public string test
.field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> '<>u__$awaiter1'
.field private object '<>t__stack'
.method private hidebysig newslot virtual final
instance void MoveNext() cil managed
{
.override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext
// Code size 172 (0xac)
.maxstack 3
.locals init (bool V_0,
string V_1,
class [mscorlib]System.Exception V_2,
int32 V_3,
valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> V_4,
valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> V_5)
.try
{
IL_0000: ldc.i4.1
IL_0001: stloc.0
IL_0002: ldarg.0
IL_0003: ldfld int32 valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_0008: stloc.3
IL_0009: ldloc.3
IL_000a: ldc.i4.0
IL_000b: beq.s IL_004f
IL_000d: ldarg.0
IL_000e: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<!0> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>4__this'
IL_0013: ldarg.0
IL_0014: ldfld string valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::test
IL_0019: call instance class [mscorlib]System.Threading.Tasks.Task`1<string> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<!T>::'<>n__FabricatedMethod2'(string)
IL_001e: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<!0> class [mscorlib]System.Threading.Tasks.Task`1<string>::GetAwaiter()
IL_0023: stloc.s V_4
IL_0025: ldloca.s V_4
IL_0027: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>::get_IsCompleted()
IL_002c: brtrue.s IL_006e
IL_002e: ldarg.0
IL_002f: ldc.i4.0
IL_0030: stfld int32 valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_0035: ldarg.0
IL_0036: ldloc.s V_4
IL_0038: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>u__$awaiter1'
IL_003d: ldarg.0
IL_003e: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_0043: ldloca.s V_4
IL_0045: ldarg.0
IL_0046: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::AwaitUnsafeOnCompleted<valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>,valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!0>>(!!0&,
!!1&)
IL_004b: ldc.i4.0
IL_004c: stloc.0
IL_004d: leave.s IL_00ab
IL_004f: ldarg.0
IL_0050: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>u__$awaiter1'
IL_0055: stloc.s V_4
IL_0057: ldarg.0
IL_0058: ldloca.s V_5
IL_005a: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>
IL_0060: ldloc.s V_5
IL_0062: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>u__$awaiter1'
IL_0067: ldarg.0
IL_0068: ldc.i4.m1
IL_0069: stfld int32 valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_006e: ldloca.s V_4
IL_0070: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>::GetResult()
IL_0075: ldloca.s V_4
IL_0077: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>
IL_007d: stloc.1
IL_007e: leave.s IL_0097
} // end .try
catch [mscorlib]System.Exception
{
IL_0080: stloc.2
IL_0081: ldarg.0
IL_0082: ldc.i4.s -2
IL_0084: stfld int32 valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_0089: ldarg.0
IL_008a: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_008f: ldloc.2
IL_0090: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::SetException(class [mscorlib]System.Exception)
IL_0095: leave.s IL_00ab
} // end handler
IL_0097: ldarg.0
IL_0098: ldc.i4.s -2
IL_009a: stfld int32 valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_009f: ldarg.0
IL_00a0: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_00a5: ldloc.1
IL_00a6: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::SetResult(!0)
IL_00ab: ret
} // end of method '<Test>d__0'::MoveNext
.method private hidebysig newslot virtual final
instance void SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine param0) cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
.override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::SetStateMachine
// Code size 13 (0xd)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_0006: ldarg.1
IL_0007: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine)
IL_000c: ret
} // end of method '<Test>d__0'::SetStateMachine
} // end of class '<Test>d__0'
.method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1<string>
Test(string test) cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerStepThroughAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 3F 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..?ICSharpCode.D
65 63 6F 6D 70 69 6C 65 72 2E 54 65 73 74 73 2E // ecompiler.Tests.
54 65 73 74 43 61 73 65 73 2E 49 4C 50 72 65 74 // TestCases.ILPret
74 79 2E 42 32 60 31 2B 3C 54 65 73 74 3E 64 5F // ty.B2`1+<Test>d_
5F 30 00 00 ) // _0..
// Code size 66 (0x42)
.maxstack 2
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T> V_0,
valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> V_1)
IL_0000: ldloca.s V_0
IL_0002: ldarg.0
IL_0003: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<!0> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>4__this'
IL_0008: ldloca.s V_0
IL_000a: ldarg.1
IL_000b: stfld string valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::test
IL_0010: ldloca.s V_0
IL_0012: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!0> valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::Create()
IL_0017: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_001c: ldloca.s V_0
IL_001e: ldc.i4.m1
IL_001f: stfld int32 valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_0024: ldloca.s V_0
IL_0026: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_002b: stloc.1
IL_002c: ldloca.s V_1
IL_002e: ldloca.s V_0
IL_0030: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::Start<valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!0>>(!!0&)
IL_0035: ldloca.s V_0
IL_0037: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_003c: call instance class [mscorlib]System.Threading.Tasks.Task`1<!0> valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::get_Task()
IL_0041: ret
} // end of method B2`1::Test
.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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A::.ctor()
IL_0006: ret
} // end of method B2`1::.ctor
.method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1<string>
'<>n__FabricatedMethod2'(string A_1) cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: call instance class [mscorlib]System.Threading.Tasks.Task`1<string> ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A::Test(string)
IL_0007: ret
} // end of method B2`1::'<>n__FabricatedMethod2'
} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C
extends [mscorlib]System.Object
{

202
ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il

@ -306,6 +306,208 @@ @@ -306,6 +306,208 @@
} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<T>
extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A
{
.class auto ansi sealed nested private beforefieldinit '<Test>d__0'<T>
extends [mscorlib]System.Object
implements [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field public int32 '<>1__state'
.field public valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> '<>t__builder'
.field public string test
.field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<!T> '<>4__this'
.field private string '<>s__1'
.field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> '<>u__1'
.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 '<Test>d__0'::.ctor
.method private hidebysig newslot virtual final
instance void MoveNext() cil managed
{
.override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext
// Code size 181 (0xb5)
.maxstack 3
.locals init (int32 V_0,
string V_1,
valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> V_2,
class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T> V_3,
class [mscorlib]System.Exception V_4)
IL_0000: ldarg.0
IL_0001: ldfld int32 class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_0006: stloc.0
.try
{
IL_0007: ldloc.0
IL_0008: brfalse.s IL_000c
IL_000a: br.s IL_000e
IL_000c: br.s IL_0053
IL_000e: nop
IL_000f: ldarg.0
IL_0010: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<!0> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>4__this'
IL_0015: ldarg.0
IL_0016: ldfld string class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::test
IL_001b: call instance class [mscorlib]System.Threading.Tasks.Task`1<string> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<!T>::'<>n__0'(string)
IL_0020: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<!0> class [mscorlib]System.Threading.Tasks.Task`1<string>::GetAwaiter()
IL_0025: stloc.2
IL_0026: ldloca.s V_2
IL_0028: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>::get_IsCompleted()
IL_002d: brtrue.s IL_006f
IL_002f: ldarg.0
IL_0030: ldc.i4.0
IL_0031: dup
IL_0032: stloc.0
IL_0033: stfld int32 class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_0038: ldarg.0
IL_0039: ldloc.2
IL_003a: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>u__1'
IL_003f: ldarg.0
IL_0040: stloc.3
IL_0041: ldarg.0
IL_0042: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_0047: ldloca.s V_2
IL_0049: ldloca.s V_3
IL_004b: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::AwaitUnsafeOnCompleted<valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>,class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!0>>(!!0&,
!!1&)
IL_0050: nop
IL_0051: leave.s IL_00b4
IL_0053: ldarg.0
IL_0054: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>u__1'
IL_0059: stloc.2
IL_005a: ldarg.0
IL_005b: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>u__1'
IL_0060: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>
IL_0066: ldarg.0
IL_0067: ldc.i4.m1
IL_0068: dup
IL_0069: stloc.0
IL_006a: stfld int32 class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_006f: ldarg.0
IL_0070: ldloca.s V_2
IL_0072: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<string>::GetResult()
IL_0077: stfld string class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>s__1'
IL_007c: ldarg.0
IL_007d: ldfld string class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>s__1'
IL_0082: stloc.1
IL_0083: leave.s IL_009f
} // end .try
catch [mscorlib]System.Exception
{
IL_0085: stloc.s V_4
IL_0087: ldarg.0
IL_0088: ldc.i4.s -2
IL_008a: stfld int32 class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_008f: ldarg.0
IL_0090: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_0095: ldloc.s V_4
IL_0097: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::SetException(class [mscorlib]System.Exception)
IL_009c: nop
IL_009d: leave.s IL_00b4
} // end handler
IL_009f: ldarg.0
IL_00a0: ldc.i4.s -2
IL_00a2: stfld int32 class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_00a7: ldarg.0
IL_00a8: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_00ad: ldloc.1
IL_00ae: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::SetResult(!0)
IL_00b3: nop
IL_00b4: ret
} // end of method '<Test>d__0'::MoveNext
.method private hidebysig newslot virtual final
instance void SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine stateMachine) cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
.override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::SetStateMachine
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method '<Test>d__0'::SetStateMachine
} // end of class '<Test>d__0'
.method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1<string>
Test(string test) cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 3F 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..?ICSharpCode.D
65 63 6F 6D 70 69 6C 65 72 2E 54 65 73 74 73 2E // ecompiler.Tests.
54 65 73 74 43 61 73 65 73 2E 49 4C 50 72 65 74 // TestCases.ILPret
74 79 2E 42 32 60 31 2B 3C 54 65 73 74 3E 64 5F // ty.B2`1+<Test>d_
5F 30 00 00 ) // _0..
.custom instance void [mscorlib]System.Diagnostics.DebuggerStepThroughAttribute::.ctor() = ( 01 00 00 00 )
// Code size 66 (0x42)
.maxstack 2
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T> V_0,
valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> V_1)
IL_0000: newobj instance void class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ldarg.0
IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1<!0> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>4__this'
IL_000d: ldloc.0
IL_000e: ldarg.1
IL_000f: stfld string class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::test
IL_0014: ldloc.0
IL_0015: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!0> valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::Create()
IL_001a: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_001f: ldloc.0
IL_0020: ldc.i4.m1
IL_0021: stfld int32 class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>1__state'
IL_0026: ldloc.0
IL_0027: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_002c: stloc.1
IL_002d: ldloca.s V_1
IL_002f: ldloca.s V_0
IL_0031: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::Start<class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!0>>(!!0&)
IL_0036: ldloc.0
IL_0037: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string> class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1/'<Test>d__0'<!T>::'<>t__builder'
IL_003c: call instance class [mscorlib]System.Threading.Tasks.Task`1<!0> valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<string>::get_Task()
IL_0041: ret
} // end of method B2`1::Test
.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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method B2`1::.ctor
.method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1<string>
'<>n__0'(string test) cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: call instance class [mscorlib]System.Threading.Tasks.Task`1<string> ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A::Test(string)
IL_0007: ret
} // end of method B2`1::'<>n__0'
} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B2`1
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C
extends [mscorlib]System.Object
{

126
ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs

@ -8,79 +8,83 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -8,79 +8,83 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{
class ProxyCallReplacer : IILTransform
{
ILTransformContext context;
public void Run(ILFunction function, ILTransformContext context)
{
this.context = context;
var module = context.TypeSystem.ModuleDefinition;
var metadata = context.TypeSystem.GetMetadata();
foreach (var inst in function.Descendants.OfType<CallInstruction>()) {
var handle = (MethodDefinitionHandle)inst.Method.MetadataToken;
if (handle.IsNil
|| !IsDefinedInCurrentOrOuterClass(inst.Method, context.Function.Method.DeclaringTypeDefinition)
|| !inst.Method.IsCompilerGeneratedOrIsInCompilerGeneratedClass()) {
continue;
}
MethodDefinition methodDef = metadata.GetMethodDefinition((MethodDefinitionHandle)inst.Method.MetadataToken);
if (!methodDef.HasBody()) continue;
// partially copied from CSharpDecompiler
var specializingTypeSystem = this.context.TypeSystem.GetSpecializingTypeSystem(inst.Method.Substitution);
var ilReader = new ILReader(specializingTypeSystem);
System.Threading.CancellationToken cancellationToken = new System.Threading.CancellationToken();
var proxyFunction = ilReader.ReadIL(module, handle, module.Reader.GetMethodBody(methodDef.RelativeVirtualAddress), cancellationToken);
var transformContext = new ILTransformContext(proxyFunction, specializingTypeSystem, this.context.Settings) {
CancellationToken = cancellationToken,
DecompileRun = context.DecompileRun
};
foreach (var transform in CSharp.CSharpDecompiler.GetILTransforms()) {
if (transform.GetType() != typeof(ProxyCallReplacer)) { // don't call itself on itself
cancellationToken.ThrowIfCancellationRequested();
transform.Run(proxyFunction, transformContext);
}
Run(inst, context);
}
}
void Run(CallInstruction inst, ILTransformContext context)
{
if (inst.Method.MetadataToken.IsNil || inst.Method.MetadataToken.Kind != HandleKind.MethodDefinition)
return;
var handle = (MethodDefinitionHandle)inst.Method.MetadataToken;
if (!IsDefinedInCurrentOrOuterClass(inst.Method, context.Function.Method.DeclaringTypeDefinition))
return;
if (!inst.Method.IsCompilerGeneratedOrIsInCompilerGeneratedClass())
return;
var module = context.TypeSystem.ModuleDefinition;
var metadata = module.Metadata;
MethodDefinition methodDef = metadata.GetMethodDefinition((MethodDefinitionHandle)inst.Method.MetadataToken);
if (!methodDef.HasBody())
return;
// partially copied from CSharpDecompiler
var specializingTypeSystem = context.TypeSystem.GetSpecializingTypeSystem(inst.Method.Substitution);
var ilReader = new ILReader(specializingTypeSystem);
System.Threading.CancellationToken cancellationToken = new System.Threading.CancellationToken();
var proxyFunction = ilReader.ReadIL(module, handle, module.Reader.GetMethodBody(methodDef.RelativeVirtualAddress), cancellationToken);
var transformContext = new ILTransformContext(proxyFunction, specializingTypeSystem, context.Settings) {
CancellationToken = cancellationToken,
DecompileRun = context.DecompileRun
};
foreach (var transform in CSharp.CSharpDecompiler.GetILTransforms()) {
if (transform.GetType() != typeof(ProxyCallReplacer)) { // don't call itself on itself
cancellationToken.ThrowIfCancellationRequested();
transform.Run(proxyFunction, transformContext);
}
}
if (!(proxyFunction.Body is BlockContainer blockContainer))
if (!(proxyFunction.Body is BlockContainer blockContainer))
return;
if (blockContainer.Blocks.Count != 1)
return;
var block = blockContainer.Blocks[0];
Call call = null;
if (block.Instructions.Count == 1) {
// leave IL_0000 (call Test(ldloc this, ldloc A_1))
if (!block.Instructions[0].MatchLeave(blockContainer, out ILInstruction returnValue))
return;
if (blockContainer.Blocks.Count != 1)
call = returnValue as Call;
} else if (block.Instructions.Count == 2) {
// call Test(ldloc this, ldloc A_1)
// leave IL_0000(nop)
call = block.Instructions[0] as Call;
if (!block.Instructions[1].MatchLeave(blockContainer, out ILInstruction returnValue))
return;
var block = blockContainer.Blocks[0];
Call call = null;
if (block.Instructions.Count == 1) {
// leave IL_0000 (call Test(ldloc this, ldloc A_1))
if (!block.Instructions[0].MatchLeave(blockContainer, out ILInstruction returnValue))
return;
call = returnValue as Call;
} else if (block.Instructions.Count == 2) {
// call Test(ldloc this, ldloc A_1)
// leave IL_0000(nop)
call = block.Instructions[0] as Call;
if (!block.Instructions[1].MatchLeave(blockContainer, out ILInstruction returnValue))
return;
if (!returnValue.MatchNop())
return;
}
if (call == null) {
return;
}
if (call.Method.IsConstructor)
if (!returnValue.MatchNop())
return;
}
if (call == null) {
return;
}
if (call.Method.IsConstructor)
return;
// check if original arguments are only correct ldloc calls
for (int i = 0; i < call.Arguments.Count; i++) {
var originalArg = call.Arguments[i];
if (!originalArg.MatchLdLoc(out ILVariable var) ||
var.Kind != VariableKind.Parameter ||
var.Index != i - 1) {
return;
}
// check if original arguments are only correct ldloc calls
for (int i = 0; i < call.Arguments.Count; i++) {
var originalArg = call.Arguments[i];
if (!originalArg.MatchLdLoc(out ILVariable var) ||
var.Kind != VariableKind.Parameter ||
var.Index != i - 1) {
return;
}
}
Call newInst = (Call)call.Clone();
Call newInst = (Call)call.Clone();
newInst.Arguments.ReplaceList(inst.Arguments);
inst.ReplaceWith(newInst);
}
newInst.Arguments.ReplaceList(inst.Arguments);
inst.ReplaceWith(newInst);
}
static bool IsDefinedInCurrentOrOuterClass(IMethod method, ITypeDefinition declaringTypeDefinition)

2
ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs

@ -227,7 +227,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -227,7 +227,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
DeclaringType = declaringType,
Name = metadata.GetString(fieldDef.Name),
ReturnType = FieldTypeReference.Resolve(fieldDefHandle, metadata, context, typeAttributeOptions),
IsStatic = (fieldDef.Attributes & System.Reflection.FieldAttributes.Static) != 0
IsStatic = (fieldDef.Attributes & System.Reflection.FieldAttributes.Static) != 0,
};
}
break;

Loading…
Cancel
Save