diff --git a/ICSharpCode.Decompiler.Tests/ExceptionHandling.cs b/ICSharpCode.Decompiler.Tests/ExceptionHandling.cs deleted file mode 100644 index 0db35e357..000000000 --- a/ICSharpCode.Decompiler.Tests/ExceptionHandling.cs +++ /dev/null @@ -1,128 +0,0 @@ -// 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. - -using System; -using System.Threading; - -public class ExceptionHandling -{ - public void MethodEndingWithEndFinally() - { - try - { - throw null; - } - finally - { - Console.WriteLine(); - } - } - - public void MethodEndingWithRethrow() - { - try - { - throw null; - } - catch - { - throw; - } - } - - public void TryCatchFinally() - { - try - { - Console.WriteLine("Try"); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - finally - { - Console.WriteLine("Finally"); - } - } - - public void TryCatchMultipleHandlers() - { - try - { - Console.WriteLine("Try"); - } - catch (InvalidOperationException ex) - { - Console.WriteLine(ex.Message); - } - catch (Exception ex2) - { - Console.WriteLine(ex2.Message); - } - catch - { - Console.WriteLine("other"); - } - } - - public void NoUsingStatementBecauseTheVariableIsAssignedTo() - { - CancellationTokenSource cancellationTokenSource = null; - try - { - cancellationTokenSource = new CancellationTokenSource(); - } - finally - { - if (cancellationTokenSource != null) - { - cancellationTokenSource.Dispose(); - } - } - } - - public void UsingStatementThatChangesTheVariable() - { - CancellationTokenSource cancellationTokenSource = null; - using (cancellationTokenSource) - { - cancellationTokenSource = new CancellationTokenSource(); - } - } - - public void TwoCatchBlocksWithSameVariable() - { - try - { - Console.WriteLine("Try1"); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - try - { - Console.WriteLine("Try2"); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } -} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs index b246afb18..863c729c8 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs @@ -16,8 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. - using System; +using System.Threading; namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { @@ -81,5 +81,73 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } return false; } + + public void MethodEndingWithEndFinally() + { + try { + throw null; + } finally { + Console.WriteLine(); + } + } + + public void MethodEndingWithRethrow() + { + try { + throw null; + } catch { + throw; + } + } + + public void TryCatchFinally() + { + try { + Console.WriteLine("Try"); + } catch (Exception ex) { + Console.WriteLine(ex.Message); + } finally { + Console.WriteLine("Finally"); + } + } + + public void TryCatchMultipleHandlers() + { + try { + Console.WriteLine("Try"); + } catch (InvalidOperationException ex) { + Console.WriteLine(ex.Message); + } catch (Exception ex2) { + Console.WriteLine(ex2.Message); + } catch { + Console.WriteLine("other"); + } + } + + //public void TwoCatchBlocksWithSameVariable() + //{ + // try { + // Console.WriteLine("Try1"); + // } catch (Exception ex) { + // Console.WriteLine(ex.Message); + // } + // try { + // Console.WriteLine("Try2"); + // } catch (Exception ex) { + // Console.WriteLine(ex.Message); + // } + //} + + public void NoUsingStatementBecauseTheVariableIsAssignedTo() + { + CancellationTokenSource cancellationTokenSource = null; + try { + cancellationTokenSource = new CancellationTokenSource(); + } finally { + if (cancellationTokenSource != null) { + cancellationTokenSource.Dispose(); + } + } + } } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.il index d420ceefa..7c51b2723 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly '3ufueglz' +.assembly crlipbnv { .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 @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module '3ufueglz.dll' -// MVID: {11FA4C6A-1160-4F37-B429-D5A05548EC92} +.module crlipbnv.dll +// MVID: {2550E8B3-391D-448D-A5A5-7F434CA2D173} .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: 0x02D90000 +// Image base: 0x00A40000 // =============== CLASS MEMBERS DECLARATION =================== @@ -219,6 +219,196 @@ IL_0024: ret } // end of method ExceptionHandling::SimpleTryFinally + .method public hidebysig instance void + MethodEndingWithEndFinally() cil managed + { + // Code size 13 (0xd) + .maxstack 1 + IL_0000: nop + .try + { + IL_0001: nop + IL_0002: ldnull + IL_0003: throw + + } // end .try + finally + { + IL_0004: nop + IL_0005: call void [mscorlib]System.Console::WriteLine() + IL_000a: nop + IL_000b: nop + IL_000c: endfinally + } // end handler + } // end of method ExceptionHandling::MethodEndingWithEndFinally + + .method public hidebysig instance void + MethodEndingWithRethrow() cil managed + { + // Code size 8 (0x8) + .maxstack 1 + IL_0000: nop + .try + { + IL_0001: nop + IL_0002: ldnull + IL_0003: throw + + } // end .try + catch [mscorlib]System.Object + { + IL_0004: pop + IL_0005: nop + IL_0006: rethrow + } // end handler + } // end of method ExceptionHandling::MethodEndingWithRethrow + + .method public hidebysig instance void + TryCatchFinally() cil managed + { + // Code size 52 (0x34) + .maxstack 1 + .locals init (class [mscorlib]System.Exception V_0) + IL_0000: nop + .try + { + .try + { + IL_0001: nop + IL_0002: ldstr "Try" + IL_0007: call void [mscorlib]System.Console::WriteLine(string) + IL_000c: nop + IL_000d: nop + IL_000e: leave.s IL_0021 + + } // end .try + catch [mscorlib]System.Exception + { + IL_0010: stloc.0 + IL_0011: nop + IL_0012: ldloc.0 + IL_0013: callvirt instance string [mscorlib]System.Exception::get_Message() + IL_0018: call void [mscorlib]System.Console::WriteLine(string) + IL_001d: nop + IL_001e: nop + IL_001f: leave.s IL_0021 + + } // end handler + IL_0021: nop + IL_0022: leave.s IL_0032 + + } // end .try + finally + { + IL_0024: nop + IL_0025: ldstr "Finally" + IL_002a: call void [mscorlib]System.Console::WriteLine(string) + IL_002f: nop + IL_0030: nop + IL_0031: endfinally + } // end handler + IL_0032: nop + IL_0033: ret + } // end of method ExceptionHandling::TryCatchFinally + + .method public hidebysig instance void + TryCatchMultipleHandlers() cil managed + { + // Code size 68 (0x44) + .maxstack 1 + .locals init (class [mscorlib]System.InvalidOperationException V_0, + class [mscorlib]System.Exception V_1) + IL_0000: nop + .try + { + IL_0001: nop + IL_0002: ldstr "Try" + IL_0007: call void [mscorlib]System.Console::WriteLine(string) + IL_000c: nop + IL_000d: nop + IL_000e: leave.s IL_0042 + + } // end .try + catch [mscorlib]System.InvalidOperationException + { + IL_0010: stloc.0 + IL_0011: nop + IL_0012: ldloc.0 + IL_0013: callvirt instance string [mscorlib]System.Exception::get_Message() + IL_0018: call void [mscorlib]System.Console::WriteLine(string) + IL_001d: nop + IL_001e: nop + IL_001f: leave.s IL_0042 + + } // end handler + catch [mscorlib]System.Exception + { + IL_0021: stloc.1 + IL_0022: nop + IL_0023: ldloc.1 + IL_0024: callvirt instance string [mscorlib]System.Exception::get_Message() + IL_0029: call void [mscorlib]System.Console::WriteLine(string) + IL_002e: nop + IL_002f: nop + IL_0030: leave.s IL_0042 + + } // end handler + catch [mscorlib]System.Object + { + IL_0032: pop + IL_0033: nop + IL_0034: ldstr "other" + IL_0039: call void [mscorlib]System.Console::WriteLine(string) + IL_003e: nop + IL_003f: nop + IL_0040: leave.s IL_0042 + + } // end handler + IL_0042: nop + IL_0043: ret + } // end of method ExceptionHandling::TryCatchMultipleHandlers + + .method public hidebysig instance void + NoUsingStatementBecauseTheVariableIsAssignedTo() cil managed + { + // Code size 35 (0x23) + .maxstack 2 + .locals init (class [mscorlib]System.Threading.CancellationTokenSource V_0, + bool V_1) + IL_0000: nop + IL_0001: ldnull + IL_0002: stloc.0 + .try + { + IL_0003: nop + IL_0004: newobj instance void [mscorlib]System.Threading.CancellationTokenSource::.ctor() + IL_0009: stloc.0 + IL_000a: nop + IL_000b: leave.s IL_0021 + + } // end .try + finally + { + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldnull + IL_0010: ceq + IL_0012: stloc.1 + IL_0013: ldloc.1 + IL_0014: brtrue.s IL_001f + + IL_0016: nop + IL_0017: ldloc.0 + IL_0018: callvirt instance void [mscorlib]System.Threading.CancellationTokenSource::Dispose() + IL_001d: nop + IL_001e: nop + IL_001f: nop + IL_0020: endfinally + } // end handler + IL_0021: nop + IL_0022: ret + } // end of method ExceptionHandling::NoUsingStatementBecauseTheVariableIsAssignedTo + .method family hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.il index c82ee1380..313b8ae43 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly c32aalgo +.assembly '2nwcwyaz' { .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 @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module c32aalgo.dll -// MVID: {7AB7254E-121A-428F-A78B-253019D759D6} +.module '2nwcwyaz.dll' +// MVID: {575315DD-46C2-4376-B77B-EDE5CA5A5039} .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: 0x00850000 +// Image base: 0x010F0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -174,6 +174,148 @@ IL_0018: ret } // end of method ExceptionHandling::SimpleTryFinally + .method public hidebysig instance void + MethodEndingWithEndFinally() cil managed + { + // Code size 8 (0x8) + .maxstack 1 + .try + { + IL_0000: ldnull + IL_0001: throw + + } // end .try + finally + { + IL_0002: call void [mscorlib]System.Console::WriteLine() + IL_0007: endfinally + } // end handler + } // end of method ExceptionHandling::MethodEndingWithEndFinally + + .method public hidebysig instance void + MethodEndingWithRethrow() cil managed + { + // Code size 5 (0x5) + .maxstack 1 + .try + { + IL_0000: ldnull + IL_0001: throw + + } // end .try + catch [mscorlib]System.Object + { + IL_0002: pop + IL_0003: rethrow + } // end handler + } // end of method ExceptionHandling::MethodEndingWithRethrow + + .method public hidebysig instance void + TryCatchFinally() cil managed + { + // Code size 40 (0x28) + .maxstack 1 + .locals init (class [mscorlib]System.Exception V_0) + .try + { + .try + { + IL_0000: ldstr "Try" + IL_0005: call void [mscorlib]System.Console::WriteLine(string) + IL_000a: leave.s IL_001a + + } // end .try + catch [mscorlib]System.Exception + { + IL_000c: stloc.0 + IL_000d: ldloc.0 + IL_000e: callvirt instance string [mscorlib]System.Exception::get_Message() + IL_0013: call void [mscorlib]System.Console::WriteLine(string) + IL_0018: leave.s IL_001a + + } // end handler + IL_001a: leave.s IL_0027 + + } // end .try + finally + { + IL_001c: ldstr "Finally" + IL_0021: call void [mscorlib]System.Console::WriteLine(string) + IL_0026: endfinally + } // end handler + IL_0027: ret + } // end of method ExceptionHandling::TryCatchFinally + + .method public hidebysig instance void + TryCatchMultipleHandlers() cil managed + { + // Code size 54 (0x36) + .maxstack 1 + .locals init (class [mscorlib]System.InvalidOperationException V_0, + class [mscorlib]System.Exception V_1) + .try + { + IL_0000: ldstr "Try" + IL_0005: call void [mscorlib]System.Console::WriteLine(string) + IL_000a: leave.s IL_0035 + + } // end .try + catch [mscorlib]System.InvalidOperationException + { + IL_000c: stloc.0 + IL_000d: ldloc.0 + IL_000e: callvirt instance string [mscorlib]System.Exception::get_Message() + IL_0013: call void [mscorlib]System.Console::WriteLine(string) + IL_0018: leave.s IL_0035 + + } // end handler + catch [mscorlib]System.Exception + { + IL_001a: stloc.1 + IL_001b: ldloc.1 + IL_001c: callvirt instance string [mscorlib]System.Exception::get_Message() + IL_0021: call void [mscorlib]System.Console::WriteLine(string) + IL_0026: leave.s IL_0035 + + } // end handler + catch [mscorlib]System.Object + { + IL_0028: pop + IL_0029: ldstr "other" + IL_002e: call void [mscorlib]System.Console::WriteLine(string) + IL_0033: leave.s IL_0035 + + } // end handler + IL_0035: ret + } // end of method ExceptionHandling::TryCatchMultipleHandlers + + .method public hidebysig instance void + NoUsingStatementBecauseTheVariableIsAssignedTo() cil managed + { + // Code size 21 (0x15) + .maxstack 1 + .locals init (class [mscorlib]System.Threading.CancellationTokenSource V_0) + IL_0000: ldnull + IL_0001: stloc.0 + .try + { + IL_0002: newobj instance void [mscorlib]System.Threading.CancellationTokenSource::.ctor() + IL_0007: stloc.0 + IL_0008: leave.s IL_0014 + + } // end .try + finally + { + IL_000a: ldloc.0 + IL_000b: brfalse.s IL_0013 + + IL_000d: ldloc.0 + IL_000e: callvirt instance void [mscorlib]System.Threading.CancellationTokenSource::Dispose() + IL_0013: endfinally + } // end handler + IL_0014: ret + } // end of method ExceptionHandling::NoUsingStatementBecauseTheVariableIsAssignedTo + .method family hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.roslyn.il index e246826ad..452204622 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module ExceptionHandling.dll -// MVID: {6C5D3E57-C537-472A-8DB8-E97514ED3668} +// MVID: {A8006418-E0B4-4B57-9F6D-4F358C3537B7} .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: 0x004C0000 +// Image base: 0x00E10000 // =============== CLASS MEMBERS DECLARATION =================== @@ -234,6 +234,137 @@ IL_0018: ret } // end of method ExceptionHandling::SimpleTryFinally + .method public hidebysig instance void + MethodEndingWithEndFinally() cil managed + { + // Code size 8 (0x8) + .maxstack 1 + .try + { + IL_0000: ldnull + IL_0001: throw + + } // end .try + finally + { + IL_0002: call void [mscorlib]System.Console::WriteLine() + IL_0007: endfinally + } // end handler + } // end of method ExceptionHandling::MethodEndingWithEndFinally + + .method public hidebysig instance void + MethodEndingWithRethrow() cil managed + { + // Code size 5 (0x5) + .maxstack 1 + .try + { + IL_0000: ldnull + IL_0001: throw + + } // end .try + catch [mscorlib]System.Object + { + IL_0002: pop + IL_0003: rethrow + } // end handler + } // end of method ExceptionHandling::MethodEndingWithRethrow + + .method public hidebysig instance void + TryCatchFinally() cil managed + { + // Code size 36 (0x24) + .maxstack 1 + .try + { + .try + { + IL_0000: ldstr "Try" + IL_0005: call void [mscorlib]System.Console::WriteLine(string) + IL_000a: leave.s IL_0023 + + } // end .try + catch [mscorlib]System.Exception + { + IL_000c: callvirt instance string [mscorlib]System.Exception::get_Message() + IL_0011: call void [mscorlib]System.Console::WriteLine(string) + IL_0016: leave.s IL_0023 + + } // end handler + } // end .try + finally + { + IL_0018: ldstr "Finally" + IL_001d: call void [mscorlib]System.Console::WriteLine(string) + IL_0022: endfinally + } // end handler + IL_0023: ret + } // end of method ExceptionHandling::TryCatchFinally + + .method public hidebysig instance void + TryCatchMultipleHandlers() cil managed + { + // Code size 50 (0x32) + .maxstack 1 + .try + { + IL_0000: ldstr "Try" + IL_0005: call void [mscorlib]System.Console::WriteLine(string) + IL_000a: leave.s IL_0031 + + } // end .try + catch [mscorlib]System.InvalidOperationException + { + IL_000c: callvirt instance string [mscorlib]System.Exception::get_Message() + IL_0011: call void [mscorlib]System.Console::WriteLine(string) + IL_0016: leave.s IL_0031 + + } // end handler + catch [mscorlib]System.Exception + { + IL_0018: callvirt instance string [mscorlib]System.Exception::get_Message() + IL_001d: call void [mscorlib]System.Console::WriteLine(string) + IL_0022: leave.s IL_0031 + + } // end handler + catch [mscorlib]System.Object + { + IL_0024: pop + IL_0025: ldstr "other" + IL_002a: call void [mscorlib]System.Console::WriteLine(string) + IL_002f: leave.s IL_0031 + + } // end handler + IL_0031: ret + } // end of method ExceptionHandling::TryCatchMultipleHandlers + + .method public hidebysig instance void + NoUsingStatementBecauseTheVariableIsAssignedTo() cil managed + { + // Code size 21 (0x15) + .maxstack 1 + .locals init (class [mscorlib]System.Threading.CancellationTokenSource V_0) + IL_0000: ldnull + IL_0001: stloc.0 + .try + { + IL_0002: newobj instance void [mscorlib]System.Threading.CancellationTokenSource::.ctor() + IL_0007: stloc.0 + IL_0008: leave.s IL_0014 + + } // end .try + finally + { + IL_000a: ldloc.0 + IL_000b: brfalse.s IL_0013 + + IL_000d: ldloc.0 + IL_000e: callvirt instance void [mscorlib]System.Threading.CancellationTokenSource::Dispose() + IL_0013: endfinally + } // end handler + IL_0014: ret + } // end of method ExceptionHandling::NoUsingStatementBecauseTheVariableIsAssignedTo + .method family hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.roslyn.il index 177af1ab5..2c3f9e2bb 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module ExceptionHandling.dll -// MVID: {132EAF1E-6B6D-4E21-B000-D06E1A4188E3} +// MVID: {9E5D4825-3895-41C9-96B8-84EF4BB28F59} .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: 0x03070000 +// Image base: 0x02A40000 // =============== CLASS MEMBERS DECLARATION =================== @@ -280,6 +280,192 @@ IL_0023: ret } // end of method ExceptionHandling::SimpleTryFinally + .method public hidebysig instance void + MethodEndingWithEndFinally() cil managed + { + // Code size 13 (0xd) + .maxstack 1 + IL_0000: nop + .try + { + IL_0001: nop + IL_0002: ldnull + IL_0003: throw + + } // end .try + finally + { + IL_0004: nop + IL_0005: call void [mscorlib]System.Console::WriteLine() + IL_000a: nop + IL_000b: nop + IL_000c: endfinally + } // end handler + } // end of method ExceptionHandling::MethodEndingWithEndFinally + + .method public hidebysig instance void + MethodEndingWithRethrow() cil managed + { + // Code size 8 (0x8) + .maxstack 1 + IL_0000: nop + .try + { + IL_0001: nop + IL_0002: ldnull + IL_0003: throw + + } // end .try + catch [mscorlib]System.Object + { + IL_0004: pop + IL_0005: nop + IL_0006: rethrow + } // end handler + } // end of method ExceptionHandling::MethodEndingWithRethrow + + .method public hidebysig instance void + TryCatchFinally() cil managed + { + // Code size 50 (0x32) + .maxstack 1 + .locals init (class [mscorlib]System.Exception V_0) + IL_0000: nop + .try + { + .try + { + IL_0001: nop + IL_0002: ldstr "Try" + IL_0007: call void [mscorlib]System.Console::WriteLine(string) + IL_000c: nop + IL_000d: nop + IL_000e: leave.s IL_0021 + + } // end .try + catch [mscorlib]System.Exception + { + IL_0010: stloc.0 + IL_0011: nop + IL_0012: ldloc.0 + IL_0013: callvirt instance string [mscorlib]System.Exception::get_Message() + IL_0018: call void [mscorlib]System.Console::WriteLine(string) + IL_001d: nop + IL_001e: nop + IL_001f: leave.s IL_0021 + + } // end handler + IL_0021: leave.s IL_0031 + + } // end .try + finally + { + IL_0023: nop + IL_0024: ldstr "Finally" + IL_0029: call void [mscorlib]System.Console::WriteLine(string) + IL_002e: nop + IL_002f: nop + IL_0030: endfinally + } // end handler + IL_0031: ret + } // end of method ExceptionHandling::TryCatchFinally + + .method public hidebysig instance void + TryCatchMultipleHandlers() cil managed + { + // Code size 67 (0x43) + .maxstack 1 + .locals init (class [mscorlib]System.InvalidOperationException V_0, + class [mscorlib]System.Exception V_1) + IL_0000: nop + .try + { + IL_0001: nop + IL_0002: ldstr "Try" + IL_0007: call void [mscorlib]System.Console::WriteLine(string) + IL_000c: nop + IL_000d: nop + IL_000e: leave.s IL_0042 + + } // end .try + catch [mscorlib]System.InvalidOperationException + { + IL_0010: stloc.0 + IL_0011: nop + IL_0012: ldloc.0 + IL_0013: callvirt instance string [mscorlib]System.Exception::get_Message() + IL_0018: call void [mscorlib]System.Console::WriteLine(string) + IL_001d: nop + IL_001e: nop + IL_001f: leave.s IL_0042 + + } // end handler + catch [mscorlib]System.Exception + { + IL_0021: stloc.1 + IL_0022: nop + IL_0023: ldloc.1 + IL_0024: callvirt instance string [mscorlib]System.Exception::get_Message() + IL_0029: call void [mscorlib]System.Console::WriteLine(string) + IL_002e: nop + IL_002f: nop + IL_0030: leave.s IL_0042 + + } // end handler + catch [mscorlib]System.Object + { + IL_0032: pop + IL_0033: nop + IL_0034: ldstr "other" + IL_0039: call void [mscorlib]System.Console::WriteLine(string) + IL_003e: nop + IL_003f: nop + IL_0040: leave.s IL_0042 + + } // end handler + IL_0042: ret + } // end of method ExceptionHandling::TryCatchMultipleHandlers + + .method public hidebysig instance void + NoUsingStatementBecauseTheVariableIsAssignedTo() cil managed + { + // Code size 34 (0x22) + .maxstack 2 + .locals init (class [mscorlib]System.Threading.CancellationTokenSource V_0, + bool V_1) + IL_0000: nop + IL_0001: ldnull + IL_0002: stloc.0 + .try + { + IL_0003: nop + IL_0004: newobj instance void [mscorlib]System.Threading.CancellationTokenSource::.ctor() + IL_0009: stloc.0 + IL_000a: nop + IL_000b: leave.s IL_0021 + + } // end .try + finally + { + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldnull + IL_0010: cgt.un + IL_0012: stloc.1 + IL_0013: ldloc.1 + IL_0014: brfalse.s IL_001f + + IL_0016: nop + IL_0017: ldloc.0 + IL_0018: callvirt instance void [mscorlib]System.Threading.CancellationTokenSource::Dispose() + IL_001d: nop + IL_001e: nop + IL_001f: nop + IL_0020: endfinally + } // end handler + IL_0021: ret + } // end of method ExceptionHandling::NoUsingStatementBecauseTheVariableIsAssignedTo + .method family hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index 469af50b9..383c4dc5b 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -221,13 +221,15 @@ namespace ICSharpCode.Decompiler.IL ImmutableStack ehStack = null; if (eh.HandlerType == Cil.ExceptionHandlerType.Catch) { var v = new ILVariable(VariableKind.Exception, typeSystem.Resolve(eh.CatchType), eh.HandlerStart.Offset) { - Name = "E_" + eh.HandlerStart.Offset + Name = "E_" + eh.HandlerStart.Offset, + HasGeneratedName = true }; variableByExceptionHandler.Add(eh, v); ehStack = ImmutableStack.Create(v); } else if (eh.HandlerType == Cil.ExceptionHandlerType.Filter) { var v = new ILVariable(VariableKind.Exception, typeSystem.Compilation.FindType(KnownTypeCode.Object), eh.HandlerStart.Offset) { - Name = "E_" + eh.HandlerStart.Offset + Name = "E_" + eh.HandlerStart.Offset, + HasGeneratedName = true }; variableByExceptionHandler.Add(eh, v); ehStack = ImmutableStack.Create(v);