From d40ecb5e0ca4ff81ddb4c72dea9a8a2be098bdbe Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 29 Sep 2017 02:25:53 +0200 Subject: [PATCH 001/190] [switch] Add StringToInt instruction --- .../ICSharpCode.Decompiler.csproj | 2 + ICSharpCode.Decompiler/IL/Instructions.cs | 96 +++++++++++++++++++ ICSharpCode.Decompiler/IL/Instructions.tt | 2 + .../IL/Instructions/LockInstruction.cs | 32 ------- .../IL/Instructions/StringToInt.cs | 45 +++++++++ .../IL/Instructions/UsingInstruction.cs | 53 ++++++++++ 6 files changed, 198 insertions(+), 32 deletions(-) create mode 100644 ICSharpCode.Decompiler/IL/Instructions/StringToInt.cs create mode 100644 ICSharpCode.Decompiler/IL/Instructions/UsingInstruction.cs diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 387d453b5..dd2bd4a91 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -271,6 +271,8 @@ + + diff --git a/ICSharpCode.Decompiler/IL/Instructions.cs b/ICSharpCode.Decompiler/IL/Instructions.cs index 015b312b7..c6f361279 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.cs +++ b/ICSharpCode.Decompiler/IL/Instructions.cs @@ -158,6 +158,8 @@ namespace ICSharpCode.Decompiler.IL /// Converts an array pointer (O) to a reference to the first element, or to a null reference if the array is null or empty. /// Also used to convert a string to a reference to the first character. ArrayToPointer, + /// Maps a string value to an integer. This is used in switch(string). + StringToInt, /// Push a typed reference of type class onto the stack. MakeRefAny, /// Push the type token stored in a typed reference. @@ -4021,6 +4023,87 @@ namespace ICSharpCode.Decompiler.IL } } namespace ICSharpCode.Decompiler.IL +{ + /// Maps a string value to an integer. This is used in switch(string). + public sealed partial class StringToInt : ILInstruction + { + public static readonly SlotInfo ArgumentSlot = new SlotInfo("Argument", canInlineInto: true); + ILInstruction argument; + public ILInstruction Argument { + get { return this.argument; } + set { + ValidateChild(value); + SetChildInstruction(ref this.argument, value, 0); + } + } + protected sealed override int GetChildCount() + { + return 1; + } + protected sealed override ILInstruction GetChild(int index) + { + switch (index) { + case 0: + return this.argument; + default: + throw new IndexOutOfRangeException(); + } + } + protected sealed override void SetChild(int index, ILInstruction value) + { + switch (index) { + case 0: + this.Argument = value; + break; + default: + throw new IndexOutOfRangeException(); + } + } + protected sealed override SlotInfo GetChildSlot(int index) + { + switch (index) { + case 0: + return ArgumentSlot; + default: + throw new IndexOutOfRangeException(); + } + } + public sealed override ILInstruction Clone() + { + var clone = (StringToInt)ShallowClone(); + clone.Argument = this.argument.Clone(); + return clone; + } + public override StackType ResultType { get { return StackType.I4; } } + protected override InstructionFlags ComputeFlags() + { + return argument.Flags; + } + public override InstructionFlags DirectFlags { + get { + return InstructionFlags.None; + } + } + public override void AcceptVisitor(ILVisitor visitor) + { + visitor.VisitStringToInt(this); + } + public override T AcceptVisitor(ILVisitor visitor) + { + return visitor.VisitStringToInt(this); + } + public override T AcceptVisitor(ILVisitor visitor, C context) + { + return visitor.VisitStringToInt(this, context); + } + protected internal override bool PerformMatch(ILInstruction other, ref Patterns.Match match) + { + var o = other as StringToInt; + return o != null && this.argument.PerformMatch(o.argument, ref match); + } + } +} +namespace ICSharpCode.Decompiler.IL { /// Push a typed reference of type class onto the stack. public sealed partial class MakeRefAny : UnaryInstruction @@ -4633,6 +4716,10 @@ namespace ICSharpCode.Decompiler.IL { Default(inst); } + protected internal virtual void VisitStringToInt(StringToInt inst) + { + Default(inst); + } protected internal virtual void VisitMakeRefAny(MakeRefAny inst) { Default(inst); @@ -4919,6 +5006,10 @@ namespace ICSharpCode.Decompiler.IL { return Default(inst); } + protected internal virtual T VisitStringToInt(StringToInt inst) + { + return Default(inst); + } protected internal virtual T VisitMakeRefAny(MakeRefAny inst) { return Default(inst); @@ -5205,6 +5296,10 @@ namespace ICSharpCode.Decompiler.IL { return Default(inst, context); } + protected internal virtual T VisitStringToInt(StringToInt inst, C context) + { + return Default(inst, context); + } protected internal virtual T VisitMakeRefAny(MakeRefAny inst, C context) { return Default(inst, context); @@ -5294,6 +5389,7 @@ namespace ICSharpCode.Decompiler.IL "ldlen", "ldelema", "array.to.pointer", + "string.to.int", "mkrefany", "refanytype", "refanyval", diff --git a/ICSharpCode.Decompiler/IL/Instructions.tt b/ICSharpCode.Decompiler/IL/Instructions.tt index 2b28a9efe..f25e3fa0d 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.tt +++ b/ICSharpCode.Decompiler/IL/Instructions.tt @@ -220,6 +220,8 @@ new OpCode("array.to.pointer", "Converts an array pointer (O) to a reference to the first element, or to a null reference if the array is null or empty." + Environment.NewLine + "Also used to convert a string to a reference to the first character.", CustomArguments("array"), ResultType("Ref")), + new OpCode("string.to.int", "Maps a string value to an integer. This is used in switch(string).", + CustomArguments("argument"), CustomConstructor, CustomWriteTo, ResultType("I4")), new OpCode("mkrefany", "Push a typed reference of type class onto the stack.", CustomClassName("MakeRefAny"), Unary, HasTypeOperand, ResultType("O")), diff --git a/ICSharpCode.Decompiler/IL/Instructions/LockInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/LockInstruction.cs index f0c1b1ebc..36cd8380e 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/LockInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/LockInstruction.cs @@ -38,36 +38,4 @@ namespace ICSharpCode.Decompiler.IL output.Write("}"); } } - - /// - /// IL using instruction. - /// Equivalent to: - /// - /// stloc v(resourceExpression) - /// try { - /// body - /// } finally { - /// v?.Dispose(); - /// } - /// - /// - /// - /// The value of v is undefined after the end of the body block. - /// - partial class UsingInstruction - { - public override void WriteTo(ITextOutput output, ILAstWritingOptions options) - { - output.Write("using ("); - Variable.WriteTo(output); - output.Write(" = "); - ResourceExpression.WriteTo(output, options); - output.WriteLine(") {"); - output.Indent(); - Body.WriteTo(output, options); - output.Unindent(); - output.WriteLine(); - output.Write("}"); - } - } } diff --git a/ICSharpCode.Decompiler/IL/Instructions/StringToInt.cs b/ICSharpCode.Decompiler/IL/Instructions/StringToInt.cs new file mode 100644 index 000000000..f804a3928 --- /dev/null +++ b/ICSharpCode.Decompiler/IL/Instructions/StringToInt.cs @@ -0,0 +1,45 @@ +// Copyright (c) 2017 Siegfried Pammer +// +// 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. + + +namespace ICSharpCode.Decompiler.IL +{ + partial class StringToInt + { + public string[] Map { get; } + + public StringToInt(ILInstruction argument, string[] map) + : base(OpCode.StringToInt) + { + this.Argument = argument; + this.Map = map; + } + + public override void WriteTo(ITextOutput output, ILAstWritingOptions options) + { + output.Write("string.to.int ("); + Argument.WriteTo(output, options); + output.Write(", { "); + for (int i = 0; i < Map.Length; i++) { + if (i > 0) output.Write(", "); + output.Write($"[{i}] = \"{Map[i]}\""); + } + output.Write(" })"); + } + } +} diff --git a/ICSharpCode.Decompiler/IL/Instructions/UsingInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/UsingInstruction.cs new file mode 100644 index 000000000..795be5914 --- /dev/null +++ b/ICSharpCode.Decompiler/IL/Instructions/UsingInstruction.cs @@ -0,0 +1,53 @@ +// Copyright (c) 2017 Siegfried Pammer +// +// 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. + + +namespace ICSharpCode.Decompiler.IL +{ + /// + /// IL using instruction. + /// Equivalent to: + /// + /// stloc v(resourceExpression) + /// try { + /// body + /// } finally { + /// v?.Dispose(); + /// } + /// + /// + /// + /// The value of v is undefined after the end of the body block. + /// + partial class UsingInstruction + { + public override void WriteTo(ITextOutput output, ILAstWritingOptions options) + { + output.Write("using ("); + Variable.WriteTo(output); + output.Write(" = "); + ResourceExpression.WriteTo(output, options); + output.WriteLine(") {"); + output.Indent(); + Body.WriteTo(output, options); + output.Unindent(); + output.WriteLine(); + output.Write("}"); + } + } +} From ddd5f43b412fd08689a6e048457084316a9fa6f2 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 29 Sep 2017 02:27:36 +0200 Subject: [PATCH 002/190] [switch] Add basic SwitchOnStringTransform for Roslyn switch on strings. --- ICSharpCode.Decompiler.Tests/Switch.cs | 89 -------------- .../TestCases/Correctness/Switch.cs | 38 +++++- .../CSharp/CSharpDecompiler.cs | 1 + .../CSharp/StatementBuilder.cs | 17 ++- .../ICSharpCode.Decompiler.csproj | 1 + .../IL/Transforms/SwitchOnStringTransform.cs | 114 ++++++++++++++++++ 6 files changed, 166 insertions(+), 94 deletions(-) delete mode 100644 ICSharpCode.Decompiler.Tests/Switch.cs create mode 100644 ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs diff --git a/ICSharpCode.Decompiler.Tests/Switch.cs b/ICSharpCode.Decompiler.Tests/Switch.cs deleted file mode 100644 index 4a20a6392..000000000 --- a/ICSharpCode.Decompiler.Tests/Switch.cs +++ /dev/null @@ -1,89 +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; - -public static class Switch -{ - public static string ShortSwitchOverString(string text) - { - switch (text) { - case "First case": - return "Text"; - default: - return "Default"; - } - } - - public static string SwitchOverString1(string text) - { - switch (text) - { - case "First case": - return "Text1"; - case "Second case": - case "2nd case": - return "Text2"; - case "Third case": - return "Text3"; - case "Fourth case": - return "Text4"; - case "Fifth case": - return "Text5"; - case "Sixth case": - return "Text6"; - case null: - return null; - default: - return "Default"; - } - } - - public static string SwitchOverString2() - { - switch (Environment.UserName) - { - case "First case": - return "Text1"; - case "Second case": - return "Text2"; - case "Third case": - return "Text3"; - case "Fourth case": - return "Text4"; - case "Fifth case": - return "Text5"; - case "Sixth case": - return "Text6"; - default: - return "Default"; - } - } - - public static string SwitchOverBool(bool b) - { - switch (b) { - case true: - return bool.TrueString; - case false: - return bool.FalseString; - default: - return null; - } - } -} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs index 61ed2f347..7816d4697 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs @@ -30,6 +30,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness Console.WriteLine(SwitchOverString2()); Console.WriteLine(SwitchOverBool(true)); Console.WriteLine(SwitchOverBool(false)); + SwitchInLoop(0); + SwitchWithGoto(1); + SwitchWithGoto(2); + SwitchWithGoto(3); + SwitchWithGoto(4); } static void TestCase(Func target, params T[] args) @@ -105,6 +110,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness return "Text5"; case "Sixth case": return "Text6"; + case "Seventh case": + return "Text7"; + case "Eighth case": + return "Text8"; + case "Ninth case": + return "Text9"; + case "Tenth case": + return "Text10"; + case "Eleventh case": + return "Text11"; default: return "Default"; } @@ -141,10 +156,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness default: Console.WriteLine("default"); Console.WriteLine("more code"); - throw new ArgumentException(); + return; } i++; } } + + public static void SwitchWithGoto(int i) + { + switch (i) { + case 1: + Console.WriteLine("one"); + goto default; + case 2: + Console.WriteLine("two"); + goto case 3; + case 3: + Console.WriteLine("three"); + break; + case 4: + Console.WriteLine("four"); + return; + default: + Console.WriteLine("default"); + break; + } + } } } \ No newline at end of file diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 1503561f0..b6ff80b98 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -85,6 +85,7 @@ namespace ICSharpCode.Decompiler.CSharp new RemoveDeadVariableInit(), new SplitVariables(), // split variables once again, because the stobj(ldloca V, ...) may open up new replacements new SwitchDetection(), + new SwitchOnStringTransform(), new BlockILTransform { // per-block transforms PostOrderTransforms = { // Even though it's a post-order block-transform as most other transforms, diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index e728c4905..bdb59f436 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -83,11 +83,13 @@ namespace ICSharpCode.Decompiler.CSharp return new IfElseStatement(condition, trueStatement, falseStatement); } - CaseLabel CreateTypedCaseLabel(long i, IType type) + CaseLabel CreateTypedCaseLabel(long i, IType type, string[] map = null) { object value; if (type.IsKnownType(KnownTypeCode.Boolean)) { value = i != 0; + } else if (type.IsKnownType(KnownTypeCode.String) && map != null) { + value = map[i]; } else if (type.Kind == TypeKind.Enum) { var enumType = type.GetDefinition().EnumUnderlyingType; value = CSharpPrimitiveCast.Cast(ReflectionHelper.GetTypeCode(enumType), i, false); @@ -101,12 +103,19 @@ namespace ICSharpCode.Decompiler.CSharp { var oldBreakTarget = breakTarget; breakTarget = null; // 'break' within a switch would only leave the switch - - var value = exprBuilder.Translate(inst.Value); + + TranslatedExpression value; + var strToInt = inst.Value as StringToInt; + if (strToInt != null) { + value = exprBuilder.Translate(strToInt.Argument); + } else { + value = exprBuilder.Translate(inst.Value); + } + var stmt = new SwitchStatement() { Expression = value }; foreach (var section in inst.Sections) { var astSection = new Syntax.SwitchSection(); - astSection.CaseLabels.AddRange(section.Labels.Values.Select(i => CreateTypedCaseLabel(i, value.Type))); + astSection.CaseLabels.AddRange(section.Labels.Values.Select(i => CreateTypedCaseLabel(i, value.Type, strToInt?.Map))); ConvertSwitchSectionBody(astSection, section.Body); stmt.SwitchSections.Add(astSection); } diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index dd2bd4a91..16409351a 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -273,6 +273,7 @@ + diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs new file mode 100644 index 000000000..7065ca5ac --- /dev/null +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -0,0 +1,114 @@ +// Copyright (c) 2017 Siegfried Pammer +// +// 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.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ICSharpCode.Decompiler.IL.Transforms +{ + class SwitchOnStringTransform : IILTransform + { + public void Run(ILFunction function, ILTransformContext context) + { + HashSet changedContainers = new HashSet(); + + foreach (var block in function.Descendants.OfType()) { + for (int i = block.Instructions.Count - 1; i >= 0; i--) { + if (!MatchRoslynSwitchOnString(block.Instructions, i, out var newSwitch)) + continue; + + block.Instructions[i].ReplaceWith(newSwitch); + block.Instructions.RemoveAt(i - 1); + + i--; + + // This happens in some cases: + // Use correct index after transformation. + if (i >= block.Instructions.Count) + i = block.Instructions.Count; + } + + if (block.Parent is BlockContainer container) + changedContainers.Add(container); + } + + foreach (var container in changedContainers) + container.SortBlocks(deleteUnreachableBlocks: true); + } + + bool MatchRoslynSwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst) + { + inst = null; + if (i < 1) return false; + if (!(instructions[i] is SwitchInstruction switchInst && switchInst.Value.MatchLdLoc(out var targetVar) && + MatchComputeStringHashCall(instructions[i - 1], targetVar, out var switchValue))) + return false; + + var stringValues = new List<(int, string, Block)>(); + int index = 0; + foreach (var section in switchInst.Sections) { + if (!section.Body.MatchBranch(out Block target)) + return false; + if (target.IncomingEdgeCount != 1 || target.Instructions.Count == 0) + return false; + if (!target.Instructions[0].MatchIfInstruction(out var condition, out var bodyBranch)) + return false; + if (!MatchStringEqualityComparison(condition, switchValue.Variable, out string stringValue)) + return false; + if (!bodyBranch.MatchBranch(out Block body)) + return false; + stringValues.Add((index++, stringValue, body)); + } + + var value = new StringToInt(switchValue.Clone(), stringValues.Select(item => item.Item2).ToArray()); + inst = new SwitchInstruction(value); + inst.Sections.AddRange(stringValues.Select(section => new SwitchSection { Labels = new Util.LongSet(section.Item1), Body = new Branch(section.Item3) })); + + return true; + } + + bool MatchComputeStringHashCall(ILInstruction inst, ILVariable targetVar, out LdLoc switchValue) + { + switchValue = null; + if (!inst.MatchStLoc(targetVar, out var value)) + return false; + if (!(value is Call c && c.Arguments.Count == 1 && c.Method.Name == "ComputeStringHash" && c.Method.IsCompilerGeneratedOrIsInCompilerGeneratedClass())) + return false; + if (!(c.Arguments[0] is LdLoc)) + return false; + switchValue = (LdLoc)c.Arguments[0]; + return true; + } + + bool MatchStringEqualityComparison(ILInstruction condition, ILVariable variable, out string stringValue) + { + stringValue = null; + ILInstruction left, right; + if (condition is Call c && c.Method.IsOperator && c.Method.Name == "op_Equality" && c.Arguments.Count == 2) { + left = c.Arguments[0]; + right = c.Arguments[1]; + if (!right.MatchLdStr(out stringValue)) + return false; + } else if (condition.MatchCompEquals(out left, out right) && right.MatchLdNull()) { + } else return false; + return left.MatchLdLoc(variable); + } + } +} From 41aa4573d93c37cd565cc66d5f575438e92c4586 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 29 Sep 2017 14:24:50 +0200 Subject: [PATCH 003/190] Fix #498: switches implemented by the compiler as Dictionary lookup are not correctly decompiled --- .../TestCases/Correctness/Switch.cs | 7 ++ .../IL/Transforms/SwitchOnStringTransform.cs | 119 +++++++++++++++++- 2 files changed, 125 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs index 7816d4697..cdecec92f 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs @@ -46,6 +46,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness public static string SparseIntegerSwitch(int i) { + Console.WriteLine("SparseIntegerSwitch: " + i); switch (i) { case -10000000: return "-10 mln"; case -100: return "-hundred"; @@ -64,6 +65,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness public static string ShortSwitchOverString(string text) { + Console.WriteLine("ShortSwitchOverString: " + text); switch (text) { case "First case": return "Text"; @@ -74,6 +76,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness public static string SwitchOverString1(string text) { + Console.WriteLine("SwitchOverString1: " + text); switch (text) { case "First case": return "Text1"; @@ -97,6 +100,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness public static string SwitchOverString2() { + Console.WriteLine("SwitchOverString2:"); switch (Environment.UserName) { case "First case": return "Text1"; @@ -127,6 +131,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness public static string SwitchOverBool(bool b) { + Console.WriteLine("SwitchOverBool: " + b); switch (b) { case true: return bool.TrueString; @@ -139,6 +144,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness public static void SwitchInLoop(int i) { + Console.WriteLine("SwitchInLoop: " + i); while (true) { switch (i) { case 1: @@ -164,6 +170,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness public static void SwitchWithGoto(int i) { + Console.WriteLine("SwitchWithGoto: " + i); switch (i) { case 1: Console.WriteLine("one"); diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 7065ca5ac..ee6f2b6a7 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.IL.Transforms { @@ -31,9 +32,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms foreach (var block in function.Descendants.OfType()) { for (int i = block.Instructions.Count - 1; i >= 0; i--) { - if (!MatchRoslynSwitchOnString(block.Instructions, i, out var newSwitch)) + SwitchInstruction newSwitch; + Block blockAfterSwitch = null; + if (!MatchLegacySwitchOnString(block.Instructions, i, out newSwitch, out blockAfterSwitch) && + !MatchRoslynSwitchOnString(block.Instructions, i, out newSwitch)) continue; + if (i + 1 < block.Instructions.Count && block.Instructions[i + 1] is Branch b && blockAfterSwitch != null) { + block.Instructions[i + 1].ReplaceWith(new Branch(blockAfterSwitch)); + } + block.Instructions[i].ReplaceWith(newSwitch); block.Instructions.RemoveAt(i - 1); @@ -53,6 +61,115 @@ namespace ICSharpCode.Decompiler.IL.Transforms container.SortBlocks(deleteUnreachableBlocks: true); } + bool MatchLegacySwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst, out Block blockAfterSwitch) + { + inst = null; + blockAfterSwitch = null; + if (i < 1) return false; + // match first block: checking switch-value for null + if (!(instructions[i].MatchIfInstruction(out var condition, out var exitBlockJump) && + instructions[i - 1].MatchStLoc(out var switchValueVar, out var switchValue) && switchValueVar.Type.IsKnownType(KnownTypeCode.String))) + return false; + if (!exitBlockJump.MatchBranch(out var exitBlock)) + return false; + if (!(condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && left.Match(switchValue).Success)) + return false; + var nextBlockJump = instructions.ElementAtOrDefault(i + 1) as Branch; + if (nextBlockJump == null || nextBlockJump.TargetBlock.IncomingEdgeCount != 1) + return false; + // match second block: checking compiler-generated Dictionary for null + var nextBlock = nextBlockJump.TargetBlock; + if (nextBlock.Instructions.Count != 2 || !nextBlock.Instructions[0].MatchIfInstruction(out condition, out var tryGetValueBlockJump)) + return false; + if (!tryGetValueBlockJump.MatchBranch(out var tryGetValueBlock)) + return false; + if (!nextBlock.Instructions[1].MatchBranch(out var dictInitBlock) || dictInitBlock.IncomingEdgeCount != 1) + return false; + if (!(condition.MatchCompNotEquals(out left, out right) && right.MatchLdNull() && + MatchDictionaryFieldLoad(left, out var dictField, out var dictionaryType))) + return false; + // match third block: initialization of compiler-generated Dictionary + if (dictInitBlock.IncomingEdgeCount != 1 || dictInitBlock.Instructions.Count < 3) + return false; + if (!ExtractStringValuesFromDictionaryInitBlock(dictInitBlock, out var stringValues, tryGetValueBlock, dictionaryType, dictField)) + return false; + // match fourth block: TryGetValue on compiler-generated Dictionary + if (tryGetValueBlock.IncomingEdgeCount != 2 || tryGetValueBlock.Instructions.Count != 2) + return false; + if (!tryGetValueBlock.Instructions[0].MatchIfInstruction(out condition, out var defaultBlockJump)) + return false; + if (!defaultBlockJump.MatchBranch(out var defaultBlock)) + return false; + if (!(condition.MatchLogicNot(out var arg) && arg is Call c && c.Method.Name == "TryGetValue" && + MatchDictionaryFieldLoad(c.Arguments[0], out var dictField2, out _) && dictField2.Equals(dictField))) + return false; + if (!c.Arguments[1].MatchLdLoc(switchValueVar) || !c.Arguments[2].MatchLdLoca(out var switchIndexVar)) + return false; + if (!tryGetValueBlock.Instructions[1].MatchBranch(out var switchBlock)) + return false; + // match fifth block: switch-instruction block + if (switchBlock.IncomingEdgeCount != 1 || switchBlock.Instructions.Count != 2) + return false; + if (!(switchBlock.Instructions[0] is SwitchInstruction switchInst && switchInst.Value.MatchLdLoc(switchIndexVar))) + return false; + if (!switchBlock.Instructions[1].MatchBranch(defaultBlock)) + return false; + // switch contains case null: + var sections = new List(switchInst.Sections); + if (exitBlock != defaultBlock) { + stringValues.Add(null); + sections.Add(new SwitchSection() { Labels = new Util.LongSet(stringValues.Count - 1), Body = new Branch(exitBlock) }); + } + var stringToInt = new StringToInt(switchValue.Clone(), stringValues.ToArray()); + inst = new SwitchInstruction(stringToInt); + inst.DefaultBody = switchInst.DefaultBody; + inst.Sections.AddRange(sections); + blockAfterSwitch = defaultBlock; + return true; + } + + bool MatchDictionaryFieldLoad(ILInstruction inst, out IField dictField, out IType dictionaryType) + { + dictField = null; + dictionaryType = null; + return inst.MatchLdObj(out var dictionaryFieldLoad, out dictionaryType) && + IsStringToIntDictionary(dictionaryType) && + dictionaryFieldLoad.MatchLdsFlda(out dictField) && + dictField.IsCompilerGeneratedOrIsInCompilerGeneratedClass(); + } + + bool ExtractStringValuesFromDictionaryInitBlock(Block block, out List values, Block targetBlock, IType dictionaryType, IField dictionaryField) + { + values = null; + if (!(block.Instructions[0].MatchStLoc(out var dictVar, out var newObjDict) && + newObjDict is NewObj newObj && newObj.Arguments.Count == 1 && newObj.Arguments[0].MatchLdcI4(out var valuesLength))) + return false; + if (block.Instructions.Count != valuesLength + 3) + return false; + values = new List(valuesLength); + for (int i = 0; i < valuesLength; i++) { + if (!(block.Instructions[i + 1] is Call c && c.Method.Name == "Add" && c.Arguments.Count == 3 && + c.Arguments[0].MatchLdLoc(dictVar) && c.Arguments[1].MatchLdStr(out var value) && c.Arguments[2].MatchLdcI4(i))) + return false; + values.Add(value); + } + if (!(block.Instructions[valuesLength + 1].MatchStObj(out var loadField, out var dictVarLoad, out var dictType) && + dictType.Equals(dictionaryType) && loadField.MatchLdsFlda(out var dictField) && dictField.Equals(dictionaryField)) && + dictVarLoad.MatchLdLoc(dictVar)) + return false; + return block.Instructions[valuesLength + 2].MatchBranch(targetBlock); + } + + bool IsStringToIntDictionary(IType dictionaryType) + { + if (dictionaryType.FullName != "System.Collections.Generic.Dictionary") + return false; + if (dictionaryType.TypeArguments.Count != 2) + return false; + return dictionaryType.TypeArguments[0].IsKnownType(KnownTypeCode.String) && + dictionaryType.TypeArguments[1].IsKnownType(KnownTypeCode.Int32); + } + bool MatchRoslynSwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst) { inst = null; From e0df621e44fd11311d227ecc8d27df4b24c41d0d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 29 Sep 2017 17:08:08 +0200 Subject: [PATCH 004/190] Implement translation of cascading if-statements with string comparisons to switch(string). --- .../TestCases/Correctness/Switch.cs | 31 +++++++ .../IL/Transforms/SwitchOnStringTransform.cs | 84 ++++++++++++++++++- 2 files changed, 111 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs index cdecec92f..f28e691cf 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs @@ -26,6 +26,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { TestCase(SparseIntegerSwitch, -100, 1, 2, 3, 4); TestCase(ShortSwitchOverString, "First case", "Else"); + TestCase(ShortSwitchOverString2, "First case", "Second case", "Third case", "Else"); + TestCase(ShortSwitchOverStringNoExplicitDefault, "First case", "Second case", "Third case", "Else"); TestCase(SwitchOverString1, "First case", "Second case", "2nd case", "Third case", "Fourth case", "Fifth case", "Sixth case", null, "default", "else"); Console.WriteLine(SwitchOverString2()); Console.WriteLine(SwitchOverBool(true)); @@ -74,6 +76,35 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness } } + public static string ShortSwitchOverString2(string text) + { + Console.WriteLine("ShortSwitchOverString2: " + text); + switch (text) { + case "First case": + return "Text1"; + case "Second case": + return "Text2"; + case "Third case": + return "Text3"; + default: + return "Default"; + } + } + + public static string ShortSwitchOverStringNoExplicitDefault(string text) + { + Console.WriteLine("ShortSwitchOverStringNoExplicitDefault: " + text); + switch (text) { + case "First case": + return "Text1"; + case "Second case": + return "Text2"; + case "Third case": + return "Text3"; + } + return "Default"; + } + public static string SwitchOverString1(string text) { Console.WriteLine("SwitchOverString1: " + text); diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index ee6f2b6a7..b533e8d3b 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler.IL.Transforms { @@ -34,7 +35,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms for (int i = block.Instructions.Count - 1; i >= 0; i--) { SwitchInstruction newSwitch; Block blockAfterSwitch = null; - if (!MatchLegacySwitchOnString(block.Instructions, i, out newSwitch, out blockAfterSwitch) && + if (!MatchCascadingIfStatements(block.Instructions, i, out newSwitch, out blockAfterSwitch) && + !MatchLegacySwitchOnString(block.Instructions, i, out newSwitch, out blockAfterSwitch) && !MatchRoslynSwitchOnString(block.Instructions, i, out newSwitch)) continue; @@ -43,9 +45,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms } block.Instructions[i].ReplaceWith(newSwitch); - block.Instructions.RemoveAt(i - 1); - - i--; + if (newSwitch.Value.MatchLdLoc(out var switchVar) && !block.Instructions[i - 1].MatchLdLoc(switchVar)) { + block.Instructions.RemoveAt(i - 1); + i--; + } // This happens in some cases: // Use correct index after transformation. @@ -61,6 +64,79 @@ namespace ICSharpCode.Decompiler.IL.Transforms container.SortBlocks(deleteUnreachableBlocks: true); } + bool MatchCascadingIfStatements(InstructionCollection instructions, int i, out SwitchInstruction inst, out Block blockAfterSwitch) + { + inst = null; + blockAfterSwitch = null; + if (i < 1) return false; + // match first block: checking switch-value for null or first value (Roslyn) + if (!(instructions[i].MatchIfInstruction(out var condition, out var firstBlockJump) && + instructions[i - 1].MatchStLoc(out var switchValueVar, out var switchValue) && switchValueVar.Type.IsKnownType(KnownTypeCode.String))) + return false; + if (!firstBlockJump.MatchBranch(out var firstBlock)) + return false; + bool isLegacy; + Block defaultBlock; + List<(string, Block)> values = new List<(string, Block)>(); + if (condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && left.MatchLdLoc(switchValueVar)) { + isLegacy = true; + defaultBlock = firstBlock; + } else if (MatchStringEqualityComparison(condition, switchValueVar, out string value)) { + isLegacy = false; + defaultBlock = null; + values.Add((value, firstBlock)); + } else return false; + if (!(instructions.ElementAtOrDefault(i + 1) is Branch nextCaseJump)) + return false; + Block currentCaseBlock = nextCaseJump.TargetBlock; + Block nextCaseBlock; + while ((nextCaseBlock = MatchCaseBlock(currentCaseBlock, switchValueVar, out string value, out Block block)) != null) { + values.Add((value, block)); + currentCaseBlock = nextCaseBlock; + } + if (!ExtractLastJumpFromBlock(currentCaseBlock, out var exitBlock)) + return false; + if (values.Count == 0) + return false; + if (!values.All(b => ExtractLastJumpFromBlock(b.Item2, out var nextExit) && nextExit == exitBlock)) + return false; + if (currentCaseBlock.IncomingEdgeCount == (isLegacy ? 2 : 1)) { + var sections = new List(values.SelectWithIndex((index, b) => new SwitchSection { Labels = new LongSet(index), Body = new Branch(b.Item2) })); + var stringToInt = new StringToInt(new LdLoc(switchValueVar), values.SelectArray(item => item.Item1)); + inst = new SwitchInstruction(stringToInt); + inst.Sections.AddRange(sections); + blockAfterSwitch = currentCaseBlock; + return true; + } + return false; + } + + bool ExtractLastJumpFromBlock(Block block, out Block exitBlock) + { + exitBlock = null; + var lastInst = block.Instructions.LastOrDefault(); + if (lastInst == null || !lastInst.MatchBranch(out exitBlock)) + return false; + return true; + } + + Block MatchCaseBlock(Block currentBlock, ILVariable switchVariable, out string value, out Block caseBlock) + { + value = null; + caseBlock = null; + if (currentBlock.IncomingEdgeCount != 1 || currentBlock.Instructions.Count != 2) + return null; + if (!currentBlock.Instructions[0].MatchIfInstruction(out var condition, out var caseBlockBranch)) + return null; + if (!caseBlockBranch.MatchBranch(out caseBlock)) + return null; + if (!MatchStringEqualityComparison(condition, switchVariable, out value)) + return null; + if (!currentBlock.Instructions[1].MatchBranch(out var nextBlock)) + return null; + return nextBlock; + } + bool MatchLegacySwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst, out Block blockAfterSwitch) { inst = null; From 2145543ada5774f48845956856f6cf26558f7f1b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 29 Sep 2017 23:54:16 +0200 Subject: [PATCH 005/190] Add Switch pretty tests --- .../ICSharpCode.Decompiler.Tests.csproj | 1 + .../PrettyTestRunner.cs | 6 + .../TestCases/Pretty/Switch.cs | 226 +++++ .../TestCases/Pretty/Switch.il | 694 ++++++++++++++ .../TestCases/Pretty/Switch.opt.il | 558 +++++++++++ .../TestCases/Pretty/Switch.opt.roslyn.il | 700 ++++++++++++++ .../TestCases/Pretty/Switch.roslyn.il | 890 ++++++++++++++++++ 7 files changed, 3075 insertions(+) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index 40842b724..683d63415 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -100,6 +100,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index 880297416..2b458282b 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -97,6 +97,12 @@ namespace ICSharpCode.Decompiler.Tests Run(cscOptions: cscOptions); } + [Test] + public void Switch([ValueSource("defaultOptions")] CompilerOptions cscOptions) + { + Run(cscOptions: cscOptions); + } + [Test] public void AnonymousTypes([Values(CompilerOptions.None, CompilerOptions.Optimize)] CompilerOptions cscOptions) { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs new file mode 100644 index 000000000..bfc8ea0c4 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -0,0 +1,226 @@ +// 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; + +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty +{ + public static class Switch + { + public static string SparseIntegerSwitch(int i) + { + Console.WriteLine("SparseIntegerSwitch: " + i); + switch (i) { + case -10000000: { + return "-10 mln"; + } + case -100: { + return "-hundred"; + } + case -1: { + return "-1"; + } + case 0: { + return "0"; + } + case 1: { + return "1"; + } + case 2: { + return "2"; + } + case 4: { + return "4"; + } + case 100: { + return "hundred"; + } + case 10000: { + return "ten thousand"; + } + case 10001: { + return "ten thousand and one"; + } + case int.MaxValue: { + return "int.MaxValue"; + } + default: { + return "something else"; + } + } + } + + public static string ShortSwitchOverString(string text) + { + Console.WriteLine("ShortSwitchOverString: " + text); + switch (text) { + case "First case": { + return "Text1"; + } + case "Second case": { + return "Text2"; + } + case "Third case": { + return "Text3"; + } + default: { + return "Default"; + } + } + } + + public static string SwitchOverString1(string text) + { + Console.WriteLine("SwitchOverString1: " + text); + switch (text) { + case "First case": { + return "Text1"; + } + case "Second case": + case "2nd case": { + return "Text2"; + } + case "Third case": { + return "Text3"; + } + case "Fourth case": { + return "Text4"; + } + case "Fifth case": { + return "Text5"; + } + case "Sixth case": { + return "Text6"; + } + case null: { + return null; + } + default: { + return "Default"; + } + } + } + + public static string SwitchOverString2() + { + Console.WriteLine("SwitchOverString2:"); + switch (Environment.UserName) { + case "First case": { + return "Text1"; + } + case "Second case": { + return "Text2"; + } + case "Third case": { + return "Text3"; + } + case "Fourth case": { + return "Text4"; + } + case "Fifth case": { + return "Text5"; + } + case "Sixth case": { + return "Text6"; + } + case "Seventh case": { + return "Text7"; + } + case "Eighth case": { + return "Text8"; + } + case "Ninth case": { + return "Text9"; + } + case "Tenth case": { + return "Text10"; + } + case "Eleventh case": { + return "Text11"; + } + default: { + return "Default"; + } + } + } + + public static string SwitchOverBool(bool b) + { + Console.WriteLine("SwitchOverBool: " + b.ToString()); + switch (b) { + case true: { + return bool.TrueString; + } + case false: { + return bool.FalseString; + } + default: { + return null; + } + } + } + + public static void SwitchInLoop(int i) + { + Console.WriteLine("SwitchInLoop: " + i); + while (true) { + switch (i) { + case 1: + Console.WriteLine("one"); + break; + case 2: + Console.WriteLine("two"); + break; + case 3: + Console.WriteLine("three"); + continue; + case 4: + Console.WriteLine("four"); + return; + default: + Console.WriteLine("default"); + Console.WriteLine("more code"); + return; + } + i++; + } + } + + public static void SwitchWithGoto(int i) + { + Console.WriteLine("SwitchWithGoto: " + i); + switch (i) { + case 1: + Console.WriteLine("one"); + goto default; + case 2: + Console.WriteLine("two"); + goto case 3; + case 3: + Console.WriteLine("three"); + break; + case 4: + Console.WriteLine("four"); + return; + default: + Console.WriteLine("default"); + break; + } + } + } +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il new file mode 100644 index 000000000..e04aa74b5 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il @@ -0,0 +1,694 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly wau4yvxd +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module wau4yvxd.dll +// MVID: {102ACC94-685A-42C5-9229-AC386C0A78B1} +.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: 0x01440000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch + extends [mscorlib]System.Object +{ + .method public hidebysig static string + SparseIntegerSwitch(int32 i) cil managed + { + // Code size 224 (0xe0) + .maxstack 2 + .locals init (string V_0, + int32 V_1) + IL_0000: nop + IL_0001: ldstr "SparseIntegerSwitch: " + IL_0006: ldarg.0 + IL_0007: box [mscorlib]System.Int32 + IL_000c: call string [mscorlib]System.String::Concat(object, + object) + IL_0011: call void [mscorlib]System.Console::WriteLine(string) + IL_0016: nop + IL_0017: ldarg.0 + IL_0018: stloc.1 + IL_0019: ldloc.1 + IL_001a: ldc.i4.4 + IL_001b: bgt.s IL_004f + + IL_001d: ldloc.1 + IL_001e: ldc.i4 0xff676980 + IL_0023: beq.s IL_0072 + + IL_0025: ldloc.1 + IL_0026: ldc.i4.s -100 + IL_0028: beq.s IL_007b + + IL_002a: ldloc.1 + IL_002b: ldc.i4.m1 + IL_002c: sub + IL_002d: switch ( + IL_0084, + IL_008d, + IL_0096, + IL_009f, + IL_00d5, + IL_00a8) + IL_004a: br IL_00d5 + + IL_004f: ldloc.1 + IL_0050: ldc.i4.s 100 + IL_0052: beq.s IL_00b1 + + IL_0054: ldloc.1 + IL_0055: ldc.i4 0x2710 + IL_005a: sub + IL_005b: switch ( + IL_00ba, + IL_00c3) + IL_0068: ldloc.1 + IL_0069: ldc.i4 0x7fffffff + IL_006e: beq.s IL_00cc + + IL_0070: br.s IL_00d5 + + IL_0072: nop + IL_0073: ldstr "-10 mln" + IL_0078: stloc.0 + IL_0079: br.s IL_00de + + IL_007b: nop + IL_007c: ldstr "-hundred" + IL_0081: stloc.0 + IL_0082: br.s IL_00de + + IL_0084: nop + IL_0085: ldstr "-1" + IL_008a: stloc.0 + IL_008b: br.s IL_00de + + IL_008d: nop + IL_008e: ldstr "0" + IL_0093: stloc.0 + IL_0094: br.s IL_00de + + IL_0096: nop + IL_0097: ldstr "1" + IL_009c: stloc.0 + IL_009d: br.s IL_00de + + IL_009f: nop + IL_00a0: ldstr "2" + IL_00a5: stloc.0 + IL_00a6: br.s IL_00de + + IL_00a8: nop + IL_00a9: ldstr "4" + IL_00ae: stloc.0 + IL_00af: br.s IL_00de + + IL_00b1: nop + IL_00b2: ldstr "hundred" + IL_00b7: stloc.0 + IL_00b8: br.s IL_00de + + IL_00ba: nop + IL_00bb: ldstr "ten thousand" + IL_00c0: stloc.0 + IL_00c1: br.s IL_00de + + IL_00c3: nop + IL_00c4: ldstr "ten thousand and one" + IL_00c9: stloc.0 + IL_00ca: br.s IL_00de + + IL_00cc: nop + IL_00cd: ldstr "int.MaxValue" + IL_00d2: stloc.0 + IL_00d3: br.s IL_00de + + IL_00d5: nop + IL_00d6: ldstr "something else" + IL_00db: stloc.0 + IL_00dc: br.s IL_00de + + IL_00de: ldloc.0 + IL_00df: ret + } // end of method Switch::SparseIntegerSwitch + + .method public hidebysig static string + ShortSwitchOverString(string text) cil managed + { + // Code size 102 (0x66) + .maxstack 2 + .locals init (string V_0, + string V_1) + IL_0000: nop + IL_0001: ldstr "ShortSwitchOverString: " + IL_0006: ldarg.0 + IL_0007: call string [mscorlib]System.String::Concat(string, + string) + IL_000c: call void [mscorlib]System.Console::WriteLine(string) + IL_0011: nop + IL_0012: ldarg.0 + IL_0013: stloc.1 + IL_0014: ldloc.1 + IL_0015: brfalse.s IL_005b + + IL_0017: ldloc.1 + IL_0018: ldstr "First case" + IL_001d: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0022: brtrue.s IL_0040 + + IL_0024: ldloc.1 + IL_0025: ldstr "Second case" + IL_002a: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_002f: brtrue.s IL_0049 + + IL_0031: ldloc.1 + IL_0032: ldstr "Third case" + IL_0037: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_003c: brtrue.s IL_0052 + + IL_003e: br.s IL_005b + + IL_0040: nop + IL_0041: ldstr "Text1" + IL_0046: stloc.0 + IL_0047: br.s IL_0064 + + IL_0049: nop + IL_004a: ldstr "Text2" + IL_004f: stloc.0 + IL_0050: br.s IL_0064 + + IL_0052: nop + IL_0053: ldstr "Text3" + IL_0058: stloc.0 + IL_0059: br.s IL_0064 + + IL_005b: nop + IL_005c: ldstr "Default" + IL_0061: stloc.0 + IL_0062: br.s IL_0064 + + IL_0064: ldloc.0 + IL_0065: ret + } // end of method Switch::ShortSwitchOverString + + .method public hidebysig static string + SwitchOverString1(string text) cil managed + { + // Code size 255 (0xff) + .maxstack 4 + .locals init (string V_0, + string V_1, + int32 V_2) + IL_0000: nop + IL_0001: ldstr "SwitchOverString1: " + IL_0006: ldarg.0 + IL_0007: call string [mscorlib]System.String::Concat(string, + string) + IL_000c: call void [mscorlib]System.Console::WriteLine(string) + IL_0011: nop + IL_0012: ldarg.0 + IL_0013: stloc.1 + IL_0014: ldloc.1 + IL_0015: brfalse IL_00ef + + IL_001a: volatile. + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{102ACC94-685A-42C5-9229-AC386C0A78B1}'::'$$method0x6000003-1' + IL_0021: brtrue.s IL_0084 + + IL_0023: ldc.i4.7 + IL_0024: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_0029: dup + IL_002a: ldstr "First case" + IL_002f: ldc.i4.0 + IL_0030: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0035: dup + IL_0036: ldstr "Second case" + IL_003b: ldc.i4.1 + IL_003c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0041: dup + IL_0042: ldstr "2nd case" + IL_0047: ldc.i4.2 + IL_0048: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_004d: dup + IL_004e: ldstr "Third case" + IL_0053: ldc.i4.3 + IL_0054: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0059: dup + IL_005a: ldstr "Fourth case" + IL_005f: ldc.i4.4 + IL_0060: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0065: dup + IL_0066: ldstr "Fifth case" + IL_006b: ldc.i4.5 + IL_006c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0071: dup + IL_0072: ldstr "Sixth case" + IL_0077: ldc.i4.6 + IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_007d: volatile. + IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{102ACC94-685A-42C5-9229-AC386C0A78B1}'::'$$method0x6000003-1' + IL_0084: volatile. + IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{102ACC94-685A-42C5-9229-AC386C0A78B1}'::'$$method0x6000003-1' + IL_008b: ldloc.1 + IL_008c: ldloca.s V_2 + IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + !1&) + IL_0093: brfalse.s IL_00f4 + + IL_0095: ldloc.2 + IL_0096: switch ( + IL_00b9, + IL_00c2, + IL_00c2, + IL_00cb, + IL_00d4, + IL_00dd, + IL_00e6) + IL_00b7: br.s IL_00f4 + + IL_00b9: nop + IL_00ba: ldstr "Text1" + IL_00bf: stloc.0 + IL_00c0: br.s IL_00fd + + IL_00c2: nop + IL_00c3: ldstr "Text2" + IL_00c8: stloc.0 + IL_00c9: br.s IL_00fd + + IL_00cb: nop + IL_00cc: ldstr "Text3" + IL_00d1: stloc.0 + IL_00d2: br.s IL_00fd + + IL_00d4: nop + IL_00d5: ldstr "Text4" + IL_00da: stloc.0 + IL_00db: br.s IL_00fd + + IL_00dd: nop + IL_00de: ldstr "Text5" + IL_00e3: stloc.0 + IL_00e4: br.s IL_00fd + + IL_00e6: nop + IL_00e7: ldstr "Text6" + IL_00ec: stloc.0 + IL_00ed: br.s IL_00fd + + IL_00ef: nop + IL_00f0: ldnull + IL_00f1: stloc.0 + IL_00f2: br.s IL_00fd + + IL_00f4: nop + IL_00f5: ldstr "Default" + IL_00fa: stloc.0 + IL_00fb: br.s IL_00fd + + IL_00fd: ldloc.0 + IL_00fe: ret + } // end of method Switch::SwitchOverString1 + + .method public hidebysig static string + SwitchOverString2() cil managed + { + // Code size 366 (0x16e) + .maxstack 4 + .locals init (string V_0, + string V_1, + int32 V_2) + IL_0000: nop + IL_0001: ldstr "SwitchOverString2:" + IL_0006: call void [mscorlib]System.Console::WriteLine(string) + IL_000b: nop + IL_000c: call string [mscorlib]System.Environment::get_UserName() + IL_0011: stloc.1 + IL_0012: ldloc.1 + IL_0013: brfalse IL_0163 + + IL_0018: volatile. + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{102ACC94-685A-42C5-9229-AC386C0A78B1}'::'$$method0x6000004-1' + IL_001f: brtrue IL_00b8 + + IL_0024: ldc.i4.s 11 + IL_0026: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_002b: dup + IL_002c: ldstr "First case" + IL_0031: ldc.i4.0 + IL_0032: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0037: dup + IL_0038: ldstr "Second case" + IL_003d: ldc.i4.1 + IL_003e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0043: dup + IL_0044: ldstr "Third case" + IL_0049: ldc.i4.2 + IL_004a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_004f: dup + IL_0050: ldstr "Fourth case" + IL_0055: ldc.i4.3 + IL_0056: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_005b: dup + IL_005c: ldstr "Fifth case" + IL_0061: ldc.i4.4 + IL_0062: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0067: dup + IL_0068: ldstr "Sixth case" + IL_006d: ldc.i4.5 + IL_006e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0073: dup + IL_0074: ldstr "Seventh case" + IL_0079: ldc.i4.6 + IL_007a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_007f: dup + IL_0080: ldstr "Eighth case" + IL_0085: ldc.i4.7 + IL_0086: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_008b: dup + IL_008c: ldstr "Ninth case" + IL_0091: ldc.i4.8 + IL_0092: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0097: dup + IL_0098: ldstr "Tenth case" + IL_009d: ldc.i4.s 9 + IL_009f: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_00a4: dup + IL_00a5: ldstr "Eleventh case" + IL_00aa: ldc.i4.s 10 + IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_00b1: volatile. + IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{102ACC94-685A-42C5-9229-AC386C0A78B1}'::'$$method0x6000004-1' + IL_00b8: volatile. + IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{102ACC94-685A-42C5-9229-AC386C0A78B1}'::'$$method0x6000004-1' + IL_00bf: ldloc.1 + IL_00c0: ldloca.s V_2 + IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + !1&) + IL_00c7: brfalse IL_0163 + + IL_00cc: ldloc.2 + IL_00cd: switch ( + IL_0100, + IL_0109, + IL_0112, + IL_011b, + IL_0124, + IL_012d, + IL_0136, + IL_013f, + IL_0148, + IL_0151, + IL_015a) + IL_00fe: br.s IL_0163 + + IL_0100: nop + IL_0101: ldstr "Text1" + IL_0106: stloc.0 + IL_0107: br.s IL_016c + + IL_0109: nop + IL_010a: ldstr "Text2" + IL_010f: stloc.0 + IL_0110: br.s IL_016c + + IL_0112: nop + IL_0113: ldstr "Text3" + IL_0118: stloc.0 + IL_0119: br.s IL_016c + + IL_011b: nop + IL_011c: ldstr "Text4" + IL_0121: stloc.0 + IL_0122: br.s IL_016c + + IL_0124: nop + IL_0125: ldstr "Text5" + IL_012a: stloc.0 + IL_012b: br.s IL_016c + + IL_012d: nop + IL_012e: ldstr "Text6" + IL_0133: stloc.0 + IL_0134: br.s IL_016c + + IL_0136: nop + IL_0137: ldstr "Text7" + IL_013c: stloc.0 + IL_013d: br.s IL_016c + + IL_013f: nop + IL_0140: ldstr "Text8" + IL_0145: stloc.0 + IL_0146: br.s IL_016c + + IL_0148: nop + IL_0149: ldstr "Text9" + IL_014e: stloc.0 + IL_014f: br.s IL_016c + + IL_0151: nop + IL_0152: ldstr "Text10" + IL_0157: stloc.0 + IL_0158: br.s IL_016c + + IL_015a: nop + IL_015b: ldstr "Text11" + IL_0160: stloc.0 + IL_0161: br.s IL_016c + + IL_0163: nop + IL_0164: ldstr "Default" + IL_0169: stloc.0 + IL_016a: br.s IL_016c + + IL_016c: ldloc.0 + IL_016d: ret + } // end of method Switch::SwitchOverString2 + + .method public hidebysig static string + SwitchOverBool(bool b) cil managed + { + // Code size 67 (0x43) + .maxstack 2 + .locals init (string V_0, + bool V_1) + IL_0000: nop + IL_0001: ldstr "SwitchOverBool: " + IL_0006: ldarga.s b + IL_0008: call instance string [mscorlib]System.Boolean::ToString() + IL_000d: call string [mscorlib]System.String::Concat(string, + string) + IL_0012: call void [mscorlib]System.Console::WriteLine(string) + IL_0017: nop + IL_0018: ldarg.0 + IL_0019: stloc.1 + IL_001a: ldloc.1 + IL_001b: switch ( + IL_0033, + IL_002a) + IL_0028: br.s IL_003c + + IL_002a: nop + IL_002b: ldsfld string [mscorlib]System.Boolean::TrueString + IL_0030: stloc.0 + IL_0031: br.s IL_0041 + + IL_0033: nop + IL_0034: ldsfld string [mscorlib]System.Boolean::FalseString + IL_0039: stloc.0 + IL_003a: br.s IL_0041 + + IL_003c: nop + IL_003d: ldnull + IL_003e: stloc.0 + IL_003f: br.s IL_0041 + + IL_0041: ldloc.0 + IL_0042: ret + } // end of method Switch::SwitchOverBool + + .method public hidebysig static void SwitchInLoop(int32 i) cil managed + { + // Code size 141 (0x8d) + .maxstack 2 + .locals init (int32 V_0, + bool V_1) + IL_0000: nop + IL_0001: ldstr "SwitchInLoop: " + IL_0006: ldarg.0 + IL_0007: box [mscorlib]System.Int32 + IL_000c: call string [mscorlib]System.String::Concat(object, + object) + IL_0011: call void [mscorlib]System.Console::WriteLine(string) + IL_0016: nop + IL_0017: br.s IL_0088 + + IL_0019: nop + IL_001a: ldarg.0 + IL_001b: stloc.0 + IL_001c: ldloc.0 + IL_001d: ldc.i4.1 + IL_001e: sub + IL_001f: switch ( + IL_0036, + IL_0043, + IL_0050, + IL_005d) + IL_0034: br.s IL_006a + + IL_0036: ldstr "one" + IL_003b: call void [mscorlib]System.Console::WriteLine(string) + IL_0040: nop + IL_0041: br.s IL_0082 + + IL_0043: ldstr "two" + IL_0048: call void [mscorlib]System.Console::WriteLine(string) + IL_004d: nop + IL_004e: br.s IL_0082 + + IL_0050: ldstr "three" + IL_0055: call void [mscorlib]System.Console::WriteLine(string) + IL_005a: nop + IL_005b: br.s IL_0088 + + IL_005d: ldstr "four" + IL_0062: call void [mscorlib]System.Console::WriteLine(string) + IL_0067: nop + IL_0068: br.s IL_008c + + IL_006a: ldstr "default" + IL_006f: call void [mscorlib]System.Console::WriteLine(string) + IL_0074: nop + IL_0075: ldstr "more code" + IL_007a: call void [mscorlib]System.Console::WriteLine(string) + IL_007f: nop + IL_0080: br.s IL_008c + + IL_0082: ldarg.0 + IL_0083: ldc.i4.1 + IL_0084: add + IL_0085: starg.s i + IL_0087: nop + IL_0088: ldc.i4.1 + IL_0089: stloc.1 + IL_008a: br.s IL_0019 + + IL_008c: ret + } // end of method Switch::SwitchInLoop + + .method public hidebysig static void SwitchWithGoto(int32 i) cil managed + { + // Code size 117 (0x75) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldstr "SwitchWithGoto: " + IL_0006: ldarg.0 + IL_0007: box [mscorlib]System.Int32 + IL_000c: call string [mscorlib]System.String::Concat(object, + object) + IL_0011: call void [mscorlib]System.Console::WriteLine(string) + IL_0016: nop + IL_0017: ldarg.0 + IL_0018: stloc.0 + IL_0019: ldloc.0 + IL_001a: ldc.i4.1 + IL_001b: sub + IL_001c: switch ( + IL_0033, + IL_0040, + IL_004d, + IL_005a) + IL_0031: br.s IL_0067 + + IL_0033: ldstr "one" + IL_0038: call void [mscorlib]System.Console::WriteLine(string) + IL_003d: nop + IL_003e: br.s IL_0067 + + IL_0040: ldstr "two" + IL_0045: call void [mscorlib]System.Console::WriteLine(string) + IL_004a: nop + IL_004b: br.s IL_004d + + IL_004d: ldstr "three" + IL_0052: call void [mscorlib]System.Console::WriteLine(string) + IL_0057: nop + IL_0058: br.s IL_0074 + + IL_005a: ldstr "four" + IL_005f: call void [mscorlib]System.Console::WriteLine(string) + IL_0064: nop + IL_0065: br.s IL_0074 + + IL_0067: ldstr "default" + IL_006c: call void [mscorlib]System.Console::WriteLine(string) + IL_0071: nop + IL_0072: br.s IL_0074 + + IL_0074: ret + } // end of method Switch::SwitchWithGoto + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch + +.class private auto ansi '{102ACC94-685A-42C5-9229-AC386C0A78B1}' + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000003-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000004-1' +} // end of class '{102ACC94-685A-42C5-9229-AC386C0A78B1}' + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// WARNING: Created Win32 resource file ../../../TestCases/Pretty\Switch.res diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il new file mode 100644 index 000000000..4c6e7946e --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il @@ -0,0 +1,558 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly gz2l4xfo +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module gz2l4xfo.dll +// MVID: {FFA858C4-FC28-4EB1-BDB5-C80B304AD168} +.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: 0x008F0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch + extends [mscorlib]System.Object +{ + .method public hidebysig static string + SparseIntegerSwitch(int32 i) cil managed + { + // Code size 181 (0xb5) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldstr "SparseIntegerSwitch: " + IL_0005: ldarg.0 + IL_0006: box [mscorlib]System.Int32 + IL_000b: call string [mscorlib]System.String::Concat(object, + object) + IL_0010: call void [mscorlib]System.Console::WriteLine(string) + IL_0015: ldarg.0 + IL_0016: stloc.0 + IL_0017: ldloc.0 + IL_0018: ldc.i4.4 + IL_0019: bgt.s IL_004a + + IL_001b: ldloc.0 + IL_001c: ldc.i4 0xff676980 + IL_0021: beq.s IL_006d + + IL_0023: ldloc.0 + IL_0024: ldc.i4.s -100 + IL_0026: beq.s IL_0073 + + IL_0028: ldloc.0 + IL_0029: ldc.i4.m1 + IL_002a: sub + IL_002b: switch ( + IL_0079, + IL_007f, + IL_0085, + IL_008b, + IL_00af, + IL_0091) + IL_0048: br.s IL_00af + + IL_004a: ldloc.0 + IL_004b: ldc.i4.s 100 + IL_004d: beq.s IL_0097 + + IL_004f: ldloc.0 + IL_0050: ldc.i4 0x2710 + IL_0055: sub + IL_0056: switch ( + IL_009d, + IL_00a3) + IL_0063: ldloc.0 + IL_0064: ldc.i4 0x7fffffff + IL_0069: beq.s IL_00a9 + + IL_006b: br.s IL_00af + + IL_006d: ldstr "-10 mln" + IL_0072: ret + + IL_0073: ldstr "-hundred" + IL_0078: ret + + IL_0079: ldstr "-1" + IL_007e: ret + + IL_007f: ldstr "0" + IL_0084: ret + + IL_0085: ldstr "1" + IL_008a: ret + + IL_008b: ldstr "2" + IL_0090: ret + + IL_0091: ldstr "4" + IL_0096: ret + + IL_0097: ldstr "hundred" + IL_009c: ret + + IL_009d: ldstr "ten thousand" + IL_00a2: ret + + IL_00a3: ldstr "ten thousand and one" + IL_00a8: ret + + IL_00a9: ldstr "int.MaxValue" + IL_00ae: ret + + IL_00af: ldstr "something else" + IL_00b4: ret + } // end of method Switch::SparseIntegerSwitch + + .method public hidebysig static string + ShortSwitchOverString(string text) cil managed + { + // Code size 86 (0x56) + .maxstack 2 + .locals init (string V_0) + IL_0000: ldstr "ShortSwitchOverString: " + IL_0005: ldarg.0 + IL_0006: call string [mscorlib]System.String::Concat(string, + string) + IL_000b: call void [mscorlib]System.Console::WriteLine(string) + IL_0010: ldarg.0 + IL_0011: dup + IL_0012: stloc.0 + IL_0013: brfalse.s IL_0050 + + IL_0015: ldloc.0 + IL_0016: ldstr "First case" + IL_001b: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0020: brtrue.s IL_003e + + IL_0022: ldloc.0 + IL_0023: ldstr "Second case" + IL_0028: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_002d: brtrue.s IL_0044 + + IL_002f: ldloc.0 + IL_0030: ldstr "Third case" + IL_0035: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_003a: brtrue.s IL_004a + + IL_003c: br.s IL_0050 + + IL_003e: ldstr "Text1" + IL_0043: ret + + IL_0044: ldstr "Text2" + IL_0049: ret + + IL_004a: ldstr "Text3" + IL_004f: ret + + IL_0050: ldstr "Default" + IL_0055: ret + } // end of method Switch::ShortSwitchOverString + + .method public hidebysig static string + SwitchOverString1(string text) cil managed + { + // Code size 227 (0xe3) + .maxstack 4 + .locals init (string V_0, + int32 V_1) + IL_0000: ldstr "SwitchOverString1: " + IL_0005: ldarg.0 + IL_0006: call string [mscorlib]System.String::Concat(string, + string) + IL_000b: call void [mscorlib]System.Console::WriteLine(string) + IL_0010: ldarg.0 + IL_0011: dup + IL_0012: stloc.0 + IL_0013: brfalse IL_00db + + IL_0018: volatile. + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}'::'$$method0x6000003-1' + IL_001f: brtrue.s IL_0082 + + IL_0021: ldc.i4.7 + IL_0022: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_0027: dup + IL_0028: ldstr "First case" + IL_002d: ldc.i4.0 + IL_002e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0033: dup + IL_0034: ldstr "Second case" + IL_0039: ldc.i4.1 + IL_003a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_003f: dup + IL_0040: ldstr "2nd case" + IL_0045: ldc.i4.2 + IL_0046: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_004b: dup + IL_004c: ldstr "Third case" + IL_0051: ldc.i4.3 + IL_0052: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0057: dup + IL_0058: ldstr "Fourth case" + IL_005d: ldc.i4.4 + IL_005e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0063: dup + IL_0064: ldstr "Fifth case" + IL_0069: ldc.i4.5 + IL_006a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_006f: dup + IL_0070: ldstr "Sixth case" + IL_0075: ldc.i4.6 + IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_007b: volatile. + IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}'::'$$method0x6000003-1' + IL_0082: volatile. + IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}'::'$$method0x6000003-1' + IL_0089: ldloc.0 + IL_008a: ldloca.s V_1 + IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + !1&) + IL_0091: brfalse.s IL_00dd + + IL_0093: ldloc.1 + IL_0094: switch ( + IL_00b7, + IL_00bd, + IL_00bd, + IL_00c3, + IL_00c9, + IL_00cf, + IL_00d5) + IL_00b5: br.s IL_00dd + + IL_00b7: ldstr "Text1" + IL_00bc: ret + + IL_00bd: ldstr "Text2" + IL_00c2: ret + + IL_00c3: ldstr "Text3" + IL_00c8: ret + + IL_00c9: ldstr "Text4" + IL_00ce: ret + + IL_00cf: ldstr "Text5" + IL_00d4: ret + + IL_00d5: ldstr "Text6" + IL_00da: ret + + IL_00db: ldnull + IL_00dc: ret + + IL_00dd: ldstr "Default" + IL_00e2: ret + } // end of method Switch::SwitchOverString1 + + .method public hidebysig static string + SwitchOverString2() cil managed + { + // Code size 323 (0x143) + .maxstack 4 + .locals init (string V_0, + int32 V_1) + IL_0000: ldstr "SwitchOverString2:" + IL_0005: call void [mscorlib]System.Console::WriteLine(string) + IL_000a: call string [mscorlib]System.Environment::get_UserName() + IL_000f: dup + IL_0010: stloc.0 + IL_0011: brfalse IL_013d + + IL_0016: volatile. + IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}'::'$$method0x6000004-1' + IL_001d: brtrue IL_00b6 + + IL_0022: ldc.i4.s 11 + IL_0024: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_0029: dup + IL_002a: ldstr "First case" + IL_002f: ldc.i4.0 + IL_0030: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0035: dup + IL_0036: ldstr "Second case" + IL_003b: ldc.i4.1 + IL_003c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0041: dup + IL_0042: ldstr "Third case" + IL_0047: ldc.i4.2 + IL_0048: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_004d: dup + IL_004e: ldstr "Fourth case" + IL_0053: ldc.i4.3 + IL_0054: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0059: dup + IL_005a: ldstr "Fifth case" + IL_005f: ldc.i4.4 + IL_0060: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0065: dup + IL_0066: ldstr "Sixth case" + IL_006b: ldc.i4.5 + IL_006c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0071: dup + IL_0072: ldstr "Seventh case" + IL_0077: ldc.i4.6 + IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_007d: dup + IL_007e: ldstr "Eighth case" + IL_0083: ldc.i4.7 + IL_0084: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0089: dup + IL_008a: ldstr "Ninth case" + IL_008f: ldc.i4.8 + IL_0090: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0095: dup + IL_0096: ldstr "Tenth case" + IL_009b: ldc.i4.s 9 + IL_009d: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_00a2: dup + IL_00a3: ldstr "Eleventh case" + IL_00a8: ldc.i4.s 10 + IL_00aa: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_00af: volatile. + IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}'::'$$method0x6000004-1' + IL_00b6: volatile. + IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}'::'$$method0x6000004-1' + IL_00bd: ldloc.0 + IL_00be: ldloca.s V_1 + IL_00c0: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + !1&) + IL_00c5: brfalse.s IL_013d + + IL_00c7: ldloc.1 + IL_00c8: switch ( + IL_00fb, + IL_0101, + IL_0107, + IL_010d, + IL_0113, + IL_0119, + IL_011f, + IL_0125, + IL_012b, + IL_0131, + IL_0137) + IL_00f9: br.s IL_013d + + IL_00fb: ldstr "Text1" + IL_0100: ret + + IL_0101: ldstr "Text2" + IL_0106: ret + + IL_0107: ldstr "Text3" + IL_010c: ret + + IL_010d: ldstr "Text4" + IL_0112: ret + + IL_0113: ldstr "Text5" + IL_0118: ret + + IL_0119: ldstr "Text6" + IL_011e: ret + + IL_011f: ldstr "Text7" + IL_0124: ret + + IL_0125: ldstr "Text8" + IL_012a: ret + + IL_012b: ldstr "Text9" + IL_0130: ret + + IL_0131: ldstr "Text10" + IL_0136: ret + + IL_0137: ldstr "Text11" + IL_013c: ret + + IL_013d: ldstr "Default" + IL_0142: ret + } // end of method Switch::SwitchOverString2 + + .method public hidebysig static string + SwitchOverBool(bool b) cil managed + { + // Code size 54 (0x36) + .maxstack 2 + .locals init (bool V_0) + IL_0000: ldstr "SwitchOverBool: " + IL_0005: ldarga.s b + IL_0007: call instance string [mscorlib]System.Boolean::ToString() + IL_000c: call string [mscorlib]System.String::Concat(string, + string) + IL_0011: call void [mscorlib]System.Console::WriteLine(string) + IL_0016: ldarg.0 + IL_0017: stloc.0 + IL_0018: ldloc.0 + IL_0019: switch ( + IL_002e, + IL_0028) + IL_0026: br.s IL_0034 + + IL_0028: ldsfld string [mscorlib]System.Boolean::TrueString + IL_002d: ret + + IL_002e: ldsfld string [mscorlib]System.Boolean::FalseString + IL_0033: ret + + IL_0034: ldnull + IL_0035: ret + } // end of method Switch::SwitchOverBool + + .method public hidebysig static void SwitchInLoop(int32 i) cil managed + { + // Code size 124 (0x7c) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldstr "SwitchInLoop: " + IL_0005: ldarg.0 + IL_0006: box [mscorlib]System.Int32 + IL_000b: call string [mscorlib]System.String::Concat(object, + object) + IL_0010: call void [mscorlib]System.Console::WriteLine(string) + IL_0015: ldarg.0 + IL_0016: stloc.0 + IL_0017: ldloc.0 + IL_0018: ldc.i4.1 + IL_0019: sub + IL_001a: switch ( + IL_0031, + IL_003d, + IL_0049, + IL_0055) + IL_002f: br.s IL_0060 + + IL_0031: ldstr "one" + IL_0036: call void [mscorlib]System.Console::WriteLine(string) + IL_003b: br.s IL_0075 + + IL_003d: ldstr "two" + IL_0042: call void [mscorlib]System.Console::WriteLine(string) + IL_0047: br.s IL_0075 + + IL_0049: ldstr "three" + IL_004e: call void [mscorlib]System.Console::WriteLine(string) + IL_0053: br.s IL_0015 + + IL_0055: ldstr "four" + IL_005a: call void [mscorlib]System.Console::WriteLine(string) + IL_005f: ret + + IL_0060: ldstr "default" + IL_0065: call void [mscorlib]System.Console::WriteLine(string) + IL_006a: ldstr "more code" + IL_006f: call void [mscorlib]System.Console::WriteLine(string) + IL_0074: ret + + IL_0075: ldarg.0 + IL_0076: ldc.i4.1 + IL_0077: add + IL_0078: starg.s i + IL_007a: br.s IL_0015 + } // end of method Switch::SwitchInLoop + + .method public hidebysig static void SwitchWithGoto(int32 i) cil managed + { + // Code size 104 (0x68) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldstr "SwitchWithGoto: " + IL_0005: ldarg.0 + IL_0006: box [mscorlib]System.Int32 + IL_000b: call string [mscorlib]System.String::Concat(object, + object) + IL_0010: call void [mscorlib]System.Console::WriteLine(string) + IL_0015: ldarg.0 + IL_0016: stloc.0 + IL_0017: ldloc.0 + IL_0018: ldc.i4.1 + IL_0019: sub + IL_001a: switch ( + IL_0031, + IL_003d, + IL_0047, + IL_0052) + IL_002f: br.s IL_005d + + IL_0031: ldstr "one" + IL_0036: call void [mscorlib]System.Console::WriteLine(string) + IL_003b: br.s IL_005d + + IL_003d: ldstr "two" + IL_0042: call void [mscorlib]System.Console::WriteLine(string) + IL_0047: ldstr "three" + IL_004c: call void [mscorlib]System.Console::WriteLine(string) + IL_0051: ret + + IL_0052: ldstr "four" + IL_0057: call void [mscorlib]System.Console::WriteLine(string) + IL_005c: ret + + IL_005d: ldstr "default" + IL_0062: call void [mscorlib]System.Console::WriteLine(string) + IL_0067: ret + } // end of method Switch::SwitchWithGoto + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch + +.class private auto ansi '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}' + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000003-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000004-1' +} // end of class '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}' + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// WARNING: Created Win32 resource file ../../../TestCases/Pretty\Switch.opt.res diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il new file mode 100644 index 000000000..a86c1b3cc --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il @@ -0,0 +1,700 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly Switch +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module Switch.dll +// MVID: {3690F18D-C570-405A-8B33-B6E0A6696EFD} +.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: 0x015B0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch + extends [mscorlib]System.Object +{ + .method public hidebysig static string + SparseIntegerSwitch(int32 i) cil managed + { + // Code size 185 (0xb9) + .maxstack 2 + IL_0000: ldstr "SparseIntegerSwitch: " + IL_0005: ldarg.0 + IL_0006: box [mscorlib]System.Int32 + IL_000b: call string [mscorlib]System.String::Concat(object, + object) + IL_0010: call void [mscorlib]System.Console::WriteLine(string) + IL_0015: ldarg.0 + IL_0016: ldc.i4.4 + IL_0017: bgt.s IL_0048 + + IL_0019: ldarg.0 + IL_001a: ldc.i4 0xff676980 + IL_001f: beq.s IL_0071 + + IL_0021: ldarg.0 + IL_0022: ldc.i4.s -100 + IL_0024: beq.s IL_0077 + + IL_0026: ldarg.0 + IL_0027: ldc.i4.m1 + IL_0028: sub + IL_0029: switch ( + IL_007d, + IL_0083, + IL_0089, + IL_008f, + IL_00b3, + IL_0095) + IL_0046: br.s IL_00b3 + + IL_0048: ldarg.0 + IL_0049: ldc.i4 0x2710 + IL_004e: bgt.s IL_005f + + IL_0050: ldarg.0 + IL_0051: ldc.i4.s 100 + IL_0053: beq.s IL_009b + + IL_0055: ldarg.0 + IL_0056: ldc.i4 0x2710 + IL_005b: beq.s IL_00a1 + + IL_005d: br.s IL_00b3 + + IL_005f: ldarg.0 + IL_0060: ldc.i4 0x2711 + IL_0065: beq.s IL_00a7 + + IL_0067: ldarg.0 + IL_0068: ldc.i4 0x7fffffff + IL_006d: beq.s IL_00ad + + IL_006f: br.s IL_00b3 + + IL_0071: ldstr "-10 mln" + IL_0076: ret + + IL_0077: ldstr "-hundred" + IL_007c: ret + + IL_007d: ldstr "-1" + IL_0082: ret + + IL_0083: ldstr "0" + IL_0088: ret + + IL_0089: ldstr "1" + IL_008e: ret + + IL_008f: ldstr "2" + IL_0094: ret + + IL_0095: ldstr "4" + IL_009a: ret + + IL_009b: ldstr "hundred" + IL_00a0: ret + + IL_00a1: ldstr "ten thousand" + IL_00a6: ret + + IL_00a7: ldstr "ten thousand and one" + IL_00ac: ret + + IL_00ad: ldstr "int.MaxValue" + IL_00b2: ret + + IL_00b3: ldstr "something else" + IL_00b8: ret + } // end of method Switch::SparseIntegerSwitch + + .method public hidebysig static string + ShortSwitchOverString(string text) cil managed + { + // Code size 81 (0x51) + .maxstack 2 + IL_0000: ldstr "ShortSwitchOverString: " + IL_0005: ldarg.0 + IL_0006: call string [mscorlib]System.String::Concat(string, + string) + IL_000b: call void [mscorlib]System.Console::WriteLine(string) + IL_0010: ldarg.0 + IL_0011: ldstr "First case" + IL_0016: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_001b: brtrue.s IL_0039 + + IL_001d: ldarg.0 + IL_001e: ldstr "Second case" + IL_0023: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0028: brtrue.s IL_003f + + IL_002a: ldarg.0 + IL_002b: ldstr "Third case" + IL_0030: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0035: brtrue.s IL_0045 + + IL_0037: br.s IL_004b + + IL_0039: ldstr "Text1" + IL_003e: ret + + IL_003f: ldstr "Text2" + IL_0044: ret + + IL_0045: ldstr "Text3" + IL_004a: ret + + IL_004b: ldstr "Default" + IL_0050: ret + } // end of method Switch::ShortSwitchOverString + + .method public hidebysig static string + SwitchOverString1(string text) cil managed + { + // Code size 289 (0x121) + .maxstack 2 + .locals init (uint32 V_0) + IL_0000: ldstr "SwitchOverString1: " + IL_0005: ldarg.0 + IL_0006: call string [mscorlib]System.String::Concat(string, + string) + IL_000b: call void [mscorlib]System.Console::WriteLine(string) + IL_0010: ldarg.0 + IL_0011: call uint32 ''::ComputeStringHash(string) + IL_0016: stloc.0 + IL_0017: ldloc.0 + IL_0018: ldc.i4 0xf3d44a6 + IL_001d: bgt.un.s IL_0052 + + IL_001f: ldloc.0 + IL_0020: ldc.i4 0x8861b86 + IL_0025: bgt.un.s IL_003d + + IL_0027: ldloc.0 + IL_0028: brfalse IL_00f0 + + IL_002d: ldloc.0 + IL_002e: ldc.i4 0x8861b86 + IL_0033: beq IL_00d2 + + IL_0038: br IL_011b + + IL_003d: ldloc.0 + IL_003e: ldc.i4 0xc9a8f4f + IL_0043: beq.s IL_0084 + + IL_0045: ldloc.0 + IL_0046: ldc.i4 0xf3d44a6 + IL_004b: beq.s IL_00b4 + + IL_004d: br IL_011b + + IL_0052: ldloc.0 + IL_0053: ldc.i4 0x652a1179 + IL_0058: bgt.un.s IL_006f + + IL_005a: ldloc.0 + IL_005b: ldc.i4 0x51650fb9 + IL_0060: beq.s IL_00e1 + + IL_0062: ldloc.0 + IL_0063: ldc.i4 0x652a1179 + IL_0068: beq.s IL_00a5 + + IL_006a: br IL_011b + + IL_006f: ldloc.0 + IL_0070: ldc.i4 0xea3d096b + IL_0075: beq.s IL_0096 + + IL_0077: ldloc.0 + IL_0078: ldc.i4 0xf701cc7f + IL_007d: beq.s IL_00c3 + + IL_007f: br IL_011b + + IL_0084: ldarg.0 + IL_0085: ldstr "First case" + IL_008a: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_008f: brtrue.s IL_00f5 + + IL_0091: br IL_011b + + IL_0096: ldarg.0 + IL_0097: ldstr "Second case" + IL_009c: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00a1: brtrue.s IL_00fb + + IL_00a3: br.s IL_011b + + IL_00a5: ldarg.0 + IL_00a6: ldstr "2nd case" + IL_00ab: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00b0: brtrue.s IL_00fb + + IL_00b2: br.s IL_011b + + IL_00b4: ldarg.0 + IL_00b5: ldstr "Third case" + IL_00ba: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00bf: brtrue.s IL_0101 + + IL_00c1: br.s IL_011b + + IL_00c3: ldarg.0 + IL_00c4: ldstr "Fourth case" + IL_00c9: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00ce: brtrue.s IL_0107 + + IL_00d0: br.s IL_011b + + IL_00d2: ldarg.0 + IL_00d3: ldstr "Fifth case" + IL_00d8: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00dd: brtrue.s IL_010d + + IL_00df: br.s IL_011b + + IL_00e1: ldarg.0 + IL_00e2: ldstr "Sixth case" + IL_00e7: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00ec: brtrue.s IL_0113 + + IL_00ee: br.s IL_011b + + IL_00f0: ldarg.0 + IL_00f1: brfalse.s IL_0119 + + IL_00f3: br.s IL_011b + + IL_00f5: ldstr "Text1" + IL_00fa: ret + + IL_00fb: ldstr "Text2" + IL_0100: ret + + IL_0101: ldstr "Text3" + IL_0106: ret + + IL_0107: ldstr "Text4" + IL_010c: ret + + IL_010d: ldstr "Text5" + IL_0112: ret + + IL_0113: ldstr "Text6" + IL_0118: ret + + IL_0119: ldnull + IL_011a: ret + + IL_011b: ldstr "Default" + IL_0120: ret + } // end of method Switch::SwitchOverString1 + + .method public hidebysig static string + SwitchOverString2() cil managed + { + // Code size 446 (0x1be) + .maxstack 2 + .locals init (string V_0, + uint32 V_1) + IL_0000: ldstr "SwitchOverString2:" + IL_0005: call void [mscorlib]System.Console::WriteLine(string) + IL_000a: call string [mscorlib]System.Environment::get_UserName() + IL_000f: stloc.0 + IL_0010: ldloc.0 + IL_0011: call uint32 ''::ComputeStringHash(string) + IL_0016: stloc.1 + IL_0017: ldloc.1 + IL_0018: ldc.i4 0x4c7c71f6 + IL_001d: bgt.un.s IL_0065 + + IL_001f: ldloc.1 + IL_0020: ldc.i4 0xc9a8f4f + IL_0025: bgt.un.s IL_003f + + IL_0027: ldloc.1 + IL_0028: ldc.i4 0x8861b86 + IL_002d: beq IL_0107 + + IL_0032: ldloc.1 + IL_0033: ldc.i4 0xc9a8f4f + IL_0038: beq.s IL_00b3 + + IL_003a: br IL_01b8 + + IL_003f: ldloc.1 + IL_0040: ldc.i4 0xf3d44a6 + IL_0045: beq IL_00dd + + IL_004a: ldloc.1 + IL_004b: ldc.i4 0x20289804 + IL_0050: beq IL_013a + + IL_0055: ldloc.1 + IL_0056: ldc.i4 0x4c7c71f6 + IL_005b: beq IL_0149 + + IL_0060: br IL_01b8 + + IL_0065: ldloc.1 + IL_0066: ldc.i4 0xa151b28a + IL_006b: bgt.un.s IL_0093 + + IL_006d: ldloc.1 + IL_006e: ldc.i4 0x4d0cea48 + IL_0073: beq IL_0167 + + IL_0078: ldloc.1 + IL_0079: ldc.i4 0x51650fb9 + IL_007e: beq IL_0119 + + IL_0083: ldloc.1 + IL_0084: ldc.i4 0xa151b28a + IL_0089: beq IL_012b + + IL_008e: br IL_01b8 + + IL_0093: ldloc.1 + IL_0094: ldc.i4 0xea3d096b + IL_0099: beq.s IL_00c8 + + IL_009b: ldloc.1 + IL_009c: ldc.i4 0xed5134d4 + IL_00a1: beq IL_0158 + + IL_00a6: ldloc.1 + IL_00a7: ldc.i4 0xf701cc7f + IL_00ac: beq.s IL_00f2 + + IL_00ae: br IL_01b8 + + IL_00b3: ldloc.0 + IL_00b4: ldstr "First case" + IL_00b9: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00be: brtrue IL_0176 + + IL_00c3: br IL_01b8 + + IL_00c8: ldloc.0 + IL_00c9: ldstr "Second case" + IL_00ce: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00d3: brtrue IL_017c + + IL_00d8: br IL_01b8 + + IL_00dd: ldloc.0 + IL_00de: ldstr "Third case" + IL_00e3: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00e8: brtrue IL_0182 + + IL_00ed: br IL_01b8 + + IL_00f2: ldloc.0 + IL_00f3: ldstr "Fourth case" + IL_00f8: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00fd: brtrue IL_0188 + + IL_0102: br IL_01b8 + + IL_0107: ldloc.0 + IL_0108: ldstr "Fifth case" + IL_010d: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0112: brtrue.s IL_018e + + IL_0114: br IL_01b8 + + IL_0119: ldloc.0 + IL_011a: ldstr "Sixth case" + IL_011f: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0124: brtrue.s IL_0194 + + IL_0126: br IL_01b8 + + IL_012b: ldloc.0 + IL_012c: ldstr "Seventh case" + IL_0131: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0136: brtrue.s IL_019a + + IL_0138: br.s IL_01b8 + + IL_013a: ldloc.0 + IL_013b: ldstr "Eighth case" + IL_0140: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0145: brtrue.s IL_01a0 + + IL_0147: br.s IL_01b8 + + IL_0149: ldloc.0 + IL_014a: ldstr "Ninth case" + IL_014f: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0154: brtrue.s IL_01a6 + + IL_0156: br.s IL_01b8 + + IL_0158: ldloc.0 + IL_0159: ldstr "Tenth case" + IL_015e: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0163: brtrue.s IL_01ac + + IL_0165: br.s IL_01b8 + + IL_0167: ldloc.0 + IL_0168: ldstr "Eleventh case" + IL_016d: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0172: brtrue.s IL_01b2 + + IL_0174: br.s IL_01b8 + + IL_0176: ldstr "Text1" + IL_017b: ret + + IL_017c: ldstr "Text2" + IL_0181: ret + + IL_0182: ldstr "Text3" + IL_0187: ret + + IL_0188: ldstr "Text4" + IL_018d: ret + + IL_018e: ldstr "Text5" + IL_0193: ret + + IL_0194: ldstr "Text6" + IL_0199: ret + + IL_019a: ldstr "Text7" + IL_019f: ret + + IL_01a0: ldstr "Text8" + IL_01a5: ret + + IL_01a6: ldstr "Text9" + IL_01ab: ret + + IL_01ac: ldstr "Text10" + IL_01b1: ret + + IL_01b2: ldstr "Text11" + IL_01b7: ret + + IL_01b8: ldstr "Default" + IL_01bd: ret + } // end of method Switch::SwitchOverString2 + + .method public hidebysig static string + SwitchOverBool(bool b) cil managed + { + // Code size 43 (0x2b) + .maxstack 8 + IL_0000: ldstr "SwitchOverBool: " + IL_0005: ldarga.s b + IL_0007: call instance string [mscorlib]System.Boolean::ToString() + IL_000c: call string [mscorlib]System.String::Concat(string, + string) + IL_0011: call void [mscorlib]System.Console::WriteLine(string) + IL_0016: ldarg.0 + IL_0017: brfalse.s IL_0023 + + IL_0019: ldarg.0 + IL_001a: ldc.i4.1 + IL_001b: bne.un.s IL_0029 + + IL_001d: ldsfld string [mscorlib]System.Boolean::TrueString + IL_0022: ret + + IL_0023: ldsfld string [mscorlib]System.Boolean::FalseString + IL_0028: ret + + IL_0029: ldnull + IL_002a: ret + } // end of method Switch::SwitchOverBool + + .method public hidebysig static void SwitchInLoop(int32 i) cil managed + { + // Code size 122 (0x7a) + .maxstack 2 + IL_0000: ldstr "SwitchInLoop: " + IL_0005: ldarg.0 + IL_0006: box [mscorlib]System.Int32 + IL_000b: call string [mscorlib]System.String::Concat(object, + object) + IL_0010: call void [mscorlib]System.Console::WriteLine(string) + IL_0015: ldarg.0 + IL_0016: ldc.i4.1 + IL_0017: sub + IL_0018: switch ( + IL_002f, + IL_003b, + IL_0047, + IL_0053) + IL_002d: br.s IL_005e + + IL_002f: ldstr "one" + IL_0034: call void [mscorlib]System.Console::WriteLine(string) + IL_0039: br.s IL_0073 + + IL_003b: ldstr "two" + IL_0040: call void [mscorlib]System.Console::WriteLine(string) + IL_0045: br.s IL_0073 + + IL_0047: ldstr "three" + IL_004c: call void [mscorlib]System.Console::WriteLine(string) + IL_0051: br.s IL_0015 + + IL_0053: ldstr "four" + IL_0058: call void [mscorlib]System.Console::WriteLine(string) + IL_005d: ret + + IL_005e: ldstr "default" + IL_0063: call void [mscorlib]System.Console::WriteLine(string) + IL_0068: ldstr "more code" + IL_006d: call void [mscorlib]System.Console::WriteLine(string) + IL_0072: ret + + IL_0073: ldarg.0 + IL_0074: ldc.i4.1 + IL_0075: add + IL_0076: starg.s i + IL_0078: br.s IL_0015 + } // end of method Switch::SwitchInLoop + + .method public hidebysig static void SwitchWithGoto(int32 i) cil managed + { + // Code size 102 (0x66) + .maxstack 2 + IL_0000: ldstr "SwitchWithGoto: " + IL_0005: ldarg.0 + IL_0006: box [mscorlib]System.Int32 + IL_000b: call string [mscorlib]System.String::Concat(object, + object) + IL_0010: call void [mscorlib]System.Console::WriteLine(string) + IL_0015: ldarg.0 + IL_0016: ldc.i4.1 + IL_0017: sub + IL_0018: switch ( + IL_002f, + IL_003b, + IL_0045, + IL_0050) + IL_002d: br.s IL_005b + + IL_002f: ldstr "one" + IL_0034: call void [mscorlib]System.Console::WriteLine(string) + IL_0039: br.s IL_005b + + IL_003b: ldstr "two" + IL_0040: call void [mscorlib]System.Console::WriteLine(string) + IL_0045: ldstr "three" + IL_004a: call void [mscorlib]System.Console::WriteLine(string) + IL_004f: ret + + IL_0050: ldstr "four" + IL_0055: call void [mscorlib]System.Console::WriteLine(string) + IL_005a: ret + + IL_005b: ldstr "default" + IL_0060: call void [mscorlib]System.Console::WriteLine(string) + IL_0065: ret + } // end of method Switch::SwitchWithGoto + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch + +.class private auto ansi sealed '' + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method assembly hidebysig static uint32 + ComputeStringHash(string s) cil managed + { + // Code size 44 (0x2c) + .maxstack 2 + .locals init (uint32 V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: brfalse.s IL_002a + + IL_0003: ldc.i4 0x811c9dc5 + IL_0008: stloc.0 + IL_0009: ldc.i4.0 + IL_000a: stloc.1 + IL_000b: br.s IL_0021 + + IL_000d: ldarg.0 + IL_000e: ldloc.1 + IL_000f: callvirt instance char [mscorlib]System.String::get_Chars(int32) + IL_0014: ldloc.0 + IL_0015: xor + IL_0016: ldc.i4 0x1000193 + IL_001b: mul + IL_001c: stloc.0 + IL_001d: ldloc.1 + IL_001e: ldc.i4.1 + IL_001f: add + IL_0020: stloc.1 + IL_0021: ldloc.1 + IL_0022: ldarg.0 + IL_0023: callvirt instance int32 [mscorlib]System.String::get_Length() + IL_0028: blt.s IL_000d + + IL_002a: ldloc.0 + IL_002b: ret + } // end of method ''::ComputeStringHash + +} // end of class '' + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il new file mode 100644 index 000000000..0132ebf10 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il @@ -0,0 +1,890 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly Switch +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module Switch.dll +// MVID: {08E636DF-9FF0-4BF4-9F8F-69859C40E218} +.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: 0x02E70000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch + extends [mscorlib]System.Object +{ + .method public hidebysig static string + SparseIntegerSwitch(int32 i) cil managed + { + // Code size 238 (0xee) + .maxstack 2 + .locals init (int32 V_0, + string V_1) + IL_0000: nop + IL_0001: ldstr "SparseIntegerSwitch: " + IL_0006: ldarg.0 + IL_0007: box [mscorlib]System.Int32 + IL_000c: call string [mscorlib]System.String::Concat(object, + object) + IL_0011: call void [mscorlib]System.Console::WriteLine(string) + IL_0016: nop + IL_0017: ldarg.0 + IL_0018: stloc.0 + IL_0019: ldloc.0 + IL_001a: ldc.i4.4 + IL_001b: bgt.s IL_0053 + + IL_001d: ldloc.0 + IL_001e: ldc.i4 0xff676980 + IL_0023: beq.s IL_0080 + + IL_0025: br.s IL_0027 + + IL_0027: ldloc.0 + IL_0028: ldc.i4.s -100 + IL_002a: beq.s IL_0089 + + IL_002c: br.s IL_002e + + IL_002e: ldloc.0 + IL_002f: ldc.i4.m1 + IL_0030: sub + IL_0031: switch ( + IL_0092, + IL_009b, + IL_00a4, + IL_00ad, + IL_00e3, + IL_00b6) + IL_004e: br IL_00e3 + + IL_0053: ldloc.0 + IL_0054: ldc.i4 0x2710 + IL_0059: bgt.s IL_006c + + IL_005b: ldloc.0 + IL_005c: ldc.i4.s 100 + IL_005e: beq.s IL_00bf + + IL_0060: br.s IL_0062 + + IL_0062: ldloc.0 + IL_0063: ldc.i4 0x2710 + IL_0068: beq.s IL_00c8 + + IL_006a: br.s IL_00e3 + + IL_006c: ldloc.0 + IL_006d: ldc.i4 0x2711 + IL_0072: beq.s IL_00d1 + + IL_0074: br.s IL_0076 + + IL_0076: ldloc.0 + IL_0077: ldc.i4 0x7fffffff + IL_007c: beq.s IL_00da + + IL_007e: br.s IL_00e3 + + IL_0080: nop + IL_0081: ldstr "-10 mln" + IL_0086: stloc.1 + IL_0087: br.s IL_00ec + + IL_0089: nop + IL_008a: ldstr "-hundred" + IL_008f: stloc.1 + IL_0090: br.s IL_00ec + + IL_0092: nop + IL_0093: ldstr "-1" + IL_0098: stloc.1 + IL_0099: br.s IL_00ec + + IL_009b: nop + IL_009c: ldstr "0" + IL_00a1: stloc.1 + IL_00a2: br.s IL_00ec + + IL_00a4: nop + IL_00a5: ldstr "1" + IL_00aa: stloc.1 + IL_00ab: br.s IL_00ec + + IL_00ad: nop + IL_00ae: ldstr "2" + IL_00b3: stloc.1 + IL_00b4: br.s IL_00ec + + IL_00b6: nop + IL_00b7: ldstr "4" + IL_00bc: stloc.1 + IL_00bd: br.s IL_00ec + + IL_00bf: nop + IL_00c0: ldstr "hundred" + IL_00c5: stloc.1 + IL_00c6: br.s IL_00ec + + IL_00c8: nop + IL_00c9: ldstr "ten thousand" + IL_00ce: stloc.1 + IL_00cf: br.s IL_00ec + + IL_00d1: nop + IL_00d2: ldstr "ten thousand and one" + IL_00d7: stloc.1 + IL_00d8: br.s IL_00ec + + IL_00da: nop + IL_00db: ldstr "int.MaxValue" + IL_00e0: stloc.1 + IL_00e1: br.s IL_00ec + + IL_00e3: nop + IL_00e4: ldstr "something else" + IL_00e9: stloc.1 + IL_00ea: br.s IL_00ec + + IL_00ec: ldloc.1 + IL_00ed: ret + } // end of method Switch::SparseIntegerSwitch + + .method public hidebysig static string + ShortSwitchOverString(string text) cil managed + { + // Code size 99 (0x63) + .maxstack 2 + .locals init (string V_0, + string V_1) + IL_0000: nop + IL_0001: ldstr "ShortSwitchOverString: " + IL_0006: ldarg.0 + IL_0007: call string [mscorlib]System.String::Concat(string, + string) + IL_000c: call void [mscorlib]System.Console::WriteLine(string) + IL_0011: nop + IL_0012: ldarg.0 + IL_0013: stloc.0 + IL_0014: ldloc.0 + IL_0015: ldstr "First case" + IL_001a: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_001f: brtrue.s IL_003d + + IL_0021: ldloc.0 + IL_0022: ldstr "Second case" + IL_0027: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_002c: brtrue.s IL_0046 + + IL_002e: ldloc.0 + IL_002f: ldstr "Third case" + IL_0034: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0039: brtrue.s IL_004f + + IL_003b: br.s IL_0058 + + IL_003d: nop + IL_003e: ldstr "Text1" + IL_0043: stloc.1 + IL_0044: br.s IL_0061 + + IL_0046: nop + IL_0047: ldstr "Text2" + IL_004c: stloc.1 + IL_004d: br.s IL_0061 + + IL_004f: nop + IL_0050: ldstr "Text3" + IL_0055: stloc.1 + IL_0056: br.s IL_0061 + + IL_0058: nop + IL_0059: ldstr "Default" + IL_005e: stloc.1 + IL_005f: br.s IL_0061 + + IL_0061: ldloc.1 + IL_0062: ret + } // end of method Switch::ShortSwitchOverString + + .method public hidebysig static string + SwitchOverString1(string text) cil managed + { + // Code size 333 (0x14d) + .maxstack 2 + .locals init (string V_0, + uint32 V_1, + string V_2) + IL_0000: nop + IL_0001: ldstr "SwitchOverString1: " + IL_0006: ldarg.0 + IL_0007: call string [mscorlib]System.String::Concat(string, + string) + IL_000c: call void [mscorlib]System.Console::WriteLine(string) + IL_0011: nop + IL_0012: ldarg.0 + IL_0013: stloc.0 + IL_0014: ldloc.0 + IL_0015: call uint32 ''::ComputeStringHash(string) + IL_001a: stloc.1 + IL_001b: ldloc.1 + IL_001c: ldc.i4 0xf3d44a6 + IL_0021: bgt.un.s IL_005a + + IL_0023: ldloc.1 + IL_0024: ldc.i4 0x8861b86 + IL_0029: bgt.un.s IL_0043 + + IL_002b: ldloc.1 + IL_002c: brfalse IL_0102 + + IL_0031: br.s IL_0033 + + IL_0033: ldloc.1 + IL_0034: ldc.i4 0x8861b86 + IL_0039: beq IL_00e4 + + IL_003e: br IL_0142 + + IL_0043: ldloc.1 + IL_0044: ldc.i4 0xc9a8f4f + IL_0049: beq.s IL_0093 + + IL_004b: br.s IL_004d + + IL_004d: ldloc.1 + IL_004e: ldc.i4 0xf3d44a6 + IL_0053: beq.s IL_00c6 + + IL_0055: br IL_0142 + + IL_005a: ldloc.1 + IL_005b: ldc.i4 0x652a1179 + IL_0060: bgt.un.s IL_007c + + IL_0062: ldloc.1 + IL_0063: ldc.i4 0x51650fb9 + IL_0068: beq IL_00f3 + + IL_006d: br.s IL_006f + + IL_006f: ldloc.1 + IL_0070: ldc.i4 0x652a1179 + IL_0075: beq.s IL_00b7 + + IL_0077: br IL_0142 + + IL_007c: ldloc.1 + IL_007d: ldc.i4 0xea3d096b + IL_0082: beq.s IL_00a5 + + IL_0084: br.s IL_0086 + + IL_0086: ldloc.1 + IL_0087: ldc.i4 0xf701cc7f + IL_008c: beq.s IL_00d5 + + IL_008e: br IL_0142 + + IL_0093: ldloc.0 + IL_0094: ldstr "First case" + IL_0099: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_009e: brtrue.s IL_0107 + + IL_00a0: br IL_0142 + + IL_00a5: ldloc.0 + IL_00a6: ldstr "Second case" + IL_00ab: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00b0: brtrue.s IL_0110 + + IL_00b2: br IL_0142 + + IL_00b7: ldloc.0 + IL_00b8: ldstr "2nd case" + IL_00bd: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00c2: brtrue.s IL_0110 + + IL_00c4: br.s IL_0142 + + IL_00c6: ldloc.0 + IL_00c7: ldstr "Third case" + IL_00cc: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00d1: brtrue.s IL_0119 + + IL_00d3: br.s IL_0142 + + IL_00d5: ldloc.0 + IL_00d6: ldstr "Fourth case" + IL_00db: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00e0: brtrue.s IL_0122 + + IL_00e2: br.s IL_0142 + + IL_00e4: ldloc.0 + IL_00e5: ldstr "Fifth case" + IL_00ea: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00ef: brtrue.s IL_012b + + IL_00f1: br.s IL_0142 + + IL_00f3: ldloc.0 + IL_00f4: ldstr "Sixth case" + IL_00f9: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00fe: brtrue.s IL_0134 + + IL_0100: br.s IL_0142 + + IL_0102: ldloc.0 + IL_0103: brfalse.s IL_013d + + IL_0105: br.s IL_0142 + + IL_0107: nop + IL_0108: ldstr "Text1" + IL_010d: stloc.2 + IL_010e: br.s IL_014b + + IL_0110: nop + IL_0111: ldstr "Text2" + IL_0116: stloc.2 + IL_0117: br.s IL_014b + + IL_0119: nop + IL_011a: ldstr "Text3" + IL_011f: stloc.2 + IL_0120: br.s IL_014b + + IL_0122: nop + IL_0123: ldstr "Text4" + IL_0128: stloc.2 + IL_0129: br.s IL_014b + + IL_012b: nop + IL_012c: ldstr "Text5" + IL_0131: stloc.2 + IL_0132: br.s IL_014b + + IL_0134: nop + IL_0135: ldstr "Text6" + IL_013a: stloc.2 + IL_013b: br.s IL_014b + + IL_013d: nop + IL_013e: ldnull + IL_013f: stloc.2 + IL_0140: br.s IL_014b + + IL_0142: nop + IL_0143: ldstr "Default" + IL_0148: stloc.2 + IL_0149: br.s IL_014b + + IL_014b: ldloc.2 + IL_014c: ret + } // end of method Switch::SwitchOverString1 + + .method public hidebysig static string + SwitchOverString2() cil managed + { + // Code size 518 (0x206) + .maxstack 2 + .locals init (string V_0, + uint32 V_1, + string V_2) + IL_0000: nop + IL_0001: ldstr "SwitchOverString2:" + IL_0006: call void [mscorlib]System.Console::WriteLine(string) + IL_000b: nop + IL_000c: call string [mscorlib]System.Environment::get_UserName() + IL_0011: stloc.0 + IL_0012: ldloc.0 + IL_0013: call uint32 ''::ComputeStringHash(string) + IL_0018: stloc.1 + IL_0019: ldloc.1 + IL_001a: ldc.i4 0x4c7c71f6 + IL_001f: bgt.un.s IL_0070 + + IL_0021: ldloc.1 + IL_0022: ldc.i4 0xc9a8f4f + IL_0027: bgt.un.s IL_0046 + + IL_0029: ldloc.1 + IL_002a: ldc.i4 0x8861b86 + IL_002f: beq IL_011a + + IL_0034: br.s IL_0036 + + IL_0036: ldloc.1 + IL_0037: ldc.i4 0xc9a8f4f + IL_003c: beq IL_00c6 + + IL_0041: br IL_01fb + + IL_0046: ldloc.1 + IL_0047: ldc.i4 0xf3d44a6 + IL_004c: beq IL_00f0 + + IL_0051: br.s IL_0053 + + IL_0053: ldloc.1 + IL_0054: ldc.i4 0x20289804 + IL_0059: beq IL_0156 + + IL_005e: br.s IL_0060 + + IL_0060: ldloc.1 + IL_0061: ldc.i4 0x4c7c71f6 + IL_0066: beq IL_0168 + + IL_006b: br IL_01fb + + IL_0070: ldloc.1 + IL_0071: ldc.i4 0xa151b28a + IL_0076: bgt.un.s IL_00a2 + + IL_0078: ldloc.1 + IL_0079: ldc.i4 0x4d0cea48 + IL_007e: beq IL_0189 + + IL_0083: br.s IL_0085 + + IL_0085: ldloc.1 + IL_0086: ldc.i4 0x51650fb9 + IL_008b: beq IL_012f + + IL_0090: br.s IL_0092 + + IL_0092: ldloc.1 + IL_0093: ldc.i4 0xa151b28a + IL_0098: beq IL_0144 + + IL_009d: br IL_01fb + + IL_00a2: ldloc.1 + IL_00a3: ldc.i4 0xea3d096b + IL_00a8: beq.s IL_00db + + IL_00aa: br.s IL_00ac + + IL_00ac: ldloc.1 + IL_00ad: ldc.i4 0xed5134d4 + IL_00b2: beq IL_017a + + IL_00b7: br.s IL_00b9 + + IL_00b9: ldloc.1 + IL_00ba: ldc.i4 0xf701cc7f + IL_00bf: beq.s IL_0105 + + IL_00c1: br IL_01fb + + IL_00c6: ldloc.0 + IL_00c7: ldstr "First case" + IL_00cc: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00d1: brtrue IL_0198 + + IL_00d6: br IL_01fb + + IL_00db: ldloc.0 + IL_00dc: ldstr "Second case" + IL_00e1: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00e6: brtrue IL_01a1 + + IL_00eb: br IL_01fb + + IL_00f0: ldloc.0 + IL_00f1: ldstr "Third case" + IL_00f6: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_00fb: brtrue IL_01aa + + IL_0100: br IL_01fb + + IL_0105: ldloc.0 + IL_0106: ldstr "Fourth case" + IL_010b: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0110: brtrue IL_01b3 + + IL_0115: br IL_01fb + + IL_011a: ldloc.0 + IL_011b: ldstr "Fifth case" + IL_0120: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0125: brtrue IL_01bc + + IL_012a: br IL_01fb + + IL_012f: ldloc.0 + IL_0130: ldstr "Sixth case" + IL_0135: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_013a: brtrue IL_01c5 + + IL_013f: br IL_01fb + + IL_0144: ldloc.0 + IL_0145: ldstr "Seventh case" + IL_014a: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_014f: brtrue.s IL_01ce + + IL_0151: br IL_01fb + + IL_0156: ldloc.0 + IL_0157: ldstr "Eighth case" + IL_015c: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0161: brtrue.s IL_01d7 + + IL_0163: br IL_01fb + + IL_0168: ldloc.0 + IL_0169: ldstr "Ninth case" + IL_016e: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0173: brtrue.s IL_01e0 + + IL_0175: br IL_01fb + + IL_017a: ldloc.0 + IL_017b: ldstr "Tenth case" + IL_0180: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0185: brtrue.s IL_01e9 + + IL_0187: br.s IL_01fb + + IL_0189: ldloc.0 + IL_018a: ldstr "Eleventh case" + IL_018f: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0194: brtrue.s IL_01f2 + + IL_0196: br.s IL_01fb + + IL_0198: nop + IL_0199: ldstr "Text1" + IL_019e: stloc.2 + IL_019f: br.s IL_0204 + + IL_01a1: nop + IL_01a2: ldstr "Text2" + IL_01a7: stloc.2 + IL_01a8: br.s IL_0204 + + IL_01aa: nop + IL_01ab: ldstr "Text3" + IL_01b0: stloc.2 + IL_01b1: br.s IL_0204 + + IL_01b3: nop + IL_01b4: ldstr "Text4" + IL_01b9: stloc.2 + IL_01ba: br.s IL_0204 + + IL_01bc: nop + IL_01bd: ldstr "Text5" + IL_01c2: stloc.2 + IL_01c3: br.s IL_0204 + + IL_01c5: nop + IL_01c6: ldstr "Text6" + IL_01cb: stloc.2 + IL_01cc: br.s IL_0204 + + IL_01ce: nop + IL_01cf: ldstr "Text7" + IL_01d4: stloc.2 + IL_01d5: br.s IL_0204 + + IL_01d7: nop + IL_01d8: ldstr "Text8" + IL_01dd: stloc.2 + IL_01de: br.s IL_0204 + + IL_01e0: nop + IL_01e1: ldstr "Text9" + IL_01e6: stloc.2 + IL_01e7: br.s IL_0204 + + IL_01e9: nop + IL_01ea: ldstr "Text10" + IL_01ef: stloc.2 + IL_01f0: br.s IL_0204 + + IL_01f2: nop + IL_01f3: ldstr "Text11" + IL_01f8: stloc.2 + IL_01f9: br.s IL_0204 + + IL_01fb: nop + IL_01fc: ldstr "Default" + IL_0201: stloc.2 + IL_0202: br.s IL_0204 + + IL_0204: ldloc.2 + IL_0205: ret + } // end of method Switch::SwitchOverString2 + + .method public hidebysig static string + SwitchOverBool(bool b) cil managed + { + // Code size 62 (0x3e) + .maxstack 2 + .locals init (bool V_0, + string V_1) + IL_0000: nop + IL_0001: ldstr "SwitchOverBool: " + IL_0006: ldarga.s b + IL_0008: call instance string [mscorlib]System.Boolean::ToString() + IL_000d: call string [mscorlib]System.String::Concat(string, + string) + IL_0012: call void [mscorlib]System.Console::WriteLine(string) + IL_0017: nop + IL_0018: ldarg.0 + IL_0019: stloc.0 + IL_001a: ldloc.0 + IL_001b: brfalse.s IL_002e + + IL_001d: br.s IL_001f + + IL_001f: ldloc.0 + IL_0020: ldc.i4.1 + IL_0021: beq.s IL_0025 + + IL_0023: br.s IL_0037 + + IL_0025: nop + IL_0026: ldsfld string [mscorlib]System.Boolean::TrueString + IL_002b: stloc.1 + IL_002c: br.s IL_003c + + IL_002e: nop + IL_002f: ldsfld string [mscorlib]System.Boolean::FalseString + IL_0034: stloc.1 + IL_0035: br.s IL_003c + + IL_0037: nop + IL_0038: ldnull + IL_0039: stloc.1 + IL_003a: br.s IL_003c + + IL_003c: ldloc.1 + IL_003d: ret + } // end of method Switch::SwitchOverBool + + .method public hidebysig static void SwitchInLoop(int32 i) cil managed + { + // Code size 141 (0x8d) + .maxstack 2 + .locals init (int32 V_0, + bool V_1) + IL_0000: nop + IL_0001: ldstr "SwitchInLoop: " + IL_0006: ldarg.0 + IL_0007: box [mscorlib]System.Int32 + IL_000c: call string [mscorlib]System.String::Concat(object, + object) + IL_0011: call void [mscorlib]System.Console::WriteLine(string) + IL_0016: nop + IL_0017: br.s IL_0088 + + IL_0019: nop + IL_001a: ldarg.0 + IL_001b: stloc.0 + IL_001c: ldloc.0 + IL_001d: ldc.i4.1 + IL_001e: sub + IL_001f: switch ( + IL_0036, + IL_0043, + IL_0050, + IL_005d) + IL_0034: br.s IL_006a + + IL_0036: ldstr "one" + IL_003b: call void [mscorlib]System.Console::WriteLine(string) + IL_0040: nop + IL_0041: br.s IL_0082 + + IL_0043: ldstr "two" + IL_0048: call void [mscorlib]System.Console::WriteLine(string) + IL_004d: nop + IL_004e: br.s IL_0082 + + IL_0050: ldstr "three" + IL_0055: call void [mscorlib]System.Console::WriteLine(string) + IL_005a: nop + IL_005b: br.s IL_0088 + + IL_005d: ldstr "four" + IL_0062: call void [mscorlib]System.Console::WriteLine(string) + IL_0067: nop + IL_0068: br.s IL_008c + + IL_006a: ldstr "default" + IL_006f: call void [mscorlib]System.Console::WriteLine(string) + IL_0074: nop + IL_0075: ldstr "more code" + IL_007a: call void [mscorlib]System.Console::WriteLine(string) + IL_007f: nop + IL_0080: br.s IL_008c + + IL_0082: ldarg.0 + IL_0083: ldc.i4.1 + IL_0084: add + IL_0085: starg.s i + IL_0087: nop + IL_0088: ldc.i4.1 + IL_0089: stloc.1 + IL_008a: br.s IL_0019 + + IL_008c: ret + } // end of method Switch::SwitchInLoop + + .method public hidebysig static void SwitchWithGoto(int32 i) cil managed + { + // Code size 117 (0x75) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldstr "SwitchWithGoto: " + IL_0006: ldarg.0 + IL_0007: box [mscorlib]System.Int32 + IL_000c: call string [mscorlib]System.String::Concat(object, + object) + IL_0011: call void [mscorlib]System.Console::WriteLine(string) + IL_0016: nop + IL_0017: ldarg.0 + IL_0018: stloc.0 + IL_0019: ldloc.0 + IL_001a: ldc.i4.1 + IL_001b: sub + IL_001c: switch ( + IL_0033, + IL_0040, + IL_004d, + IL_005a) + IL_0031: br.s IL_0067 + + IL_0033: ldstr "one" + IL_0038: call void [mscorlib]System.Console::WriteLine(string) + IL_003d: nop + IL_003e: br.s IL_0067 + + IL_0040: ldstr "two" + IL_0045: call void [mscorlib]System.Console::WriteLine(string) + IL_004a: nop + IL_004b: br.s IL_004d + + IL_004d: ldstr "three" + IL_0052: call void [mscorlib]System.Console::WriteLine(string) + IL_0057: nop + IL_0058: br.s IL_0074 + + IL_005a: ldstr "four" + IL_005f: call void [mscorlib]System.Console::WriteLine(string) + IL_0064: nop + IL_0065: br.s IL_0074 + + IL_0067: ldstr "default" + IL_006c: call void [mscorlib]System.Console::WriteLine(string) + IL_0071: nop + IL_0072: br.s IL_0074 + + IL_0074: ret + } // end of method Switch::SwitchWithGoto + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch + +.class private auto ansi sealed '' + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method assembly hidebysig static uint32 + ComputeStringHash(string s) cil managed + { + // Code size 46 (0x2e) + .maxstack 2 + .locals init (uint32 V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: brfalse.s IL_002c + + IL_0003: ldc.i4 0x811c9dc5 + IL_0008: stloc.0 + IL_0009: ldc.i4.0 + IL_000a: stloc.1 + IL_000b: br.s IL_0021 + + IL_000d: ldarg.0 + IL_000e: ldloc.1 + IL_000f: callvirt instance char [mscorlib]System.String::get_Chars(int32) + IL_0014: ldloc.0 + IL_0015: xor + IL_0016: ldc.i4 0x1000193 + IL_001b: mul + IL_001c: stloc.0 + IL_001d: ldloc.1 + IL_001e: ldc.i4.1 + IL_001f: add + IL_0020: stloc.1 + IL_0021: ldloc.1 + IL_0022: ldarg.0 + IL_0023: callvirt instance int32 [mscorlib]System.String::get_Length() + IL_0028: bge.s IL_002c + + IL_002a: br.s IL_000d + + IL_002c: ldloc.0 + IL_002d: ret + } // end of method ''::ComputeStringHash + +} // end of class '' + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** From 8ee222b37370c9c851c6e4b733a2da4dd072939b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 29 Sep 2017 23:55:06 +0200 Subject: [PATCH 006/190] Remove old switch-on-string code from PatternStatementTransform --- .../CSharp/CSharpDecompiler.cs | 8 +- .../Transforms/PatternStatementTransform.cs | 172 ------------------ 2 files changed, 4 insertions(+), 176 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index b6ff80b98..b488578ba 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -201,8 +201,8 @@ namespace ICSharpCode.Decompiler.CSharp if (settings.AsyncAwait && AsyncAwaitDecompiler.IsCompilerGeneratedStateMachine(type)) return true; } else if (type.IsCompilerGenerated()) { -// if (type.Name.StartsWith("", StringComparison.Ordinal)) -// return true; + if (type.Name.StartsWith("", StringComparison.Ordinal)) + return true; if (settings.AnonymousTypes && type.IsAnonymousType()) return true; } @@ -215,8 +215,8 @@ namespace ICSharpCode.Decompiler.CSharp return true; if (settings.AutomaticProperties && IsAutomaticPropertyBackingField(field)) return true; -// if (settings.SwitchStatementOnString && IsSwitchOnStringCache(field)) -// return true; + if (settings.SwitchStatementOnString && IsSwitchOnStringCache(field)) + return true; } // event-fields are not [CompilerGenerated] if (settings.AutomaticEvents && field.DeclaringType.Events.Any(ev => ev.Name == field.Name)) diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs b/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs index d0684ee4b..a8e29430e 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs @@ -96,11 +96,6 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms public override AstNode VisitIfElseStatement(IfElseStatement ifElseStatement) { - if (context.Settings.SwitchStatementOnString) { - AstNode result = TransformSwitchOnString(ifElseStatement); - if (result != null) - return result; - } AstNode simplifiedIfElse = SimplifyCascadingIfElseStatements(ifElseStatement); if (simplifiedIfElse != null) return simplifiedIfElse; @@ -256,174 +251,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms return null; } #endregion - - #region switch on strings - static readonly IfElseStatement switchOnStringPattern = new IfElseStatement { - Condition = new BinaryOperatorExpression { - Left = new AnyNode("switchExpr"), - Operator = BinaryOperatorType.InEquality, - Right = new NullReferenceExpression() - }, - TrueStatement = new BlockStatement { - new IfElseStatement { - Condition = new BinaryOperatorExpression { - Left = new AnyNode("cachedDict"), - Operator = BinaryOperatorType.Equality, - Right = new NullReferenceExpression() - }, - TrueStatement = new AnyNode("dictCreation") - }, - new IfElseStatement { - Condition = new InvocationExpression(new MemberReferenceExpression(new Backreference("cachedDict").ToExpression(), "TryGetValue"), - new NamedNode("switchVar", new IdentifierExpression(Pattern.AnyString)), - new DirectionExpression { - FieldDirection = FieldDirection.Out, - Expression = new IdentifierExpression(Pattern.AnyString).WithName("intVar") - }), - TrueStatement = new BlockStatement { - Statements = { - new NamedNode( - "switch", new SwitchStatement { - Expression = new IdentifierExpressionBackreference("intVar"), - SwitchSections = { new Repeat(new AnyNode()) } - }) - } - } - }, - new Repeat(new AnyNode("nonNullDefaultStmt")).ToStatement() - }, - FalseStatement = new OptionalNode("nullStmt", new BlockStatement { Statements = { new Repeat(new AnyNode()) } }) - }; - - public SwitchStatement TransformSwitchOnString(IfElseStatement node) - { - Match m = switchOnStringPattern.Match(node); - if (!m.Success) - return null; - // switchVar must be the same as switchExpr; or switchExpr must be an assignment and switchVar the left side of that assignment - if (!m.Get("switchVar").Single().IsMatch(m.Get("switchExpr").Single())) { - AssignmentExpression assign = m.Get("switchExpr").Single() as AssignmentExpression; - if (!(assign != null && m.Get("switchVar").Single().IsMatch(assign.Left))) - return null; - } - FieldReference cachedDictField = m.Get("cachedDict").Single().Annotation(); - if (cachedDictField == null) - return null; - List dictCreation = m.Get("dictCreation").Single().Statements.ToList(); - List> dict = BuildDictionary(dictCreation); - SwitchStatement sw = m.Get("switch").Single(); - sw.Expression = m.Get("switchExpr").Single().Detach(); - foreach (SwitchSection section in sw.SwitchSections) { - List labels = section.CaseLabels.ToList(); - section.CaseLabels.Clear(); - foreach (CaseLabel label in labels) { - PrimitiveExpression expr = label.Expression as PrimitiveExpression; - if (expr == null || !(expr.Value is int)) - continue; - int val = (int)expr.Value; - foreach (var pair in dict) { - if (pair.Value == val) - section.CaseLabels.Add(new CaseLabel { Expression = new PrimitiveExpression(pair.Key) }); - } - } - } - if (m.Has("nullStmt")) { - SwitchSection section = new SwitchSection(); - section.CaseLabels.Add(new CaseLabel { Expression = new NullReferenceExpression() }); - BlockStatement block = m.Get("nullStmt").Single(); - block.Statements.Add(new BreakStatement()); - section.Statements.Add(block.Detach()); - sw.SwitchSections.Add(section); - } else if (m.Has("nonNullDefaultStmt")) { - sw.SwitchSections.Add( - new SwitchSection { - CaseLabels = { new CaseLabel { Expression = new NullReferenceExpression() } }, - Statements = { new BlockStatement { new BreakStatement() } } - }); - } - if (m.Has("nonNullDefaultStmt")) { - SwitchSection section = new SwitchSection(); - section.CaseLabels.Add(new CaseLabel()); - BlockStatement block = new BlockStatement(); - block.Statements.AddRange(m.Get("nonNullDefaultStmt").Select(s => s.Detach())); - block.Add(new BreakStatement()); - section.Statements.Add(block); - sw.SwitchSections.Add(section); - } - node.ReplaceWith(sw); - return sw; - } - - List> BuildDictionary(List dictCreation) - { - if (context.Settings.ObjectOrCollectionInitializers && dictCreation.Count == 1) - return BuildDictionaryFromInitializer(dictCreation[0]); - return BuildDictionaryFromAddMethodCalls(dictCreation); - } - - static readonly Statement assignInitializedDictionary = new ExpressionStatement { - Expression = new AssignmentExpression { - Left = new AnyNode().ToExpression(), - Right = new ObjectCreateExpression { - Type = new AnyNode(), - Arguments = { new Repeat(new AnyNode()) }, - Initializer = new ArrayInitializerExpression { - Elements = { new Repeat(new AnyNode("dictJumpTable")) } - } - }, - }, - }; - - private List> BuildDictionaryFromInitializer(Statement statement) - { - List> dict = new List>(); - Match m = assignInitializedDictionary.Match(statement); - if (!m.Success) - return dict; - - foreach (ArrayInitializerExpression initializer in m.Get("dictJumpTable")) { - KeyValuePair pair; - if (TryGetPairFrom(initializer.Elements, out pair)) - dict.Add(pair); - } - - return dict; - } - - private static List> BuildDictionaryFromAddMethodCalls(List dictCreation) - { - List> dict = new List>(); - for (int i = 0; i < dictCreation.Count; i++) { - ExpressionStatement es = dictCreation[i] as ExpressionStatement; - if (es == null) - continue; - InvocationExpression ie = es.Expression as InvocationExpression; - if (ie == null) - continue; - - KeyValuePair pair; - if (TryGetPairFrom(ie.Arguments, out pair)) - dict.Add(pair); - } - return dict; - } - - private static bool TryGetPairFrom(AstNodeCollection expressions, out KeyValuePair pair) - { - PrimitiveExpression arg1 = expressions.ElementAtOrDefault(0) as PrimitiveExpression; - PrimitiveExpression arg2 = expressions.ElementAtOrDefault(1) as PrimitiveExpression; - if (arg1 != null && arg2 != null && arg1.Value is string && arg2.Value is int) { - pair = new KeyValuePair((string)arg1.Value, (int)arg2.Value); - return true; - } - - pair = default(KeyValuePair); - return false; - } - - #endregion - #region Automatic Properties static readonly PropertyDeclaration automaticPropertyPattern = new PropertyDeclaration { Attributes = { new Repeat(new AnyNode()) }, From 4394250d712e6b539a5dbcf5a75b3cd96c78980d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 29 Sep 2017 23:56:13 +0200 Subject: [PATCH 007/190] Fix Switch(string)-detection in various cases --- .../IL/Transforms/SwitchOnStringTransform.cs | 82 +++++++++++++++---- 1 file changed, 64 insertions(+), 18 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index b533e8d3b..723bb6e02 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -29,23 +29,29 @@ namespace ICSharpCode.Decompiler.IL.Transforms { public void Run(ILFunction function, ILTransformContext context) { + if (!context.Settings.SwitchStatementOnString) + return; + HashSet changedContainers = new HashSet(); foreach (var block in function.Descendants.OfType()) { for (int i = block.Instructions.Count - 1; i >= 0; i--) { SwitchInstruction newSwitch; Block blockAfterSwitch = null; - if (!MatchCascadingIfStatements(block.Instructions, i, out newSwitch, out blockAfterSwitch) && - !MatchLegacySwitchOnString(block.Instructions, i, out newSwitch, out blockAfterSwitch) && - !MatchRoslynSwitchOnString(block.Instructions, i, out newSwitch)) - continue; + bool removeExtraStore = false; // the Roslyn switch pattern uses an extra store for hash calculation. + if (!MatchCascadingIfStatements(block.Instructions, i, out newSwitch, out blockAfterSwitch)) + if (!MatchLegacySwitchOnString(block.Instructions, i, out newSwitch, out blockAfterSwitch)) + if (MatchRoslynSwitchOnString(block.Instructions, i, out newSwitch)) + removeExtraStore = true; + else + continue; if (i + 1 < block.Instructions.Count && block.Instructions[i + 1] is Branch b && blockAfterSwitch != null) { block.Instructions[i + 1].ReplaceWith(new Branch(blockAfterSwitch)); } block.Instructions[i].ReplaceWith(newSwitch); - if (newSwitch.Value.MatchLdLoc(out var switchVar) && !block.Instructions[i - 1].MatchLdLoc(switchVar)) { + if (removeExtraStore) { block.Instructions.RemoveAt(i - 1); i--; } @@ -68,37 +74,39 @@ namespace ICSharpCode.Decompiler.IL.Transforms { inst = null; blockAfterSwitch = null; - if (i < 1) return false; // match first block: checking switch-value for null or first value (Roslyn) - if (!(instructions[i].MatchIfInstruction(out var condition, out var firstBlockJump) && - instructions[i - 1].MatchStLoc(out var switchValueVar, out var switchValue) && switchValueVar.Type.IsKnownType(KnownTypeCode.String))) + if (!(instructions[i].MatchIfInstruction(out var condition, out var firstBlockJump))) return false; if (!firstBlockJump.MatchBranch(out var firstBlock)) return false; bool isLegacy; Block defaultBlock; List<(string, Block)> values = new List<(string, Block)>(); - if (condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && left.MatchLdLoc(switchValueVar)) { + if (condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && left.MatchLdLoc(out var switchValueVar)) { isLegacy = true; defaultBlock = firstBlock; - } else if (MatchStringEqualityComparison(condition, switchValueVar, out string value)) { + } else if (MatchStringEqualityComparison(condition, out switchValueVar, out string value)) { isLegacy = false; defaultBlock = null; values.Add((value, firstBlock)); } else return false; + if (!switchValueVar.IsSingleDefinition) + return false; if (!(instructions.ElementAtOrDefault(i + 1) is Branch nextCaseJump)) return false; Block currentCaseBlock = nextCaseJump.TargetBlock; Block nextCaseBlock; - while ((nextCaseBlock = MatchCaseBlock(currentCaseBlock, switchValueVar, out string value, out Block block)) != null) { + while ((nextCaseBlock = MatchCaseBlock(currentCaseBlock, ref switchValueVar, out string value, out Block block)) != null) { values.Add((value, block)); currentCaseBlock = nextCaseBlock; } - if (!ExtractLastJumpFromBlock(currentCaseBlock, out var exitBlock)) + BlockContainer container = null; + if (!ExtractLastJumpFromBlock(currentCaseBlock, out var exitBlock) && !ExtractLastLeaveFromBlock(currentCaseBlock, out container)) return false; if (values.Count == 0) return false; - if (!values.All(b => ExtractLastJumpFromBlock(b.Item2, out var nextExit) && nextExit == exitBlock)) + if (!(values.All(b => ExtractLastJumpFromBlock(b.Item2, out var nextExit) && nextExit == exitBlock) || + (exitBlock == null && values.All(b => ExtractLastLeaveFromBlock(b.Item2, out var exitContainer) && exitContainer == container)))) return false; if (currentCaseBlock.IncomingEdgeCount == (isLegacy ? 2 : 1)) { var sections = new List(values.SelectWithIndex((index, b) => new SwitchSection { Labels = new LongSet(index), Body = new Branch(b.Item2) })); @@ -120,23 +128,55 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; } - Block MatchCaseBlock(Block currentBlock, ILVariable switchVariable, out string value, out Block caseBlock) + bool ExtractLastLeaveFromBlock(Block block, out BlockContainer exitBlock) + { + exitBlock = null; + var lastInst = block.Instructions.LastOrDefault(); + if (lastInst == null || !lastInst.MatchLeave(out exitBlock, out _)) + return false; + return true; + } + + Block MatchCaseBlock(Block currentBlock, ref ILVariable switchVariable, out string value, out Block caseBlock) { value = null; caseBlock = null; + if (currentBlock.IncomingEdgeCount != 1 || currentBlock.Instructions.Count != 2) return null; if (!currentBlock.Instructions[0].MatchIfInstruction(out var condition, out var caseBlockBranch)) return null; if (!caseBlockBranch.MatchBranch(out caseBlock)) return null; - if (!MatchStringEqualityComparison(condition, switchVariable, out value)) + Block nextBlock; + if (condition.MatchLogicNot(out var inner)) { + condition = inner; + nextBlock = caseBlock; + if (!currentBlock.Instructions[1].MatchBranch(out caseBlock)) + return null; + } else { + if (!currentBlock.Instructions[1].MatchBranch(out nextBlock)) + return null; + } + if (!MatchStringEqualityComparison(condition, out var newSwitchVariable, out value)) + return null; + if (!newSwitchVariable.IsSingleDefinition) return null; - if (!currentBlock.Instructions[1].MatchBranch(out var nextBlock)) + if (switchVariable != newSwitchVariable && !(IsInitializedBy(switchVariable, newSwitchVariable) || IsInitializedBy(newSwitchVariable, switchVariable))) return null; + if (!newSwitchVariable.Type.IsKnownType(KnownTypeCode.String)) + return null; + switchVariable = newSwitchVariable; return nextBlock; } + bool IsInitializedBy(ILVariable switchVariable, ILVariable newSwitchVariable) + { + if (!switchVariable.IsSingleDefinition) + return false; + return switchVariable.StoreInstructions.OfType().Single().Value.MatchLdLoc(newSwitchVariable); + } + bool MatchLegacySwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst, out Block blockAfterSwitch) { inst = null; @@ -148,7 +188,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!exitBlockJump.MatchBranch(out var exitBlock)) return false; - if (!(condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && left.Match(switchValue).Success)) + if (!(condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && (left.Match(switchValue).Success || left.MatchLdLoc(switchValueVar)))) return false; var nextBlockJump = instructions.ElementAtOrDefault(i + 1) as Branch; if (nextBlockJump == null || nextBlockJump.TargetBlock.IncomingEdgeCount != 1) @@ -291,8 +331,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms } bool MatchStringEqualityComparison(ILInstruction condition, ILVariable variable, out string stringValue) + { + return MatchStringEqualityComparison(condition, out var v, out stringValue) && v == variable; + } + + bool MatchStringEqualityComparison(ILInstruction condition, out ILVariable variable, out string stringValue) { stringValue = null; + variable = null; ILInstruction left, right; if (condition is Call c && c.Method.IsOperator && c.Method.Name == "op_Equality" && c.Arguments.Count == 2) { left = c.Arguments[0]; @@ -301,7 +347,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; } else if (condition.MatchCompEquals(out left, out right) && right.MatchLdNull()) { } else return false; - return left.MatchLdLoc(variable); + return left.MatchLdLoc(out variable); } } } From b78ef2209bc7fb78b20c47ed097514ad47ee734e Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 1 Oct 2017 20:08:33 +0200 Subject: [PATCH 008/190] Add InlineReturnTransform --- .../CSharp/CSharpDecompiler.cs | 1 + .../ICSharpCode.Decompiler.csproj | 1 + .../IL/Transforms/InlineReturnTransform.cs | 83 +++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 ICSharpCode.Decompiler/IL/Transforms/InlineReturnTransform.cs diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index b488578ba..00717a4bd 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -71,6 +71,7 @@ namespace ICSharpCode.Decompiler.CSharp new SplitVariables(), new ILInlining(), new DetectPinnedRegions(), // must run after inlining but before non-critical control flow transforms + new InlineReturnTransform(), new YieldReturnDecompiler(), // must run after inlining but before loop detection new AsyncAwaitDecompiler(), // must run after inlining but before loop detection new DetectCatchWhenConditionBlocks(), // must run after inlining but before loop detection diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 16409351a..35edd7dbc 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -273,6 +273,7 @@ + diff --git a/ICSharpCode.Decompiler/IL/Transforms/InlineReturnTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/InlineReturnTransform.cs new file mode 100644 index 000000000..ae5138358 --- /dev/null +++ b/ICSharpCode.Decompiler/IL/Transforms/InlineReturnTransform.cs @@ -0,0 +1,83 @@ +// Copyright (c) 2017 Siegfried Pammer +// +// 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.Collections.Generic; +using System.Linq; + +namespace ICSharpCode.Decompiler.IL.Transforms +{ + /// + /// This transform duplicates return blocks if they return a local variable that was assigned right before thie return. + /// + class InlineReturnTransform : IILTransform + { + public void Run(ILFunction function, ILTransformContext context) + { + var instructionsToModify = new List<(BlockContainer, Block, Branch)>(); + var possibleReturnVars = new Queue<(ILVariable, Block)>(); + var tempList = new List<(BlockContainer, Block, Branch)>(); + + foreach (var leave in function.Descendants.OfType()) { + if (!(leave.Parent is Block b && b.Instructions.Count == 1)) + continue; + if (!leave.Value.MatchLdLoc(out var returnVar) || returnVar.Kind != VariableKind.Local) + continue; + possibleReturnVars.Enqueue((returnVar, b)); + } + + while (possibleReturnVars.Count > 0) { + var (returnVar, leaveBlock) = possibleReturnVars.Dequeue(); + bool transform = true; + foreach (StLoc store in returnVar.StoreInstructions.OfType()) { + if (!(store.Parent is Block storeBlock)) { + transform = false; + break; + } + if (store.ChildIndex + 2 != storeBlock.Instructions.Count) { + transform = false; + break; + } + if (!(storeBlock.Instructions[store.ChildIndex + 1] is Branch br)) { + transform = false; + break; + } + if (br.TargetBlock != leaveBlock) { + transform = false; + break; + } + var targetBlockContainer = BlockContainer.FindClosestContainer(store); + if (targetBlockContainer == null) { + transform = false; + break; + } + tempList.Add((targetBlockContainer, leaveBlock, br)); + } + if (transform) + instructionsToModify.AddRange(tempList); + tempList.Clear(); + } + + foreach (var (container, block, br) in instructionsToModify) { + var newBlock = (Block)block.Clone(); + container.Blocks.Add(newBlock); + br.TargetBlock = newBlock; + } + } + } +} From 9719926b6bc1e43c9d43d811e5c27d9e797209b8 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 1 Oct 2017 22:01:31 +0200 Subject: [PATCH 009/190] Fix some more bugs in SwitchOnStringTransform --- .../TestCases/Pretty/Switch.cs | 6 +-- .../IL/Transforms/SwitchOnStringTransform.cs | 46 +++++++++++++------ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index bfc8ea0c4..c76d1ff85 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -56,7 +56,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty case 10001: { return "ten thousand and one"; } - case int.MaxValue: { + case 2147483647: { return "int.MaxValue"; } default: { @@ -107,8 +107,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty case "Sixth case": { return "Text6"; } - case null: { - return null; + case (string)null: { + return (string)null; } default: { return "Default"; diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 723bb6e02..a72cff6db 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -19,7 +19,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; +using ICSharpCode.Decompiler.IL.ControlFlow; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.Util; @@ -56,6 +56,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms i--; } + // Combine cases with the same branch target: + SwitchDetection.SimplifySwitchInstruction(block); + // This happens in some cases: // Use correct index after transformation. if (i >= block.Instructions.Count) @@ -100,13 +103,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms values.Add((value, block)); currentCaseBlock = nextCaseBlock; } - BlockContainer container = null; - if (!ExtractLastJumpFromBlock(currentCaseBlock, out var exitBlock) && !ExtractLastLeaveFromBlock(currentCaseBlock, out container)) + var container = BlockContainer.FindClosestContainer(firstBlock); + if (!ExtractLastJumpFromBlock(currentCaseBlock, out var exitBlock) && !ExtractLastLeaveFromBlock(currentCaseBlock, container)) return false; if (values.Count == 0) return false; - if (!(values.All(b => ExtractLastJumpFromBlock(b.Item2, out var nextExit) && nextExit == exitBlock) || - (exitBlock == null && values.All(b => ExtractLastLeaveFromBlock(b.Item2, out var exitContainer) && exitContainer == container)))) + if (!(values.All(b => ExtractLastJumpFromBlock(b.Item2, out var nextExit) && IsExitBlock(nextExit, container)) || + (exitBlock == null && values.All(b => ExtractLastLeaveFromBlock(b.Item2, container))))) return false; if (currentCaseBlock.IncomingEdgeCount == (isLegacy ? 2 : 1)) { var sections = new List(values.SelectWithIndex((index, b) => new SwitchSection { Labels = new LongSet(index), Body = new Branch(b.Item2) })); @@ -119,6 +122,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; } + bool IsExitBlock(Block nextExit, BlockContainer container) + { + if (nextExit.Instructions.Count != 1) + return false; + return nextExit.Instructions[0].MatchLeave(container, out _); + } + bool ExtractLastJumpFromBlock(Block block, out Block exitBlock) { exitBlock = null; @@ -128,13 +138,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; } - bool ExtractLastLeaveFromBlock(Block block, out BlockContainer exitBlock) + bool ExtractLastLeaveFromBlock(Block block, BlockContainer container) { - exitBlock = null; var lastInst = block.Instructions.LastOrDefault(); - if (lastInst == null || !lastInst.MatchLeave(out exitBlock, out _)) + if (lastInst == null || !lastInst.MatchLeave(out var b, out _)) return false; - return true; + return b == container; } Block MatchCaseBlock(Block currentBlock, ref ILVariable switchVariable, out string value, out Block caseBlock) @@ -174,7 +183,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms { if (!switchVariable.IsSingleDefinition) return false; - return switchVariable.StoreInstructions.OfType().Single().Value.MatchLdLoc(newSwitchVariable); + var storeInst = switchVariable.StoreInstructions.OfType().SingleOrDefault(); + if (storeInst == null) + return false; + return storeInst.Value.MatchLdLoc(newSwitchVariable); } bool MatchLegacySwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst, out Block blockAfterSwitch) @@ -236,7 +248,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms stringValues.Add(null); sections.Add(new SwitchSection() { Labels = new Util.LongSet(stringValues.Count - 1), Body = new Branch(exitBlock) }); } - var stringToInt = new StringToInt(switchValue.Clone(), stringValues.ToArray()); + var stringToInt = new StringToInt(new LdLoc(switchValueVar), stringValues.ToArray()); inst = new SwitchInstruction(stringToInt); inst.DefaultBody = switchInst.DefaultBody; inst.Sections.AddRange(sections); @@ -299,14 +311,22 @@ namespace ICSharpCode.Decompiler.IL.Transforms foreach (var section in switchInst.Sections) { if (!section.Body.MatchBranch(out Block target)) return false; - if (target.IncomingEdgeCount != 1 || target.Instructions.Count == 0) + if (target.IncomingEdgeCount != 1 || target.Instructions.Count != 2) return false; if (!target.Instructions[0].MatchIfInstruction(out var condition, out var bodyBranch)) return false; - if (!MatchStringEqualityComparison(condition, switchValue.Variable, out string stringValue)) + if (!target.Instructions[1].MatchBranch(out Block exit)) return false; if (!bodyBranch.MatchBranch(out Block body)) return false; + if (!MatchStringEqualityComparison(condition, switchValue.Variable, out string stringValue)) { + if (condition.MatchLogicNot(out condition) && MatchStringEqualityComparison(condition, switchValue.Variable, out stringValue)) { + var swap = body; + body = exit; + exit = swap; + } else + return false; + } stringValues.Add((index++, stringValue, body)); } From 66dc52c33c897e212202ab1a8e9ff5562aaa0347 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 1 Oct 2017 22:05:40 +0200 Subject: [PATCH 010/190] Fix handling of 'leave' instruction in SwitchAnalysis. This is necessary for detecting a sparse switch when the default case consists of "return;". --- .../IL/ControlFlow/SwitchAnalysis.cs | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs index 928b934c6..c280faa02 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs @@ -42,8 +42,18 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow /// public readonly List> Sections = new List>(); + /// + /// Used to de-duplicate sections with a branch instruction. + /// Invariant: (Sections[targetBlockToSectionIndex[branch.TargetBlock]].Instruction as Branch).TargetBlock == branch.TargetBlock + /// readonly Dictionary targetBlockToSectionIndex = new Dictionary(); + /// + /// Used to de-duplicate sections with a value-less leave instruction. + /// Invariant: (Sections[targetBlockToSectionIndex[leave.TargetContainer]].Instruction as Leave).TargetContainer == leave.TargetContainer + /// + readonly Dictionary targetContainerToSectionIndex = new Dictionary(); + /// /// Blocks that can be deleted if the tail of the initial block is replaced with a switch instruction. /// @@ -61,6 +71,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow switchVar = null; rootBlock = block; targetBlockToSectionIndex.Clear(); + targetContainerToSectionIndex.Clear(); Sections.Clear(); InnerBlocks.Clear(); ContainsILSwitch = false; @@ -180,10 +191,8 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow if (values.IsEmpty) { return; } - Block targetBlock; - if (inst.MatchBranch(out targetBlock)) { - int index; - if (targetBlockToSectionIndex.TryGetValue(targetBlock, out index)) { + if (inst.MatchBranch(out Block targetBlock)) { + if (targetBlockToSectionIndex.TryGetValue(targetBlock, out int index)) { Sections[index] = new KeyValuePair( Sections[index].Key.UnionWith(values), inst @@ -192,6 +201,16 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow targetBlockToSectionIndex.Add(targetBlock, Sections.Count); Sections.Add(new KeyValuePair(values, inst)); } + } else if (inst.MatchLeave(out BlockContainer targetContainer)) { + if (targetContainerToSectionIndex.TryGetValue(targetContainer, out int index)) { + Sections[index] = new KeyValuePair( + Sections[index].Key.UnionWith(values), + inst + ); + } else { + targetContainerToSectionIndex.Add(targetContainer, Sections.Count); + Sections.Add(new KeyValuePair(values, inst)); + } } else { Sections.Add(new KeyValuePair(values, inst)); } From 930d142a62baf39d7be892a2662e2880a505b4a2 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 2 Oct 2017 08:28:34 +0200 Subject: [PATCH 011/190] Fix bug in SwitchOnStringTransform introduced by 9719926b6bc1e43c9d43d811e5c27d9e797209b8: Ignore exit instruction if condition is not inverted. Otherwise we need a special case for br and leave. --- .../PrettyTestRunner.cs | 2 +- .../TestCases/Pretty/Switch.cs | 103 ++++++++++-------- .../IL/Transforms/SwitchOnStringTransform.cs | 6 +- 3 files changed, 60 insertions(+), 51 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index 2b458282b..f8f0c8049 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -97,7 +97,7 @@ namespace ICSharpCode.Decompiler.Tests Run(cscOptions: cscOptions); } - [Test] + [Test, Ignore("unnecessary casts on null literals, control-flow issues with switch in loops, goto, goto case, etc.")] public void Switch([ValueSource("defaultOptions")] CompilerOptions cscOptions) { Run(cscOptions: cscOptions); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index c76d1ff85..858d91a79 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -27,41 +27,41 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("SparseIntegerSwitch: " + i); switch (i) { case -10000000: { - return "-10 mln"; - } + return "-10 mln"; + } case -100: { - return "-hundred"; - } + return "-hundred"; + } case -1: { - return "-1"; - } + return "-1"; + } case 0: { - return "0"; - } - case 1: { - return "1"; - } + return "0"; + } + case 1: { + return "1"; + } case 2: { - return "2"; - } + return "2"; + } case 4: { - return "4"; - } + return "4"; + } case 100: { - return "hundred"; - } + return "hundred"; + } case 10000: { - return "ten thousand"; - } + return "ten thousand"; + } case 10001: { - return "ten thousand and one"; - } + return "ten thousand and one"; + } case 2147483647: { - return "int.MaxValue"; - } + return "int.MaxValue"; + } default: { - return "something else"; - } + return "something else"; + } } } @@ -70,17 +70,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("ShortSwitchOverString: " + text); switch (text) { case "First case": { - return "Text1"; - } + return "Text1"; + } case "Second case": { - return "Text2"; - } + return "Text2"; + } case "Third case": { - return "Text3"; - } + return "Text3"; + } default: { - return "Default"; - } + return "Default"; + } } } @@ -107,8 +107,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty case "Sixth case": { return "Text6"; } - case (string)null: { - return (string)null; + case null: { + return null; } default: { return "Default"; @@ -119,7 +119,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static string SwitchOverString2() { Console.WriteLine("SwitchOverString2:"); - switch (Environment.UserName) { + string userName = Environment.UserName; + switch (userName) { case "First case": { return "Text1"; } @@ -180,22 +181,27 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("SwitchInLoop: " + i); while (true) { switch (i) { - case 1: + case 1: { Console.WriteLine("one"); break; - case 2: + } + case 2: { Console.WriteLine("two"); break; - case 3: + } + case 3: { Console.WriteLine("three"); continue; - case 4: + } + case 4: { Console.WriteLine("four"); return; - default: + } + default: { Console.WriteLine("default"); Console.WriteLine("more code"); return; + } } i++; } @@ -205,21 +211,26 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { Console.WriteLine("SwitchWithGoto: " + i); switch (i) { - case 1: + case 1: { Console.WriteLine("one"); goto default; - case 2: + } + case 2: { Console.WriteLine("two"); goto case 3; - case 3: + } + case 3: { Console.WriteLine("three"); break; - case 4: + } + case 4: { Console.WriteLine("four"); return; - default: + } + default: { Console.WriteLine("default"); break; + } } } } diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index a72cff6db..f0bbd13ae 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -315,15 +315,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!target.Instructions[0].MatchIfInstruction(out var condition, out var bodyBranch)) return false; - if (!target.Instructions[1].MatchBranch(out Block exit)) - return false; if (!bodyBranch.MatchBranch(out Block body)) return false; if (!MatchStringEqualityComparison(condition, switchValue.Variable, out string stringValue)) { if (condition.MatchLogicNot(out condition) && MatchStringEqualityComparison(condition, switchValue.Variable, out stringValue)) { - var swap = body; + if (!target.Instructions[1].MatchBranch(out Block exit)) + return false; body = exit; - exit = swap; } else return false; } From 1bff19a7ce8a103f8b992ede689cd5f6f57e5091 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 2 Oct 2017 22:17:13 +0200 Subject: [PATCH 012/190] Remove unnecessary casts in switch tests --- .../CSharp/ExpressionBuilder.cs | 24 ++++++++++--------- .../CSharp/StatementBuilder.cs | 2 +- .../CSharp/TranslatedExpression.cs | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 1ccf44910..9a1120768 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -93,19 +93,21 @@ namespace ICSharpCode.Decompiler.CSharp return astType; } - public ExpressionWithResolveResult ConvertConstantValue(ResolveResult rr) + public ExpressionWithResolveResult ConvertConstantValue(ResolveResult rr, bool allowImplicitConversion = false) { var expr = astBuilder.ConvertConstantValue(rr); - if (expr is NullReferenceExpression && rr.Type.Kind != TypeKind.Null) { - expr = new CastExpression(ConvertType(rr.Type), expr); - } else { - switch (rr.Type.GetDefinition()?.KnownTypeCode) { - case KnownTypeCode.SByte: - case KnownTypeCode.Byte: - case KnownTypeCode.Int16: - case KnownTypeCode.UInt16: - expr = new CastExpression(new PrimitiveType(KnownTypeReference.GetCSharpNameByTypeCode(rr.Type.GetDefinition().KnownTypeCode)), expr); - break; + if (!allowImplicitConversion) { + if (expr is NullReferenceExpression && rr.Type.Kind != TypeKind.Null) { + expr = new CastExpression(ConvertType(rr.Type), expr); + } else { + switch (rr.Type.GetDefinition()?.KnownTypeCode) { + case KnownTypeCode.SByte: + case KnownTypeCode.Byte: + case KnownTypeCode.Int16: + case KnownTypeCode.UInt16: + expr = new CastExpression(new PrimitiveType(KnownTypeReference.GetCSharpNameByTypeCode(rr.Type.GetDefinition().KnownTypeCode)), expr); + break; + } } } var exprRR = expr.Annotation(); diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index bdb59f436..d5923cb3e 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -96,7 +96,7 @@ namespace ICSharpCode.Decompiler.CSharp } else { value = CSharpPrimitiveCast.Cast(ReflectionHelper.GetTypeCode(type), i, false); } - return new CaseLabel(exprBuilder.ConvertConstantValue(new ConstantResolveResult(type, value))); + return new CaseLabel(exprBuilder.ConvertConstantValue(new ConstantResolveResult(type, value), allowImplicitConversion: true)); } protected internal override Statement VisitSwitchInstruction(SwitchInstruction inst) diff --git a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs index 8d49ce4cd..7c01dc7f0 100644 --- a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs @@ -296,7 +296,7 @@ namespace ICSharpCode.Decompiler.CSharp } var rr = expressionBuilder.resolver.WithCheckForOverflow(checkForOverflow).ResolveCast(targetType, ResolveResult); if (rr.IsCompileTimeConstant && !rr.IsError) { - return expressionBuilder.ConvertConstantValue(rr) + return expressionBuilder.ConvertConstantValue(rr, allowImplicitConversion) .WithILInstruction(this.ILInstructions); } if (targetType.Kind == TypeKind.Pointer && (0.Equals(ResolveResult.ConstantValue) || 0u.Equals(ResolveResult.ConstantValue))) { From 945ebc770229edf9873189ab9caa6759731018f5 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 2 Oct 2017 22:20:54 +0200 Subject: [PATCH 013/190] Add test cases for switch on int? --- .../TestCases/Pretty/Switch.cs | 142 +++- .../TestCases/Pretty/Switch.il | 711 +++++++++++----- .../TestCases/Pretty/Switch.opt.il | 435 +++++++--- .../TestCases/Pretty/Switch.opt.roslyn.il | 212 ++++- .../TestCases/Pretty/Switch.roslyn.il | 785 ++++++++++++------ 5 files changed, 1662 insertions(+), 623 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index 858d91a79..4b31f0a2a 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -27,41 +27,119 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("SparseIntegerSwitch: " + i); switch (i) { case -10000000: { - return "-10 mln"; - } + return "-10 mln"; + } case -100: { - return "-hundred"; - } + return "-hundred"; + } case -1: { - return "-1"; - } + return "-1"; + } case 0: { - return "0"; - } + return "0"; + } case 1: { - return "1"; - } + return "1"; + } case 2: { - return "2"; - } + return "2"; + } case 4: { - return "4"; - } + return "4"; + } case 100: { - return "hundred"; - } + return "hundred"; + } case 10000: { - return "ten thousand"; - } + return "ten thousand"; + } case 10001: { - return "ten thousand and one"; - } + return "ten thousand and one"; + } case 2147483647: { - return "int.MaxValue"; - } + return "int.MaxValue"; + } default: { - return "something else"; - } + return "something else"; + } + } + } + + public static string SwitchOverNullableInt(int? i) + { + switch (i) { + case null: { + return "null"; + } + case 0: { + return "zero"; + } + case 5: { + return "five"; + } + case 10: { + return "ten"; + } + default: { + return "large"; + } + } + } + + public static string SwitchOverNullableIntShifted(int? i) + { + switch (i + 5) { + case null: { + return "null"; + } + case 0: { + return "zero"; + } + case 5: { + return "five"; + } + case 10: { + return "ten"; + } + default: { + return "large"; + } + } + } + + public static string SwitchOverNullableIntNoNullCase(int? i) + { + switch (i) { + case 0: { + return "zero"; + } + case 5: { + return "five"; + } + case 10: { + return "ten"; + } + default: { + return "other"; + } + } + } + + public static string SwitchOverNullableIntNoNullCaseShifted(int? i) + { + switch (i + 5) { + case 0: { + return "zero"; + } + case 5: { + return "five"; + } + case 10: { + return "ten"; + } + default: { + return "other"; + } } } @@ -70,17 +148,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("ShortSwitchOverString: " + text); switch (text) { case "First case": { - return "Text1"; - } + return "Text1"; + } case "Second case": { - return "Text2"; - } + return "Text2"; + } case "Third case": { - return "Text3"; - } + return "Text3"; + } default: { - return "Default"; - } + return "Default"; + } } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il index e04aa74b5..c64e70f03 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly wau4yvxd +.assembly iuizqapl { .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 wau4yvxd.dll -// MVID: {102ACC94-685A-42C5-9229-AC386C0A78B1} +.module iuizqapl.dll +// MVID: {207B14E2-2177-4CF2-8D8E-2CD85A17CF5C} .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: 0x01440000 +// Image base: 0x027D0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -157,6 +157,250 @@ IL_00df: ret } // end of method Switch::SparseIntegerSwitch + .method public hidebysig static string + SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 74 (0x4a) + .maxstack 2 + .locals init (string V_0, + int32 V_1) + IL_0000: nop + IL_0001: ldarga.s i + IL_0003: dup + IL_0004: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0009: stloc.1 + IL_000a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000f: brfalse.s IL_0020 + + IL_0011: ldloc.1 + IL_0012: ldc.i4.0 + IL_0013: beq.s IL_0028 + + IL_0015: ldloc.1 + IL_0016: ldc.i4.5 + IL_0017: beq.s IL_0030 + + IL_0019: ldloc.1 + IL_001a: ldc.i4.s 10 + IL_001c: beq.s IL_0038 + + IL_001e: br.s IL_0040 + + IL_0020: ldstr "null" + IL_0025: stloc.0 + IL_0026: br.s IL_0048 + + IL_0028: ldstr "zero" + IL_002d: stloc.0 + IL_002e: br.s IL_0048 + + IL_0030: ldstr "five" + IL_0035: stloc.0 + IL_0036: br.s IL_0048 + + IL_0038: ldstr "ten" + IL_003d: stloc.0 + IL_003e: br.s IL_0048 + + IL_0040: ldstr "large" + IL_0045: stloc.0 + IL_0046: br.s IL_0048 + + IL_0048: ldloc.0 + IL_0049: ret + } // end of method Switch::SwitchOverNullableInt + + .method public hidebysig static string + SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 112 (0x70) + .maxstack 2 + .locals init (string V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloca.s V_1 + IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000a: brtrue.s IL_0017 + + IL_000c: ldloca.s V_2 + IL_000e: initobj valuetype [mscorlib]System.Nullable`1 + IL_0014: ldloc.2 + IL_0015: br.s IL_0025 + + IL_0017: ldloca.s V_1 + IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001e: ldc.i4.5 + IL_001f: add + IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0025: nop + IL_0026: stloc.2 + IL_0027: ldloca.s V_2 + IL_0029: dup + IL_002a: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_002f: stloc.3 + IL_0030: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0035: brfalse.s IL_0046 + + IL_0037: ldloc.3 + IL_0038: ldc.i4.0 + IL_0039: beq.s IL_004e + + IL_003b: ldloc.3 + IL_003c: ldc.i4.5 + IL_003d: beq.s IL_0056 + + IL_003f: ldloc.3 + IL_0040: ldc.i4.s 10 + IL_0042: beq.s IL_005e + + IL_0044: br.s IL_0066 + + IL_0046: ldstr "null" + IL_004b: stloc.0 + IL_004c: br.s IL_006e + + IL_004e: ldstr "zero" + IL_0053: stloc.0 + IL_0054: br.s IL_006e + + IL_0056: ldstr "five" + IL_005b: stloc.0 + IL_005c: br.s IL_006e + + IL_005e: ldstr "ten" + IL_0063: stloc.0 + IL_0064: br.s IL_006e + + IL_0066: ldstr "large" + IL_006b: stloc.0 + IL_006c: br.s IL_006e + + IL_006e: ldloc.0 + IL_006f: ret + } // end of method Switch::SwitchOverNullableIntShifted + + .method public hidebysig static string + SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 66 (0x42) + .maxstack 2 + .locals init (string V_0, + int32 V_1) + IL_0000: nop + IL_0001: ldarga.s i + IL_0003: dup + IL_0004: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0009: stloc.1 + IL_000a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000f: brfalse.s IL_0038 + + IL_0011: ldloc.1 + IL_0012: ldc.i4.0 + IL_0013: beq.s IL_0020 + + IL_0015: ldloc.1 + IL_0016: ldc.i4.5 + IL_0017: beq.s IL_0028 + + IL_0019: ldloc.1 + IL_001a: ldc.i4.s 10 + IL_001c: beq.s IL_0030 + + IL_001e: br.s IL_0038 + + IL_0020: ldstr "zero" + IL_0025: stloc.0 + IL_0026: br.s IL_0040 + + IL_0028: ldstr "five" + IL_002d: stloc.0 + IL_002e: br.s IL_0040 + + IL_0030: ldstr "ten" + IL_0035: stloc.0 + IL_0036: br.s IL_0040 + + IL_0038: ldstr "other" + IL_003d: stloc.0 + IL_003e: br.s IL_0040 + + IL_0040: ldloc.0 + IL_0041: ret + } // end of method Switch::SwitchOverNullableIntNoNullCase + + .method public hidebysig static string + SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 104 (0x68) + .maxstack 2 + .locals init (string V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloca.s V_1 + IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000a: brtrue.s IL_0017 + + IL_000c: ldloca.s V_2 + IL_000e: initobj valuetype [mscorlib]System.Nullable`1 + IL_0014: ldloc.2 + IL_0015: br.s IL_0025 + + IL_0017: ldloca.s V_1 + IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001e: ldc.i4.5 + IL_001f: add + IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0025: nop + IL_0026: stloc.2 + IL_0027: ldloca.s V_2 + IL_0029: dup + IL_002a: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_002f: stloc.3 + IL_0030: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0035: brfalse.s IL_005e + + IL_0037: ldloc.3 + IL_0038: ldc.i4.0 + IL_0039: beq.s IL_0046 + + IL_003b: ldloc.3 + IL_003c: ldc.i4.5 + IL_003d: beq.s IL_004e + + IL_003f: ldloc.3 + IL_0040: ldc.i4.s 10 + IL_0042: beq.s IL_0056 + + IL_0044: br.s IL_005e + + IL_0046: ldstr "zero" + IL_004b: stloc.0 + IL_004c: br.s IL_0066 + + IL_004e: ldstr "five" + IL_0053: stloc.0 + IL_0054: br.s IL_0066 + + IL_0056: ldstr "ten" + IL_005b: stloc.0 + IL_005c: br.s IL_0066 + + IL_005e: ldstr "other" + IL_0063: stloc.0 + IL_0064: br.s IL_0066 + + IL_0066: ldloc.0 + IL_0067: ret + } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted + .method public hidebysig static string ShortSwitchOverString(string text) cil managed { @@ -241,7 +485,7 @@ IL_0015: brfalse IL_00ef IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{102ACC94-685A-42C5-9229-AC386C0A78B1}'::'$$method0x6000003-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000007-1' IL_0021: brtrue.s IL_0084 IL_0023: ldc.i4.7 @@ -282,9 +526,9 @@ IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007d: volatile. - IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{102ACC94-685A-42C5-9229-AC386C0A78B1}'::'$$method0x6000003-1' + IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000007-1' IL_0084: volatile. - IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{102ACC94-685A-42C5-9229-AC386C0A78B1}'::'$$method0x6000003-1' + IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000007-1' IL_008b: ldloc.1 IL_008c: ldloca.s V_2 IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -349,168 +593,171 @@ .method public hidebysig static string SwitchOverString2() cil managed { - // Code size 366 (0x16e) + // Code size 368 (0x170) .maxstack 4 .locals init (string V_0, string V_1, - int32 V_2) + string V_2, + int32 V_3) IL_0000: nop IL_0001: ldstr "SwitchOverString2:" IL_0006: call void [mscorlib]System.Console::WriteLine(string) IL_000b: nop IL_000c: call string [mscorlib]System.Environment::get_UserName() - IL_0011: stloc.1 - IL_0012: ldloc.1 - IL_0013: brfalse IL_0163 - - IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{102ACC94-685A-42C5-9229-AC386C0A78B1}'::'$$method0x6000004-1' - IL_001f: brtrue IL_00b8 - - IL_0024: ldc.i4.s 11 - IL_0026: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) - IL_002b: dup - IL_002c: ldstr "First case" - IL_0031: ldc.i4.0 - IL_0032: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0011: stloc.0 + IL_0012: ldloc.0 + IL_0013: stloc.2 + IL_0014: ldloc.2 + IL_0015: brfalse IL_0165 + + IL_001a: volatile. + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000008-1' + IL_0021: brtrue IL_00ba + + IL_0026: ldc.i4.s 11 + IL_0028: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_002d: dup + IL_002e: ldstr "First case" + IL_0033: ldc.i4.0 + IL_0034: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0037: dup - IL_0038: ldstr "Second case" - IL_003d: ldc.i4.1 - IL_003e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0039: dup + IL_003a: ldstr "Second case" + IL_003f: ldc.i4.1 + IL_0040: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0043: dup - IL_0044: ldstr "Third case" - IL_0049: ldc.i4.2 - IL_004a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0045: dup + IL_0046: ldstr "Third case" + IL_004b: ldc.i4.2 + IL_004c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_004f: dup - IL_0050: ldstr "Fourth case" - IL_0055: ldc.i4.3 - IL_0056: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0051: dup + IL_0052: ldstr "Fourth case" + IL_0057: ldc.i4.3 + IL_0058: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_005b: dup - IL_005c: ldstr "Fifth case" - IL_0061: ldc.i4.4 - IL_0062: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_005d: dup + IL_005e: ldstr "Fifth case" + IL_0063: ldc.i4.4 + IL_0064: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0067: dup - IL_0068: ldstr "Sixth case" - IL_006d: ldc.i4.5 - IL_006e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0069: dup + IL_006a: ldstr "Sixth case" + IL_006f: ldc.i4.5 + IL_0070: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0073: dup - IL_0074: ldstr "Seventh case" - IL_0079: ldc.i4.6 - IL_007a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0075: dup + IL_0076: ldstr "Seventh case" + IL_007b: ldc.i4.6 + IL_007c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_007f: dup - IL_0080: ldstr "Eighth case" - IL_0085: ldc.i4.7 - IL_0086: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0081: dup + IL_0082: ldstr "Eighth case" + IL_0087: ldc.i4.7 + IL_0088: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_008b: dup - IL_008c: ldstr "Ninth case" - IL_0091: ldc.i4.8 - IL_0092: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_008d: dup + IL_008e: ldstr "Ninth case" + IL_0093: ldc.i4.8 + IL_0094: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0097: dup - IL_0098: ldstr "Tenth case" - IL_009d: ldc.i4.s 9 - IL_009f: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0099: dup + IL_009a: ldstr "Tenth case" + IL_009f: ldc.i4.s 9 + IL_00a1: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_00a4: dup - IL_00a5: ldstr "Eleventh case" - IL_00aa: ldc.i4.s 10 - IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_00a6: dup + IL_00a7: ldstr "Eleventh case" + IL_00ac: ldc.i4.s 10 + IL_00ae: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_00b1: volatile. - IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{102ACC94-685A-42C5-9229-AC386C0A78B1}'::'$$method0x6000004-1' - IL_00b8: volatile. - IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{102ACC94-685A-42C5-9229-AC386C0A78B1}'::'$$method0x6000004-1' - IL_00bf: ldloc.1 - IL_00c0: ldloca.s V_2 - IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + IL_00b3: volatile. + IL_00b5: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000008-1' + IL_00ba: volatile. + IL_00bc: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000008-1' + IL_00c1: ldloc.2 + IL_00c2: ldloca.s V_3 + IL_00c4: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, !1&) - IL_00c7: brfalse IL_0163 - - IL_00cc: ldloc.2 - IL_00cd: switch ( - IL_0100, - IL_0109, - IL_0112, - IL_011b, - IL_0124, - IL_012d, - IL_0136, - IL_013f, - IL_0148, - IL_0151, - IL_015a) - IL_00fe: br.s IL_0163 - - IL_0100: nop - IL_0101: ldstr "Text1" - IL_0106: stloc.0 - IL_0107: br.s IL_016c - - IL_0109: nop - IL_010a: ldstr "Text2" - IL_010f: stloc.0 - IL_0110: br.s IL_016c - - IL_0112: nop - IL_0113: ldstr "Text3" - IL_0118: stloc.0 - IL_0119: br.s IL_016c - - IL_011b: nop - IL_011c: ldstr "Text4" - IL_0121: stloc.0 - IL_0122: br.s IL_016c - - IL_0124: nop - IL_0125: ldstr "Text5" - IL_012a: stloc.0 - IL_012b: br.s IL_016c - - IL_012d: nop - IL_012e: ldstr "Text6" - IL_0133: stloc.0 - IL_0134: br.s IL_016c - - IL_0136: nop - IL_0137: ldstr "Text7" - IL_013c: stloc.0 - IL_013d: br.s IL_016c - - IL_013f: nop - IL_0140: ldstr "Text8" - IL_0145: stloc.0 - IL_0146: br.s IL_016c - - IL_0148: nop - IL_0149: ldstr "Text9" - IL_014e: stloc.0 - IL_014f: br.s IL_016c - - IL_0151: nop - IL_0152: ldstr "Text10" - IL_0157: stloc.0 - IL_0158: br.s IL_016c - - IL_015a: nop - IL_015b: ldstr "Text11" - IL_0160: stloc.0 - IL_0161: br.s IL_016c - - IL_0163: nop - IL_0164: ldstr "Default" - IL_0169: stloc.0 - IL_016a: br.s IL_016c - - IL_016c: ldloc.0 - IL_016d: ret + IL_00c9: brfalse IL_0165 + + IL_00ce: ldloc.3 + IL_00cf: switch ( + IL_0102, + IL_010b, + IL_0114, + IL_011d, + IL_0126, + IL_012f, + IL_0138, + IL_0141, + IL_014a, + IL_0153, + IL_015c) + IL_0100: br.s IL_0165 + + IL_0102: nop + IL_0103: ldstr "Text1" + IL_0108: stloc.1 + IL_0109: br.s IL_016e + + IL_010b: nop + IL_010c: ldstr "Text2" + IL_0111: stloc.1 + IL_0112: br.s IL_016e + + IL_0114: nop + IL_0115: ldstr "Text3" + IL_011a: stloc.1 + IL_011b: br.s IL_016e + + IL_011d: nop + IL_011e: ldstr "Text4" + IL_0123: stloc.1 + IL_0124: br.s IL_016e + + IL_0126: nop + IL_0127: ldstr "Text5" + IL_012c: stloc.1 + IL_012d: br.s IL_016e + + IL_012f: nop + IL_0130: ldstr "Text6" + IL_0135: stloc.1 + IL_0136: br.s IL_016e + + IL_0138: nop + IL_0139: ldstr "Text7" + IL_013e: stloc.1 + IL_013f: br.s IL_016e + + IL_0141: nop + IL_0142: ldstr "Text8" + IL_0147: stloc.1 + IL_0148: br.s IL_016e + + IL_014a: nop + IL_014b: ldstr "Text9" + IL_0150: stloc.1 + IL_0151: br.s IL_016e + + IL_0153: nop + IL_0154: ldstr "Text10" + IL_0159: stloc.1 + IL_015a: br.s IL_016e + + IL_015c: nop + IL_015d: ldstr "Text11" + IL_0162: stloc.1 + IL_0163: br.s IL_016e + + IL_0165: nop + IL_0166: ldstr "Default" + IL_016b: stloc.1 + IL_016c: br.s IL_016e + + IL_016e: ldloc.1 + IL_016f: ret } // end of method Switch::SwitchOverString2 .method public hidebysig static string @@ -557,7 +804,7 @@ .method public hidebysig static void SwitchInLoop(int32 i) cil managed { - // Code size 141 (0x8d) + // Code size 146 (0x92) .maxstack 2 .locals init (int32 V_0, bool V_1) @@ -569,7 +816,7 @@ object) IL_0011: call void [mscorlib]System.Console::WriteLine(string) IL_0016: nop - IL_0017: br.s IL_0088 + IL_0017: br.s IL_008d IL_0019: nop IL_001a: ldarg.0 @@ -579,54 +826,59 @@ IL_001e: sub IL_001f: switch ( IL_0036, - IL_0043, - IL_0050, - IL_005d) - IL_0034: br.s IL_006a + IL_0044, + IL_0052, + IL_0060) + IL_0034: br.s IL_006e + + IL_0036: nop + IL_0037: ldstr "one" + IL_003c: call void [mscorlib]System.Console::WriteLine(string) + IL_0041: nop + IL_0042: br.s IL_0087 + + IL_0044: nop + IL_0045: ldstr "two" + IL_004a: call void [mscorlib]System.Console::WriteLine(string) + IL_004f: nop + IL_0050: br.s IL_0087 - IL_0036: ldstr "one" - IL_003b: call void [mscorlib]System.Console::WriteLine(string) - IL_0040: nop - IL_0041: br.s IL_0082 - - IL_0043: ldstr "two" - IL_0048: call void [mscorlib]System.Console::WriteLine(string) - IL_004d: nop - IL_004e: br.s IL_0082 + IL_0052: nop + IL_0053: ldstr "three" + IL_0058: call void [mscorlib]System.Console::WriteLine(string) + IL_005d: nop + IL_005e: br.s IL_008d + + IL_0060: nop + IL_0061: ldstr "four" + IL_0066: call void [mscorlib]System.Console::WriteLine(string) + IL_006b: nop + IL_006c: br.s IL_0091 + + IL_006e: nop + IL_006f: ldstr "default" + IL_0074: call void [mscorlib]System.Console::WriteLine(string) + IL_0079: nop + IL_007a: ldstr "more code" + IL_007f: call void [mscorlib]System.Console::WriteLine(string) + IL_0084: nop + IL_0085: br.s IL_0091 - IL_0050: ldstr "three" - IL_0055: call void [mscorlib]System.Console::WriteLine(string) - IL_005a: nop - IL_005b: br.s IL_0088 - - IL_005d: ldstr "four" - IL_0062: call void [mscorlib]System.Console::WriteLine(string) - IL_0067: nop - IL_0068: br.s IL_008c - - IL_006a: ldstr "default" - IL_006f: call void [mscorlib]System.Console::WriteLine(string) - IL_0074: nop - IL_0075: ldstr "more code" - IL_007a: call void [mscorlib]System.Console::WriteLine(string) - IL_007f: nop - IL_0080: br.s IL_008c - - IL_0082: ldarg.0 - IL_0083: ldc.i4.1 - IL_0084: add - IL_0085: starg.s i - IL_0087: nop + IL_0087: ldarg.0 IL_0088: ldc.i4.1 - IL_0089: stloc.1 - IL_008a: br.s IL_0019 - - IL_008c: ret + IL_0089: add + IL_008a: starg.s i + IL_008c: nop + IL_008d: ldc.i4.1 + IL_008e: stloc.1 + IL_008f: br.s IL_0019 + + IL_0091: ret } // end of method Switch::SwitchInLoop .method public hidebysig static void SwitchWithGoto(int32 i) cil managed { - // Code size 117 (0x75) + // Code size 122 (0x7a) .maxstack 2 .locals init (int32 V_0) IL_0000: nop @@ -644,48 +896,53 @@ IL_001b: sub IL_001c: switch ( IL_0033, - IL_0040, - IL_004d, - IL_005a) - IL_0031: br.s IL_0067 - - IL_0033: ldstr "one" - IL_0038: call void [mscorlib]System.Console::WriteLine(string) - IL_003d: nop - IL_003e: br.s IL_0067 - - IL_0040: ldstr "two" - IL_0045: call void [mscorlib]System.Console::WriteLine(string) - IL_004a: nop - IL_004b: br.s IL_004d - - IL_004d: ldstr "three" - IL_0052: call void [mscorlib]System.Console::WriteLine(string) - IL_0057: nop - IL_0058: br.s IL_0074 - - IL_005a: ldstr "four" - IL_005f: call void [mscorlib]System.Console::WriteLine(string) - IL_0064: nop - IL_0065: br.s IL_0074 - - IL_0067: ldstr "default" - IL_006c: call void [mscorlib]System.Console::WriteLine(string) - IL_0071: nop - IL_0072: br.s IL_0074 - - IL_0074: ret + IL_0041, + IL_004f, + IL_005d) + IL_0031: br.s IL_006b + + IL_0033: nop + IL_0034: ldstr "one" + IL_0039: call void [mscorlib]System.Console::WriteLine(string) + IL_003e: nop + IL_003f: br.s IL_006b + + IL_0041: nop + IL_0042: ldstr "two" + IL_0047: call void [mscorlib]System.Console::WriteLine(string) + IL_004c: nop + IL_004d: br.s IL_004f + + IL_004f: nop + IL_0050: ldstr "three" + IL_0055: call void [mscorlib]System.Console::WriteLine(string) + IL_005a: nop + IL_005b: br.s IL_0079 + + IL_005d: nop + IL_005e: ldstr "four" + IL_0063: call void [mscorlib]System.Console::WriteLine(string) + IL_0068: nop + IL_0069: br.s IL_0079 + + IL_006b: nop + IL_006c: ldstr "default" + IL_0071: call void [mscorlib]System.Console::WriteLine(string) + IL_0076: nop + IL_0077: br.s IL_0079 + + IL_0079: ret } // end of method Switch::SwitchWithGoto } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{102ACC94-685A-42C5-9229-AC386C0A78B1}' +.class private auto ansi '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000003-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000004-1' -} // end of class '{102ACC94-685A-42C5-9229-AC386C0A78B1}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000007-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000008-1' +} // end of class '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il index 4c6e7946e..0765e0099 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly gz2l4xfo +.assembly utwwumxi { .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 gz2l4xfo.dll -// MVID: {FFA858C4-FC28-4EB1-BDB5-C80B304AD168} +.module utwwumxi.dll +// MVID: {30E98C35-5F99-4742-941F-78E7F27D8BD5} .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: 0x008F0000 +// Image base: 0x02C70000 // =============== CLASS MEMBERS DECLARATION =================== @@ -127,6 +127,212 @@ IL_00b4: ret } // end of method Switch::SparseIntegerSwitch + .method public hidebysig static string + SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 61 (0x3d) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldarga.s i + IL_0002: dup + IL_0003: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0008: stloc.0 + IL_0009: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000e: brfalse.s IL_001f + + IL_0010: ldloc.0 + IL_0011: ldc.i4.0 + IL_0012: beq.s IL_0025 + + IL_0014: ldloc.0 + IL_0015: ldc.i4.5 + IL_0016: beq.s IL_002b + + IL_0018: ldloc.0 + IL_0019: ldc.i4.s 10 + IL_001b: beq.s IL_0031 + + IL_001d: br.s IL_0037 + + IL_001f: ldstr "null" + IL_0024: ret + + IL_0025: ldstr "zero" + IL_002a: ret + + IL_002b: ldstr "five" + IL_0030: ret + + IL_0031: ldstr "ten" + IL_0036: ret + + IL_0037: ldstr "large" + IL_003c: ret + } // end of method Switch::SwitchOverNullableInt + + .method public hidebysig static string + SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 98 (0x62) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brtrue.s IL_0016 + + IL_000b: ldloca.s V_1 + IL_000d: initobj valuetype [mscorlib]System.Nullable`1 + IL_0013: ldloc.1 + IL_0014: br.s IL_0024 + + IL_0016: ldloca.s V_0 + IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001d: ldc.i4.5 + IL_001e: add + IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0024: stloc.2 + IL_0025: ldloca.s V_2 + IL_0027: dup + IL_0028: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_002d: stloc.3 + IL_002e: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0033: brfalse.s IL_0044 + + IL_0035: ldloc.3 + IL_0036: ldc.i4.0 + IL_0037: beq.s IL_004a + + IL_0039: ldloc.3 + IL_003a: ldc.i4.5 + IL_003b: beq.s IL_0050 + + IL_003d: ldloc.3 + IL_003e: ldc.i4.s 10 + IL_0040: beq.s IL_0056 + + IL_0042: br.s IL_005c + + IL_0044: ldstr "null" + IL_0049: ret + + IL_004a: ldstr "zero" + IL_004f: ret + + IL_0050: ldstr "five" + IL_0055: ret + + IL_0056: ldstr "ten" + IL_005b: ret + + IL_005c: ldstr "large" + IL_0061: ret + } // end of method Switch::SwitchOverNullableIntShifted + + .method public hidebysig static string + SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 55 (0x37) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldarga.s i + IL_0002: dup + IL_0003: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0008: stloc.0 + IL_0009: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000e: brfalse.s IL_0031 + + IL_0010: ldloc.0 + IL_0011: ldc.i4.0 + IL_0012: beq.s IL_001f + + IL_0014: ldloc.0 + IL_0015: ldc.i4.5 + IL_0016: beq.s IL_0025 + + IL_0018: ldloc.0 + IL_0019: ldc.i4.s 10 + IL_001b: beq.s IL_002b + + IL_001d: br.s IL_0031 + + IL_001f: ldstr "zero" + IL_0024: ret + + IL_0025: ldstr "five" + IL_002a: ret + + IL_002b: ldstr "ten" + IL_0030: ret + + IL_0031: ldstr "other" + IL_0036: ret + } // end of method Switch::SwitchOverNullableIntNoNullCase + + .method public hidebysig static string + SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 92 (0x5c) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brtrue.s IL_0016 + + IL_000b: ldloca.s V_1 + IL_000d: initobj valuetype [mscorlib]System.Nullable`1 + IL_0013: ldloc.1 + IL_0014: br.s IL_0024 + + IL_0016: ldloca.s V_0 + IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001d: ldc.i4.5 + IL_001e: add + IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0024: stloc.2 + IL_0025: ldloca.s V_2 + IL_0027: dup + IL_0028: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_002d: stloc.3 + IL_002e: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0033: brfalse.s IL_0056 + + IL_0035: ldloc.3 + IL_0036: ldc.i4.0 + IL_0037: beq.s IL_0044 + + IL_0039: ldloc.3 + IL_003a: ldc.i4.5 + IL_003b: beq.s IL_004a + + IL_003d: ldloc.3 + IL_003e: ldc.i4.s 10 + IL_0040: beq.s IL_0050 + + IL_0042: br.s IL_0056 + + IL_0044: ldstr "zero" + IL_0049: ret + + IL_004a: ldstr "five" + IL_004f: ret + + IL_0050: ldstr "ten" + IL_0055: ret + + IL_0056: ldstr "other" + IL_005b: ret + } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted + .method public hidebysig static string ShortSwitchOverString(string text) cil managed { @@ -194,7 +400,7 @@ IL_0013: brfalse IL_00db IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}'::'$$method0x6000003-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000007-1' IL_001f: brtrue.s IL_0082 IL_0021: ldc.i4.7 @@ -235,9 +441,9 @@ IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007b: volatile. - IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}'::'$$method0x6000003-1' + IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000007-1' IL_0082: volatile. - IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}'::'$$method0x6000003-1' + IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000007-1' IL_0089: ldloc.0 IL_008a: ldloca.s V_1 IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -283,138 +489,141 @@ .method public hidebysig static string SwitchOverString2() cil managed { - // Code size 323 (0x143) + // Code size 325 (0x145) .maxstack 4 .locals init (string V_0, - int32 V_1) + string V_1, + int32 V_2) IL_0000: ldstr "SwitchOverString2:" IL_0005: call void [mscorlib]System.Console::WriteLine(string) IL_000a: call string [mscorlib]System.Environment::get_UserName() - IL_000f: dup - IL_0010: stloc.0 - IL_0011: brfalse IL_013d - - IL_0016: volatile. - IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}'::'$$method0x6000004-1' - IL_001d: brtrue IL_00b6 - - IL_0022: ldc.i4.s 11 - IL_0024: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) - IL_0029: dup - IL_002a: ldstr "First case" - IL_002f: ldc.i4.0 - IL_0030: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_000f: stloc.0 + IL_0010: ldloc.0 + IL_0011: dup + IL_0012: stloc.1 + IL_0013: brfalse IL_013f + + IL_0018: volatile. + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000008-1' + IL_001f: brtrue IL_00b8 + + IL_0024: ldc.i4.s 11 + IL_0026: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_002b: dup + IL_002c: ldstr "First case" + IL_0031: ldc.i4.0 + IL_0032: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0035: dup - IL_0036: ldstr "Second case" - IL_003b: ldc.i4.1 - IL_003c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0037: dup + IL_0038: ldstr "Second case" + IL_003d: ldc.i4.1 + IL_003e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0041: dup - IL_0042: ldstr "Third case" - IL_0047: ldc.i4.2 - IL_0048: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0043: dup + IL_0044: ldstr "Third case" + IL_0049: ldc.i4.2 + IL_004a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_004d: dup - IL_004e: ldstr "Fourth case" - IL_0053: ldc.i4.3 - IL_0054: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_004f: dup + IL_0050: ldstr "Fourth case" + IL_0055: ldc.i4.3 + IL_0056: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0059: dup - IL_005a: ldstr "Fifth case" - IL_005f: ldc.i4.4 - IL_0060: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_005b: dup + IL_005c: ldstr "Fifth case" + IL_0061: ldc.i4.4 + IL_0062: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0065: dup - IL_0066: ldstr "Sixth case" - IL_006b: ldc.i4.5 - IL_006c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0067: dup + IL_0068: ldstr "Sixth case" + IL_006d: ldc.i4.5 + IL_006e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0071: dup - IL_0072: ldstr "Seventh case" - IL_0077: ldc.i4.6 - IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0073: dup + IL_0074: ldstr "Seventh case" + IL_0079: ldc.i4.6 + IL_007a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_007d: dup - IL_007e: ldstr "Eighth case" - IL_0083: ldc.i4.7 - IL_0084: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_007f: dup + IL_0080: ldstr "Eighth case" + IL_0085: ldc.i4.7 + IL_0086: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0089: dup - IL_008a: ldstr "Ninth case" - IL_008f: ldc.i4.8 - IL_0090: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_008b: dup + IL_008c: ldstr "Ninth case" + IL_0091: ldc.i4.8 + IL_0092: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0095: dup - IL_0096: ldstr "Tenth case" - IL_009b: ldc.i4.s 9 - IL_009d: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0097: dup + IL_0098: ldstr "Tenth case" + IL_009d: ldc.i4.s 9 + IL_009f: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_00a2: dup - IL_00a3: ldstr "Eleventh case" - IL_00a8: ldc.i4.s 10 - IL_00aa: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_00a4: dup + IL_00a5: ldstr "Eleventh case" + IL_00aa: ldc.i4.s 10 + IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_00af: volatile. - IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}'::'$$method0x6000004-1' - IL_00b6: volatile. - IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}'::'$$method0x6000004-1' - IL_00bd: ldloc.0 - IL_00be: ldloca.s V_1 - IL_00c0: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + IL_00b1: volatile. + IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000008-1' + IL_00b8: volatile. + IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000008-1' + IL_00bf: ldloc.1 + IL_00c0: ldloca.s V_2 + IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, !1&) - IL_00c5: brfalse.s IL_013d + IL_00c7: brfalse.s IL_013f - IL_00c7: ldloc.1 - IL_00c8: switch ( - IL_00fb, - IL_0101, - IL_0107, - IL_010d, - IL_0113, - IL_0119, - IL_011f, - IL_0125, - IL_012b, - IL_0131, - IL_0137) - IL_00f9: br.s IL_013d + IL_00c9: ldloc.2 + IL_00ca: switch ( + IL_00fd, + IL_0103, + IL_0109, + IL_010f, + IL_0115, + IL_011b, + IL_0121, + IL_0127, + IL_012d, + IL_0133, + IL_0139) + IL_00fb: br.s IL_013f - IL_00fb: ldstr "Text1" - IL_0100: ret + IL_00fd: ldstr "Text1" + IL_0102: ret - IL_0101: ldstr "Text2" - IL_0106: ret + IL_0103: ldstr "Text2" + IL_0108: ret - IL_0107: ldstr "Text3" - IL_010c: ret + IL_0109: ldstr "Text3" + IL_010e: ret - IL_010d: ldstr "Text4" - IL_0112: ret + IL_010f: ldstr "Text4" + IL_0114: ret - IL_0113: ldstr "Text5" - IL_0118: ret + IL_0115: ldstr "Text5" + IL_011a: ret - IL_0119: ldstr "Text6" - IL_011e: ret + IL_011b: ldstr "Text6" + IL_0120: ret - IL_011f: ldstr "Text7" - IL_0124: ret + IL_0121: ldstr "Text7" + IL_0126: ret - IL_0125: ldstr "Text8" - IL_012a: ret + IL_0127: ldstr "Text8" + IL_012c: ret - IL_012b: ldstr "Text9" - IL_0130: ret + IL_012d: ldstr "Text9" + IL_0132: ret - IL_0131: ldstr "Text10" - IL_0136: ret + IL_0133: ldstr "Text10" + IL_0138: ret - IL_0137: ldstr "Text11" - IL_013c: ret + IL_0139: ldstr "Text11" + IL_013e: ret - IL_013d: ldstr "Default" - IL_0142: ret + IL_013f: ldstr "Default" + IL_0144: ret } // end of method Switch::SwitchOverString2 .method public hidebysig static string @@ -543,13 +752,13 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}' +.class private auto ansi '{30E98C35-5F99-4742-941F-78E7F27D8BD5}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000003-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000004-1' -} // end of class '{FFA858C4-FC28-4EB1-BDB5-C80B304AD168}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000007-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000008-1' +} // end of class '{30E98C35-5F99-4742-941F-78E7F27D8BD5}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il index a86c1b3cc..ef1606d38 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {3690F18D-C570-405A-8B33-B6E0A6696EFD} +// MVID: {E38DFC98-1601-4EC8-896E-FC0EA87D4437} .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: 0x015B0000 +// Image base: 0x02590000 // =============== CLASS MEMBERS DECLARATION =================== @@ -136,6 +136,214 @@ IL_00b8: ret } // end of method Switch::SparseIntegerSwitch + .method public hidebysig static string + SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 63 (0x3f) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brfalse.s IL_0021 + + IL_000b: ldloca.s V_0 + IL_000d: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0012: stloc.1 + IL_0013: ldloc.1 + IL_0014: brfalse.s IL_0027 + + IL_0016: ldloc.1 + IL_0017: ldc.i4.5 + IL_0018: beq.s IL_002d + + IL_001a: ldloc.1 + IL_001b: ldc.i4.s 10 + IL_001d: beq.s IL_0033 + + IL_001f: br.s IL_0039 + + IL_0021: ldstr "null" + IL_0026: ret + + IL_0027: ldstr "zero" + IL_002c: ret + + IL_002d: ldstr "five" + IL_0032: ret + + IL_0033: ldstr "ten" + IL_0038: ret + + IL_0039: ldstr "large" + IL_003e: ret + } // end of method Switch::SwitchOverNullableInt + + .method public hidebysig static string + SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 98 (0x62) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.1 + IL_0002: ldloca.s V_1 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brtrue.s IL_0016 + + IL_000b: ldloca.s V_2 + IL_000d: initobj valuetype [mscorlib]System.Nullable`1 + IL_0013: ldloc.2 + IL_0014: br.s IL_0024 + + IL_0016: ldloca.s V_1 + IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001d: ldc.i4.5 + IL_001e: add + IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0024: stloc.0 + IL_0025: ldloca.s V_0 + IL_0027: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_002c: brfalse.s IL_0044 + + IL_002e: ldloca.s V_0 + IL_0030: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0035: stloc.3 + IL_0036: ldloc.3 + IL_0037: brfalse.s IL_004a + + IL_0039: ldloc.3 + IL_003a: ldc.i4.5 + IL_003b: beq.s IL_0050 + + IL_003d: ldloc.3 + IL_003e: ldc.i4.s 10 + IL_0040: beq.s IL_0056 + + IL_0042: br.s IL_005c + + IL_0044: ldstr "null" + IL_0049: ret + + IL_004a: ldstr "zero" + IL_004f: ret + + IL_0050: ldstr "five" + IL_0055: ret + + IL_0056: ldstr "ten" + IL_005b: ret + + IL_005c: ldstr "large" + IL_0061: ret + } // end of method Switch::SwitchOverNullableIntShifted + + .method public hidebysig static string + SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 57 (0x39) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brfalse.s IL_0033 + + IL_000b: ldloca.s V_0 + IL_000d: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0012: stloc.1 + IL_0013: ldloc.1 + IL_0014: brfalse.s IL_0021 + + IL_0016: ldloc.1 + IL_0017: ldc.i4.5 + IL_0018: beq.s IL_0027 + + IL_001a: ldloc.1 + IL_001b: ldc.i4.s 10 + IL_001d: beq.s IL_002d + + IL_001f: br.s IL_0033 + + IL_0021: ldstr "zero" + IL_0026: ret + + IL_0027: ldstr "five" + IL_002c: ret + + IL_002d: ldstr "ten" + IL_0032: ret + + IL_0033: ldstr "other" + IL_0038: ret + } // end of method Switch::SwitchOverNullableIntNoNullCase + + .method public hidebysig static string + SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 92 (0x5c) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.1 + IL_0002: ldloca.s V_1 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brtrue.s IL_0016 + + IL_000b: ldloca.s V_2 + IL_000d: initobj valuetype [mscorlib]System.Nullable`1 + IL_0013: ldloc.2 + IL_0014: br.s IL_0024 + + IL_0016: ldloca.s V_1 + IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001d: ldc.i4.5 + IL_001e: add + IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0024: stloc.0 + IL_0025: ldloca.s V_0 + IL_0027: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_002c: brfalse.s IL_0056 + + IL_002e: ldloca.s V_0 + IL_0030: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0035: stloc.3 + IL_0036: ldloc.3 + IL_0037: brfalse.s IL_0044 + + IL_0039: ldloc.3 + IL_003a: ldc.i4.5 + IL_003b: beq.s IL_004a + + IL_003d: ldloc.3 + IL_003e: ldc.i4.s 10 + IL_0040: beq.s IL_0050 + + IL_0042: br.s IL_0056 + + IL_0044: ldstr "zero" + IL_0049: ret + + IL_004a: ldstr "five" + IL_004f: ret + + IL_0050: ldstr "ten" + IL_0055: ret + + IL_0056: ldstr "other" + IL_005b: ret + } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted + .method public hidebysig static string ShortSwitchOverString(string text) cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il index 0132ebf10..f94d258ba 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {08E636DF-9FF0-4BF4-9F8F-69859C40E218} +// MVID: {7C3CB7C3-DBBF-4EB8-ACC1-E7AFA899FD3B} .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: 0x02E70000 +// Image base: 0x019E0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -177,6 +177,280 @@ IL_00ed: ret } // end of method Switch::SparseIntegerSwitch + .method public hidebysig static string + SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 82 (0x52) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + int32 V_2, + string V_3) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: stloc.0 + IL_0005: ldloca.s V_0 + IL_0007: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000c: brfalse.s IL_0028 + + IL_000e: ldloca.s V_0 + IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0015: stloc.2 + IL_0016: ldloc.2 + IL_0017: brfalse.s IL_0030 + + IL_0019: br.s IL_001b + + IL_001b: ldloc.2 + IL_001c: ldc.i4.5 + IL_001d: beq.s IL_0038 + + IL_001f: br.s IL_0021 + + IL_0021: ldloc.2 + IL_0022: ldc.i4.s 10 + IL_0024: beq.s IL_0040 + + IL_0026: br.s IL_0048 + + IL_0028: ldstr "null" + IL_002d: stloc.3 + IL_002e: br.s IL_0050 + + IL_0030: ldstr "zero" + IL_0035: stloc.3 + IL_0036: br.s IL_0050 + + IL_0038: ldstr "five" + IL_003d: stloc.3 + IL_003e: br.s IL_0050 + + IL_0040: ldstr "ten" + IL_0045: stloc.3 + IL_0046: br.s IL_0050 + + IL_0048: ldstr "large" + IL_004d: stloc.3 + IL_004e: br.s IL_0050 + + IL_0050: ldloc.3 + IL_0051: ret + } // end of method Switch::SwitchOverNullableInt + + .method public hidebysig static string + SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 127 (0x7f) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + valuetype [mscorlib]System.Nullable`1 V_3, + int32 V_4, + string V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.2 + IL_0003: ldloca.s V_2 + IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000a: brtrue.s IL_0017 + + IL_000c: ldloca.s V_3 + IL_000e: initobj valuetype [mscorlib]System.Nullable`1 + IL_0014: ldloc.3 + IL_0015: br.s IL_0025 + + IL_0017: ldloca.s V_2 + IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001e: ldc.i4.5 + IL_001f: add + IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0025: stloc.1 + IL_0026: ldloc.1 + IL_0027: stloc.0 + IL_0028: ldloca.s V_0 + IL_002a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_002f: brfalse.s IL_004f + + IL_0031: ldloca.s V_0 + IL_0033: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0038: stloc.s V_4 + IL_003a: ldloc.s V_4 + IL_003c: brfalse.s IL_0058 + + IL_003e: br.s IL_0040 + + IL_0040: ldloc.s V_4 + IL_0042: ldc.i4.5 + IL_0043: beq.s IL_0061 + + IL_0045: br.s IL_0047 + + IL_0047: ldloc.s V_4 + IL_0049: ldc.i4.s 10 + IL_004b: beq.s IL_006a + + IL_004d: br.s IL_0073 + + IL_004f: ldstr "null" + IL_0054: stloc.s V_5 + IL_0056: br.s IL_007c + + IL_0058: ldstr "zero" + IL_005d: stloc.s V_5 + IL_005f: br.s IL_007c + + IL_0061: ldstr "five" + IL_0066: stloc.s V_5 + IL_0068: br.s IL_007c + + IL_006a: ldstr "ten" + IL_006f: stloc.s V_5 + IL_0071: br.s IL_007c + + IL_0073: ldstr "large" + IL_0078: stloc.s V_5 + IL_007a: br.s IL_007c + + IL_007c: ldloc.s V_5 + IL_007e: ret + } // end of method Switch::SwitchOverNullableIntShifted + + .method public hidebysig static string + SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 74 (0x4a) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + int32 V_2, + string V_3) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: stloc.0 + IL_0005: ldloca.s V_0 + IL_0007: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000c: brfalse.s IL_0040 + + IL_000e: ldloca.s V_0 + IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0015: stloc.2 + IL_0016: ldloc.2 + IL_0017: brfalse.s IL_0028 + + IL_0019: br.s IL_001b + + IL_001b: ldloc.2 + IL_001c: ldc.i4.5 + IL_001d: beq.s IL_0030 + + IL_001f: br.s IL_0021 + + IL_0021: ldloc.2 + IL_0022: ldc.i4.s 10 + IL_0024: beq.s IL_0038 + + IL_0026: br.s IL_0040 + + IL_0028: ldstr "zero" + IL_002d: stloc.3 + IL_002e: br.s IL_0048 + + IL_0030: ldstr "five" + IL_0035: stloc.3 + IL_0036: br.s IL_0048 + + IL_0038: ldstr "ten" + IL_003d: stloc.3 + IL_003e: br.s IL_0048 + + IL_0040: ldstr "other" + IL_0045: stloc.3 + IL_0046: br.s IL_0048 + + IL_0048: ldloc.3 + IL_0049: ret + } // end of method Switch::SwitchOverNullableIntNoNullCase + + .method public hidebysig static string + SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 118 (0x76) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + valuetype [mscorlib]System.Nullable`1 V_3, + int32 V_4, + string V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.2 + IL_0003: ldloca.s V_2 + IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000a: brtrue.s IL_0017 + + IL_000c: ldloca.s V_3 + IL_000e: initobj valuetype [mscorlib]System.Nullable`1 + IL_0014: ldloc.3 + IL_0015: br.s IL_0025 + + IL_0017: ldloca.s V_2 + IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001e: ldc.i4.5 + IL_001f: add + IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0025: stloc.1 + IL_0026: ldloc.1 + IL_0027: stloc.0 + IL_0028: ldloca.s V_0 + IL_002a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_002f: brfalse.s IL_006a + + IL_0031: ldloca.s V_0 + IL_0033: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0038: stloc.s V_4 + IL_003a: ldloc.s V_4 + IL_003c: brfalse.s IL_004f + + IL_003e: br.s IL_0040 + + IL_0040: ldloc.s V_4 + IL_0042: ldc.i4.5 + IL_0043: beq.s IL_0058 + + IL_0045: br.s IL_0047 + + IL_0047: ldloc.s V_4 + IL_0049: ldc.i4.s 10 + IL_004b: beq.s IL_0061 + + IL_004d: br.s IL_006a + + IL_004f: ldstr "zero" + IL_0054: stloc.s V_5 + IL_0056: br.s IL_0073 + + IL_0058: ldstr "five" + IL_005d: stloc.s V_5 + IL_005f: br.s IL_0073 + + IL_0061: ldstr "ten" + IL_0066: stloc.s V_5 + IL_0068: br.s IL_0073 + + IL_006a: ldstr "other" + IL_006f: stloc.s V_5 + IL_0071: br.s IL_0073 + + IL_0073: ldloc.s V_5 + IL_0075: ret + } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted + .method public hidebysig static string ShortSwitchOverString(string text) cil managed { @@ -424,11 +698,12 @@ .method public hidebysig static string SwitchOverString2() cil managed { - // Code size 518 (0x206) + // Code size 520 (0x208) .maxstack 2 .locals init (string V_0, - uint32 V_1, - string V_2) + string V_1, + uint32 V_2, + string V_3) IL_0000: nop IL_0001: ldstr "SwitchOverString2:" IL_0006: call void [mscorlib]System.Console::WriteLine(string) @@ -436,236 +711,238 @@ IL_000c: call string [mscorlib]System.Environment::get_UserName() IL_0011: stloc.0 IL_0012: ldloc.0 - IL_0013: call uint32 ''::ComputeStringHash(string) - IL_0018: stloc.1 - IL_0019: ldloc.1 - IL_001a: ldc.i4 0x4c7c71f6 - IL_001f: bgt.un.s IL_0070 + IL_0013: stloc.1 + IL_0014: ldloc.1 + IL_0015: call uint32 ''::ComputeStringHash(string) + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldc.i4 0x4c7c71f6 + IL_0021: bgt.un.s IL_0072 - IL_0021: ldloc.1 - IL_0022: ldc.i4 0xc9a8f4f - IL_0027: bgt.un.s IL_0046 + IL_0023: ldloc.2 + IL_0024: ldc.i4 0xc9a8f4f + IL_0029: bgt.un.s IL_0048 - IL_0029: ldloc.1 - IL_002a: ldc.i4 0x8861b86 - IL_002f: beq IL_011a + IL_002b: ldloc.2 + IL_002c: ldc.i4 0x8861b86 + IL_0031: beq IL_011c - IL_0034: br.s IL_0036 + IL_0036: br.s IL_0038 - IL_0036: ldloc.1 - IL_0037: ldc.i4 0xc9a8f4f - IL_003c: beq IL_00c6 + IL_0038: ldloc.2 + IL_0039: ldc.i4 0xc9a8f4f + IL_003e: beq IL_00c8 - IL_0041: br IL_01fb + IL_0043: br IL_01fd - IL_0046: ldloc.1 - IL_0047: ldc.i4 0xf3d44a6 - IL_004c: beq IL_00f0 + IL_0048: ldloc.2 + IL_0049: ldc.i4 0xf3d44a6 + IL_004e: beq IL_00f2 - IL_0051: br.s IL_0053 + IL_0053: br.s IL_0055 - IL_0053: ldloc.1 - IL_0054: ldc.i4 0x20289804 - IL_0059: beq IL_0156 + IL_0055: ldloc.2 + IL_0056: ldc.i4 0x20289804 + IL_005b: beq IL_0158 - IL_005e: br.s IL_0060 + IL_0060: br.s IL_0062 - IL_0060: ldloc.1 - IL_0061: ldc.i4 0x4c7c71f6 - IL_0066: beq IL_0168 + IL_0062: ldloc.2 + IL_0063: ldc.i4 0x4c7c71f6 + IL_0068: beq IL_016a - IL_006b: br IL_01fb + IL_006d: br IL_01fd - IL_0070: ldloc.1 - IL_0071: ldc.i4 0xa151b28a - IL_0076: bgt.un.s IL_00a2 + IL_0072: ldloc.2 + IL_0073: ldc.i4 0xa151b28a + IL_0078: bgt.un.s IL_00a4 - IL_0078: ldloc.1 - IL_0079: ldc.i4 0x4d0cea48 - IL_007e: beq IL_0189 + IL_007a: ldloc.2 + IL_007b: ldc.i4 0x4d0cea48 + IL_0080: beq IL_018b - IL_0083: br.s IL_0085 + IL_0085: br.s IL_0087 - IL_0085: ldloc.1 - IL_0086: ldc.i4 0x51650fb9 - IL_008b: beq IL_012f + IL_0087: ldloc.2 + IL_0088: ldc.i4 0x51650fb9 + IL_008d: beq IL_0131 - IL_0090: br.s IL_0092 + IL_0092: br.s IL_0094 - IL_0092: ldloc.1 - IL_0093: ldc.i4 0xa151b28a - IL_0098: beq IL_0144 + IL_0094: ldloc.2 + IL_0095: ldc.i4 0xa151b28a + IL_009a: beq IL_0146 - IL_009d: br IL_01fb + IL_009f: br IL_01fd - IL_00a2: ldloc.1 - IL_00a3: ldc.i4 0xea3d096b - IL_00a8: beq.s IL_00db + IL_00a4: ldloc.2 + IL_00a5: ldc.i4 0xea3d096b + IL_00aa: beq.s IL_00dd - IL_00aa: br.s IL_00ac + IL_00ac: br.s IL_00ae - IL_00ac: ldloc.1 - IL_00ad: ldc.i4 0xed5134d4 - IL_00b2: beq IL_017a + IL_00ae: ldloc.2 + IL_00af: ldc.i4 0xed5134d4 + IL_00b4: beq IL_017c - IL_00b7: br.s IL_00b9 + IL_00b9: br.s IL_00bb - IL_00b9: ldloc.1 - IL_00ba: ldc.i4 0xf701cc7f - IL_00bf: beq.s IL_0105 + IL_00bb: ldloc.2 + IL_00bc: ldc.i4 0xf701cc7f + IL_00c1: beq.s IL_0107 - IL_00c1: br IL_01fb + IL_00c3: br IL_01fd - IL_00c6: ldloc.0 - IL_00c7: ldstr "First case" - IL_00cc: call bool [mscorlib]System.String::op_Equality(string, + IL_00c8: ldloc.1 + IL_00c9: ldstr "First case" + IL_00ce: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00d1: brtrue IL_0198 + IL_00d3: brtrue IL_019a - IL_00d6: br IL_01fb + IL_00d8: br IL_01fd - IL_00db: ldloc.0 - IL_00dc: ldstr "Second case" - IL_00e1: call bool [mscorlib]System.String::op_Equality(string, + IL_00dd: ldloc.1 + IL_00de: ldstr "Second case" + IL_00e3: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00e6: brtrue IL_01a1 + IL_00e8: brtrue IL_01a3 - IL_00eb: br IL_01fb + IL_00ed: br IL_01fd - IL_00f0: ldloc.0 - IL_00f1: ldstr "Third case" - IL_00f6: call bool [mscorlib]System.String::op_Equality(string, + IL_00f2: ldloc.1 + IL_00f3: ldstr "Third case" + IL_00f8: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00fb: brtrue IL_01aa + IL_00fd: brtrue IL_01ac - IL_0100: br IL_01fb + IL_0102: br IL_01fd - IL_0105: ldloc.0 - IL_0106: ldstr "Fourth case" - IL_010b: call bool [mscorlib]System.String::op_Equality(string, + IL_0107: ldloc.1 + IL_0108: ldstr "Fourth case" + IL_010d: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0110: brtrue IL_01b3 + IL_0112: brtrue IL_01b5 - IL_0115: br IL_01fb + IL_0117: br IL_01fd - IL_011a: ldloc.0 - IL_011b: ldstr "Fifth case" - IL_0120: call bool [mscorlib]System.String::op_Equality(string, + IL_011c: ldloc.1 + IL_011d: ldstr "Fifth case" + IL_0122: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0125: brtrue IL_01bc + IL_0127: brtrue IL_01be - IL_012a: br IL_01fb + IL_012c: br IL_01fd - IL_012f: ldloc.0 - IL_0130: ldstr "Sixth case" - IL_0135: call bool [mscorlib]System.String::op_Equality(string, + IL_0131: ldloc.1 + IL_0132: ldstr "Sixth case" + IL_0137: call bool [mscorlib]System.String::op_Equality(string, string) - IL_013a: brtrue IL_01c5 + IL_013c: brtrue IL_01c7 - IL_013f: br IL_01fb + IL_0141: br IL_01fd - IL_0144: ldloc.0 - IL_0145: ldstr "Seventh case" - IL_014a: call bool [mscorlib]System.String::op_Equality(string, + IL_0146: ldloc.1 + IL_0147: ldstr "Seventh case" + IL_014c: call bool [mscorlib]System.String::op_Equality(string, string) - IL_014f: brtrue.s IL_01ce + IL_0151: brtrue.s IL_01d0 - IL_0151: br IL_01fb + IL_0153: br IL_01fd - IL_0156: ldloc.0 - IL_0157: ldstr "Eighth case" - IL_015c: call bool [mscorlib]System.String::op_Equality(string, + IL_0158: ldloc.1 + IL_0159: ldstr "Eighth case" + IL_015e: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0161: brtrue.s IL_01d7 + IL_0163: brtrue.s IL_01d9 - IL_0163: br IL_01fb + IL_0165: br IL_01fd - IL_0168: ldloc.0 - IL_0169: ldstr "Ninth case" - IL_016e: call bool [mscorlib]System.String::op_Equality(string, + IL_016a: ldloc.1 + IL_016b: ldstr "Ninth case" + IL_0170: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0173: brtrue.s IL_01e0 + IL_0175: brtrue.s IL_01e2 - IL_0175: br IL_01fb + IL_0177: br IL_01fd - IL_017a: ldloc.0 - IL_017b: ldstr "Tenth case" - IL_0180: call bool [mscorlib]System.String::op_Equality(string, + IL_017c: ldloc.1 + IL_017d: ldstr "Tenth case" + IL_0182: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0185: brtrue.s IL_01e9 + IL_0187: brtrue.s IL_01eb - IL_0187: br.s IL_01fb + IL_0189: br.s IL_01fd - IL_0189: ldloc.0 - IL_018a: ldstr "Eleventh case" - IL_018f: call bool [mscorlib]System.String::op_Equality(string, + IL_018b: ldloc.1 + IL_018c: ldstr "Eleventh case" + IL_0191: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0194: brtrue.s IL_01f2 - - IL_0196: br.s IL_01fb - - IL_0198: nop - IL_0199: ldstr "Text1" - IL_019e: stloc.2 - IL_019f: br.s IL_0204 - - IL_01a1: nop - IL_01a2: ldstr "Text2" - IL_01a7: stloc.2 - IL_01a8: br.s IL_0204 - - IL_01aa: nop - IL_01ab: ldstr "Text3" - IL_01b0: stloc.2 - IL_01b1: br.s IL_0204 - - IL_01b3: nop - IL_01b4: ldstr "Text4" - IL_01b9: stloc.2 - IL_01ba: br.s IL_0204 - - IL_01bc: nop - IL_01bd: ldstr "Text5" - IL_01c2: stloc.2 - IL_01c3: br.s IL_0204 - - IL_01c5: nop - IL_01c6: ldstr "Text6" - IL_01cb: stloc.2 - IL_01cc: br.s IL_0204 - - IL_01ce: nop - IL_01cf: ldstr "Text7" - IL_01d4: stloc.2 - IL_01d5: br.s IL_0204 - - IL_01d7: nop - IL_01d8: ldstr "Text8" - IL_01dd: stloc.2 - IL_01de: br.s IL_0204 - - IL_01e0: nop - IL_01e1: ldstr "Text9" - IL_01e6: stloc.2 - IL_01e7: br.s IL_0204 - - IL_01e9: nop - IL_01ea: ldstr "Text10" - IL_01ef: stloc.2 - IL_01f0: br.s IL_0204 - - IL_01f2: nop - IL_01f3: ldstr "Text11" - IL_01f8: stloc.2 - IL_01f9: br.s IL_0204 - - IL_01fb: nop - IL_01fc: ldstr "Default" - IL_0201: stloc.2 - IL_0202: br.s IL_0204 - - IL_0204: ldloc.2 - IL_0205: ret + IL_0196: brtrue.s IL_01f4 + + IL_0198: br.s IL_01fd + + IL_019a: nop + IL_019b: ldstr "Text1" + IL_01a0: stloc.3 + IL_01a1: br.s IL_0206 + + IL_01a3: nop + IL_01a4: ldstr "Text2" + IL_01a9: stloc.3 + IL_01aa: br.s IL_0206 + + IL_01ac: nop + IL_01ad: ldstr "Text3" + IL_01b2: stloc.3 + IL_01b3: br.s IL_0206 + + IL_01b5: nop + IL_01b6: ldstr "Text4" + IL_01bb: stloc.3 + IL_01bc: br.s IL_0206 + + IL_01be: nop + IL_01bf: ldstr "Text5" + IL_01c4: stloc.3 + IL_01c5: br.s IL_0206 + + IL_01c7: nop + IL_01c8: ldstr "Text6" + IL_01cd: stloc.3 + IL_01ce: br.s IL_0206 + + IL_01d0: nop + IL_01d1: ldstr "Text7" + IL_01d6: stloc.3 + IL_01d7: br.s IL_0206 + + IL_01d9: nop + IL_01da: ldstr "Text8" + IL_01df: stloc.3 + IL_01e0: br.s IL_0206 + + IL_01e2: nop + IL_01e3: ldstr "Text9" + IL_01e8: stloc.3 + IL_01e9: br.s IL_0206 + + IL_01eb: nop + IL_01ec: ldstr "Text10" + IL_01f1: stloc.3 + IL_01f2: br.s IL_0206 + + IL_01f4: nop + IL_01f5: ldstr "Text11" + IL_01fa: stloc.3 + IL_01fb: br.s IL_0206 + + IL_01fd: nop + IL_01fe: ldstr "Default" + IL_0203: stloc.3 + IL_0204: br.s IL_0206 + + IL_0206: ldloc.3 + IL_0207: ret } // end of method Switch::SwitchOverString2 .method public hidebysig static string @@ -717,7 +994,7 @@ .method public hidebysig static void SwitchInLoop(int32 i) cil managed { - // Code size 141 (0x8d) + // Code size 146 (0x92) .maxstack 2 .locals init (int32 V_0, bool V_1) @@ -729,7 +1006,7 @@ object) IL_0011: call void [mscorlib]System.Console::WriteLine(string) IL_0016: nop - IL_0017: br.s IL_0088 + IL_0017: br.s IL_008d IL_0019: nop IL_001a: ldarg.0 @@ -739,54 +1016,59 @@ IL_001e: sub IL_001f: switch ( IL_0036, - IL_0043, - IL_0050, - IL_005d) - IL_0034: br.s IL_006a - - IL_0036: ldstr "one" - IL_003b: call void [mscorlib]System.Console::WriteLine(string) - IL_0040: nop - IL_0041: br.s IL_0082 - - IL_0043: ldstr "two" - IL_0048: call void [mscorlib]System.Console::WriteLine(string) - IL_004d: nop - IL_004e: br.s IL_0082 - - IL_0050: ldstr "three" - IL_0055: call void [mscorlib]System.Console::WriteLine(string) - IL_005a: nop - IL_005b: br.s IL_0088 - - IL_005d: ldstr "four" - IL_0062: call void [mscorlib]System.Console::WriteLine(string) - IL_0067: nop - IL_0068: br.s IL_008c - - IL_006a: ldstr "default" - IL_006f: call void [mscorlib]System.Console::WriteLine(string) - IL_0074: nop - IL_0075: ldstr "more code" - IL_007a: call void [mscorlib]System.Console::WriteLine(string) - IL_007f: nop - IL_0080: br.s IL_008c - - IL_0082: ldarg.0 - IL_0083: ldc.i4.1 - IL_0084: add - IL_0085: starg.s i - IL_0087: nop + IL_0044, + IL_0052, + IL_0060) + IL_0034: br.s IL_006e + + IL_0036: nop + IL_0037: ldstr "one" + IL_003c: call void [mscorlib]System.Console::WriteLine(string) + IL_0041: nop + IL_0042: br.s IL_0087 + + IL_0044: nop + IL_0045: ldstr "two" + IL_004a: call void [mscorlib]System.Console::WriteLine(string) + IL_004f: nop + IL_0050: br.s IL_0087 + + IL_0052: nop + IL_0053: ldstr "three" + IL_0058: call void [mscorlib]System.Console::WriteLine(string) + IL_005d: nop + IL_005e: br.s IL_008d + + IL_0060: nop + IL_0061: ldstr "four" + IL_0066: call void [mscorlib]System.Console::WriteLine(string) + IL_006b: nop + IL_006c: br.s IL_0091 + + IL_006e: nop + IL_006f: ldstr "default" + IL_0074: call void [mscorlib]System.Console::WriteLine(string) + IL_0079: nop + IL_007a: ldstr "more code" + IL_007f: call void [mscorlib]System.Console::WriteLine(string) + IL_0084: nop + IL_0085: br.s IL_0091 + + IL_0087: ldarg.0 IL_0088: ldc.i4.1 - IL_0089: stloc.1 - IL_008a: br.s IL_0019 - - IL_008c: ret + IL_0089: add + IL_008a: starg.s i + IL_008c: nop + IL_008d: ldc.i4.1 + IL_008e: stloc.1 + IL_008f: br.s IL_0019 + + IL_0091: ret } // end of method Switch::SwitchInLoop .method public hidebysig static void SwitchWithGoto(int32 i) cil managed { - // Code size 117 (0x75) + // Code size 122 (0x7a) .maxstack 2 .locals init (int32 V_0) IL_0000: nop @@ -804,37 +1086,42 @@ IL_001b: sub IL_001c: switch ( IL_0033, - IL_0040, - IL_004d, - IL_005a) - IL_0031: br.s IL_0067 + IL_0041, + IL_004f, + IL_005d) + IL_0031: br.s IL_006b - IL_0033: ldstr "one" - IL_0038: call void [mscorlib]System.Console::WriteLine(string) - IL_003d: nop - IL_003e: br.s IL_0067 + IL_0033: nop + IL_0034: ldstr "one" + IL_0039: call void [mscorlib]System.Console::WriteLine(string) + IL_003e: nop + IL_003f: br.s IL_006b - IL_0040: ldstr "two" - IL_0045: call void [mscorlib]System.Console::WriteLine(string) - IL_004a: nop - IL_004b: br.s IL_004d + IL_0041: nop + IL_0042: ldstr "two" + IL_0047: call void [mscorlib]System.Console::WriteLine(string) + IL_004c: nop + IL_004d: br.s IL_004f - IL_004d: ldstr "three" - IL_0052: call void [mscorlib]System.Console::WriteLine(string) - IL_0057: nop - IL_0058: br.s IL_0074 + IL_004f: nop + IL_0050: ldstr "three" + IL_0055: call void [mscorlib]System.Console::WriteLine(string) + IL_005a: nop + IL_005b: br.s IL_0079 - IL_005a: ldstr "four" - IL_005f: call void [mscorlib]System.Console::WriteLine(string) - IL_0064: nop - IL_0065: br.s IL_0074 + IL_005d: nop + IL_005e: ldstr "four" + IL_0063: call void [mscorlib]System.Console::WriteLine(string) + IL_0068: nop + IL_0069: br.s IL_0079 - IL_0067: ldstr "default" - IL_006c: call void [mscorlib]System.Console::WriteLine(string) - IL_0071: nop - IL_0072: br.s IL_0074 + IL_006b: nop + IL_006c: ldstr "default" + IL_0071: call void [mscorlib]System.Console::WriteLine(string) + IL_0076: nop + IL_0077: br.s IL_0079 - IL_0074: ret + IL_0079: ret } // end of method Switch::SwitchWithGoto } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch From ef4dd6431eca770dbfc5b0fbbd72ae2722c49cd9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 4 Oct 2017 22:51:48 +0200 Subject: [PATCH 014/190] Add documentation to InlineReturnTransform and SwitchOnStringTransform --- .../IL/Transforms/InlineReturnTransform.cs | 88 +++++++++++-------- .../IL/Transforms/SwitchOnStringTransform.cs | 43 ++++++++- 2 files changed, 89 insertions(+), 42 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/InlineReturnTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/InlineReturnTransform.cs index ae5138358..7245316c4 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/InlineReturnTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/InlineReturnTransform.cs @@ -23,61 +23,73 @@ using System.Linq; namespace ICSharpCode.Decompiler.IL.Transforms { /// - /// This transform duplicates return blocks if they return a local variable that was assigned right before thie return. + /// This transform duplicates return blocks if they return a local variable that was assigned right before the return. /// class InlineReturnTransform : IILTransform { public void Run(ILFunction function, ILTransformContext context) { var instructionsToModify = new List<(BlockContainer, Block, Branch)>(); - var possibleReturnVars = new Queue<(ILVariable, Block)>(); - var tempList = new List<(BlockContainer, Block, Branch)>(); + // Process all leave instructions in a leave-block, that is a block consisting solely of a leave instruction. foreach (var leave in function.Descendants.OfType()) { - if (!(leave.Parent is Block b && b.Instructions.Count == 1)) + if (!(leave.Parent is Block leaveBlock && leaveBlock.Instructions.Count == 1)) continue; + // Skip, if the leave instruction has no value or the value is not a load of a local variable. if (!leave.Value.MatchLdLoc(out var returnVar) || returnVar.Kind != VariableKind.Local) continue; - possibleReturnVars.Enqueue((returnVar, b)); + // If all instructions can be modified, add item to the global list. + if (CanModifyInstructions(returnVar, leaveBlock, out var list)); + instructionsToModify.AddRange(list); } - while (possibleReturnVars.Count > 0) { - var (returnVar, leaveBlock) = possibleReturnVars.Dequeue(); - bool transform = true; - foreach (StLoc store in returnVar.StoreInstructions.OfType()) { - if (!(store.Parent is Block storeBlock)) { - transform = false; - break; - } - if (store.ChildIndex + 2 != storeBlock.Instructions.Count) { - transform = false; - break; - } - if (!(storeBlock.Instructions[store.ChildIndex + 1] is Branch br)) { - transform = false; - break; - } - if (br.TargetBlock != leaveBlock) { - transform = false; - break; - } - var targetBlockContainer = BlockContainer.FindClosestContainer(store); - if (targetBlockContainer == null) { - transform = false; - break; - } - tempList.Add((targetBlockContainer, leaveBlock, br)); + foreach (var (container, b, br) in instructionsToModify) { + Block block = b; + // if there is only one branch to this return block, move it to the matching container. + // otherwise duplicate the return block. + if (block.IncomingEdgeCount == 1) { + block.Remove(); + } else { + block = (Block)block.Clone(); } - if (transform) - instructionsToModify.AddRange(tempList); - tempList.Clear(); + container.Blocks.Add(block); + // adjust the target of the branch to the newly created block. + br.TargetBlock = block; } + } - foreach (var (container, block, br) in instructionsToModify) { - var newBlock = (Block)block.Clone(); - container.Blocks.Add(newBlock); - br.TargetBlock = newBlock; + /// + /// Determines a list of all store instructions that write to a given . + /// Returns false if any of these instructions does not meet the following criteria: + /// - must be a stloc + /// - must be a direct child of a block + /// - must be the penultimate instruction + /// - must be followed by a branch instruction to + /// - must have a BlockContainer as ancestor. + /// Returns true, if all instructions meet these criteria, and contains a list of 3-tuples. + /// Each tuple consists of the target block container, the leave block, and the branch instruction that should be modified. + /// + static bool CanModifyInstructions(ILVariable returnVar, Block leaveBlock, out List<(BlockContainer, Block, Branch)> instructionsToModify) + { + instructionsToModify = new List<(BlockContainer, Block, Branch)>(); + foreach (var inst in returnVar.StoreInstructions) { + if (!(inst is StLoc store)) + return false; + if (!(store.Parent is Block storeBlock)) + return false; + if (store.ChildIndex + 2 != storeBlock.Instructions.Count) + return false; + if (!(storeBlock.Instructions[store.ChildIndex + 1] is Branch br)) + return false; + if (br.TargetBlock != leaveBlock) + return false; + var targetBlockContainer = BlockContainer.FindClosestContainer(store); + if (targetBlockContainer == null) + return false; + instructionsToModify.Add((targetBlockContainer, leaveBlock, br)); } + + return true; } } } diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index f0bbd13ae..70f0903f0 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -25,6 +25,9 @@ using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler.IL.Transforms { + /// + /// Detects switch-on-string patterns employed by the C# compiler and transforms them to an ILAst-switch-instruction. + /// class SwitchOnStringTransform : IILTransform { public void Run(ILFunction function, ILTransformContext context) @@ -78,6 +81,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms inst = null; blockAfterSwitch = null; // match first block: checking switch-value for null or first value (Roslyn) + // if (call op_Equality(ldloc switchValueVar, ldstr value)) br firstBlock + // -or- + // if (comp(ldloc switchValueVar == ldnull)) br defaultBlock if (!(instructions[i].MatchIfInstruction(out var condition, out var firstBlockJump))) return false; if (!firstBlockJump.MatchBranch(out var firstBlock)) @@ -85,32 +91,43 @@ namespace ICSharpCode.Decompiler.IL.Transforms bool isLegacy; Block defaultBlock; List<(string, Block)> values = new List<(string, Block)>(); + // match null check: this is used by the old C# compiler. if (condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && left.MatchLdLoc(out var switchValueVar)) { isLegacy = true; defaultBlock = firstBlock; + // Roslyn: match call to operator ==(string, string) } else if (MatchStringEqualityComparison(condition, out switchValueVar, out string value)) { isLegacy = false; defaultBlock = null; values.Add((value, firstBlock)); } else return false; + // switchValueVar must be assigned only once. if (!switchValueVar.IsSingleDefinition) return false; + // if instruction must be followed by a branch to the next case if (!(instructions.ElementAtOrDefault(i + 1) is Branch nextCaseJump)) return false; + // extract all cases and add them to the values list. Block currentCaseBlock = nextCaseJump.TargetBlock; Block nextCaseBlock; while ((nextCaseBlock = MatchCaseBlock(currentCaseBlock, ref switchValueVar, out string value, out Block block)) != null) { values.Add((value, block)); currentCaseBlock = nextCaseBlock; } + // the last instruction of the last case/default block must be either + // a branch to the a block after the switch statement or a leave instruction. var container = BlockContainer.FindClosestContainer(firstBlock); if (!ExtractLastJumpFromBlock(currentCaseBlock, out var exitBlock) && !ExtractLastLeaveFromBlock(currentCaseBlock, container)) return false; + // We didn't find any cases, exit if (values.Count == 0) return false; + // All case blocks must either leave the current block container or branch to the same block after the switch statement. if (!(values.All(b => ExtractLastJumpFromBlock(b.Item2, out var nextExit) && IsExitBlock(nextExit, container)) || (exitBlock == null && values.All(b => ExtractLastLeaveFromBlock(b.Item2, container))))) return false; + // if the block after the switch has the correct number of branches, generate the switch statement + // and return it and the block. if (currentCaseBlock.IncomingEdgeCount == (isLegacy ? 2 : 1)) { var sections = new List(values.SelectWithIndex((index, b) => new SwitchSection { Labels = new LongSet(index), Body = new Branch(b.Item2) })); var stringToInt = new StringToInt(new LdLoc(switchValueVar), values.SelectArray(item => item.Item1)); @@ -146,6 +163,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms return b == container; } + /// + /// Each case consists of two blocks: + /// 1. block: + /// if (call op_Equality(ldloc switchVariable, ldstr value)) br caseBlock + /// br nextBlock + /// This method matches the above pattern or its inverted form: + /// the call to ==(string, string) is wrapped in logic.not and the branch targets are reversed. + /// Returns the next block that follows in the block-chain. + /// The is updated if the value gets copied to a different variable. + /// See comments below for more info. + /// Block MatchCaseBlock(Block currentBlock, ref ILVariable switchVariable, out string value, out Block caseBlock) { value = null; @@ -167,10 +195,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!currentBlock.Instructions[1].MatchBranch(out nextBlock)) return null; } + // Sometimes the switch pattern uses one variable at the beginning for null checks + // and another variable for the if-else-if-else-pattern. + // both variables must be only assigned once and be of the type: System.String. if (!MatchStringEqualityComparison(condition, out var newSwitchVariable, out value)) return null; if (!newSwitchVariable.IsSingleDefinition) return null; + // if the used variable differs and both variables are not related, return null: if (switchVariable != newSwitchVariable && !(IsInitializedBy(switchVariable, newSwitchVariable) || IsInitializedBy(newSwitchVariable, switchVariable))) return null; if (!newSwitchVariable.Type.IsKnownType(KnownTypeCode.String)) @@ -179,14 +211,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms return nextBlock; } - bool IsInitializedBy(ILVariable switchVariable, ILVariable newSwitchVariable) + /// + /// Returns true if is only assigned once and the initialization is done by copying . + /// + bool IsInitializedBy(ILVariable left, ILVariable right) { - if (!switchVariable.IsSingleDefinition) + if (!left.IsSingleDefinition) return false; - var storeInst = switchVariable.StoreInstructions.OfType().SingleOrDefault(); + var storeInst = left.StoreInstructions.OfType().SingleOrDefault(); if (storeInst == null) return false; - return storeInst.Value.MatchLdLoc(newSwitchVariable); + return storeInst.Value.MatchLdLoc(right); } bool MatchLegacySwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst, out Block blockAfterSwitch) From fd775ec0823466adbe7375363f8437cc298ea290 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 5 Oct 2017 08:11:23 +0200 Subject: [PATCH 015/190] Fix threading bug in LoadedAssembly. --- .../DotNetCore/DotNetCorePathFinderExtensions.cs | 1 - ILSpy/LoadedAssembly.cs | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinderExtensions.cs b/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinderExtensions.cs index ced78ebf2..0fe9b4d63 100644 --- a/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinderExtensions.cs +++ b/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinderExtensions.cs @@ -8,7 +8,6 @@ using Newtonsoft.Json.Linq; namespace ICSharpCode.Decompiler { - public static class DotNetCorePathFinderExtensions { public static string DetectTargetFrameworkId(this AssemblyDefinition assembly) diff --git a/ILSpy/LoadedAssembly.cs b/ILSpy/LoadedAssembly.cs index 3b89c1951..e37683f02 100644 --- a/ILSpy/LoadedAssembly.cs +++ b/ILSpy/LoadedAssembly.cs @@ -51,13 +51,14 @@ namespace ICSharpCode.ILSpy this.assemblyTask = Task.Factory.StartNew(LoadAssembly, stream); // requires that this.fileName is set this.shortName = Path.GetFileNameWithoutExtension(fileName); - this.targetFrameworkId = new Lazy(AssemblyDefinition.DetectTargetFrameworkId, false); + this.targetFrameworkId = new Lazy(() => AssemblyDefinition?.DetectTargetFrameworkId(), false); } /// /// Returns a target framework identifier in the form '<framework>Version=v<version>'. + /// Returns an empty string if no TargetFrameworkAttribute was found or the file doesn't contain an assembly header, i.e., is only a module. /// - public string TargetFrameworkId => targetFrameworkId.Value; + public string TargetFrameworkId => targetFrameworkId.Value ?? string.Empty; public Dictionary LoadedAssemblyReferencesInfo => loadedAssemblyReferences; From 0fa58c3d53493f8fece34629f299badca1ac5379 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 5 Oct 2017 14:33:38 +0200 Subject: [PATCH 016/190] Fix #567: switch statement not properly decompile --- .../TestCases/Pretty/Switch.cs | 256 +++++--- .../TestCases/Pretty/Switch.il | 563 ++++++++---------- .../TestCases/Pretty/Switch.opt.il | 474 +++++++-------- .../TestCases/Pretty/Switch.opt.roslyn.il | 419 ++++++------- .../TestCases/Pretty/Switch.roslyn.il | 533 +++++++---------- .../IL/Transforms/SwitchOnStringTransform.cs | 18 +- 6 files changed, 1018 insertions(+), 1245 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index 4b31f0a2a..e5f42c278 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -17,11 +17,28 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Collections.Generic; +using System.Reflection; namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { public static class Switch { + public class SetProperty + { + public readonly PropertyInfo Property; + + public int Set { + get; + set; + } + + public SetProperty(PropertyInfo property) + { + this.Property = property; + } + } + public static string SparseIntegerSwitch(int i) { Console.WriteLine("SparseIntegerSwitch: " + i); @@ -65,83 +82,83 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } - public static string SwitchOverNullableInt(int? i) - { - switch (i) { - case null: { - return "null"; - } - case 0: { - return "zero"; - } - case 5: { - return "five"; - } - case 10: { - return "ten"; - } - default: { - return "large"; - } - } - } + //public static string SwitchOverNullableInt(int? i) + //{ + // switch (i) { + // case null: { + // return "null"; + // } + // case 0: { + // return "zero"; + // } + // case 5: { + // return "five"; + // } + // case 10: { + // return "ten"; + // } + // default: { + // return "large"; + // } + // } + //} - public static string SwitchOverNullableIntShifted(int? i) - { - switch (i + 5) { - case null: { - return "null"; - } - case 0: { - return "zero"; - } - case 5: { - return "five"; - } - case 10: { - return "ten"; - } - default: { - return "large"; - } - } - } + //public static string SwitchOverNullableIntShifted(int? i) + //{ + // switch (i + 5) { + // case null: { + // return "null"; + // } + // case 0: { + // return "zero"; + // } + // case 5: { + // return "five"; + // } + // case 10: { + // return "ten"; + // } + // default: { + // return "large"; + // } + // } + //} - public static string SwitchOverNullableIntNoNullCase(int? i) - { - switch (i) { - case 0: { - return "zero"; - } - case 5: { - return "five"; - } - case 10: { - return "ten"; - } - default: { - return "other"; - } - } - } + //public static string SwitchOverNullableIntNoNullCase(int? i) + //{ + // switch (i) { + // case 0: { + // return "zero"; + // } + // case 5: { + // return "five"; + // } + // case 10: { + // return "ten"; + // } + // default: { + // return "other"; + // } + // } + //} - public static string SwitchOverNullableIntNoNullCaseShifted(int? i) - { - switch (i + 5) { - case 0: { - return "zero"; - } - case 5: { - return "five"; - } - case 10: { - return "ten"; - } - default: { - return "other"; - } - } - } + //public static string SwitchOverNullableIntNoNullCaseShifted(int? i) + //{ + // switch (i + 5) { + // case 0: { + // return "zero"; + // } + // case 5: { + // return "five"; + // } + // case 10: { + // return "ten"; + // } + // default: { + // return "other"; + // } + // } + //} public static string ShortSwitchOverString(string text) { @@ -285,29 +302,76 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } - public static void SwitchWithGoto(int i) + //public static void SwitchWithGoto(int i) + //{ + // Console.WriteLine("SwitchWithGoto: " + i); + // switch (i) { + // case 1: { + // Console.WriteLine("one"); + // goto default; + // } + // case 2: { + // Console.WriteLine("two"); + // goto case 3; + // } + // case 3: { + // Console.WriteLine("three"); + // break; + // } + // case 4: { + // Console.WriteLine("four"); + // return; + // } + // default: { + // Console.WriteLine("default"); + // break; + // } + // } + //} + + private static SetProperty[] GetProperties() { - Console.WriteLine("SwitchWithGoto: " + i); - switch (i) { - case 1: { - Console.WriteLine("one"); - goto default; - } - case 2: { - Console.WriteLine("two"); - goto case 3; - } - case 3: { - Console.WriteLine("three"); - break; - } - case 4: { - Console.WriteLine("four"); - return; - } - default: { - Console.WriteLine("default"); - break; + return new SetProperty[0]; + } + + public static void SwitchOnStringInForLoop() + { + List list = new List(); + List list2 = new List(); + SetProperty[] properties = Switch.GetProperties(); + for (int i = 0; i < properties.Length; i++) { + SetProperty setProperty = properties[i]; + string name = setProperty.Property.Name; + switch (name) { + case "Name1": { + setProperty.Set = 1; + list.Add(setProperty); + break; + } + case "Name2": { + setProperty.Set = 2; + list.Add(setProperty); + break; + } + case "Name3": { + setProperty.Set = 3; + list.Add(setProperty); + break; + } + case "Name4": { + setProperty.Set = 4; + list.Add(setProperty); + break; + } + case "Name5": + case "Name6": { + list.Add(setProperty); + break; + } + default: { + list2.Add(setProperty); + break; + } } } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il index c64e70f03..eed5597a0 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il @@ -10,25 +10,25 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly iuizqapl +.assembly gn0oqkcb { - .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .permissionset reqmin = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module iuizqapl.dll -// MVID: {207B14E2-2177-4CF2-8D8E-2CD85A17CF5C} +.module gn0oqkcb.dll +// MVID: {D3E1C722-15E3-49C8-B86B-96413DA7BEEE} .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: 0x027D0000 +// Image base: 0x00C80000 // =============== CLASS MEMBERS DECLARATION =================== @@ -36,6 +36,63 @@ .class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch extends [mscorlib]System.Object { + .class auto ansi nested public beforefieldinit SetProperty + extends [mscorlib]System.Object + { + .field public initonly class [mscorlib]System.Reflection.PropertyInfo Property + .field private int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig specialname + instance int32 get_Set() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 11 (0xb) + .maxstack 1 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'k__BackingField' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method SetProperty::get_Set + + .method public hidebysig specialname + instance void set_Set(int32 'value') 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: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'k__BackingField' + IL_0007: ret + } // end of method SetProperty::set_Set + + .method public hidebysig specialname rtspecialname + instance void .ctor(class [mscorlib]System.Reflection.PropertyInfo 'property') cil managed + { + // Code size 17 (0x11) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: nop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property + IL_000f: nop + IL_0010: ret + } // end of method SetProperty::.ctor + + .property instance int32 Set() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::get_Set() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + } // end of property SetProperty::Set + } // end of class SetProperty + .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { @@ -157,250 +214,6 @@ IL_00df: ret } // end of method Switch::SparseIntegerSwitch - .method public hidebysig static string - SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 74 (0x4a) - .maxstack 2 - .locals init (string V_0, - int32 V_1) - IL_0000: nop - IL_0001: ldarga.s i - IL_0003: dup - IL_0004: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_0009: stloc.1 - IL_000a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_000f: brfalse.s IL_0020 - - IL_0011: ldloc.1 - IL_0012: ldc.i4.0 - IL_0013: beq.s IL_0028 - - IL_0015: ldloc.1 - IL_0016: ldc.i4.5 - IL_0017: beq.s IL_0030 - - IL_0019: ldloc.1 - IL_001a: ldc.i4.s 10 - IL_001c: beq.s IL_0038 - - IL_001e: br.s IL_0040 - - IL_0020: ldstr "null" - IL_0025: stloc.0 - IL_0026: br.s IL_0048 - - IL_0028: ldstr "zero" - IL_002d: stloc.0 - IL_002e: br.s IL_0048 - - IL_0030: ldstr "five" - IL_0035: stloc.0 - IL_0036: br.s IL_0048 - - IL_0038: ldstr "ten" - IL_003d: stloc.0 - IL_003e: br.s IL_0048 - - IL_0040: ldstr "large" - IL_0045: stloc.0 - IL_0046: br.s IL_0048 - - IL_0048: ldloc.0 - IL_0049: ret - } // end of method Switch::SwitchOverNullableInt - - .method public hidebysig static string - SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 112 (0x70) - .maxstack 2 - .locals init (string V_0, - valuetype [mscorlib]System.Nullable`1 V_1, - valuetype [mscorlib]System.Nullable`1 V_2, - int32 V_3) - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: stloc.1 - IL_0003: ldloca.s V_1 - IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_000a: brtrue.s IL_0017 - - IL_000c: ldloca.s V_2 - IL_000e: initobj valuetype [mscorlib]System.Nullable`1 - IL_0014: ldloc.2 - IL_0015: br.s IL_0025 - - IL_0017: ldloca.s V_1 - IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_001e: ldc.i4.5 - IL_001f: add - IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) - IL_0025: nop - IL_0026: stloc.2 - IL_0027: ldloca.s V_2 - IL_0029: dup - IL_002a: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_002f: stloc.3 - IL_0030: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_0035: brfalse.s IL_0046 - - IL_0037: ldloc.3 - IL_0038: ldc.i4.0 - IL_0039: beq.s IL_004e - - IL_003b: ldloc.3 - IL_003c: ldc.i4.5 - IL_003d: beq.s IL_0056 - - IL_003f: ldloc.3 - IL_0040: ldc.i4.s 10 - IL_0042: beq.s IL_005e - - IL_0044: br.s IL_0066 - - IL_0046: ldstr "null" - IL_004b: stloc.0 - IL_004c: br.s IL_006e - - IL_004e: ldstr "zero" - IL_0053: stloc.0 - IL_0054: br.s IL_006e - - IL_0056: ldstr "five" - IL_005b: stloc.0 - IL_005c: br.s IL_006e - - IL_005e: ldstr "ten" - IL_0063: stloc.0 - IL_0064: br.s IL_006e - - IL_0066: ldstr "large" - IL_006b: stloc.0 - IL_006c: br.s IL_006e - - IL_006e: ldloc.0 - IL_006f: ret - } // end of method Switch::SwitchOverNullableIntShifted - - .method public hidebysig static string - SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 66 (0x42) - .maxstack 2 - .locals init (string V_0, - int32 V_1) - IL_0000: nop - IL_0001: ldarga.s i - IL_0003: dup - IL_0004: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_0009: stloc.1 - IL_000a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_000f: brfalse.s IL_0038 - - IL_0011: ldloc.1 - IL_0012: ldc.i4.0 - IL_0013: beq.s IL_0020 - - IL_0015: ldloc.1 - IL_0016: ldc.i4.5 - IL_0017: beq.s IL_0028 - - IL_0019: ldloc.1 - IL_001a: ldc.i4.s 10 - IL_001c: beq.s IL_0030 - - IL_001e: br.s IL_0038 - - IL_0020: ldstr "zero" - IL_0025: stloc.0 - IL_0026: br.s IL_0040 - - IL_0028: ldstr "five" - IL_002d: stloc.0 - IL_002e: br.s IL_0040 - - IL_0030: ldstr "ten" - IL_0035: stloc.0 - IL_0036: br.s IL_0040 - - IL_0038: ldstr "other" - IL_003d: stloc.0 - IL_003e: br.s IL_0040 - - IL_0040: ldloc.0 - IL_0041: ret - } // end of method Switch::SwitchOverNullableIntNoNullCase - - .method public hidebysig static string - SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 104 (0x68) - .maxstack 2 - .locals init (string V_0, - valuetype [mscorlib]System.Nullable`1 V_1, - valuetype [mscorlib]System.Nullable`1 V_2, - int32 V_3) - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: stloc.1 - IL_0003: ldloca.s V_1 - IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_000a: brtrue.s IL_0017 - - IL_000c: ldloca.s V_2 - IL_000e: initobj valuetype [mscorlib]System.Nullable`1 - IL_0014: ldloc.2 - IL_0015: br.s IL_0025 - - IL_0017: ldloca.s V_1 - IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_001e: ldc.i4.5 - IL_001f: add - IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) - IL_0025: nop - IL_0026: stloc.2 - IL_0027: ldloca.s V_2 - IL_0029: dup - IL_002a: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_002f: stloc.3 - IL_0030: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_0035: brfalse.s IL_005e - - IL_0037: ldloc.3 - IL_0038: ldc.i4.0 - IL_0039: beq.s IL_0046 - - IL_003b: ldloc.3 - IL_003c: ldc.i4.5 - IL_003d: beq.s IL_004e - - IL_003f: ldloc.3 - IL_0040: ldc.i4.s 10 - IL_0042: beq.s IL_0056 - - IL_0044: br.s IL_005e - - IL_0046: ldstr "zero" - IL_004b: stloc.0 - IL_004c: br.s IL_0066 - - IL_004e: ldstr "five" - IL_0053: stloc.0 - IL_0054: br.s IL_0066 - - IL_0056: ldstr "ten" - IL_005b: stloc.0 - IL_005c: br.s IL_0066 - - IL_005e: ldstr "other" - IL_0063: stloc.0 - IL_0064: br.s IL_0066 - - IL_0066: ldloc.0 - IL_0067: ret - } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted - .method public hidebysig static string ShortSwitchOverString(string text) cil managed { @@ -485,7 +298,7 @@ IL_0015: brfalse IL_00ef IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000007-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000003-1' IL_0021: brtrue.s IL_0084 IL_0023: ldc.i4.7 @@ -526,9 +339,9 @@ IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007d: volatile. - IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000007-1' + IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000003-1' IL_0084: volatile. - IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000007-1' + IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000003-1' IL_008b: ldloc.1 IL_008c: ldloca.s V_2 IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -611,7 +424,7 @@ IL_0015: brfalse IL_0165 IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000008-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000004-1' IL_0021: brtrue IL_00ba IL_0026: ldc.i4.s 11 @@ -672,9 +485,9 @@ IL_00ae: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00b3: volatile. - IL_00b5: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000008-1' + IL_00b5: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000004-1' IL_00ba: volatile. - IL_00bc: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000008-1' + IL_00bc: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000004-1' IL_00c1: ldloc.2 IL_00c2: ldloca.s V_3 IL_00c4: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -876,73 +689,201 @@ IL_0091: ret } // end of method Switch::SwitchInLoop - .method public hidebysig static void SwitchWithGoto(int32 i) cil managed + .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] + GetProperties() cil managed { - // Code size 122 (0x7a) - .maxstack 2 - .locals init (int32 V_0) + // Code size 12 (0xc) + .maxstack 1 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] V_0) IL_0000: nop - IL_0001: ldstr "SwitchWithGoto: " - IL_0006: ldarg.0 - IL_0007: box [mscorlib]System.Int32 - IL_000c: call string [mscorlib]System.String::Concat(object, - object) - IL_0011: call void [mscorlib]System.Console::WriteLine(string) - IL_0016: nop - IL_0017: ldarg.0 - IL_0018: stloc.0 - IL_0019: ldloc.0 - IL_001a: ldc.i4.1 - IL_001b: sub - IL_001c: switch ( - IL_0033, - IL_0041, - IL_004f, - IL_005d) - IL_0031: br.s IL_006b - - IL_0033: nop - IL_0034: ldstr "one" - IL_0039: call void [mscorlib]System.Console::WriteLine(string) - IL_003e: nop - IL_003f: br.s IL_006b - - IL_0041: nop - IL_0042: ldstr "two" - IL_0047: call void [mscorlib]System.Console::WriteLine(string) - IL_004c: nop - IL_004d: br.s IL_004f - - IL_004f: nop - IL_0050: ldstr "three" - IL_0055: call void [mscorlib]System.Console::WriteLine(string) - IL_005a: nop - IL_005b: br.s IL_0079 - - IL_005d: nop - IL_005e: ldstr "four" - IL_0063: call void [mscorlib]System.Console::WriteLine(string) - IL_0068: nop - IL_0069: br.s IL_0079 + IL_0001: ldc.i4.0 + IL_0002: newarr ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty + IL_0007: stloc.0 + IL_0008: br.s IL_000a - IL_006b: nop - IL_006c: ldstr "default" - IL_0071: call void [mscorlib]System.Console::WriteLine(string) - IL_0076: nop - IL_0077: br.s IL_0079 + IL_000a: ldloc.0 + IL_000b: ret + } // end of method Switch::GetProperties - IL_0079: ret - } // end of method Switch::SwitchWithGoto + .method public hidebysig static void SwitchOnStringInForLoop() cil managed + { + // Code size 334 (0x14e) + .maxstack 4 + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, + class [mscorlib]System.Collections.Generic.List`1 V_1, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] V_2, + int32 V_3, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty V_4, + string V_5, + string V_6, + int32 V_7, + bool V_8) + IL_0000: nop + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0006: stloc.0 + IL_0007: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000c: stloc.1 + IL_000d: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch::GetProperties() + IL_0012: stloc.2 + IL_0013: ldc.i4.0 + IL_0014: stloc.3 + IL_0015: br IL_013e + + IL_001a: nop + IL_001b: ldloc.2 + IL_001c: ldloc.3 + IL_001d: ldelem.ref + IL_001e: stloc.s V_4 + IL_0020: ldloc.s V_4 + IL_0022: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property + IL_0027: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() + IL_002c: stloc.s V_5 + IL_002e: ldloc.s V_5 + IL_0030: stloc.s V_6 + IL_0032: ldloc.s V_6 + IL_0034: brfalse IL_012d + + IL_0039: volatile. + IL_003b: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000008-1' + IL_0040: brtrue.s IL_0097 + + IL_0042: ldc.i4.6 + IL_0043: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_0048: dup + IL_0049: ldstr "Name1" + IL_004e: ldc.i4.0 + IL_004f: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0054: dup + IL_0055: ldstr "Name2" + IL_005a: ldc.i4.1 + IL_005b: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0060: dup + IL_0061: ldstr "Name3" + IL_0066: ldc.i4.2 + IL_0067: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_006c: dup + IL_006d: ldstr "Name4" + IL_0072: ldc.i4.3 + IL_0073: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0078: dup + IL_0079: ldstr "Name5" + IL_007e: ldc.i4.4 + IL_007f: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0084: dup + IL_0085: ldstr "Name6" + IL_008a: ldc.i4.5 + IL_008b: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0090: volatile. + IL_0092: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000008-1' + IL_0097: volatile. + IL_0099: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000008-1' + IL_009e: ldloc.s V_6 + IL_00a0: ldloca.s V_7 + IL_00a2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + !1&) + IL_00a7: brfalse IL_012d + + IL_00ac: ldloc.s V_7 + IL_00ae: switch ( + IL_00cd, + IL_00e2, + IL_00f7, + IL_010c, + IL_0121, + IL_0121) + IL_00cb: br.s IL_012d + + IL_00cd: nop + IL_00ce: ldloc.s V_4 + IL_00d0: ldc.i4.1 + IL_00d1: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00d6: nop + IL_00d7: ldloc.0 + IL_00d8: ldloc.s V_4 + IL_00da: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00df: nop + IL_00e0: br.s IL_0139 + + IL_00e2: nop + IL_00e3: ldloc.s V_4 + IL_00e5: ldc.i4.2 + IL_00e6: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00eb: nop + IL_00ec: ldloc.0 + IL_00ed: ldloc.s V_4 + IL_00ef: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00f4: nop + IL_00f5: br.s IL_0139 + + IL_00f7: nop + IL_00f8: ldloc.s V_4 + IL_00fa: ldc.i4.3 + IL_00fb: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_0100: nop + IL_0101: ldloc.0 + IL_0102: ldloc.s V_4 + IL_0104: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0109: nop + IL_010a: br.s IL_0139 + + IL_010c: nop + IL_010d: ldloc.s V_4 + IL_010f: ldc.i4.4 + IL_0110: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_0115: nop + IL_0116: ldloc.0 + IL_0117: ldloc.s V_4 + IL_0119: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_011e: nop + IL_011f: br.s IL_0139 + + IL_0121: nop + IL_0122: ldloc.0 + IL_0123: ldloc.s V_4 + IL_0125: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_012a: nop + IL_012b: br.s IL_0139 + + IL_012d: nop + IL_012e: ldloc.1 + IL_012f: ldloc.s V_4 + IL_0131: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0136: nop + IL_0137: br.s IL_0139 + + IL_0139: nop + IL_013a: ldloc.3 + IL_013b: ldc.i4.1 + IL_013c: add + IL_013d: stloc.3 + IL_013e: ldloc.3 + IL_013f: ldloc.2 + IL_0140: ldlen + IL_0141: conv.i4 + IL_0142: clt + IL_0144: stloc.s V_8 + IL_0146: ldloc.s V_8 + IL_0148: brtrue IL_001a + + IL_014d: ret + } // end of method Switch::SwitchOnStringInForLoop } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}' +.class private auto ansi '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000007-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000003-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000004-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000008-1' -} // end of class '{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}' +} // end of class '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il index 0765e0099..becdf49a9 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il @@ -10,25 +10,25 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly utwwumxi +.assembly zlaei1fn { - .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .permissionset reqmin = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module utwwumxi.dll -// MVID: {30E98C35-5F99-4742-941F-78E7F27D8BD5} +.module zlaei1fn.dll +// MVID: {64CCBA80-944A-4F77-9230-24B174DEE22A} .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: 0x02C70000 +// Image base: 0x00680000 // =============== CLASS MEMBERS DECLARATION =================== @@ -36,6 +36,55 @@ .class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch extends [mscorlib]System.Object { + .class auto ansi nested public beforefieldinit SetProperty + extends [mscorlib]System.Object + { + .field public initonly class [mscorlib]System.Reflection.PropertyInfo Property + .field private int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig specialname + instance int32 get_Set() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'k__BackingField' + IL_0006: ret + } // end of method SetProperty::get_Set + + .method public hidebysig specialname + instance void set_Set(int32 'value') 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: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'k__BackingField' + IL_0007: ret + } // end of method SetProperty::set_Set + + .method public hidebysig specialname rtspecialname + instance void .ctor(class [mscorlib]System.Reflection.PropertyInfo 'property') cil managed + { + // Code size 14 (0xe) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property + IL_000d: ret + } // end of method SetProperty::.ctor + + .property instance int32 Set() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::get_Set() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + } // end of property SetProperty::Set + } // end of class SetProperty + .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { @@ -127,212 +176,6 @@ IL_00b4: ret } // end of method Switch::SparseIntegerSwitch - .method public hidebysig static string - SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 61 (0x3d) - .maxstack 2 - .locals init (int32 V_0) - IL_0000: ldarga.s i - IL_0002: dup - IL_0003: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_0008: stloc.0 - IL_0009: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_000e: brfalse.s IL_001f - - IL_0010: ldloc.0 - IL_0011: ldc.i4.0 - IL_0012: beq.s IL_0025 - - IL_0014: ldloc.0 - IL_0015: ldc.i4.5 - IL_0016: beq.s IL_002b - - IL_0018: ldloc.0 - IL_0019: ldc.i4.s 10 - IL_001b: beq.s IL_0031 - - IL_001d: br.s IL_0037 - - IL_001f: ldstr "null" - IL_0024: ret - - IL_0025: ldstr "zero" - IL_002a: ret - - IL_002b: ldstr "five" - IL_0030: ret - - IL_0031: ldstr "ten" - IL_0036: ret - - IL_0037: ldstr "large" - IL_003c: ret - } // end of method Switch::SwitchOverNullableInt - - .method public hidebysig static string - SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 98 (0x62) - .maxstack 2 - .locals init (valuetype [mscorlib]System.Nullable`1 V_0, - valuetype [mscorlib]System.Nullable`1 V_1, - valuetype [mscorlib]System.Nullable`1 V_2, - int32 V_3) - IL_0000: ldarg.0 - IL_0001: stloc.0 - IL_0002: ldloca.s V_0 - IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_0009: brtrue.s IL_0016 - - IL_000b: ldloca.s V_1 - IL_000d: initobj valuetype [mscorlib]System.Nullable`1 - IL_0013: ldloc.1 - IL_0014: br.s IL_0024 - - IL_0016: ldloca.s V_0 - IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_001d: ldc.i4.5 - IL_001e: add - IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) - IL_0024: stloc.2 - IL_0025: ldloca.s V_2 - IL_0027: dup - IL_0028: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_002d: stloc.3 - IL_002e: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_0033: brfalse.s IL_0044 - - IL_0035: ldloc.3 - IL_0036: ldc.i4.0 - IL_0037: beq.s IL_004a - - IL_0039: ldloc.3 - IL_003a: ldc.i4.5 - IL_003b: beq.s IL_0050 - - IL_003d: ldloc.3 - IL_003e: ldc.i4.s 10 - IL_0040: beq.s IL_0056 - - IL_0042: br.s IL_005c - - IL_0044: ldstr "null" - IL_0049: ret - - IL_004a: ldstr "zero" - IL_004f: ret - - IL_0050: ldstr "five" - IL_0055: ret - - IL_0056: ldstr "ten" - IL_005b: ret - - IL_005c: ldstr "large" - IL_0061: ret - } // end of method Switch::SwitchOverNullableIntShifted - - .method public hidebysig static string - SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 55 (0x37) - .maxstack 2 - .locals init (int32 V_0) - IL_0000: ldarga.s i - IL_0002: dup - IL_0003: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_0008: stloc.0 - IL_0009: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_000e: brfalse.s IL_0031 - - IL_0010: ldloc.0 - IL_0011: ldc.i4.0 - IL_0012: beq.s IL_001f - - IL_0014: ldloc.0 - IL_0015: ldc.i4.5 - IL_0016: beq.s IL_0025 - - IL_0018: ldloc.0 - IL_0019: ldc.i4.s 10 - IL_001b: beq.s IL_002b - - IL_001d: br.s IL_0031 - - IL_001f: ldstr "zero" - IL_0024: ret - - IL_0025: ldstr "five" - IL_002a: ret - - IL_002b: ldstr "ten" - IL_0030: ret - - IL_0031: ldstr "other" - IL_0036: ret - } // end of method Switch::SwitchOverNullableIntNoNullCase - - .method public hidebysig static string - SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 92 (0x5c) - .maxstack 2 - .locals init (valuetype [mscorlib]System.Nullable`1 V_0, - valuetype [mscorlib]System.Nullable`1 V_1, - valuetype [mscorlib]System.Nullable`1 V_2, - int32 V_3) - IL_0000: ldarg.0 - IL_0001: stloc.0 - IL_0002: ldloca.s V_0 - IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_0009: brtrue.s IL_0016 - - IL_000b: ldloca.s V_1 - IL_000d: initobj valuetype [mscorlib]System.Nullable`1 - IL_0013: ldloc.1 - IL_0014: br.s IL_0024 - - IL_0016: ldloca.s V_0 - IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_001d: ldc.i4.5 - IL_001e: add - IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) - IL_0024: stloc.2 - IL_0025: ldloca.s V_2 - IL_0027: dup - IL_0028: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_002d: stloc.3 - IL_002e: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_0033: brfalse.s IL_0056 - - IL_0035: ldloc.3 - IL_0036: ldc.i4.0 - IL_0037: beq.s IL_0044 - - IL_0039: ldloc.3 - IL_003a: ldc.i4.5 - IL_003b: beq.s IL_004a - - IL_003d: ldloc.3 - IL_003e: ldc.i4.s 10 - IL_0040: beq.s IL_0050 - - IL_0042: br.s IL_0056 - - IL_0044: ldstr "zero" - IL_0049: ret - - IL_004a: ldstr "five" - IL_004f: ret - - IL_0050: ldstr "ten" - IL_0055: ret - - IL_0056: ldstr "other" - IL_005b: ret - } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted - .method public hidebysig static string ShortSwitchOverString(string text) cil managed { @@ -400,7 +243,7 @@ IL_0013: brfalse IL_00db IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000007-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000003-1' IL_001f: brtrue.s IL_0082 IL_0021: ldc.i4.7 @@ -441,9 +284,9 @@ IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007b: volatile. - IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000007-1' + IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000003-1' IL_0082: volatile. - IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000007-1' + IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000003-1' IL_0089: ldloc.0 IL_008a: ldloca.s V_1 IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -504,7 +347,7 @@ IL_0013: brfalse IL_013f IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000008-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000004-1' IL_001f: brtrue IL_00b8 IL_0024: ldc.i4.s 11 @@ -565,9 +408,9 @@ IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00b1: volatile. - IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000008-1' + IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000004-1' IL_00b8: volatile. - IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000008-1' + IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000004-1' IL_00bf: ldloc.1 IL_00c0: ldloca.s V_2 IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -708,57 +551,170 @@ IL_007a: br.s IL_0015 } // end of method Switch::SwitchInLoop - .method public hidebysig static void SwitchWithGoto(int32 i) cil managed + .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] + GetProperties() cil managed { - // Code size 104 (0x68) - .maxstack 2 - .locals init (int32 V_0) - IL_0000: ldstr "SwitchWithGoto: " - IL_0005: ldarg.0 - IL_0006: box [mscorlib]System.Int32 - IL_000b: call string [mscorlib]System.String::Concat(object, - object) - IL_0010: call void [mscorlib]System.Console::WriteLine(string) - IL_0015: ldarg.0 - IL_0016: stloc.0 - IL_0017: ldloc.0 - IL_0018: ldc.i4.1 - IL_0019: sub - IL_001a: switch ( - IL_0031, - IL_003d, - IL_0047, - IL_0052) - IL_002f: br.s IL_005d - - IL_0031: ldstr "one" - IL_0036: call void [mscorlib]System.Console::WriteLine(string) - IL_003b: br.s IL_005d - - IL_003d: ldstr "two" - IL_0042: call void [mscorlib]System.Console::WriteLine(string) - IL_0047: ldstr "three" - IL_004c: call void [mscorlib]System.Console::WriteLine(string) - IL_0051: ret - - IL_0052: ldstr "four" - IL_0057: call void [mscorlib]System.Console::WriteLine(string) - IL_005c: ret + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: newarr ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty + IL_0006: ret + } // end of method Switch::GetProperties + + .method public hidebysig static void SwitchOnStringInForLoop() cil managed + { + // Code size 303 (0x12f) + .maxstack 4 + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, + class [mscorlib]System.Collections.Generic.List`1 V_1, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] V_2, + int32 V_3, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty V_4, + string V_5, + string V_6, + int32 V_7) + IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0005: stloc.0 + IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000b: stloc.1 + IL_000c: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch::GetProperties() + IL_0011: stloc.2 + IL_0012: ldc.i4.0 + IL_0013: stloc.3 + IL_0014: br IL_0125 + + IL_0019: ldloc.2 + IL_001a: ldloc.3 + IL_001b: ldelem.ref + IL_001c: stloc.s V_4 + IL_001e: ldloc.s V_4 + IL_0020: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property + IL_0025: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() + IL_002a: stloc.s V_5 + IL_002c: ldloc.s V_5 + IL_002e: dup + IL_002f: stloc.s V_6 + IL_0031: brfalse IL_0119 + + IL_0036: volatile. + IL_0038: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000008-1' + IL_003d: brtrue.s IL_0094 + + IL_003f: ldc.i4.6 + IL_0040: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_0045: dup + IL_0046: ldstr "Name1" + IL_004b: ldc.i4.0 + IL_004c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0051: dup + IL_0052: ldstr "Name2" + IL_0057: ldc.i4.1 + IL_0058: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_005d: dup + IL_005e: ldstr "Name3" + IL_0063: ldc.i4.2 + IL_0064: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0069: dup + IL_006a: ldstr "Name4" + IL_006f: ldc.i4.3 + IL_0070: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0075: dup + IL_0076: ldstr "Name5" + IL_007b: ldc.i4.4 + IL_007c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0081: dup + IL_0082: ldstr "Name6" + IL_0087: ldc.i4.5 + IL_0088: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_008d: volatile. + IL_008f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000008-1' + IL_0094: volatile. + IL_0096: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000008-1' + IL_009b: ldloc.s V_6 + IL_009d: ldloca.s V_7 + IL_009f: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + !1&) + IL_00a4: brfalse.s IL_0119 - IL_005d: ldstr "default" - IL_0062: call void [mscorlib]System.Console::WriteLine(string) - IL_0067: ret - } // end of method Switch::SwitchWithGoto + IL_00a6: ldloc.s V_7 + IL_00a8: switch ( + IL_00c7, + IL_00d9, + IL_00eb, + IL_00fd, + IL_010f, + IL_010f) + IL_00c5: br.s IL_0119 + + IL_00c7: ldloc.s V_4 + IL_00c9: ldc.i4.1 + IL_00ca: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00cf: ldloc.0 + IL_00d0: ldloc.s V_4 + IL_00d2: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00d7: br.s IL_0121 + + IL_00d9: ldloc.s V_4 + IL_00db: ldc.i4.2 + IL_00dc: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00e1: ldloc.0 + IL_00e2: ldloc.s V_4 + IL_00e4: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00e9: br.s IL_0121 + + IL_00eb: ldloc.s V_4 + IL_00ed: ldc.i4.3 + IL_00ee: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00f3: ldloc.0 + IL_00f4: ldloc.s V_4 + IL_00f6: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00fb: br.s IL_0121 + + IL_00fd: ldloc.s V_4 + IL_00ff: ldc.i4.4 + IL_0100: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_0105: ldloc.0 + IL_0106: ldloc.s V_4 + IL_0108: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_010d: br.s IL_0121 + + IL_010f: ldloc.0 + IL_0110: ldloc.s V_4 + IL_0112: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0117: br.s IL_0121 + + IL_0119: ldloc.1 + IL_011a: ldloc.s V_4 + IL_011c: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0121: ldloc.3 + IL_0122: ldc.i4.1 + IL_0123: add + IL_0124: stloc.3 + IL_0125: ldloc.3 + IL_0126: ldloc.2 + IL_0127: ldlen + IL_0128: conv.i4 + IL_0129: blt IL_0019 + + IL_012e: ret + } // end of method Switch::SwitchOnStringInForLoop } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{30E98C35-5F99-4742-941F-78E7F27D8BD5}' +.class private auto ansi '{64CCBA80-944A-4F77-9230-24B174DEE22A}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000007-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000003-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000004-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000008-1' -} // end of class '{30E98C35-5F99-4742-941F-78E7F27D8BD5}' +} // end of class '{64CCBA80-944A-4F77-9230-24B174DEE22A}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il index ef1606d38..48993c1fe 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {E38DFC98-1601-4EC8-896E-FC0EA87D4437} +// MVID: {25FC064E-F764-4556-A3C7-F6570E457CDD} .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: 0x02590000 +// Image base: 0x00B30000 // =============== CLASS MEMBERS DECLARATION =================== @@ -40,6 +40,55 @@ .class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch extends [mscorlib]System.Object { + .class auto ansi nested public beforefieldinit SetProperty + extends [mscorlib]System.Object + { + .field public initonly class [mscorlib]System.Reflection.PropertyInfo Property + .field private int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig specialname + instance int32 get_Set() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'k__BackingField' + IL_0006: ret + } // end of method SetProperty::get_Set + + .method public hidebysig specialname + instance void set_Set(int32 'value') 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: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'k__BackingField' + IL_0007: ret + } // end of method SetProperty::set_Set + + .method public hidebysig specialname rtspecialname + instance void .ctor(class [mscorlib]System.Reflection.PropertyInfo 'property') cil managed + { + // Code size 14 (0xe) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property + IL_000d: ret + } // end of method SetProperty::.ctor + + .property instance int32 Set() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::get_Set() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + } // end of property SetProperty::Set + } // end of class SetProperty + .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { @@ -136,214 +185,6 @@ IL_00b8: ret } // end of method Switch::SparseIntegerSwitch - .method public hidebysig static string - SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 63 (0x3f) - .maxstack 2 - .locals init (valuetype [mscorlib]System.Nullable`1 V_0, - int32 V_1) - IL_0000: ldarg.0 - IL_0001: stloc.0 - IL_0002: ldloca.s V_0 - IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_0009: brfalse.s IL_0021 - - IL_000b: ldloca.s V_0 - IL_000d: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_0012: stloc.1 - IL_0013: ldloc.1 - IL_0014: brfalse.s IL_0027 - - IL_0016: ldloc.1 - IL_0017: ldc.i4.5 - IL_0018: beq.s IL_002d - - IL_001a: ldloc.1 - IL_001b: ldc.i4.s 10 - IL_001d: beq.s IL_0033 - - IL_001f: br.s IL_0039 - - IL_0021: ldstr "null" - IL_0026: ret - - IL_0027: ldstr "zero" - IL_002c: ret - - IL_002d: ldstr "five" - IL_0032: ret - - IL_0033: ldstr "ten" - IL_0038: ret - - IL_0039: ldstr "large" - IL_003e: ret - } // end of method Switch::SwitchOverNullableInt - - .method public hidebysig static string - SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 98 (0x62) - .maxstack 2 - .locals init (valuetype [mscorlib]System.Nullable`1 V_0, - valuetype [mscorlib]System.Nullable`1 V_1, - valuetype [mscorlib]System.Nullable`1 V_2, - int32 V_3) - IL_0000: ldarg.0 - IL_0001: stloc.1 - IL_0002: ldloca.s V_1 - IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_0009: brtrue.s IL_0016 - - IL_000b: ldloca.s V_2 - IL_000d: initobj valuetype [mscorlib]System.Nullable`1 - IL_0013: ldloc.2 - IL_0014: br.s IL_0024 - - IL_0016: ldloca.s V_1 - IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_001d: ldc.i4.5 - IL_001e: add - IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) - IL_0024: stloc.0 - IL_0025: ldloca.s V_0 - IL_0027: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_002c: brfalse.s IL_0044 - - IL_002e: ldloca.s V_0 - IL_0030: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_0035: stloc.3 - IL_0036: ldloc.3 - IL_0037: brfalse.s IL_004a - - IL_0039: ldloc.3 - IL_003a: ldc.i4.5 - IL_003b: beq.s IL_0050 - - IL_003d: ldloc.3 - IL_003e: ldc.i4.s 10 - IL_0040: beq.s IL_0056 - - IL_0042: br.s IL_005c - - IL_0044: ldstr "null" - IL_0049: ret - - IL_004a: ldstr "zero" - IL_004f: ret - - IL_0050: ldstr "five" - IL_0055: ret - - IL_0056: ldstr "ten" - IL_005b: ret - - IL_005c: ldstr "large" - IL_0061: ret - } // end of method Switch::SwitchOverNullableIntShifted - - .method public hidebysig static string - SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 57 (0x39) - .maxstack 2 - .locals init (valuetype [mscorlib]System.Nullable`1 V_0, - int32 V_1) - IL_0000: ldarg.0 - IL_0001: stloc.0 - IL_0002: ldloca.s V_0 - IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_0009: brfalse.s IL_0033 - - IL_000b: ldloca.s V_0 - IL_000d: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_0012: stloc.1 - IL_0013: ldloc.1 - IL_0014: brfalse.s IL_0021 - - IL_0016: ldloc.1 - IL_0017: ldc.i4.5 - IL_0018: beq.s IL_0027 - - IL_001a: ldloc.1 - IL_001b: ldc.i4.s 10 - IL_001d: beq.s IL_002d - - IL_001f: br.s IL_0033 - - IL_0021: ldstr "zero" - IL_0026: ret - - IL_0027: ldstr "five" - IL_002c: ret - - IL_002d: ldstr "ten" - IL_0032: ret - - IL_0033: ldstr "other" - IL_0038: ret - } // end of method Switch::SwitchOverNullableIntNoNullCase - - .method public hidebysig static string - SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 92 (0x5c) - .maxstack 2 - .locals init (valuetype [mscorlib]System.Nullable`1 V_0, - valuetype [mscorlib]System.Nullable`1 V_1, - valuetype [mscorlib]System.Nullable`1 V_2, - int32 V_3) - IL_0000: ldarg.0 - IL_0001: stloc.1 - IL_0002: ldloca.s V_1 - IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_0009: brtrue.s IL_0016 - - IL_000b: ldloca.s V_2 - IL_000d: initobj valuetype [mscorlib]System.Nullable`1 - IL_0013: ldloc.2 - IL_0014: br.s IL_0024 - - IL_0016: ldloca.s V_1 - IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_001d: ldc.i4.5 - IL_001e: add - IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) - IL_0024: stloc.0 - IL_0025: ldloca.s V_0 - IL_0027: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_002c: brfalse.s IL_0056 - - IL_002e: ldloca.s V_0 - IL_0030: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_0035: stloc.3 - IL_0036: ldloc.3 - IL_0037: brfalse.s IL_0044 - - IL_0039: ldloc.3 - IL_003a: ldc.i4.5 - IL_003b: beq.s IL_004a - - IL_003d: ldloc.3 - IL_003e: ldc.i4.s 10 - IL_0040: beq.s IL_0050 - - IL_0042: br.s IL_0056 - - IL_0044: ldstr "zero" - IL_0049: ret - - IL_004a: ldstr "five" - IL_004f: ret - - IL_0050: ldstr "ten" - IL_0055: ret - - IL_0056: ldstr "other" - IL_005b: ret - } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted - .method public hidebysig static string ShortSwitchOverString(string text) cil managed { @@ -818,44 +659,134 @@ IL_0078: br.s IL_0015 } // end of method Switch::SwitchInLoop - .method public hidebysig static void SwitchWithGoto(int32 i) cil managed + .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] + GetProperties() cil managed { - // Code size 102 (0x66) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: newarr ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty + IL_0006: ret + } // end of method Switch::GetProperties + + .method public hidebysig static void SwitchOnStringInForLoop() cil managed + { + // Code size 234 (0xea) .maxstack 2 - IL_0000: ldstr "SwitchWithGoto: " - IL_0005: ldarg.0 - IL_0006: box [mscorlib]System.Int32 - IL_000b: call string [mscorlib]System.String::Concat(object, - object) - IL_0010: call void [mscorlib]System.Console::WriteLine(string) - IL_0015: ldarg.0 - IL_0016: ldc.i4.1 - IL_0017: sub - IL_0018: switch ( - IL_002f, - IL_003b, - IL_0045, - IL_0050) - IL_002d: br.s IL_005b + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, + class [mscorlib]System.Collections.Generic.List`1 V_1, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] V_2, + int32 V_3, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty V_4, + string V_5) + IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0005: stloc.0 + IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000b: stloc.1 + IL_000c: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch::GetProperties() + IL_0011: stloc.2 + IL_0012: ldc.i4.0 + IL_0013: stloc.3 + IL_0014: br IL_00e0 + + IL_0019: ldloc.2 + IL_001a: ldloc.3 + IL_001b: ldelem.ref + IL_001c: stloc.s V_4 + IL_001e: ldloc.s V_4 + IL_0020: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property + IL_0025: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() + IL_002a: stloc.s V_5 + IL_002c: ldloc.s V_5 + IL_002e: ldstr "Name1" + IL_0033: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0038: brtrue.s IL_0082 - IL_002f: ldstr "one" - IL_0034: call void [mscorlib]System.Console::WriteLine(string) - IL_0039: br.s IL_005b + IL_003a: ldloc.s V_5 + IL_003c: ldstr "Name2" + IL_0041: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0046: brtrue.s IL_0094 - IL_003b: ldstr "two" - IL_0040: call void [mscorlib]System.Console::WriteLine(string) - IL_0045: ldstr "three" - IL_004a: call void [mscorlib]System.Console::WriteLine(string) - IL_004f: ret - - IL_0050: ldstr "four" - IL_0055: call void [mscorlib]System.Console::WriteLine(string) - IL_005a: ret - - IL_005b: ldstr "default" - IL_0060: call void [mscorlib]System.Console::WriteLine(string) - IL_0065: ret - } // end of method Switch::SwitchWithGoto + IL_0048: ldloc.s V_5 + IL_004a: ldstr "Name3" + IL_004f: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0054: brtrue.s IL_00a6 + + IL_0056: ldloc.s V_5 + IL_0058: ldstr "Name4" + IL_005d: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0062: brtrue.s IL_00b8 + + IL_0064: ldloc.s V_5 + IL_0066: ldstr "Name5" + IL_006b: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0070: brtrue.s IL_00ca + + IL_0072: ldloc.s V_5 + IL_0074: ldstr "Name6" + IL_0079: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_007e: brtrue.s IL_00ca + + IL_0080: br.s IL_00d4 + + IL_0082: ldloc.s V_4 + IL_0084: ldc.i4.1 + IL_0085: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_008a: ldloc.0 + IL_008b: ldloc.s V_4 + IL_008d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0092: br.s IL_00dc + + IL_0094: ldloc.s V_4 + IL_0096: ldc.i4.2 + IL_0097: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_009c: ldloc.0 + IL_009d: ldloc.s V_4 + IL_009f: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00a4: br.s IL_00dc + + IL_00a6: ldloc.s V_4 + IL_00a8: ldc.i4.3 + IL_00a9: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00ae: ldloc.0 + IL_00af: ldloc.s V_4 + IL_00b1: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00b6: br.s IL_00dc + + IL_00b8: ldloc.s V_4 + IL_00ba: ldc.i4.4 + IL_00bb: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00c0: ldloc.0 + IL_00c1: ldloc.s V_4 + IL_00c3: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00c8: br.s IL_00dc + + IL_00ca: ldloc.0 + IL_00cb: ldloc.s V_4 + IL_00cd: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00d2: br.s IL_00dc + + IL_00d4: ldloc.1 + IL_00d5: ldloc.s V_4 + IL_00d7: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00dc: ldloc.3 + IL_00dd: ldc.i4.1 + IL_00de: add + IL_00df: stloc.3 + IL_00e0: ldloc.3 + IL_00e1: ldloc.2 + IL_00e2: ldlen + IL_00e3: conv.i4 + IL_00e4: blt IL_0019 + + IL_00e9: ret + } // end of method Switch::SwitchOnStringInForLoop } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il index f94d258ba..4da071b46 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {7C3CB7C3-DBBF-4EB8-ACC1-E7AFA899FD3B} +// MVID: {134EA2E4-FA5A-4D44-A0FD-C4E5A18E39B1} .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: 0x019E0000 +// Image base: 0x00C40000 // =============== CLASS MEMBERS DECLARATION =================== @@ -40,6 +40,58 @@ .class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch extends [mscorlib]System.Object { + .class auto ansi nested public beforefieldinit SetProperty + extends [mscorlib]System.Object + { + .field public initonly class [mscorlib]System.Reflection.PropertyInfo Property + .field private int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method public hidebysig specialname + instance int32 get_Set() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'k__BackingField' + IL_0006: ret + } // end of method SetProperty::get_Set + + .method public hidebysig specialname + instance void set_Set(int32 'value') 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: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'k__BackingField' + IL_0007: ret + } // end of method SetProperty::set_Set + + .method public hidebysig specialname rtspecialname + instance void .ctor(class [mscorlib]System.Reflection.PropertyInfo 'property') cil managed + { + // Code size 16 (0x10) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: nop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property + IL_000f: ret + } // end of method SetProperty::.ctor + + .property instance int32 Set() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::get_Set() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + } // end of property SetProperty::Set + } // end of class SetProperty + .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { @@ -177,280 +229,6 @@ IL_00ed: ret } // end of method Switch::SparseIntegerSwitch - .method public hidebysig static string - SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 82 (0x52) - .maxstack 2 - .locals init (valuetype [mscorlib]System.Nullable`1 V_0, - valuetype [mscorlib]System.Nullable`1 V_1, - int32 V_2, - string V_3) - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: stloc.1 - IL_0003: ldloc.1 - IL_0004: stloc.0 - IL_0005: ldloca.s V_0 - IL_0007: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_000c: brfalse.s IL_0028 - - IL_000e: ldloca.s V_0 - IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_0015: stloc.2 - IL_0016: ldloc.2 - IL_0017: brfalse.s IL_0030 - - IL_0019: br.s IL_001b - - IL_001b: ldloc.2 - IL_001c: ldc.i4.5 - IL_001d: beq.s IL_0038 - - IL_001f: br.s IL_0021 - - IL_0021: ldloc.2 - IL_0022: ldc.i4.s 10 - IL_0024: beq.s IL_0040 - - IL_0026: br.s IL_0048 - - IL_0028: ldstr "null" - IL_002d: stloc.3 - IL_002e: br.s IL_0050 - - IL_0030: ldstr "zero" - IL_0035: stloc.3 - IL_0036: br.s IL_0050 - - IL_0038: ldstr "five" - IL_003d: stloc.3 - IL_003e: br.s IL_0050 - - IL_0040: ldstr "ten" - IL_0045: stloc.3 - IL_0046: br.s IL_0050 - - IL_0048: ldstr "large" - IL_004d: stloc.3 - IL_004e: br.s IL_0050 - - IL_0050: ldloc.3 - IL_0051: ret - } // end of method Switch::SwitchOverNullableInt - - .method public hidebysig static string - SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 127 (0x7f) - .maxstack 2 - .locals init (valuetype [mscorlib]System.Nullable`1 V_0, - valuetype [mscorlib]System.Nullable`1 V_1, - valuetype [mscorlib]System.Nullable`1 V_2, - valuetype [mscorlib]System.Nullable`1 V_3, - int32 V_4, - string V_5) - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: stloc.2 - IL_0003: ldloca.s V_2 - IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_000a: brtrue.s IL_0017 - - IL_000c: ldloca.s V_3 - IL_000e: initobj valuetype [mscorlib]System.Nullable`1 - IL_0014: ldloc.3 - IL_0015: br.s IL_0025 - - IL_0017: ldloca.s V_2 - IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_001e: ldc.i4.5 - IL_001f: add - IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) - IL_0025: stloc.1 - IL_0026: ldloc.1 - IL_0027: stloc.0 - IL_0028: ldloca.s V_0 - IL_002a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_002f: brfalse.s IL_004f - - IL_0031: ldloca.s V_0 - IL_0033: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_0038: stloc.s V_4 - IL_003a: ldloc.s V_4 - IL_003c: brfalse.s IL_0058 - - IL_003e: br.s IL_0040 - - IL_0040: ldloc.s V_4 - IL_0042: ldc.i4.5 - IL_0043: beq.s IL_0061 - - IL_0045: br.s IL_0047 - - IL_0047: ldloc.s V_4 - IL_0049: ldc.i4.s 10 - IL_004b: beq.s IL_006a - - IL_004d: br.s IL_0073 - - IL_004f: ldstr "null" - IL_0054: stloc.s V_5 - IL_0056: br.s IL_007c - - IL_0058: ldstr "zero" - IL_005d: stloc.s V_5 - IL_005f: br.s IL_007c - - IL_0061: ldstr "five" - IL_0066: stloc.s V_5 - IL_0068: br.s IL_007c - - IL_006a: ldstr "ten" - IL_006f: stloc.s V_5 - IL_0071: br.s IL_007c - - IL_0073: ldstr "large" - IL_0078: stloc.s V_5 - IL_007a: br.s IL_007c - - IL_007c: ldloc.s V_5 - IL_007e: ret - } // end of method Switch::SwitchOverNullableIntShifted - - .method public hidebysig static string - SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 74 (0x4a) - .maxstack 2 - .locals init (valuetype [mscorlib]System.Nullable`1 V_0, - valuetype [mscorlib]System.Nullable`1 V_1, - int32 V_2, - string V_3) - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: stloc.1 - IL_0003: ldloc.1 - IL_0004: stloc.0 - IL_0005: ldloca.s V_0 - IL_0007: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_000c: brfalse.s IL_0040 - - IL_000e: ldloca.s V_0 - IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_0015: stloc.2 - IL_0016: ldloc.2 - IL_0017: brfalse.s IL_0028 - - IL_0019: br.s IL_001b - - IL_001b: ldloc.2 - IL_001c: ldc.i4.5 - IL_001d: beq.s IL_0030 - - IL_001f: br.s IL_0021 - - IL_0021: ldloc.2 - IL_0022: ldc.i4.s 10 - IL_0024: beq.s IL_0038 - - IL_0026: br.s IL_0040 - - IL_0028: ldstr "zero" - IL_002d: stloc.3 - IL_002e: br.s IL_0048 - - IL_0030: ldstr "five" - IL_0035: stloc.3 - IL_0036: br.s IL_0048 - - IL_0038: ldstr "ten" - IL_003d: stloc.3 - IL_003e: br.s IL_0048 - - IL_0040: ldstr "other" - IL_0045: stloc.3 - IL_0046: br.s IL_0048 - - IL_0048: ldloc.3 - IL_0049: ret - } // end of method Switch::SwitchOverNullableIntNoNullCase - - .method public hidebysig static string - SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed - { - // Code size 118 (0x76) - .maxstack 2 - .locals init (valuetype [mscorlib]System.Nullable`1 V_0, - valuetype [mscorlib]System.Nullable`1 V_1, - valuetype [mscorlib]System.Nullable`1 V_2, - valuetype [mscorlib]System.Nullable`1 V_3, - int32 V_4, - string V_5) - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: stloc.2 - IL_0003: ldloca.s V_2 - IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_000a: brtrue.s IL_0017 - - IL_000c: ldloca.s V_3 - IL_000e: initobj valuetype [mscorlib]System.Nullable`1 - IL_0014: ldloc.3 - IL_0015: br.s IL_0025 - - IL_0017: ldloca.s V_2 - IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_001e: ldc.i4.5 - IL_001f: add - IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) - IL_0025: stloc.1 - IL_0026: ldloc.1 - IL_0027: stloc.0 - IL_0028: ldloca.s V_0 - IL_002a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_002f: brfalse.s IL_006a - - IL_0031: ldloca.s V_0 - IL_0033: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() - IL_0038: stloc.s V_4 - IL_003a: ldloc.s V_4 - IL_003c: brfalse.s IL_004f - - IL_003e: br.s IL_0040 - - IL_0040: ldloc.s V_4 - IL_0042: ldc.i4.5 - IL_0043: beq.s IL_0058 - - IL_0045: br.s IL_0047 - - IL_0047: ldloc.s V_4 - IL_0049: ldc.i4.s 10 - IL_004b: beq.s IL_0061 - - IL_004d: br.s IL_006a - - IL_004f: ldstr "zero" - IL_0054: stloc.s V_5 - IL_0056: br.s IL_0073 - - IL_0058: ldstr "five" - IL_005d: stloc.s V_5 - IL_005f: br.s IL_0073 - - IL_0061: ldstr "ten" - IL_0066: stloc.s V_5 - IL_0068: br.s IL_0073 - - IL_006a: ldstr "other" - IL_006f: stloc.s V_5 - IL_0071: br.s IL_0073 - - IL_0073: ldloc.s V_5 - IL_0075: ret - } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted - .method public hidebysig static string ShortSwitchOverString(string text) cil managed { @@ -1066,63 +844,168 @@ IL_0091: ret } // end of method Switch::SwitchInLoop - .method public hidebysig static void SwitchWithGoto(int32 i) cil managed + .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] + GetProperties() cil managed { - // Code size 122 (0x7a) + // Code size 12 (0xc) + .maxstack 1 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] V_0) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: newarr ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty + IL_0007: stloc.0 + IL_0008: br.s IL_000a + + IL_000a: ldloc.0 + IL_000b: ret + } // end of method Switch::GetProperties + + .method public hidebysig static void SwitchOnStringInForLoop() cil managed + { + // Code size 265 (0x109) .maxstack 2 - .locals init (int32 V_0) + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, + class [mscorlib]System.Collections.Generic.List`1 V_1, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] V_2, + int32 V_3, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty V_4, + string V_5, + string V_6, + bool V_7) IL_0000: nop - IL_0001: ldstr "SwitchWithGoto: " - IL_0006: ldarg.0 - IL_0007: box [mscorlib]System.Int32 - IL_000c: call string [mscorlib]System.String::Concat(object, - object) - IL_0011: call void [mscorlib]System.Console::WriteLine(string) - IL_0016: nop - IL_0017: ldarg.0 - IL_0018: stloc.0 - IL_0019: ldloc.0 - IL_001a: ldc.i4.1 - IL_001b: sub - IL_001c: switch ( - IL_0033, - IL_0041, - IL_004f, - IL_005d) - IL_0031: br.s IL_006b - - IL_0033: nop - IL_0034: ldstr "one" - IL_0039: call void [mscorlib]System.Console::WriteLine(string) - IL_003e: nop - IL_003f: br.s IL_006b + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0006: stloc.0 + IL_0007: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000c: stloc.1 + IL_000d: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch::GetProperties() + IL_0012: stloc.2 + IL_0013: ldc.i4.0 + IL_0014: stloc.3 + IL_0015: br IL_00f9 + + IL_001a: nop + IL_001b: ldloc.2 + IL_001c: ldloc.3 + IL_001d: ldelem.ref + IL_001e: stloc.s V_4 + IL_0020: ldloc.s V_4 + IL_0022: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property + IL_0027: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() + IL_002c: stloc.s V_5 + IL_002e: ldloc.s V_5 + IL_0030: stloc.s V_6 + IL_0032: ldloc.s V_6 + IL_0034: ldstr "Name1" + IL_0039: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_003e: brtrue.s IL_0088 - IL_0041: nop - IL_0042: ldstr "two" - IL_0047: call void [mscorlib]System.Console::WriteLine(string) - IL_004c: nop - IL_004d: br.s IL_004f + IL_0040: ldloc.s V_6 + IL_0042: ldstr "Name2" + IL_0047: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_004c: brtrue.s IL_009d - IL_004f: nop - IL_0050: ldstr "three" - IL_0055: call void [mscorlib]System.Console::WriteLine(string) - IL_005a: nop - IL_005b: br.s IL_0079 + IL_004e: ldloc.s V_6 + IL_0050: ldstr "Name3" + IL_0055: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_005a: brtrue.s IL_00b2 - IL_005d: nop - IL_005e: ldstr "four" - IL_0063: call void [mscorlib]System.Console::WriteLine(string) - IL_0068: nop - IL_0069: br.s IL_0079 + IL_005c: ldloc.s V_6 + IL_005e: ldstr "Name4" + IL_0063: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0068: brtrue.s IL_00c7 - IL_006b: nop - IL_006c: ldstr "default" - IL_0071: call void [mscorlib]System.Console::WriteLine(string) - IL_0076: nop - IL_0077: br.s IL_0079 + IL_006a: ldloc.s V_6 + IL_006c: ldstr "Name5" + IL_0071: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0076: brtrue.s IL_00dc - IL_0079: ret - } // end of method Switch::SwitchWithGoto + IL_0078: ldloc.s V_6 + IL_007a: ldstr "Name6" + IL_007f: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0084: brtrue.s IL_00dc + + IL_0086: br.s IL_00e8 + + IL_0088: nop + IL_0089: ldloc.s V_4 + IL_008b: ldc.i4.1 + IL_008c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_0091: nop + IL_0092: ldloc.0 + IL_0093: ldloc.s V_4 + IL_0095: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_009a: nop + IL_009b: br.s IL_00f4 + + IL_009d: nop + IL_009e: ldloc.s V_4 + IL_00a0: ldc.i4.2 + IL_00a1: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00a6: nop + IL_00a7: ldloc.0 + IL_00a8: ldloc.s V_4 + IL_00aa: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00af: nop + IL_00b0: br.s IL_00f4 + + IL_00b2: nop + IL_00b3: ldloc.s V_4 + IL_00b5: ldc.i4.3 + IL_00b6: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00bb: nop + IL_00bc: ldloc.0 + IL_00bd: ldloc.s V_4 + IL_00bf: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00c4: nop + IL_00c5: br.s IL_00f4 + + IL_00c7: nop + IL_00c8: ldloc.s V_4 + IL_00ca: ldc.i4.4 + IL_00cb: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00d0: nop + IL_00d1: ldloc.0 + IL_00d2: ldloc.s V_4 + IL_00d4: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00d9: nop + IL_00da: br.s IL_00f4 + + IL_00dc: nop + IL_00dd: ldloc.0 + IL_00de: ldloc.s V_4 + IL_00e0: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00e5: nop + IL_00e6: br.s IL_00f4 + + IL_00e8: nop + IL_00e9: ldloc.1 + IL_00ea: ldloc.s V_4 + IL_00ec: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00f1: nop + IL_00f2: br.s IL_00f4 + + IL_00f4: nop + IL_00f5: ldloc.3 + IL_00f6: ldc.i4.1 + IL_00f7: add + IL_00f8: stloc.3 + IL_00f9: ldloc.3 + IL_00fa: ldloc.2 + IL_00fb: ldlen + IL_00fc: conv.i4 + IL_00fd: clt + IL_00ff: stloc.s V_7 + IL_0101: ldloc.s V_7 + IL_0103: brtrue IL_001a + + IL_0108: ret + } // end of method Switch::SwitchOnStringInForLoop } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 70f0903f0..dc35b6158 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -123,9 +123,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (values.Count == 0) return false; // All case blocks must either leave the current block container or branch to the same block after the switch statement. - if (!(values.All(b => ExtractLastJumpFromBlock(b.Item2, out var nextExit) && IsExitBlock(nextExit, container)) || - (exitBlock == null && values.All(b => ExtractLastLeaveFromBlock(b.Item2, container))))) - return false; + if (exitBlock == null) { + if (!values.All(b => ExtractLastLeaveFromBlock(b.Item2, container))) + return false; + } else { + // Compare blocks by label as duplicated blocks should have the same label. + if (!(values.All(b => ExtractLastJumpFromBlock(b.Item2, out var nextExitBlock) && nextExitBlock.Label == exitBlock.Label))) + return false; + } // if the block after the switch has the correct number of branches, generate the switch statement // and return it and the block. if (currentCaseBlock.IncomingEdgeCount == (isLegacy ? 2 : 1)) { @@ -139,13 +144,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; } - bool IsExitBlock(Block nextExit, BlockContainer container) - { - if (nextExit.Instructions.Count != 1) - return false; - return nextExit.Instructions[0].MatchLeave(container, out _); - } - bool ExtractLastJumpFromBlock(Block block, out Block exitBlock) { exitBlock = null; From 38482888a132503b5cc5c71bffc610d60fd45454 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 5 Oct 2017 17:47:03 +0200 Subject: [PATCH 017/190] Fix Using pretty tests and remove semicolon on single-line if. --- ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs | 2 +- ICSharpCode.Decompiler/IL/Transforms/InlineReturnTransform.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs index 3f615c56b..a531888f0 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs @@ -58,7 +58,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void SimpleUsingExpressionStatementWithDeclaration() { using (MemoryStream memoryStream = new MemoryStream()) { - memoryStream.WriteByte((byte)42); + memoryStream.WriteByte(42); Console.WriteLine("using-body: " + memoryStream.Position); } } diff --git a/ICSharpCode.Decompiler/IL/Transforms/InlineReturnTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/InlineReturnTransform.cs index 7245316c4..e9c53f8ca 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/InlineReturnTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/InlineReturnTransform.cs @@ -39,7 +39,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!leave.Value.MatchLdLoc(out var returnVar) || returnVar.Kind != VariableKind.Local) continue; // If all instructions can be modified, add item to the global list. - if (CanModifyInstructions(returnVar, leaveBlock, out var list)); + if (CanModifyInstructions(returnVar, leaveBlock, out var list)) instructionsToModify.AddRange(list); } From cca842a9698463ae0b55471810167bdc8eab0d5e Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 6 Oct 2017 13:30:20 +0200 Subject: [PATCH 018/190] Fix #440: Ldarg operand is incorrect when parameter has no name --- ICSharpCode.Decompiler/Disassembler/DisassemblerHelpers.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/Disassembler/DisassemblerHelpers.cs b/ICSharpCode.Decompiler/Disassembler/DisassemblerHelpers.cs index be7ed7dd8..481b2b5c5 100644 --- a/ICSharpCode.Decompiler/Disassembler/DisassemblerHelpers.cs +++ b/ICSharpCode.Decompiler/Disassembler/DisassemblerHelpers.cs @@ -343,9 +343,10 @@ namespace ICSharpCode.Decompiler.Disassembler ParameterReference paramRef = operand as ParameterReference; if (paramRef != null) { - if (string.IsNullOrEmpty(paramRef.Name)) - writer.WriteReference(paramRef.Index.ToString(), paramRef); - else + if (string.IsNullOrEmpty(paramRef.Name)) { + var paramDef = paramRef.Resolve(); + writer.WriteReference((paramDef == null ? paramRef.Index : paramDef.Sequence).ToString(), paramRef); + } else writer.WriteReference(Escape(paramRef.Name), paramRef); return; } From 8a68a94d355302d4db0f144a02791aa80b6ab24e Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 7 Oct 2017 00:13:14 +0200 Subject: [PATCH 019/190] Simplify use of SwitchInstruction in ILAst * the default case is now handled as a normal case * when dealing with basic blocks, SwitchInstruction will be the last instruction in the block * introduced ILAst instruction for 'goto case' --- .../CSharp/StatementBuilder.cs | 26 +++-- .../FlowAnalysis/DataFlowVisitor.cs | 16 ++- ICSharpCode.Decompiler/IL/BlockBuilder.cs | 11 +- .../IL/ControlFlow/ConditionDetection.cs | 39 +------ .../IL/ControlFlow/StateRangeAnalysis.cs | 4 - .../IL/ControlFlow/SwitchAnalysis.cs | 23 ++-- .../IL/ControlFlow/SwitchDetection.cs | 37 +++--- ICSharpCode.Decompiler/IL/ILReader.cs | 5 +- ICSharpCode.Decompiler/IL/Instructions.cs | 62 +++++++++- ICSharpCode.Decompiler/IL/Instructions.tt | 9 +- .../IL/Instructions/Branch.cs | 15 +-- .../IL/Instructions/SwitchInstruction.cs | 109 +++++++++++++----- .../IL/Transforms/SwitchOnStringTransform.cs | 1 - 13 files changed, 223 insertions(+), 134 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index d5923cb3e..3ddb00fe9 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -112,21 +112,29 @@ namespace ICSharpCode.Decompiler.CSharp value = exprBuilder.Translate(inst.Value); } - var stmt = new SwitchStatement() { Expression = value }; + // Pick the section with the most labels as default section. + IL.SwitchSection defaultSection = inst.Sections.First(); + foreach (var section in inst.Sections) { + if (section.Labels.Count() > defaultSection.Labels.Count()) { + defaultSection = section; + } + } + + var stmt = new SwitchStatement() { Expression = value }; foreach (var section in inst.Sections) { var astSection = new Syntax.SwitchSection(); - astSection.CaseLabels.AddRange(section.Labels.Values.Select(i => CreateTypedCaseLabel(i, value.Type, strToInt?.Map))); + if (section == defaultSection) { + astSection.CaseLabels.Add(new CaseLabel()); + } else { + if (section.HasNullLabel) { + astSection.CaseLabels.Add(new CaseLabel(new NullReferenceExpression())); + } + astSection.CaseLabels.AddRange(section.Labels.Values.Select(i => CreateTypedCaseLabel(i, value.Type, strToInt?.Map))); + } ConvertSwitchSectionBody(astSection, section.Body); stmt.SwitchSections.Add(astSection); } - if (inst.DefaultBody.OpCode != OpCode.Nop) { - var astSection = new Syntax.SwitchSection(); - astSection.CaseLabels.Add(new CaseLabel()); - ConvertSwitchSectionBody(astSection, inst.DefaultBody); - stmt.SwitchSections.Add(astSection); - } - breakTarget = oldBreakTarget; return stmt; } diff --git a/ICSharpCode.Decompiler/FlowAnalysis/DataFlowVisitor.cs b/ICSharpCode.Decompiler/FlowAnalysis/DataFlowVisitor.cs index 2ac18d313..0632edc79 100644 --- a/ICSharpCode.Decompiler/FlowAnalysis/DataFlowVisitor.cs +++ b/ICSharpCode.Decompiler/FlowAnalysis/DataFlowVisitor.cs @@ -614,17 +614,27 @@ namespace ICSharpCode.Decompiler.FlowAnalysis DebugStartPoint(inst); inst.Value.AcceptVisitor(this); State beforeSections = state.Clone(); - inst.DefaultBody.AcceptVisitor(this); + inst.Sections[0].AcceptVisitor(this); State afterSections = state.Clone(); - foreach (var section in inst.Sections) { + for (int i = 1; i < inst.Sections.Count; ++i) { state.ReplaceWith(beforeSections); - section.AcceptVisitor(this); + inst.Sections[i].AcceptVisitor(this); afterSections.JoinWith(state); } state = afterSections; DebugEndPoint(inst); } + protected internal override void VisitGotoCase(GotoCase inst) + { + // Handling goto case here is tricky: + // We'll need a fixed-point iteration for SwitchInstruction similar to BlockContainer, + // and we'll need to handle GotoCase like Branch, including stuff like ProcessBranchesLeavingTryFinally(). + // Hopefully we won't need a data-flow analysis in the decompiler pipeline after 'goto case' instructions + // are already introduced. + throw new NotImplementedException(); + } + protected internal override void VisitYieldReturn(YieldReturn inst) { DebugStartPoint(inst); diff --git a/ICSharpCode.Decompiler/IL/BlockBuilder.cs b/ICSharpCode.Decompiler/IL/BlockBuilder.cs index 2ba957cb4..46e51c794 100644 --- a/ICSharpCode.Decompiler/IL/BlockBuilder.cs +++ b/ICSharpCode.Decompiler/IL/BlockBuilder.cs @@ -163,8 +163,15 @@ namespace ICSharpCode.Decompiler.IL if (currentBlock == null) return; currentBlock.ILRange = new Interval(currentBlock.ILRange.Start, currentILOffset); - if (fallthrough) - currentBlock.Instructions.Add(new Branch(currentILOffset)); + if (fallthrough) { + if (currentBlock.Instructions.LastOrDefault() is SwitchInstruction switchInst && switchInst.Sections.Last().Body.MatchNop()) { + // Instead of putting the default branch after the switch instruction + switchInst.Sections.Last().Body = new Branch(currentILOffset); + Debug.Assert(switchInst.HasFlag(InstructionFlags.EndPointUnreachable)); + } else { + currentBlock.Instructions.Add(new Branch(currentILOffset)); + } + } currentBlock = null; } diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs index 48ecdf218..21da91022 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs @@ -63,18 +63,17 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow // Last instruction is one with unreachable endpoint // (guaranteed by combination of BlockContainer and Block invariants) Debug.Assert(block.Instructions.Last().HasFlag(InstructionFlags.EndPointUnreachable)); + ILInstruction exitInst = block.Instructions.Last(); + if (exitInst is SwitchInstruction switchInst) { + HandleSwitchInstruction(cfgNode, block, switchInst); + } // Previous-to-last instruction might have conditional control flow, // usually an IfInstruction with a branch: IfInstruction ifInst = block.Instructions.SecondToLastOrDefault() as IfInstruction; if (ifInst != null && ifInst.FalseInst.OpCode == OpCode.Nop) { HandleIfInstruction(cfgNode, block, ifInst, ref exitInst); - } else { - SwitchInstruction switchInst = block.Instructions.SecondToLastOrDefault() as SwitchInstruction; - if (switchInst != null) { - HandleSwitchInstruction(cfgNode, block, switchInst, ref exitInst); - } } if (IsUsableBranchToChild(cfgNode, exitInst)) { // "...; goto usableblock;" @@ -289,9 +288,8 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow && cfgNode.Dominates(context.ControlFlowGraph.GetNode(targetBlock)); } - private void HandleSwitchInstruction(ControlFlowNode cfgNode, Block block, SwitchInstruction sw, ref ILInstruction exitInst) + private void HandleSwitchInstruction(ControlFlowNode cfgNode, Block block, SwitchInstruction sw) { - Debug.Assert(sw.DefaultBody is Nop); // First, move blocks into the switch section foreach (var section in sw.Sections) { if (IsUsableBranchToChild(cfgNode, section.Body)) { @@ -301,32 +299,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow section.Body = targetBlock; } } - // Move the code following the switch into the default section - if (IsUsableBranchToChild(cfgNode, exitInst)) { - // switch(...){} goto targetBlock; - // ---> switch(..) { default: { targetBlock } } - var targetBlock = ((Branch)exitInst).TargetBlock; - targetBlock.Remove(); - sw.DefaultBody = targetBlock; - if (IsBranchOrLeave(targetBlock.Instructions.Last())) { - exitInst = block.Instructions[block.Instructions.Count - 1] = targetBlock.Instructions.Last(); - targetBlock.Instructions.RemoveAt(targetBlock.Instructions.Count - 1); - } else { - exitInst = null; - block.Instructions.RemoveAt(block.Instructions.Count - 1); - } - } - // Remove compatible exitInsts from switch sections: - foreach (var section in sw.Sections) { - Block sectionBlock = section.Body as Block; - if (sectionBlock != null && exitInst == null && IsBranchOrLeave(sectionBlock.Instructions.Last())) { - exitInst = sectionBlock.Instructions.Last(); - sectionBlock.Instructions.RemoveAt(sectionBlock.Instructions.Count - 1); - block.Instructions.Add(exitInst); - } else if (sectionBlock != null && DetectExitPoints.CompatibleExitInstruction(exitInst, sectionBlock.Instructions.Last())) { - sectionBlock.Instructions.RemoveAt(sectionBlock.Instructions.Count - 1); - } - } + // TODO: find a common exit point among the cases, and if possible inline that into this block. sw.Sections.ReplaceList(sw.Sections.OrderBy(s => s.Body.ILRange.Start)); } diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/StateRangeAnalysis.cs b/ICSharpCode.Decompiler/IL/ControlFlow/StateRangeAnalysis.cs index fa4fa097c..9ef815526 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/StateRangeAnalysis.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/StateRangeAnalysis.cs @@ -140,7 +140,6 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow SymbolicValue val = evalContext.Eval(switchInst.Value); if (val.Type != SymbolicValueType.State) goto default; - List allSectionLabels = new List(); List exitIntervals = new List(); foreach (var section in switchInst.Sections) { // switch (state + Constant) @@ -148,12 +147,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow // iff (state + Constant == value) // iff (state == value - Constant) var effectiveLabels = section.Labels.AddOffset(unchecked(-val.Constant)); - allSectionLabels.AddRange(effectiveLabels.Intervals); var result = AssignStateRanges(section.Body, stateRange.IntersectWith(effectiveLabels)); exitIntervals.AddRange(result.Intervals); } - var defaultSectionLabels = stateRange.ExceptWith(new LongSet(allSectionLabels)); - exitIntervals.AddRange(AssignStateRanges(switchInst.DefaultBody, defaultSectionLabels).Intervals); // exitIntervals = union of exits of all sections return new LongSet(exitIntervals); case IfInstruction ifInst: diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs index c280faa02..962c76f3f 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs @@ -94,25 +94,26 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow /// If false, analyze the whole block. bool AnalyzeBlock(Block block, LongSet inputValues, bool tailOnly = false) { + if (block.Instructions.Count == 0) { + // might happen if the block was already marked for deletion in SwitchDetection + return false; + } if (tailOnly) { Debug.Assert(block == rootBlock); - if (block.Instructions.Count < 2) - return false; } else { Debug.Assert(switchVar != null); // switchVar should always be determined by the top-level call if (block.IncomingEdgeCount != 1 || block == rootBlock) return false; // for now, let's only consider if-structures that form a tree - if (block.Instructions.Count != 2) - return false; if (block.Parent != rootBlock.Parent) return false; // all blocks should belong to the same container } - var inst = block.Instructions[block.Instructions.Count - 2]; - ILInstruction condition, trueInst; LongSet trueValues; - if (inst.MatchIfInstruction(out condition, out trueInst) + if (block.Instructions.Count >= 2 + && block.Instructions[block.Instructions.Count - 2].MatchIfInstruction(out var condition, out var trueInst) && AnalyzeCondition(condition, out trueValues) ) { + if (!(tailOnly || block.Instructions.Count == 2)) + return false; trueValues = trueValues.IntersectWith(inputValues); Block trueBlock; if (trueInst.MatchBranch(out trueBlock) && AnalyzeBlock(trueBlock, trueValues)) { @@ -122,8 +123,10 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow // Create switch section for trueInst. AddSection(trueValues, trueInst); } - } else if (inst.OpCode == OpCode.SwitchInstruction) { - if (AnalyzeSwitch((SwitchInstruction)inst, inputValues, out trueValues)) { + } else if (block.Instructions.Last() is SwitchInstruction switchInst) { + if (!(tailOnly || block.Instructions.Count == 1)) + return false; + if (AnalyzeSwitch(switchInst, inputValues, out trueValues)) { ContainsILSwitch = true; // OK } else { // switch analysis failed (e.g. switchVar mismatch) return false; @@ -147,7 +150,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow private bool AnalyzeSwitch(SwitchInstruction inst, LongSet inputValues, out LongSet anyMatchValues) { - Debug.Assert(inst.DefaultBody is Nop); + Debug.Assert(!inst.IsLifted); anyMatchValues = LongSet.Empty; long offset; if (MatchSwitchVar(inst.Value)) { diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs index 897d41e7e..5c31baa9a 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs @@ -60,16 +60,19 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow var sw = new SwitchInstruction(new LdLoc(analysis.SwitchVariable)); foreach (var section in analysis.Sections) { - if (!section.Key.SetEquals(defaultSection.Key)) { - sw.Sections.Add(new SwitchSection - { - Labels = section.Key, - Body = section.Value - }); - } + sw.Sections.Add(new SwitchSection { + Labels = section.Key, + Body = section.Value + }); + } + if (block.Instructions.Last() is Branch) { + Debug.Assert(block.Instructions.SecondToLastOrDefault() is IfInstruction); + block.Instructions.RemoveAt(block.Instructions.Count - 1); + } else { + Debug.Assert(block.Instructions.Last() is SwitchInstruction); } - block.Instructions[block.Instructions.Count - 2] = sw; - block.Instructions[block.Instructions.Count - 1] = defaultSection.Value; + block.Instructions[block.Instructions.Count - 1] = sw; + // mark all inner blocks that were converted to the switch statement for deletion foreach (var innerBlock in analysis.InnerBlocks) { Debug.Assert(innerBlock.Parent == block.Parent); @@ -87,8 +90,8 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow internal static void SimplifySwitchInstruction(Block block) { // due to our of of basic blocks at this point, - // switch instructions can only appear as second-to-last insturction - var sw = block.Instructions.SecondToLastOrDefault() as SwitchInstruction; + // switch instructions can only appear as last insturction + var sw = block.Instructions.LastOrDefault() as SwitchInstruction; if (sw == null) return; @@ -96,19 +99,13 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow // Any switch instructions will only have branch instructions in the sections. // Combine sections with identical branch target: - block.Instructions.Last().MatchBranch(out Block defaultTarget); var dict = new Dictionary(); // branch target -> switch section sw.Sections.RemoveAll( section => { - Block target; - if (section.Body.MatchBranch(out target)) { - SwitchSection primarySection; - if (target == defaultTarget) { - // This section is just an alternative for 'default'. - Debug.Assert(sw.DefaultBody is Nop); - return true; // remove this section - } else if (dict.TryGetValue(target, out primarySection)) { + if (section.Body.MatchBranch(out Block target)) { + if (dict.TryGetValue(target, out SwitchSection primarySection)) { primarySection.Labels = primarySection.Labels.UnionWith(section.Labels); + primarySection.HasNullLabel |= section.HasNullLabel; return true; // remove this section } else { dict.Add(target, section); diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index b401f5c5d..9ed9cb9ad 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -1232,7 +1232,10 @@ namespace ICSharpCode.Decompiler.IL section.Body = new Branch(target); instr.Sections.Add(section); } - + var defaultSection = new SwitchSection(); + defaultSection.Labels = new LongSet(new LongInterval(0, labels.Length)).Invert(); + defaultSection.Body = new Nop(); + instr.Sections.Add(defaultSection); return instr; } diff --git a/ICSharpCode.Decompiler/IL/Instructions.cs b/ICSharpCode.Decompiler/IL/Instructions.cs index c6f361279..ccb7bdedf 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.cs +++ b/ICSharpCode.Decompiler/IL/Instructions.cs @@ -63,6 +63,8 @@ namespace ICSharpCode.Decompiler.IL SwitchInstruction, /// Switch section within a switch statement SwitchSection, + /// Unconditional branch to switch section. goto case target; + GotoCase, /// Try-catch statement. TryCatch, /// Catch handler within a try-catch statement. @@ -1014,6 +1016,15 @@ namespace ICSharpCode.Decompiler.IL public sealed partial class Branch : SimpleInstruction { public override StackType ResultType { get { return StackType.Void; } } + protected override InstructionFlags ComputeFlags() + { + return InstructionFlags.EndPointUnreachable | InstructionFlags.MayBranch; + } + public override InstructionFlags DirectFlags { + get { + return InstructionFlags.EndPointUnreachable | InstructionFlags.MayBranch; + } + } public override void AcceptVisitor(ILVisitor visitor) { visitor.VisitBranch(this); @@ -1319,7 +1330,7 @@ namespace ICSharpCode.Decompiler.IL protected internal override bool PerformMatch(ILInstruction other, ref Patterns.Match match) { var o = other as SwitchInstruction; - return o != null && Value.PerformMatch(o.Value, ref match) && DefaultBody.PerformMatch(o.DefaultBody, ref match) && Patterns.ListMatch.DoMatch(this.Sections, o.Sections, ref match); + return o != null && IsLifted == o.IsLifted && Value.PerformMatch(o.Value, ref match) && Patterns.ListMatch.DoMatch(this.Sections, o.Sections, ref match); } } } @@ -1391,7 +1402,41 @@ namespace ICSharpCode.Decompiler.IL protected internal override bool PerformMatch(ILInstruction other, ref Patterns.Match match) { var o = other as SwitchSection; - return o != null && this.body.PerformMatch(o.body, ref match) && this.Labels.Intervals.SequenceEqual(o.Labels.Intervals); + return o != null && this.body.PerformMatch(o.body, ref match) && this.Labels.SetEquals(o.Labels) && this.HasNullLabel == o.HasNullLabel; + } + } +} +namespace ICSharpCode.Decompiler.IL +{ + /// Unconditional branch to switch section. goto case target; + public sealed partial class GotoCase : SimpleInstruction + { + public override StackType ResultType { get { return StackType.Void; } } + protected override InstructionFlags ComputeFlags() + { + return InstructionFlags.EndPointUnreachable | InstructionFlags.MayBranch; + } + public override InstructionFlags DirectFlags { + get { + return InstructionFlags.EndPointUnreachable | InstructionFlags.MayBranch; + } + } + public override void AcceptVisitor(ILVisitor visitor) + { + visitor.VisitGotoCase(this); + } + public override T AcceptVisitor(ILVisitor visitor) + { + return visitor.VisitGotoCase(this); + } + public override T AcceptVisitor(ILVisitor visitor, C context) + { + return visitor.VisitGotoCase(this, context); + } + protected internal override bool PerformMatch(ILInstruction other, ref Patterns.Match match) + { + var o = other as GotoCase; + return o != null && this.TargetSection == o.TargetSection; } } } @@ -4528,6 +4573,10 @@ namespace ICSharpCode.Decompiler.IL { Default(inst); } + protected internal virtual void VisitGotoCase(GotoCase inst) + { + Default(inst); + } protected internal virtual void VisitTryCatch(TryCatch inst) { Default(inst); @@ -4818,6 +4867,10 @@ namespace ICSharpCode.Decompiler.IL { return Default(inst); } + protected internal virtual T VisitGotoCase(GotoCase inst) + { + return Default(inst); + } protected internal virtual T VisitTryCatch(TryCatch inst) { return Default(inst); @@ -5108,6 +5161,10 @@ namespace ICSharpCode.Decompiler.IL { return Default(inst, context); } + protected internal virtual T VisitGotoCase(GotoCase inst, C context) + { + return Default(inst, context); + } protected internal virtual T VisitTryCatch(TryCatch inst, C context) { return Default(inst, context); @@ -5342,6 +5399,7 @@ namespace ICSharpCode.Decompiler.IL "if.notnull", "switch", "switch.section", + "goto.case", "try.catch", "try.catch.handler", "try.finally", diff --git a/ICSharpCode.Decompiler/IL/Instructions.tt b/ICSharpCode.Decompiler/IL/Instructions.tt index f25e3fa0d..c75172ddf 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.tt +++ b/ICSharpCode.Decompiler/IL/Instructions.tt @@ -73,7 +73,7 @@ new OpCode("bit.not", "Bitwise NOT", Unary, CustomConstructor, MatchCondition("IsLifted == o.IsLifted && UnderlyingResultType == o.UnderlyingResultType")), new OpCode("arglist", "Retrieves the RuntimeArgumentHandle.", NoArguments, ResultType("O")), new OpCode("br", "Unconditional branch. goto target;", - CustomClassName("Branch"), NoArguments, CustomConstructor, UnconditionalBranch, MayBranch, CustomComputeFlags, + CustomClassName("Branch"), NoArguments, CustomConstructor, UnconditionalBranch, MayBranch, MatchCondition("this.TargetBlock == o.TargetBlock")), new OpCode("leave", "Unconditional branch to end of block container. Return is represented using IsLeavingFunction and an (optional) return value. The block container evaluates to the value produced by the argument of the leave instruction.", CustomConstructor, CustomArguments("value"), UnconditionalBranch, MayBranch, CustomWriteTo, CustomComputeFlags, @@ -93,11 +93,14 @@ }), CustomConstructor, CustomComputeFlags, CustomWriteTo), new OpCode("switch", "Switch statement", CustomClassName("SwitchInstruction"), CustomConstructor, CustomComputeFlags, CustomWriteTo, ResultType("Void"), - MatchCondition("Value.PerformMatch(o.Value, ref match) && DefaultBody.PerformMatch(o.DefaultBody, ref match) && Patterns.ListMatch.DoMatch(this.Sections, o.Sections, ref match)")), + MatchCondition("IsLifted == o.IsLifted && Value.PerformMatch(o.Value, ref match) && Patterns.ListMatch.DoMatch(this.Sections, o.Sections, ref match)")), new OpCode("switch.section", "Switch section within a switch statement", CustomClassName("SwitchSection"), CustomChildren(new [] { new ChildInfo("body") }), CustomConstructor, CustomComputeFlags, CustomWriteTo, ResultType("Void"), - MatchCondition("this.Labels.Intervals.SequenceEqual(o.Labels.Intervals)")), + MatchCondition("this.Labels.SetEquals(o.Labels) && this.HasNullLabel == o.HasNullLabel")), + new OpCode("goto.case", "Unconditional branch to switch section. goto case target;", + CustomClassName("GotoCase"), NoArguments, CustomConstructor, UnconditionalBranch, MayBranch, + MatchCondition("this.TargetSection == o.TargetSection")), new OpCode("try.catch", "Try-catch statement.", BaseClass("TryInstruction"), CustomConstructor, CustomComputeFlags, CustomWriteTo, MatchCondition("TryBlock.PerformMatch(o.TryBlock, ref match)"), diff --git a/ICSharpCode.Decompiler/IL/Instructions/Branch.cs b/ICSharpCode.Decompiler/IL/Instructions/Branch.cs index 8cfab388b..7085ab6a1 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/Branch.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/Branch.cs @@ -39,23 +39,10 @@ namespace ICSharpCode.Decompiler.IL public Branch(Block targetBlock) : base(OpCode.Branch) { - if (targetBlock == null) - throw new ArgumentNullException(nameof(targetBlock)); - this.targetBlock = targetBlock; + this.targetBlock = targetBlock ?? throw new ArgumentNullException(nameof(targetBlock)); this.targetILOffset = targetBlock.ILRange.Start; } - protected override InstructionFlags ComputeFlags() - { - return InstructionFlags.MayBranch | InstructionFlags.EndPointUnreachable; - } - - public override InstructionFlags DirectFlags { - get { - return InstructionFlags.MayBranch | InstructionFlags.EndPointUnreachable; - } - } - public int TargetILOffset { get { return targetBlock != null ? targetBlock.ILRange.Start : targetILOffset; } } diff --git a/ICSharpCode.Decompiler/IL/Instructions/SwitchInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/SwitchInstruction.cs index 8e22ffe20..5de07f592 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/SwitchInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/SwitchInstruction.cs @@ -16,6 +16,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +using System; using System.Diagnostics; using System.Linq; using ICSharpCode.Decompiler.Util; @@ -32,15 +33,19 @@ namespace ICSharpCode.Decompiler.IL partial class SwitchInstruction { public static readonly SlotInfo ValueSlot = new SlotInfo("Value", canInlineInto: true); - public static readonly SlotInfo DefaultBodySlot = new SlotInfo("DefaultBody"); public static readonly SlotInfo SectionSlot = new SlotInfo("Section", isCollection: true); - + + /// + /// If the switch instruction is lifted, the value instruction produces a value of type Nullable{T} for some + /// integral type T. The section with SwitchSection.HasNullLabel is called if the value is null. + /// + public bool IsLifted; + public SwitchInstruction(ILInstruction value) : base(OpCode.SwitchInstruction) { this.Value = value; - this.DefaultBody = new Nop(); - this.Sections = new InstructionCollection(this, 2); + this.Sections = new InstructionCollection(this, 1); } ILInstruction value; @@ -52,21 +57,11 @@ namespace ICSharpCode.Decompiler.IL } } - ILInstruction defaultBody; - - public ILInstruction DefaultBody { - get { return this.defaultBody; } - set { - ValidateChild(value); - SetChildInstruction(ref this.defaultBody, value, 1); - } - } - public readonly InstructionCollection Sections; protected override InstructionFlags ComputeFlags() { - var sectionFlags = defaultBody.Flags; + var sectionFlags = InstructionFlags.EndPointUnreachable; // neutral element for CombineBranches() foreach (var section in Sections) { sectionFlags = SemanticHelper.CombineBranches(sectionFlags, section.Flags); } @@ -81,15 +76,15 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { - output.Write("switch ("); + output.Write("switch"); + if (IsLifted) + output.Write(".lifted"); + output.Write(" ("); value.WriteTo(output, options); output.Write(") "); output.MarkFoldStart("{...}"); output.WriteLine("{"); output.Indent(); - output.Write("default: "); - defaultBody.WriteTo(output, options); - output.WriteLine(); foreach (var section in this.Sections) { section.WriteTo(output, options); output.WriteLine(); @@ -101,34 +96,28 @@ namespace ICSharpCode.Decompiler.IL protected override int GetChildCount() { - return 2 + Sections.Count; + return 1 + Sections.Count; } protected override ILInstruction GetChild(int index) { if (index == 0) return value; - else if (index == 1) - return defaultBody; - return Sections[index - 2]; + return Sections[index - 1]; } protected override void SetChild(int index, ILInstruction value) { if (index == 0) Value = value; - else if (index == 1) - DefaultBody = value; else - Sections[index - 2] = (SwitchSection)value; + Sections[index - 1] = (SwitchSection)value; } protected override SlotInfo GetChildSlot(int index) { if (index == 0) return ValueSlot; - else if (index == 1) - return DefaultBodySlot; return SectionSlot; } @@ -137,7 +126,6 @@ namespace ICSharpCode.Decompiler.IL var clone = new SwitchInstruction(value.Clone()); clone.ILRange = this.ILRange; clone.Value = value.Clone(); - this.DefaultBody = defaultBody.Clone(); clone.Sections.AddRange(this.Sections.Select(h => (SwitchSection)h.Clone())); return clone; } @@ -145,12 +133,19 @@ namespace ICSharpCode.Decompiler.IL internal override void CheckInvariant(ILPhase phase) { base.CheckInvariant(phase); + bool expectNullSection = this.IsLifted; LongSet sets = LongSet.Empty; foreach (var section in Sections) { - Debug.Assert(!section.Labels.IsEmpty); + if (section.HasNullLabel) { + Debug.Assert(expectNullSection, "Duplicate 'case null' or 'case null' in non-lifted switch."); + expectNullSection = false; + } + Debug.Assert(!section.Labels.IsEmpty || section.HasNullLabel); Debug.Assert(!section.Labels.Overlaps(sets)); sets = sets.UnionWith(section.Labels); } + Debug.Assert(sets.SetEquals(LongSet.Universe), "switch does not handle all possible cases"); + Debug.Assert(!expectNullSection, "Lifted switch is missing 'case null'"); } } @@ -162,6 +157,14 @@ namespace ICSharpCode.Decompiler.IL this.Labels = LongSet.Empty; } + /// + /// If true, serves as 'case null' in a lifted switch. + /// + public bool HasNullLabel { get; set; } + + /// + /// The set of labels that cause execution to jump to this switch section. + /// public LongSet Labels { get; set; } protected override InstructionFlags ComputeFlags() @@ -177,11 +180,53 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { - output.Write("case "); - output.Write(Labels.ToString()); + output.WriteDefinition("case", this, isLocal: true); + output.Write(' '); + if (HasNullLabel) { + output.Write("null"); + if (!Labels.IsEmpty) { + output.Write(", "); + output.Write(Labels.ToString()); + } + } else { + output.Write(Labels.ToString()); + } output.Write(": "); body.WriteTo(output, options); } } + + /// + /// Unconditional branch to switch section. goto case target;/goto default; + /// + /// + /// Like normal branches, can trigger finally blocks. + /// + partial class GotoCase // : IBranchOrLeaveInstruction + { + public SwitchSection TargetSection { get; } + + public GotoCase(SwitchSection target) : base(OpCode.GotoCase) + { + this.TargetSection = target ?? throw new ArgumentNullException(nameof(target)); + } + + internal override void CheckInvariant(ILPhase phase) + { + base.CheckInvariant(phase); + var parentSwitch = this.Ancestors.OfType().First(); + Debug.Assert(parentSwitch == TargetSection.Parent); + } + + public override void WriteTo(ITextOutput output, ILAstWritingOptions options) + { + output.Write("goto.case "); + if (TargetSection.HasNullLabel) { + output.WriteReference("null", TargetSection, isLocal: true); + } else { + output.WriteReference(TargetSection.Labels.Values.First().ToString(), TargetSection, isLocal: true); + } + } + } } diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index dc35b6158..0b7d27359 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -283,7 +283,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms } var stringToInt = new StringToInt(new LdLoc(switchValueVar), stringValues.ToArray()); inst = new SwitchInstruction(stringToInt); - inst.DefaultBody = switchInst.DefaultBody; inst.Sections.AddRange(sections); blockAfterSwitch = defaultBlock; return true; From 5399b93df76abf1a5530b4f0969947218838fd12 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 7 Oct 2017 12:42:52 +0200 Subject: [PATCH 020/190] ConnectMethodDecompiler: Adapt to new switch transformation. --- ILSpy.BamlDecompiler/BamlResourceEntryNode.cs | 10 +++++----- ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ILSpy.BamlDecompiler/BamlResourceEntryNode.cs b/ILSpy.BamlDecompiler/BamlResourceEntryNode.cs index 9b0a515dd..30444af81 100644 --- a/ILSpy.BamlDecompiler/BamlResourceEntryNode.cs +++ b/ILSpy.BamlDecompiler/BamlResourceEntryNode.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Xml.Linq; using ICSharpCode.AvalonEdit.Highlighting; +using ICSharpCode.Decompiler.Util; using ICSharpCode.ILSpy; using ICSharpCode.ILSpy.TextView; using ICSharpCode.ILSpy.TreeNodes; @@ -135,7 +136,7 @@ namespace ILSpy.BamlDecompiler } } - static void RemoveConnectionIds(XElement element, Dictionary eventMappings) + static void RemoveConnectionIds(XElement element, List<(LongSet key, EventRegistration[] value)> eventMappings) { foreach (var child in element.Elements()) RemoveConnectionIds(child, eventMappings); @@ -143,10 +144,9 @@ namespace ILSpy.BamlDecompiler var removableAttrs = new List(); var addableAttrs = new List(); foreach (var attr in element.Attributes(XName.Get("ConnectionId", XmlBamlReader.XWPFNamespace))) { - int id; - if (int.TryParse(attr.Value, out id) && eventMappings.ContainsKey(id)) { - var map = eventMappings[id]; - foreach (var entry in map) { + int id, index; + if (int.TryParse(attr.Value, out id) && (index = eventMappings.FindIndex(item => item.key.Contains(id))) > -1) { + foreach (var entry in eventMappings[index].value) { string xmlns = ""; // TODO : implement xmlns resolver! addableAttrs.Add(new XAttribute(xmlns + entry.EventName, entry.MethodName)); } diff --git a/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs b/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs index 7c970ea54..a28f63d7b 100644 --- a/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs +++ b/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs @@ -10,6 +10,7 @@ using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.IL; using ICSharpCode.Decompiler.IL.Transforms; using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.Decompiler.Util; using Mono.Cecil; namespace ILSpy.BamlDecompiler @@ -34,9 +35,9 @@ namespace ILSpy.BamlDecompiler this.assembly = assembly; } - public Dictionary DecompileEventMappings(string fullTypeName, CancellationToken cancellationToken) + public List<(LongSet, EventRegistration[])> DecompileEventMappings(string fullTypeName, CancellationToken cancellationToken) { - var result = new Dictionary(); + var result = new List<(LongSet, EventRegistration[])>(); TypeDefinition type = this.assembly.MainModule.GetType(fullTypeName); if (type == null) @@ -70,8 +71,7 @@ namespace ILSpy.BamlDecompiler if (ilSwitch != null) { foreach (var section in ilSwitch.Sections) { var events = FindEvents(section.Body); - foreach (long id in section.Labels.Values) - result.Add(id, events); + result.Add((section.Labels, events)); } } else { foreach (var ifInst in function.Descendants.OfType()) { @@ -82,7 +82,7 @@ namespace ILSpy.BamlDecompiler if (!comp.Right.MatchLdcI4(out id)) continue; var events = FindEvents(comp.Kind == ComparisonKind.Inequality ? ifInst.FalseInst : ifInst.TrueInst); - result.Add(id, events); + result.Add((new LongSet(id), events)); } } return result; From 621e355f364b09f4f272d5d7a7f5c7a665748a23 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 7 Oct 2017 12:46:03 +0200 Subject: [PATCH 021/190] Adapt SwitchOnStringTransform to switch instruction changes. --- ICSharpCode.Decompiler/IL/DetectedLoop.cs | 2 +- .../IL/Transforms/SwitchOnStringTransform.cs | 135 +++++++----------- 2 files changed, 52 insertions(+), 85 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/DetectedLoop.cs b/ICSharpCode.Decompiler/IL/DetectedLoop.cs index 276ca2657..9b935fc00 100644 --- a/ICSharpCode.Decompiler/IL/DetectedLoop.cs +++ b/ICSharpCode.Decompiler/IL/DetectedLoop.cs @@ -76,7 +76,7 @@ namespace ICSharpCode.Decompiler.IL conditions.Add(ifInst.Condition); i--; } - if (i == -1) { + if (i == -1 && conditions.Any()) { return b; } } diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 0b7d27359..ef199199a 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -38,36 +38,31 @@ namespace ICSharpCode.Decompiler.IL.Transforms HashSet changedContainers = new HashSet(); foreach (var block in function.Descendants.OfType()) { + bool changed = false; for (int i = block.Instructions.Count - 1; i >= 0; i--) { SwitchInstruction newSwitch; - Block blockAfterSwitch = null; - bool removeExtraStore = false; // the Roslyn switch pattern uses an extra store for hash calculation. - if (!MatchCascadingIfStatements(block.Instructions, i, out newSwitch, out blockAfterSwitch)) - if (!MatchLegacySwitchOnString(block.Instructions, i, out newSwitch, out blockAfterSwitch)) - if (MatchRoslynSwitchOnString(block.Instructions, i, out newSwitch)) - removeExtraStore = true; - else - continue; - - if (i + 1 < block.Instructions.Count && block.Instructions[i + 1] is Branch b && blockAfterSwitch != null) { - block.Instructions[i + 1].ReplaceWith(new Branch(blockAfterSwitch)); + if (SimplifyCascadingIfStatements(block.Instructions, i, out newSwitch)) { + block.Instructions[i + 1].ReplaceWith(newSwitch); + block.Instructions.RemoveAt(i); + changed = true; + continue; } - - block.Instructions[i].ReplaceWith(newSwitch); - if (removeExtraStore) { - block.Instructions.RemoveAt(i - 1); + if (MatchLegacySwitchOnString(block.Instructions, i, out newSwitch)) { + block.Instructions[i + 1].ReplaceWith(newSwitch); + block.Instructions.RemoveAt(i); + changed = true; + continue; + } + if (MatchRoslynSwitchOnString(block.Instructions, i, out newSwitch)) { + block.Instructions[i - 1].ReplaceWith(newSwitch); + block.Instructions.RemoveAt(i); + changed = true; i--; + continue; } - - // Combine cases with the same branch target: - SwitchDetection.SimplifySwitchInstruction(block); - - // This happens in some cases: - // Use correct index after transformation. - if (i >= block.Instructions.Count) - i = block.Instructions.Count; } - + if (!changed) continue; + SwitchDetection.SimplifySwitchInstruction(block); if (block.Parent is BlockContainer container) changedContainers.Add(container); } @@ -76,10 +71,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms container.SortBlocks(deleteUnreachableBlocks: true); } - bool MatchCascadingIfStatements(InstructionCollection instructions, int i, out SwitchInstruction inst, out Block blockAfterSwitch) + bool SimplifyCascadingIfStatements(InstructionCollection instructions, int i, out SwitchInstruction inst) { inst = null; - blockAfterSwitch = null; // match first block: checking switch-value for null or first value (Roslyn) // if (call op_Equality(ldloc switchValueVar, ldstr value)) br firstBlock // -or- @@ -89,16 +83,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!firstBlockJump.MatchBranch(out var firstBlock)) return false; bool isLegacy; - Block defaultBlock; List<(string, Block)> values = new List<(string, Block)>(); // match null check: this is used by the old C# compiler. if (condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && left.MatchLdLoc(out var switchValueVar)) { isLegacy = true; - defaultBlock = firstBlock; - // Roslyn: match call to operator ==(string, string) + values.Add((null, firstBlock)); + // Roslyn: match call to operator ==(string, string) } else if (MatchStringEqualityComparison(condition, out switchValueVar, out string value)) { isLegacy = false; - defaultBlock = null; values.Add((value, firstBlock)); } else return false; // switchValueVar must be assigned only once. @@ -114,53 +106,20 @@ namespace ICSharpCode.Decompiler.IL.Transforms values.Add((value, block)); currentCaseBlock = nextCaseBlock; } - // the last instruction of the last case/default block must be either - // a branch to the a block after the switch statement or a leave instruction. - var container = BlockContainer.FindClosestContainer(firstBlock); - if (!ExtractLastJumpFromBlock(currentCaseBlock, out var exitBlock) && !ExtractLastLeaveFromBlock(currentCaseBlock, container)) + // We didn't find enough cases, exit + if (values.Count < 3) return false; - // We didn't find any cases, exit - if (values.Count == 0) - return false; - // All case blocks must either leave the current block container or branch to the same block after the switch statement. - if (exitBlock == null) { - if (!values.All(b => ExtractLastLeaveFromBlock(b.Item2, container))) - return false; - } else { - // Compare blocks by label as duplicated blocks should have the same label. - if (!(values.All(b => ExtractLastJumpFromBlock(b.Item2, out var nextExitBlock) && nextExitBlock.Label == exitBlock.Label))) - return false; - } - // if the block after the switch has the correct number of branches, generate the switch statement - // and return it and the block. - if (currentCaseBlock.IncomingEdgeCount == (isLegacy ? 2 : 1)) { - var sections = new List(values.SelectWithIndex((index, b) => new SwitchSection { Labels = new LongSet(index), Body = new Branch(b.Item2) })); - var stringToInt = new StringToInt(new LdLoc(switchValueVar), values.SelectArray(item => item.Item1)); - inst = new SwitchInstruction(stringToInt); - inst.Sections.AddRange(sections); - blockAfterSwitch = currentCaseBlock; - return true; - } - return false; - } - - bool ExtractLastJumpFromBlock(Block block, out Block exitBlock) - { - exitBlock = null; - var lastInst = block.Instructions.LastOrDefault(); - if (lastInst == null || !lastInst.MatchBranch(out exitBlock)) + // The block after all cases should only be reachable from the previous block and the null-check (in legacy code). + if (currentCaseBlock.IncomingEdgeCount != (isLegacy ? 2 : 1)) return false; + var sections = new List(values.SelectWithIndex((index, b) => new SwitchSection { Labels = new LongSet(index), Body = new Branch(b.Item2) })); + sections.Add(new SwitchSection { Labels = new LongSet(new LongInterval(0, sections.Count)).Invert(), Body = new Branch(currentCaseBlock) }); + var stringToInt = new StringToInt(new LdLoc(switchValueVar), values.SelectArray(item => item.Item1)); + inst = new SwitchInstruction(stringToInt); + inst.Sections.AddRange(sections); return true; } - bool ExtractLastLeaveFromBlock(Block block, BlockContainer container) - { - var lastInst = block.Instructions.LastOrDefault(); - if (lastInst == null || !lastInst.MatchLeave(out var b, out _)) - return false; - return b == container; - } - /// /// Each case consists of two blocks: /// 1. block: @@ -222,16 +181,15 @@ namespace ICSharpCode.Decompiler.IL.Transforms return storeInst.Value.MatchLdLoc(right); } - bool MatchLegacySwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst, out Block blockAfterSwitch) + bool MatchLegacySwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst) { inst = null; - blockAfterSwitch = null; if (i < 1) return false; // match first block: checking switch-value for null if (!(instructions[i].MatchIfInstruction(out var condition, out var exitBlockJump) && instructions[i - 1].MatchStLoc(out var switchValueVar, out var switchValue) && switchValueVar.Type.IsKnownType(KnownTypeCode.String))) return false; - if (!exitBlockJump.MatchBranch(out var exitBlock)) + if (!exitBlockJump.MatchBranch(out var nullValueCaseBlock)) return false; if (!(condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && (left.Match(switchValue).Success || left.MatchLdLoc(switchValueVar)))) return false; @@ -269,22 +227,25 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!tryGetValueBlock.Instructions[1].MatchBranch(out var switchBlock)) return false; // match fifth block: switch-instruction block - if (switchBlock.IncomingEdgeCount != 1 || switchBlock.Instructions.Count != 2) + if (switchBlock.IncomingEdgeCount != 1 || switchBlock.Instructions.Count != 1) return false; if (!(switchBlock.Instructions[0] is SwitchInstruction switchInst && switchInst.Value.MatchLdLoc(switchIndexVar))) return false; - if (!switchBlock.Instructions[1].MatchBranch(defaultBlock)) - return false; - // switch contains case null: var sections = new List(switchInst.Sections); - if (exitBlock != defaultBlock) { + // switch contains case null: + if (nullValueCaseBlock != defaultBlock) { + var label = new Util.LongSet(switchInst.Sections.Count); + var possibleConflicts = switchInst.Sections.Where(sec => sec.Labels.Overlaps(label)).ToArray(); + if (possibleConflicts.Length > 1) + return false; + else if (possibleConflicts.Length == 1) + possibleConflicts[0].Labels = possibleConflicts[0].Labels.ExceptWith(label); stringValues.Add(null); - sections.Add(new SwitchSection() { Labels = new Util.LongSet(stringValues.Count - 1), Body = new Branch(exitBlock) }); + sections.Add(new SwitchSection() { Labels = label, Body = new Branch(nullValueCaseBlock) }); } var stringToInt = new StringToInt(new LdLoc(switchValueVar), stringValues.ToArray()); inst = new SwitchInstruction(stringToInt); inst.Sections.AddRange(sections); - blockAfterSwitch = defaultBlock; return true; } @@ -340,10 +301,15 @@ namespace ICSharpCode.Decompiler.IL.Transforms var stringValues = new List<(int, string, Block)>(); int index = 0; + Block defaultBlock = null; foreach (var section in switchInst.Sections) { if (!section.Body.MatchBranch(out Block target)) return false; - if (target.IncomingEdgeCount != 1 || target.Instructions.Count != 2) + if (target.IncomingEdgeCount > 1) { + defaultBlock = target; + continue; + } + if (target.Instructions.Count != 2) return false; if (!target.Instructions[0].MatchIfInstruction(out var condition, out var bodyBranch)) return false; @@ -359,10 +325,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms } stringValues.Add((index++, stringValue, body)); } - + var defaultLabel = new LongSet(new LongInterval(0, index)).Invert(); var value = new StringToInt(switchValue.Clone(), stringValues.Select(item => item.Item2).ToArray()); inst = new SwitchInstruction(value); inst.Sections.AddRange(stringValues.Select(section => new SwitchSection { Labels = new Util.LongSet(section.Item1), Body = new Branch(section.Item3) })); + inst.Sections.Add(new SwitchSection { Labels = defaultLabel, Body = new Branch(defaultBlock) }); return true; } From f42d1a4b34c7bf6b5e33682a68b8b3e8e19375f6 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 7 Oct 2017 13:54:49 +0200 Subject: [PATCH 022/190] Fix crash in SwitchDetection. --- ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs index 5c31baa9a..6e2fa3e67 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs @@ -65,11 +65,12 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow Body = section.Value }); } - if (block.Instructions.Last() is Branch) { + if (block.Instructions.Last() is SwitchInstruction) { + // we'll replace the switch + } else { Debug.Assert(block.Instructions.SecondToLastOrDefault() is IfInstruction); + // Remove branch/leave after if; it's getting moved into a section. block.Instructions.RemoveAt(block.Instructions.Count - 1); - } else { - Debug.Assert(block.Instructions.Last() is SwitchInstruction); } block.Instructions[block.Instructions.Count - 1] = sw; From afcbc8c6cff0fda51a2e008f487d200377a1b20b Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 7 Oct 2017 15:37:54 +0200 Subject: [PATCH 023/190] #899: Add cpblk and initblk instructions to ILAst. --- .../CSharp/StatementBuilder.cs | 28 ++ ICSharpCode.Decompiler/IL/ILReader.cs | 4 +- ICSharpCode.Decompiler/IL/Instructions.cs | 338 ++++++++++++++++++ ICSharpCode.Decompiler/IL/Instructions.tt | 10 +- 4 files changed, 377 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 8de9734cf..0987baa21 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -757,5 +757,33 @@ namespace ICSharpCode.Decompiler.CSharp return block.ChildIndex == container.Blocks.Count - 1 && container == leave.TargetContainer; } + + protected internal override Statement VisitInitblk(Initblk inst) + { + var stmt = new ExpressionStatement(new InvocationExpression { + Target = new IdentifierExpression("memset"), + Arguments = { + exprBuilder.Translate(inst.Address), + exprBuilder.Translate(inst.Value), + exprBuilder.Translate(inst.Size) + } + }); + stmt.AddChild(new Comment(" IL initblk instruction"), Roles.Comment); + return stmt; + } + + protected internal override Statement VisitCpblk(Cpblk inst) + { + var stmt = new ExpressionStatement(new InvocationExpression { + Target = new IdentifierExpression("memcpy"), + Arguments = { + exprBuilder.Translate(inst.DestAddress), + exprBuilder.Translate(inst.SourceAddress), + exprBuilder.Translate(inst.Size) + } + }); + stmt.AddChild(new Comment(" IL cpblk instruction"), Roles.Comment); + return stmt; + } } } diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index b401f5c5d..da225de77 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -523,7 +523,7 @@ namespace ICSharpCode.Decompiler.IL case Cil.Code.Conv_Ovf_U_Un: return Push(new Conv(Pop(), PrimitiveType.U, true, Sign.Unsigned)); case Cil.Code.Cpblk: - throw new NotImplementedException(); + return new Cpblk(size: Pop(StackType.I4), sourceAddress: PopPointer(), destAddress: PopPointer()); case Cil.Code.Div: return BinaryNumeric(BinaryNumericOperator.Div, false, Sign.Signed); case Cil.Code.Div_Un: @@ -535,7 +535,7 @@ namespace ICSharpCode.Decompiler.IL case Cil.Code.Endfinally: return new Leave(null); case Cil.Code.Initblk: - throw new NotImplementedException(); + return new Initblk(size: Pop(StackType.I4), value: Pop(StackType.I4), address: PopPointer()); case Cil.Code.Jmp: throw new NotImplementedException(); case Cil.Code.Ldarg: diff --git a/ICSharpCode.Decompiler/IL/Instructions.cs b/ICSharpCode.Decompiler/IL/Instructions.cs index 015b312b7..fc83ed656 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.cs +++ b/ICSharpCode.Decompiler/IL/Instructions.cs @@ -121,6 +121,10 @@ namespace ICSharpCode.Decompiler.IL LdMemberToken, /// Allocates space in the stack frame LocAlloc, + /// memcpy(destAddress, sourceAddress, size); + Cpblk, + /// memset(address, value, size) + Initblk, /// Load address of instance field LdFlda, /// Load static field address @@ -2860,6 +2864,286 @@ namespace ICSharpCode.Decompiler.IL } } namespace ICSharpCode.Decompiler.IL +{ + /// memcpy(destAddress, sourceAddress, size); + public sealed partial class Cpblk : ILInstruction, ISupportsVolatilePrefix, ISupportsUnalignedPrefix + { + public Cpblk(ILInstruction destAddress, ILInstruction sourceAddress, ILInstruction size) : base(OpCode.Cpblk) + { + this.DestAddress = destAddress; + this.SourceAddress = sourceAddress; + this.Size = size; + } + public static readonly SlotInfo DestAddressSlot = new SlotInfo("DestAddress", canInlineInto: true); + ILInstruction destAddress; + public ILInstruction DestAddress { + get { return this.destAddress; } + set { + ValidateChild(value); + SetChildInstruction(ref this.destAddress, value, 0); + } + } + public static readonly SlotInfo SourceAddressSlot = new SlotInfo("SourceAddress", canInlineInto: true); + ILInstruction sourceAddress; + public ILInstruction SourceAddress { + get { return this.sourceAddress; } + set { + ValidateChild(value); + SetChildInstruction(ref this.sourceAddress, value, 1); + } + } + public static readonly SlotInfo SizeSlot = new SlotInfo("Size", canInlineInto: true); + ILInstruction size; + public ILInstruction Size { + get { return this.size; } + set { + ValidateChild(value); + SetChildInstruction(ref this.size, value, 2); + } + } + protected sealed override int GetChildCount() + { + return 3; + } + protected sealed override ILInstruction GetChild(int index) + { + switch (index) { + case 0: + return this.destAddress; + case 1: + return this.sourceAddress; + case 2: + return this.size; + default: + throw new IndexOutOfRangeException(); + } + } + protected sealed override void SetChild(int index, ILInstruction value) + { + switch (index) { + case 0: + this.DestAddress = value; + break; + case 1: + this.SourceAddress = value; + break; + case 2: + this.Size = value; + break; + default: + throw new IndexOutOfRangeException(); + } + } + protected sealed override SlotInfo GetChildSlot(int index) + { + switch (index) { + case 0: + return DestAddressSlot; + case 1: + return SourceAddressSlot; + case 2: + return SizeSlot; + default: + throw new IndexOutOfRangeException(); + } + } + public sealed override ILInstruction Clone() + { + var clone = (Cpblk)ShallowClone(); + clone.DestAddress = this.destAddress.Clone(); + clone.SourceAddress = this.sourceAddress.Clone(); + clone.Size = this.size.Clone(); + return clone; + } + /// Gets/Sets whether the memory access is volatile. + public bool IsVolatile { get; set; } + /// Returns the alignment specified by the 'unaligned' prefix; or 0 if there was no 'unaligned' prefix. + public byte UnalignedPrefix { get; set; } + public override StackType ResultType { get { return StackType.Void; } } + protected override InstructionFlags ComputeFlags() + { + return destAddress.Flags | sourceAddress.Flags | size.Flags | InstructionFlags.MayThrow | InstructionFlags.SideEffect; + } + public override InstructionFlags DirectFlags { + get { + return InstructionFlags.MayThrow | InstructionFlags.SideEffect; + } + } + public override void WriteTo(ITextOutput output, ILAstWritingOptions options) + { + if (IsVolatile) + output.Write("volatile."); + if (UnalignedPrefix > 0) + output.Write("unaligned(" + UnalignedPrefix + ")."); + output.Write(OpCode); + output.Write('('); + this.destAddress.WriteTo(output, options); + output.Write(", "); + this.sourceAddress.WriteTo(output, options); + output.Write(", "); + this.size.WriteTo(output, options); + output.Write(')'); + } + public override void AcceptVisitor(ILVisitor visitor) + { + visitor.VisitCpblk(this); + } + public override T AcceptVisitor(ILVisitor visitor) + { + return visitor.VisitCpblk(this); + } + public override T AcceptVisitor(ILVisitor visitor, C context) + { + return visitor.VisitCpblk(this, context); + } + protected internal override bool PerformMatch(ILInstruction other, ref Patterns.Match match) + { + var o = other as Cpblk; + return o != null && this.destAddress.PerformMatch(o.destAddress, ref match) && this.sourceAddress.PerformMatch(o.sourceAddress, ref match) && this.size.PerformMatch(o.size, ref match) && IsVolatile == o.IsVolatile && UnalignedPrefix == o.UnalignedPrefix; + } + } +} +namespace ICSharpCode.Decompiler.IL +{ + /// memset(address, value, size) + public sealed partial class Initblk : ILInstruction, ISupportsVolatilePrefix, ISupportsUnalignedPrefix + { + public Initblk(ILInstruction address, ILInstruction value, ILInstruction size) : base(OpCode.Initblk) + { + this.Address = address; + this.Value = value; + this.Size = size; + } + public static readonly SlotInfo AddressSlot = new SlotInfo("Address", canInlineInto: true); + ILInstruction address; + public ILInstruction Address { + get { return this.address; } + set { + ValidateChild(value); + SetChildInstruction(ref this.address, value, 0); + } + } + public static readonly SlotInfo ValueSlot = new SlotInfo("Value", canInlineInto: true); + ILInstruction value; + public ILInstruction Value { + get { return this.value; } + set { + ValidateChild(value); + SetChildInstruction(ref this.value, value, 1); + } + } + public static readonly SlotInfo SizeSlot = new SlotInfo("Size", canInlineInto: true); + ILInstruction size; + public ILInstruction Size { + get { return this.size; } + set { + ValidateChild(value); + SetChildInstruction(ref this.size, value, 2); + } + } + protected sealed override int GetChildCount() + { + return 3; + } + protected sealed override ILInstruction GetChild(int index) + { + switch (index) { + case 0: + return this.address; + case 1: + return this.value; + case 2: + return this.size; + default: + throw new IndexOutOfRangeException(); + } + } + protected sealed override void SetChild(int index, ILInstruction value) + { + switch (index) { + case 0: + this.Address = value; + break; + case 1: + this.Value = value; + break; + case 2: + this.Size = value; + break; + default: + throw new IndexOutOfRangeException(); + } + } + protected sealed override SlotInfo GetChildSlot(int index) + { + switch (index) { + case 0: + return AddressSlot; + case 1: + return ValueSlot; + case 2: + return SizeSlot; + default: + throw new IndexOutOfRangeException(); + } + } + public sealed override ILInstruction Clone() + { + var clone = (Initblk)ShallowClone(); + clone.Address = this.address.Clone(); + clone.Value = this.value.Clone(); + clone.Size = this.size.Clone(); + return clone; + } + /// Gets/Sets whether the memory access is volatile. + public bool IsVolatile { get; set; } + /// Returns the alignment specified by the 'unaligned' prefix; or 0 if there was no 'unaligned' prefix. + public byte UnalignedPrefix { get; set; } + public override StackType ResultType { get { return StackType.Void; } } + protected override InstructionFlags ComputeFlags() + { + return address.Flags | value.Flags | size.Flags | InstructionFlags.MayThrow | InstructionFlags.SideEffect; + } + public override InstructionFlags DirectFlags { + get { + return InstructionFlags.MayThrow | InstructionFlags.SideEffect; + } + } + public override void WriteTo(ITextOutput output, ILAstWritingOptions options) + { + if (IsVolatile) + output.Write("volatile."); + if (UnalignedPrefix > 0) + output.Write("unaligned(" + UnalignedPrefix + ")."); + output.Write(OpCode); + output.Write('('); + this.address.WriteTo(output, options); + output.Write(", "); + this.value.WriteTo(output, options); + output.Write(", "); + this.size.WriteTo(output, options); + output.Write(')'); + } + public override void AcceptVisitor(ILVisitor visitor) + { + visitor.VisitInitblk(this); + } + public override T AcceptVisitor(ILVisitor visitor) + { + return visitor.VisitInitblk(this); + } + public override T AcceptVisitor(ILVisitor visitor, C context) + { + return visitor.VisitInitblk(this, context); + } + protected internal override bool PerformMatch(ILInstruction other, ref Patterns.Match match) + { + var o = other as Initblk; + return o != null && this.address.PerformMatch(o.address, ref match) && this.value.PerformMatch(o.value, ref match) && this.size.PerformMatch(o.size, ref match) && IsVolatile == o.IsVolatile && UnalignedPrefix == o.UnalignedPrefix; + } + } +} +namespace ICSharpCode.Decompiler.IL { /// Load address of instance field public sealed partial class LdFlda : ILInstruction, IInstructionWithFieldOperand @@ -4561,6 +4845,14 @@ namespace ICSharpCode.Decompiler.IL { Default(inst); } + protected internal virtual void VisitCpblk(Cpblk inst) + { + Default(inst); + } + protected internal virtual void VisitInitblk(Initblk inst) + { + Default(inst); + } protected internal virtual void VisitLdFlda(LdFlda inst) { Default(inst); @@ -4847,6 +5139,14 @@ namespace ICSharpCode.Decompiler.IL { return Default(inst); } + protected internal virtual T VisitCpblk(Cpblk inst) + { + return Default(inst); + } + protected internal virtual T VisitInitblk(Initblk inst) + { + return Default(inst); + } protected internal virtual T VisitLdFlda(LdFlda inst) { return Default(inst); @@ -5133,6 +5433,14 @@ namespace ICSharpCode.Decompiler.IL { return Default(inst, context); } + protected internal virtual T VisitCpblk(Cpblk inst, C context) + { + return Default(inst, context); + } + protected internal virtual T VisitInitblk(Initblk inst, C context) + { + return Default(inst, context); + } protected internal virtual T VisitLdFlda(LdFlda inst, C context) { return Default(inst, context); @@ -5276,6 +5584,8 @@ namespace ICSharpCode.Decompiler.IL "ldtypetoken", "ldmembertoken", "localloc", + "cpblk", + "initblk", "ldflda", "ldsflda", "castclass", @@ -5585,6 +5895,34 @@ namespace ICSharpCode.Decompiler.IL argument = default(ILInstruction); return false; } + public bool MatchCpblk(out ILInstruction destAddress, out ILInstruction sourceAddress, out ILInstruction size) + { + var inst = this as Cpblk; + if (inst != null) { + destAddress = inst.DestAddress; + sourceAddress = inst.SourceAddress; + size = inst.Size; + return true; + } + destAddress = default(ILInstruction); + sourceAddress = default(ILInstruction); + size = default(ILInstruction); + return false; + } + public bool MatchInitblk(out ILInstruction address, out ILInstruction value, out ILInstruction size) + { + var inst = this as Initblk; + if (inst != null) { + address = inst.Address; + value = inst.Value; + size = inst.Size; + return true; + } + address = default(ILInstruction); + value = default(ILInstruction); + size = default(ILInstruction); + return false; + } public bool MatchLdFlda(out ILInstruction target, out IField field) { var inst = this as LdFlda; diff --git a/ICSharpCode.Decompiler/IL/Instructions.tt b/ICSharpCode.Decompiler/IL/Instructions.tt index 2b28a9efe..927b59c24 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.tt +++ b/ICSharpCode.Decompiler/IL/Instructions.tt @@ -176,7 +176,15 @@ CustomClassName("LdMemberToken"), NoArguments, HasMemberOperand, ResultType("O")), new OpCode("localloc", "Allocates space in the stack frame", CustomClassName("LocAlloc"), Unary, ResultType("I"), MayThrow), - + new OpCode("cpblk", "memcpy(destAddress, sourceAddress, size);", + CustomArguments("destAddress", "sourceAddress", "size"), + MayThrow, MemoryAccess, + SupportsVolatilePrefix, SupportsUnalignedPrefix, ResultType("Void")), + new OpCode("initblk", "memset(address, value, size)", + CustomArguments("address", "value", "size"), + MayThrow, MemoryAccess, + SupportsVolatilePrefix, SupportsUnalignedPrefix, ResultType("Void")), + new OpCode("ldflda", "Load address of instance field", CustomClassName("LdFlda"), CustomArguments("target"), MayThrowIfNotDelayed, HasFieldOperand, ResultType("Ref")), new OpCode("ldsflda", "Load static field address", From 6a1b6231408c660b9d301e45b47c6614961d09f6 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 7 Oct 2017 19:33:29 +0200 Subject: [PATCH 024/190] #899: decode jmp instruction into tail call --- .../CorrectnessTestRunner.cs | 6 +++ .../ICSharpCode.Decompiler.Tests.csproj | 1 + .../TestCases/Correctness/Jmp.il | 47 +++++++++++++++++++ ICSharpCode.Decompiler/IL/ILReader.cs | 18 ++++++- 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Correctness/Jmp.il diff --git a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs index bfeaf5e85..d984705c6 100644 --- a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs @@ -162,6 +162,12 @@ namespace ICSharpCode.Decompiler.Tests RunIL("BitNot.il", CompilerOptions.UseDebug | CompilerOptions.Force32Bit, AssemblerOptions.Force32Bit); } + [Test] + public void Jmp() + { + RunIL("Jmp.il"); + } + [Test] public void UnsafeCode([ValueSource("defaultOptions")] CompilerOptions options) { diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index a46ed0bcf..f39ff4d6d 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -44,6 +44,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Jmp.il b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Jmp.il new file mode 100644 index 000000000..fc87d3ff8 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Jmp.il @@ -0,0 +1,47 @@ +.assembly extern mscorlib +{ + .publickeytoken = ( b7 7a 5c 56 19 34 e0 89 ) + .ver 4:0:0:0 +} + +.assembly 'Jmp' +{ + .ver 0:0:0:0 +} + +.module Jmp.exe +.corflags 0x00000001 // ILOnly + +.class private auto ansi abstract sealed beforefieldinit Program + extends [mscorlib]System.Object +{ + .method public hidebysig static void Main (string[] args) cil managed + { + .maxstack 8 + .entrypoint + + ldstr "Method1(100) = {0}" + ldc.i4 100 + call int32 Program::Method1(int32) + box int32 + call void [mscorlib]System.Console::WriteLine(string, object) + ret + } // end of method Main + + .method public static int32 Method1(int32 val) + { + ldarg.0 + ldc.i4.1 + add + starg.s 0 + jmp int32 Program::Method2(int32) + } + + .method public static int32 Method2(int32 val) + { + ldarg.0 + ldc.i4.5 + mul + ret + } +} diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index da225de77..ac122c74a 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -537,7 +537,7 @@ namespace ICSharpCode.Decompiler.IL case Cil.Code.Initblk: return new Initblk(size: Pop(StackType.I4), value: Pop(StackType.I4), address: PopPointer()); case Cil.Code.Jmp: - throw new NotImplementedException(); + return DecodeJmp(); case Cil.Code.Ldarg: case Cil.Code.Ldarg_S: return Push(Ldarg(((ParameterDefinition)cecilInst.Operand).Sequence)); @@ -1251,6 +1251,22 @@ namespace ICSharpCode.Decompiler.IL return Push(new BinaryNumericInstruction(@operator, left, right, checkForOverflow, sign)); } + ILInstruction DecodeJmp() + { + IMethod method = ReadAndDecodeMethodReference(); + // Translate jmp into tail call: + Call call = new Call(method); + call.IsTail = true; + call.ILStackWasEmpty = true; + if (!method.IsStatic) { + call.Arguments.Add(Ldarg(0)); + } + foreach (var p in method.Parameters) { + call.Arguments.Add(Ldarg(call.Arguments.Count)); + } + return new Leave(mainContainer, call); + } + ILInstruction LdToken(IMetadataTokenProvider token) { if (token is TypeReference) From 43c2f891a0f183009630bc188e34e6632fd589f1 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 7 Oct 2017 13:26:31 +0200 Subject: [PATCH 025/190] SwitchOnStringTransform: make sure switch variable is of type string in Roslyn case. --- .../IL/Transforms/SwitchOnStringTransform.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index ef199199a..774857f80 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -93,8 +93,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms isLegacy = false; values.Add((value, firstBlock)); } else return false; - // switchValueVar must be assigned only once. - if (!switchValueVar.IsSingleDefinition) + // switchValueVar must be assigned only once and must be of type string. + if (!switchValueVar.IsSingleDefinition || !switchValueVar.Type.IsKnownType(KnownTypeCode.String)) return false; // if instruction must be followed by a branch to the next case if (!(instructions.ElementAtOrDefault(i + 1) is Branch nextCaseJump)) From bd165642cb3db8fc0abf3c7133a1933285fd1576 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 7 Oct 2017 22:15:53 +0200 Subject: [PATCH 026/190] Fix #489: Add support for switch statement pattern using Hashtable --- .../IL/Transforms/SwitchOnStringTransform.cs | 152 +++++++++++++++--- 1 file changed, 134 insertions(+), 18 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 774857f80..96836b3db 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -47,7 +47,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms changed = true; continue; } - if (MatchLegacySwitchOnString(block.Instructions, i, out newSwitch)) { + if (MatchLegacySwitchOnStringWithHashtable(block.Instructions, i, out newSwitch)) { + block.Instructions[i + 1].ReplaceWith(newSwitch); + block.Instructions.RemoveAt(i); + changed = true; + continue; + } + if (MatchLegacySwitchOnStringWithDict(block.Instructions, i, out newSwitch)) { block.Instructions[i + 1].ReplaceWith(newSwitch); block.Instructions.RemoveAt(i); changed = true; @@ -181,7 +187,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms return storeInst.Value.MatchLdLoc(right); } - bool MatchLegacySwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst) + /// + /// Matches the C# 2.0 switch-on-string pattern, which uses Dictionary<string, int>. + /// + bool MatchLegacySwitchOnStringWithDict(InstructionCollection instructions, int i, out SwitchInstruction inst) { inst = null; if (i < 1) return false; @@ -205,12 +214,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!nextBlock.Instructions[1].MatchBranch(out var dictInitBlock) || dictInitBlock.IncomingEdgeCount != 1) return false; if (!(condition.MatchCompNotEquals(out left, out right) && right.MatchLdNull() && - MatchDictionaryFieldLoad(left, out var dictField, out var dictionaryType))) + MatchDictionaryFieldLoad(left, IsStringToIntDictionary, out var dictField, out var dictionaryType))) return false; // match third block: initialization of compiler-generated Dictionary if (dictInitBlock.IncomingEdgeCount != 1 || dictInitBlock.Instructions.Count < 3) return false; - if (!ExtractStringValuesFromDictionaryInitBlock(dictInitBlock, out var stringValues, tryGetValueBlock, dictionaryType, dictField)) + if (!ExtractStringValuesFromInitBlock(dictInitBlock, out var stringValues, tryGetValueBlock, dictionaryType, dictField)) return false; // match fourth block: TryGetValue on compiler-generated Dictionary if (tryGetValueBlock.IncomingEdgeCount != 2 || tryGetValueBlock.Instructions.Count != 2) @@ -220,7 +229,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!defaultBlockJump.MatchBranch(out var defaultBlock)) return false; if (!(condition.MatchLogicNot(out var arg) && arg is Call c && c.Method.Name == "TryGetValue" && - MatchDictionaryFieldLoad(c.Arguments[0], out var dictField2, out _) && dictField2.Equals(dictField))) + MatchDictionaryFieldLoad(c.Arguments[0], IsStringToIntDictionary, out var dictField2, out _) && dictField2.Equals(dictField))) return false; if (!c.Arguments[1].MatchLdLoc(switchValueVar) || !c.Arguments[2].MatchLdLoca(out var switchIndexVar)) return false; @@ -249,36 +258,41 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; } - bool MatchDictionaryFieldLoad(ILInstruction inst, out IField dictField, out IType dictionaryType) + bool MatchDictionaryFieldLoad(ILInstruction inst, Func typeMatcher, out IField dictField, out IType dictionaryType) { dictField = null; dictionaryType = null; return inst.MatchLdObj(out var dictionaryFieldLoad, out dictionaryType) && - IsStringToIntDictionary(dictionaryType) && + typeMatcher(dictionaryType) && dictionaryFieldLoad.MatchLdsFlda(out dictField) && - dictField.IsCompilerGeneratedOrIsInCompilerGeneratedClass(); + (dictField.IsCompilerGeneratedOrIsInCompilerGeneratedClass() || dictField.Name.StartsWith("$$method", StringComparison.Ordinal)); } - bool ExtractStringValuesFromDictionaryInitBlock(Block block, out List values, Block targetBlock, IType dictionaryType, IField dictionaryField) + bool ExtractStringValuesFromInitBlock(Block block, out List values, Block targetBlock, IType dictionaryType, IField dictionaryField) { values = null; if (!(block.Instructions[0].MatchStLoc(out var dictVar, out var newObjDict) && - newObjDict is NewObj newObj && newObj.Arguments.Count == 1 && newObj.Arguments[0].MatchLdcI4(out var valuesLength))) - return false; - if (block.Instructions.Count != valuesLength + 3) + newObjDict is NewObj newObj && newObj.Arguments.Count >= 1 && newObj.Arguments[0].MatchLdcI4(out var valuesLength))) return false; values = new List(valuesLength); - for (int i = 0; i < valuesLength; i++) { - if (!(block.Instructions[i + 1] is Call c && c.Method.Name == "Add" && c.Arguments.Count == 3 && - c.Arguments[0].MatchLdLoc(dictVar) && c.Arguments[1].MatchLdStr(out var value) && c.Arguments[2].MatchLdcI4(i))) - return false; + int i = 0; + while (i + 1 < block.Instructions.Count - 2 && MatchAddCall(block.Instructions[i + 1], dictVar, i, out var value)) { values.Add(value); + i++; } - if (!(block.Instructions[valuesLength + 1].MatchStObj(out var loadField, out var dictVarLoad, out var dictType) && + if (!(block.Instructions[i + 1].MatchStObj(out var loadField, out var dictVarLoad, out var dictType) && dictType.Equals(dictionaryType) && loadField.MatchLdsFlda(out var dictField) && dictField.Equals(dictionaryField)) && dictVarLoad.MatchLdLoc(dictVar)) return false; - return block.Instructions[valuesLength + 2].MatchBranch(targetBlock); + return block.Instructions[i + 2].MatchBranch(targetBlock); + } + + bool MatchAddCall(ILInstruction inst, ILVariable dictVar, int i, out string value) + { + value = null; + return inst is Call c && c.Method.Name == "Add" && c.Arguments.Count == 3 && + c.Arguments[0].MatchLdLoc(dictVar) && c.Arguments[1].MatchLdStr(out value) && + (c.Arguments[2].MatchLdcI4(i) || (c.Arguments[2].MatchBox(out var arg, out _) && arg.MatchLdcI4(i))); } bool IsStringToIntDictionary(IType dictionaryType) @@ -291,6 +305,108 @@ namespace ICSharpCode.Decompiler.IL.Transforms dictionaryType.TypeArguments[1].IsKnownType(KnownTypeCode.Int32); } + bool IsNonGenericHashtable(IType dictionaryType) + { + if (dictionaryType.FullName != "System.Collections.Hashtable") + return false; + if (dictionaryType.TypeArguments.Count != 0) + return false; + return true; + } + + bool MatchLegacySwitchOnStringWithHashtable(InstructionCollection instructions, int i, out SwitchInstruction inst) + { + inst = null; + // match first block: checking compiler-generated Hashtable for null + // if (comp(volatile.ldobj System.Collections.Hashtable(ldsflda $$method0x600003f-1) != ldnull)) br switchHeadBlock + // br tableInitBlock + if (!(instructions[i].MatchIfInstruction(out var condition, out var branchToSwitchHead) && i + 1 < instructions.Count)) + return false; + if (!instructions[i + 1].MatchBranch(out var tableInitBlock) || tableInitBlock.IncomingEdgeCount != 1) + return false; + if (!(condition.MatchCompNotEquals(out var left, out var right) && right.MatchLdNull() && + MatchDictionaryFieldLoad(left, IsNonGenericHashtable, out var dictField, out var dictionaryType))) + return false; + if (!branchToSwitchHead.MatchBranch(out var switchHead)) + return false; + // match second block: initialization of compiler-generated Hashtable + // stloc table(newobj Hashtable..ctor(ldc.i4 capacity, ldc.f loadFactor)) + // call Add(ldloc table, ldstr value, box System.Int32(ldc.i4 index)) + // ... more calls to Add ... + // volatile.stobj System.Collections.Hashtable(ldsflda $$method0x600003f - 1, ldloc table) + // br switchHeadBlock + if (tableInitBlock.IncomingEdgeCount != 1 || tableInitBlock.Instructions.Count < 3) + return false; + if (!ExtractStringValuesFromInitBlock(tableInitBlock, out var stringValues, switchHead, dictionaryType, dictField)) + return false; + // match third block: checking switch-value for null + // stloc tmp(ldloc switch-value) + // stloc switchVariable(ldloc tmp) + // if (comp(ldloc tmp == ldnull)) br nullCaseBlock + // br getItemBlock + if (switchHead.Instructions.Count != 4 || switchHead.IncomingEdgeCount != 2) + return false; + if (!switchHead.Instructions[0].MatchStLoc(out var tmp, out var switchValue)) + return false; + if (!switchHead.Instructions[1].MatchStLoc(out var switchVariable, out var tmpLoad) || !tmpLoad.MatchLdLoc(tmp)) + return false; + if (!switchHead.Instructions[2].MatchIfInstruction(out condition, out var nullCaseBlockBranch)) + return false; + if (!switchHead.Instructions[3].MatchBranch(out var getItemBlock) || !nullCaseBlockBranch.MatchBranch(out var nullCaseBlock)) + return false; + if (!(condition.MatchCompEquals(out left, out right) && right.MatchLdNull() && left.MatchLdLoc(tmp))) + return false; + // match fourth block: get_Item on compiler-generated Hashtable + // stloc tmp2(call get_Item(volatile.ldobj System.Collections.Hashtable(ldsflda $$method0x600003f - 1), ldloc switchVariable)) + // stloc switchVariable(ldloc tmp2) + // if (comp(ldloc tmp2 == ldnull)) br defaultCaseBlock + // br switchBlock + if (getItemBlock.IncomingEdgeCount != 1 || getItemBlock.Instructions.Count != 4) + return false; + if (!(getItemBlock.Instructions[0].MatchStLoc(out var tmp2, out var getItem) && getItem is Call getItemCall && getItemCall.Method.Name == "get_Item")) + return false; + if (!getItemBlock.Instructions[1].MatchStLoc(out var switchVariable2, out var tmp2Load) || !tmp2Load.MatchLdLoc(tmp2)) + return false; + if (!ILVariableEqualityComparer.Instance.Equals(switchVariable, switchVariable2)) + return false; + if (!getItemBlock.Instructions[2].MatchIfInstruction(out condition, out var defaultBlockBranch)) + return false; + if (!getItemBlock.Instructions[3].MatchBranch(out var switchBlock) || !defaultBlockBranch.MatchBranch(out var defaultBlock)) + return false; + if (!(condition.MatchCompEquals(out left, out right) && right.MatchLdNull() && left.MatchLdLoc(tmp2))) + return false; + if (!(getItemCall.Arguments.Count == 2 && MatchDictionaryFieldLoad(getItemCall.Arguments[0], IsStringToIntDictionary, out var dictField2, out _) && dictField2.Equals(dictField)) && + getItemCall.Arguments[1].MatchLdLoc(switchVariable2)) + return false; + // match fifth block: switch-instruction block + // switch (ldobj System.Int32(unbox System.Int32(ldloc switchVariable))) { + // case [0..1): br caseBlock1 + // ... more cases ... + // case [long.MinValue..0),[13..long.MaxValue]: br defaultBlock + // } + if (switchBlock.IncomingEdgeCount != 1 || switchBlock.Instructions.Count != 1) + return false; + if (!(switchBlock.Instructions[0] is SwitchInstruction switchInst && switchInst.Value.MatchLdObj(out var target, out var ldobjType) && + target.MatchUnbox(out var arg, out var unboxType) && arg.MatchLdLoc(switchVariable2) && ldobjType.IsKnownType(KnownTypeCode.Int32) && unboxType.Equals(ldobjType))) + return false; + var sections = new List(switchInst.Sections); + // switch contains case null: + if (nullCaseBlock != defaultBlock) { + var label = new Util.LongSet(switchInst.Sections.Count); + var possibleConflicts = switchInst.Sections.Where(sec => sec.Labels.Overlaps(label)).ToArray(); + if (possibleConflicts.Length > 1) + return false; + else if (possibleConflicts.Length == 1) + possibleConflicts[0].Labels = possibleConflicts[0].Labels.ExceptWith(label); + stringValues.Add(null); + sections.Add(new SwitchSection() { Labels = label, Body = new Branch(nullCaseBlock) }); + } + var stringToInt = new StringToInt(switchValue, stringValues.ToArray()); + inst = new SwitchInstruction(stringToInt); + inst.Sections.AddRange(sections); + return true; + } + bool MatchRoslynSwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst) { inst = null; From ebab7d5de00b49e661b2e605e62edfe1c548962e Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 7 Oct 2017 22:25:40 +0200 Subject: [PATCH 027/190] #899: Add calli opcode to ILAst --- .../Disassembler/DisassemblerHelpers.cs | 13 ++ .../ICSharpCode.Decompiler.csproj | 1 + ICSharpCode.Decompiler/IL/ILReader.cs | 35 +++- ICSharpCode.Decompiler/IL/Instructions.cs | 40 +++++ ICSharpCode.Decompiler/IL/Instructions.tt | 6 + .../IL/Instructions/CallIndirect.cs | 170 ++++++++++++++++++ .../TypeSystem/CecilLoader.cs | 2 + 7 files changed, 265 insertions(+), 2 deletions(-) create mode 100644 ICSharpCode.Decompiler/IL/Instructions/CallIndirect.cs diff --git a/ICSharpCode.Decompiler/Disassembler/DisassemblerHelpers.cs b/ICSharpCode.Decompiler/Disassembler/DisassemblerHelpers.cs index 481b2b5c5..ba895ed79 100644 --- a/ICSharpCode.Decompiler/Disassembler/DisassemblerHelpers.cs +++ b/ICSharpCode.Decompiler/Disassembler/DisassemblerHelpers.cs @@ -289,6 +289,19 @@ namespace ICSharpCode.Decompiler.Disassembler writer.Write(" modreq("); ((RequiredModifierType)type).ModifierType.WriteTo(writer, ILNameSyntax.TypeName); writer.Write(") "); + } else if (type is FunctionPointerType fpt) { + writer.Write("method "); + fpt.ReturnType.WriteTo(writer, syntax); + writer.Write(" *("); + bool first = true; + foreach (var p in fpt.Parameters) { + if (first) + first = false; + else + writer.Write(", "); + p.ParameterType.WriteTo(writer, syntax); + } + writer.Write(')'); } else if (type is SentinelType) { writer.Write("..., "); ((SentinelType)type).ElementType.WriteTo(writer, syntax); diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 581380e6d..912fa636d 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -271,6 +271,7 @@ + diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index ac122c74a..dbf152ee7 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -443,7 +443,7 @@ namespace ICSharpCode.Decompiler.IL case Cil.Code.Callvirt: return DecodeCall(OpCode.CallVirt); case Cil.Code.Calli: - throw new NotImplementedException(); + return DecodeCallIndirect(); case Cil.Code.Ceq: return Push(Comparison(ComparisonKind.Equality)); case Cil.Code.Cgt: @@ -916,9 +916,16 @@ namespace ICSharpCode.Decompiler.IL ILInstruction inst = Pop(); if (expectedType != inst.ResultType) { if (expectedType == StackType.I && inst.ResultType == StackType.I4) { + // IL allows implicit I4->I conversions inst = new Conv(inst, PrimitiveType.I, false, Sign.None); + } else if (expectedType == StackType.I4 && inst.ResultType == StackType.I) { + // C++/CLI also sometimes implicitly converts in the other direction: + inst = new Conv(inst, PrimitiveType.I4, false, Sign.None); } else if (expectedType == StackType.Ref && inst.ResultType == StackType.I) { // implicitly start GC tracking + } else if (expectedType == StackType.I && inst.ResultType == StackType.Ref) { + // Implicitly stop GC tracking; this occurs when passing the result of 'ldloca' or 'ldsflda' + // to a method expecting a native pointer. } else if (inst is InvalidExpression) { ((InvalidExpression)inst).ExpectedResultType = expectedType; } else { @@ -1105,7 +1112,31 @@ namespace ICSharpCode.Decompiler.IL return call; } } - + + ILInstruction DecodeCallIndirect() + { + var functionPointer = Pop(StackType.I); + var signature = (CallSite)currentInstruction.Operand; + Debug.Assert(!signature.HasThis); + var parameterTypes = new IType[signature.Parameters.Count]; + var arguments = new ILInstruction[parameterTypes.Length]; + for (int i = signature.Parameters.Count - 1; i >= 0; i--) { + parameterTypes[i] = typeSystem.Resolve(signature.Parameters[i].ParameterType); + arguments[i] = Pop(parameterTypes[i].GetStackType()); + } + var call = new CallIndirect( + signature.CallingConvention, + typeSystem.Resolve(signature.ReturnType), + parameterTypes.ToImmutableArray(), + arguments, + functionPointer + ); + if (call.ResultType != StackType.Void) + return Push(call); + else + return call; + } + static int GetPopCount(OpCode callCode, MethodReference methodReference) { int popCount = methodReference.Parameters.Count; diff --git a/ICSharpCode.Decompiler/IL/Instructions.cs b/ICSharpCode.Decompiler/IL/Instructions.cs index fc83ed656..a98f573bf 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.cs +++ b/ICSharpCode.Decompiler/IL/Instructions.cs @@ -83,6 +83,8 @@ namespace ICSharpCode.Decompiler.IL Call, /// Virtual method call. CallVirt, + /// Unsafe function pointer call. + CallIndirect, /// Checks that the input float is not NaN or infinite. Ckfinite, /// Numeric cast. @@ -1954,6 +1956,31 @@ namespace ICSharpCode.Decompiler.IL } } namespace ICSharpCode.Decompiler.IL +{ + /// Unsafe function pointer call. + public sealed partial class CallIndirect : ILInstruction + { + + public override void AcceptVisitor(ILVisitor visitor) + { + visitor.VisitCallIndirect(this); + } + public override T AcceptVisitor(ILVisitor visitor) + { + return visitor.VisitCallIndirect(this); + } + public override T AcceptVisitor(ILVisitor visitor, C context) + { + return visitor.VisitCallIndirect(this, context); + } + protected internal override bool PerformMatch(ILInstruction other, ref Patterns.Match match) + { + var o = other as CallIndirect; + return o != null && EqualSignature(o) && Patterns.ListMatch.DoMatch(this.Arguments, o.Arguments, ref match) && this.FunctionPointer.PerformMatch(o.FunctionPointer, ref match); + } + } +} +namespace ICSharpCode.Decompiler.IL { /// Checks that the input float is not NaN or infinite. public sealed partial class Ckfinite : UnaryInstruction @@ -4769,6 +4796,10 @@ namespace ICSharpCode.Decompiler.IL { Default(inst); } + protected internal virtual void VisitCallIndirect(CallIndirect inst) + { + Default(inst); + } protected internal virtual void VisitCkfinite(Ckfinite inst) { Default(inst); @@ -5063,6 +5094,10 @@ namespace ICSharpCode.Decompiler.IL { return Default(inst); } + protected internal virtual T VisitCallIndirect(CallIndirect inst) + { + return Default(inst); + } protected internal virtual T VisitCkfinite(Ckfinite inst) { return Default(inst); @@ -5357,6 +5392,10 @@ namespace ICSharpCode.Decompiler.IL { return Default(inst, context); } + protected internal virtual T VisitCallIndirect(CallIndirect inst, C context) + { + return Default(inst, context); + } protected internal virtual T VisitCkfinite(Ckfinite inst, C context) { return Default(inst, context); @@ -5565,6 +5604,7 @@ namespace ICSharpCode.Decompiler.IL "comp", "call", "callvirt", + "calli", "ckfinite", "conv", "ldloc", diff --git a/ICSharpCode.Decompiler/IL/Instructions.tt b/ICSharpCode.Decompiler/IL/Instructions.tt index 927b59c24..eacecfe0f 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.tt +++ b/ICSharpCode.Decompiler/IL/Instructions.tt @@ -135,6 +135,12 @@ new OpCode("call", "Non-virtual method call.", Call), new OpCode("callvirt", "Virtual method call.", CustomClassName("CallVirt"), Call), + new OpCode("calli", "Unsafe function pointer call.", + CustomClassName("CallIndirect"), + CustomConstructor, CustomWriteTo, + MatchCondition("EqualSignature(o)"), + MatchCondition("Patterns.ListMatch.DoMatch(this.Arguments, o.Arguments, ref match)"), + MatchCondition("this.FunctionPointer.PerformMatch(o.FunctionPointer, ref match)")), new OpCode("ckfinite", "Checks that the input float is not NaN or infinite.", Unary, MayThrow, VoidResult), new OpCode("conv", "Numeric cast.", diff --git a/ICSharpCode.Decompiler/IL/Instructions/CallIndirect.cs b/ICSharpCode.Decompiler/IL/Instructions/CallIndirect.cs new file mode 100644 index 000000000..7b74939a2 --- /dev/null +++ b/ICSharpCode.Decompiler/IL/Instructions/CallIndirect.cs @@ -0,0 +1,170 @@ +// Copyright (c) 2017 Daniel Grunwald +// +// 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.Collections.Generic; +using System.Collections.Immutable; +using System.Diagnostics; +using System.Linq; +using ICSharpCode.Decompiler.TypeSystem; + +namespace ICSharpCode.Decompiler.IL +{ + partial class CallIndirect + { + public static readonly SlotInfo ArgumentSlot = new SlotInfo("Argument", canInlineInto: true, isCollection: true); + public static readonly SlotInfo FunctionPointerSlot = new SlotInfo("FunctionPointer", canInlineInto: true); + + public readonly InstructionCollection Arguments; + ILInstruction functionPointer; + + public Mono.Cecil.MethodCallingConvention CallingConvention { get; } + public IType ReturnType { get; } + public ImmutableArray ParameterTypes { get; } + + /// + /// A 'final instruction' that gets executed after the Instructions collection. + /// Provides the return value for the block. + /// + /// + /// Blocks in containers must have 'Nop' as a final instruction. + /// + public ILInstruction FunctionPointer { + get { + return functionPointer; + } + set { + ValidateChild(value); + SetChildInstruction(ref functionPointer, value, Arguments.Count); + } + } + + protected internal override void InstructionCollectionUpdateComplete() + { + base.InstructionCollectionUpdateComplete(); + if (functionPointer?.Parent == this) + functionPointer.ChildIndex = Arguments.Count; + } + + public CallIndirect(Mono.Cecil.MethodCallingConvention callingConvention, IType returnType, ImmutableArray parameterTypes, + IEnumerable arguments, ILInstruction functionPointer) : base(OpCode.CallIndirect) + { + this.CallingConvention = callingConvention; + this.ReturnType = returnType ?? throw new ArgumentNullException("returnType"); + this.ParameterTypes = parameterTypes.ToImmutableArray(); + this.Arguments = new InstructionCollection(this, 0); + this.Arguments.AddRange(arguments); + this.FunctionPointer = functionPointer; + } + + public override ILInstruction Clone() + { + return new CallIndirect(CallingConvention, ReturnType, ParameterTypes, + this.Arguments.Select(inst => inst.Clone()), functionPointer.Clone() + ) { + ILRange = this.ILRange + }; + } + + public override StackType ResultType => ReturnType.GetStackType(); + + internal override void CheckInvariant(ILPhase phase) + { + base.CheckInvariant(phase); + Debug.Assert(Arguments.Count == ParameterTypes.Length); + } + + public override void WriteTo(ITextOutput output, ILAstWritingOptions options) + { + output.Write("call.indirect "); + ReturnType.WriteTo(output); + output.Write('('); + bool first = true; + foreach (var (inst, type) in Arguments.Zip(ParameterTypes, (a,b) => (a,b))) { + if (first) + first = false; + else + output.Write(", "); + inst.WriteTo(output, options); + output.Write(" : "); + type.WriteTo(output); + } + if (Arguments.Count > 0) + output.Write(", "); + functionPointer.WriteTo(output, options); + output.Write(')'); + } + + protected override int GetChildCount() + { + return Arguments.Count + 1; + } + + protected override ILInstruction GetChild(int index) + { + if (index == Arguments.Count) + return functionPointer; + return Arguments[index]; + } + + protected override void SetChild(int index, ILInstruction value) + { + if (index == Arguments.Count) + FunctionPointer = value; + else + Arguments[index] = value; + } + + protected override SlotInfo GetChildSlot(int index) + { + if (index == Arguments.Count) + return FunctionPointerSlot; + else + return ArgumentSlot; + } + + protected override InstructionFlags ComputeFlags() + { + var flags = this.DirectFlags; + foreach (var inst in Arguments) { + flags |= inst.Flags; + } + flags |= functionPointer.Flags; + return flags; + } + + public override InstructionFlags DirectFlags { + get { + return InstructionFlags.MayThrow | InstructionFlags.SideEffect; + } + } + + bool EqualSignature(CallIndirect other) + { + if (CallingConvention != other.CallingConvention) + return false; + if (ParameterTypes.Length != other.ParameterTypes.Length) + return false; + for (int i = 0; i < ParameterTypes.Length; i++) { + if (!ParameterTypes[i].Equals(other.ParameterTypes[i])) + return false; + } + return ReturnType.Equals(other.ReturnType); + } + } +} diff --git a/ICSharpCode.Decompiler/TypeSystem/CecilLoader.cs b/ICSharpCode.Decompiler/TypeSystem/CecilLoader.cs index c52d0df6b..b07a0c835 100644 --- a/ICSharpCode.Decompiler/TypeSystem/CecilLoader.cs +++ b/ICSharpCode.Decompiler/TypeSystem/CecilLoader.cs @@ -350,6 +350,8 @@ namespace ICSharpCode.Decompiler.TypeSystem } else if (type is GenericParameter) { GenericParameter typeGP = (GenericParameter)type; return TypeParameterReference.Create(typeGP.Owner is MethodReference ? SymbolKind.Method : SymbolKind.TypeDefinition, typeGP.Position); + } else if (type is FunctionPointerType) { + return KnownTypeReference.Get(KnownTypeCode.IntPtr); } else if (type.IsNested) { ITypeReference typeRef = CreateType(type.DeclaringType, typeAttributes, ref typeIndex); int partTypeParameterCount; From e8b3ce99dc9ddcffce9c8244635e59d2c6571735 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 7 Oct 2017 22:26:09 +0200 Subject: [PATCH 028/190] clean up the mini C# lexer a bit --- ILSpy/Languages/CSharpLexer.cs | 111 +++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 48 deletions(-) diff --git a/ILSpy/Languages/CSharpLexer.cs b/ILSpy/Languages/CSharpLexer.cs index 42bab3925..4d839adee 100644 --- a/ILSpy/Languages/CSharpLexer.cs +++ b/ILSpy/Languages/CSharpLexer.cs @@ -101,35 +101,11 @@ namespace ICSharpCode.ILSpy protected Literal curToken = null; protected Literal peekToken = null; - string[] specialCommentTags = null; protected StringBuilder sb = new StringBuilder(); // used for the original value of strings (with escape sequences). protected StringBuilder originalValue = new StringBuilder(); - - public bool SkipAllComments { get; set; } - public bool EvaluateConditionalCompilation { get; set; } - public virtual IDictionary ConditionalCompilationSymbols { - get { throw new NotSupportedException(); } - } - - protected static IEnumerable GetSymbols(string symbols) - { - if (!string.IsNullOrEmpty(symbols)) { - foreach (string symbol in symbols.Split(';', ' ', '\t')) { - string s = symbol.Trim(); - if (s.Length == 0) - continue; - yield return s; - } - } - } - - public virtual void SetConditionalCompilationSymbols(string symbols) - { - throw new NotSupportedException(); - } - + protected int Line { get { return line; @@ -367,8 +343,6 @@ namespace ICSharpCode.ILSpy internal sealed class Lexer : AbstractLexer { - bool isAtLineBegin = true; - public Lexer(TextReader reader) : base(reader) { } @@ -376,10 +350,6 @@ namespace ICSharpCode.ILSpy protected override Literal Next() { char ch; - if (Line == 1 && Col == 1) { - isAtLineBegin = true; - } - while (true) { int nextChar = ReaderRead(); if (nextChar == -1) @@ -394,18 +364,36 @@ namespace ICSharpCode.ILSpy case '\r': case '\n': HandleLineEnd((char)nextChar); - isAtLineBegin = true; continue; case '"': token = ReadString(); - isAtLineBegin = false; break; case '\'': token = ReadChar(); - isAtLineBegin = false; break; - default: - isAtLineBegin = false; // non-ws chars are handled here + case '@': + int next = ReaderRead(); + if (next == -1) { + Error(Line, Col, String.Format("EOF after @")); + continue; + } else { + int x = Col - 1; + int y = Line; + ch = (char)next; + if (ch == '"') { + token = ReadVerbatimString(); + } else if (Char.IsLetterOrDigit(ch) || ch == '_') { + bool canBeKeyword; + string s = ReadIdent(ch, out canBeKeyword); + return new Literal(null, null, LiteralFormat.None); + } else { + HandleLineEnd(ch); + Error(y, x, String.Format("Unexpected char in Lexer.Next() : {0}", ch)); + continue; + } + } + break; + default: // non-ws chars are handled here ch = (char)nextChar; if (Char.IsLetter(ch) || ch == '_' || ch == '\\') { int x = Col - 1; // Col was incremented above, but we want the start of the identifier @@ -441,16 +429,26 @@ namespace ICSharpCode.ILSpy while (true) { if (ch == '\\') { peek = ReaderPeek(); + if (peek != 'u' && peek != 'U') { + Error(Line, Col, "Identifiers can only contain unicode escape sequences"); + } canBeKeyword = false; string surrogatePair; ReadEscapeSequence(out ch, out surrogatePair); if (surrogatePair != null) { + if (!char.IsLetterOrDigit(surrogatePair, 0)) { + Error(Line, Col, "Unicode escape sequences in identifiers cannot be used to represent characters that are invalid in identifiers"); + } for (int i = 0; i < surrogatePair.Length - 1; i++) { if (curPos < MAX_IDENTIFIER_LENGTH) { identBuffer[curPos++] = surrogatePair[i]; } } ch = surrogatePair[surrogatePair.Length - 1]; + } else { + if (!IsIdentifierPart(ch)) { + Error(Line, Col, "Unicode escape sequences in identifiers cannot be used to represent characters that are invalid in identifiers"); + } } } @@ -459,6 +457,7 @@ namespace ICSharpCode.ILSpy // prevents \ from being added identBuffer[curPos++] = ch; } else { + Error(Line, Col, String.Format("Identifier too long")); while (IsIdentifierPart(ReaderPeek())) { ReaderRead(); } @@ -507,6 +506,7 @@ namespace ICSharpCode.ILSpy } if (sb.Length == 0) { sb.Append('0'); // dummy value to prevent exception + Error(y, x, "Invalid hexadecimal integer literal"); } ishex = true; prefix = "0x"; @@ -527,6 +527,9 @@ namespace ICSharpCode.ILSpy peek = '.'; } else { isdouble = true; // double is default + if (ishex) { + Error(y, x, "No hexadecimal floating point values allowed"); + } sb.Append('.'); while (Char.IsDigit((char)ReaderPeek())) { // read decimal digits beyond the dot @@ -592,6 +595,7 @@ namespace ICSharpCode.ILSpy if (float.TryParse(digit, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { return new Literal(stringValue, num, LiteralFormat.DecimalNumber); } else { + Error(y, x, String.Format("Can't parse float {0}", digit)); return new Literal(stringValue, 0f, LiteralFormat.DecimalNumber); } } @@ -600,6 +604,7 @@ namespace ICSharpCode.ILSpy if (decimal.TryParse(digit, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { return new Literal(stringValue, num, LiteralFormat.DecimalNumber); } else { + Error(y, x, String.Format("Can't parse decimal {0}", digit)); return new Literal(stringValue, 0m, LiteralFormat.DecimalNumber); } } @@ -608,7 +613,7 @@ namespace ICSharpCode.ILSpy if (double.TryParse(digit, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { return new Literal(stringValue, num, LiteralFormat.DecimalNumber); } else { - + Error(y, x, String.Format("Can't parse double {0}", digit)); return new Literal(stringValue, 0d, LiteralFormat.DecimalNumber); } } @@ -617,12 +622,12 @@ namespace ICSharpCode.ILSpy ulong result; if (ishex) { if (!ulong.TryParse(digit, NumberStyles.HexNumber, null, out result)) { - + Error(y, x, String.Format("Can't parse hexadecimal constant {0}", digit)); return new Literal(stringValue.ToString(), 0, LiteralFormat.HexadecimalNumber); } } else { if (!ulong.TryParse(digit, NumberStyles.Integer, null, out result)) { - + Error(y, x, String.Format("Can't parse integral constant {0}", digit)); return new Literal(stringValue.ToString(), 0, LiteralFormat.DecimalNumber); } } @@ -645,7 +650,7 @@ namespace ICSharpCode.ILSpy if (ulong.TryParse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number, CultureInfo.InvariantCulture, out num)) { token = new Literal(stringValue, num, literalFormat); } else { - + Error(y, x, String.Format("Can't parse unsigned long {0}", digit)); token = new Literal(stringValue, 0UL, literalFormat); } } else { @@ -653,7 +658,7 @@ namespace ICSharpCode.ILSpy if (long.TryParse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number, CultureInfo.InvariantCulture, out num)) { token = new Literal(stringValue, num, literalFormat); } else { - + Error(y, x, String.Format("Can't parse long {0}", digit)); token = new Literal(stringValue, 0L, literalFormat); } } @@ -663,7 +668,7 @@ namespace ICSharpCode.ILSpy if (uint.TryParse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number, CultureInfo.InvariantCulture, out num)) { token = new Literal(stringValue, num, literalFormat); } else { - + Error(y, x, String.Format("Can't parse unsigned int {0}", digit)); token = new Literal(stringValue, (uint)0, literalFormat); } } else { @@ -671,7 +676,7 @@ namespace ICSharpCode.ILSpy if (int.TryParse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number, CultureInfo.InvariantCulture, out num)) { token = new Literal(stringValue, num, literalFormat); } else { - + Error(y, x, String.Format("Can't parse int {0}", digit)); token = new Literal(stringValue, 0, literalFormat); } } @@ -711,7 +716,7 @@ namespace ICSharpCode.ILSpy } } else if (HandleLineEnd(ch)) { // call HandleLineEnd to ensure line numbers are still correct after the error - + Error(y, x, "No new line is allowed inside a string literal"); break; } else { originalValue.Append(ch); @@ -720,7 +725,7 @@ namespace ICSharpCode.ILSpy } if (!doneNormally) { - + Error(y, x, "End of file reached inside string literal"); } return new Literal(originalValue.ToString(), sb.ToString(), LiteralFormat.StringLiteral); @@ -753,7 +758,7 @@ namespace ICSharpCode.ILSpy } if (nextChar == -1) { - + Error(Line, Col, "End of file reached inside verbatim string literal"); } return new Literal(originalValue.ToString(), sb.ToString(), LiteralFormat.VerbatimStringLiteral); @@ -777,6 +782,7 @@ namespace ICSharpCode.ILSpy int nextChar = ReaderRead(); if (nextChar == -1) { + Error(Line, Col, "End of file reached inside escape sequence"); ch = '\0'; return String.Empty; } @@ -825,6 +831,9 @@ namespace ICSharpCode.ILSpy number = GetHexNumber(c); escapeSequenceBuffer[curPos++] = c; + if (number < 0) { + Error(Line, Col - 1, String.Format("Invalid char in literal : {0}", c)); + } for (int i = 0; i < 3; ++i) { if (IsHex((char)ReaderPeek())) { c = (char)ReaderRead(); @@ -847,6 +856,7 @@ namespace ICSharpCode.ILSpy escapeSequenceBuffer[curPos++] = c; number = 16 * number + idx; } else { + Error(Line, Col - 1, String.Format("Invalid char in literal : {0}", (char)ReaderPeek())); break; } } @@ -858,6 +868,7 @@ namespace ICSharpCode.ILSpy } break; default: + Error(Line, Col, String.Format("Unexpected escape sequence : {0}", c)); ch = '\0'; break; } @@ -879,16 +890,20 @@ namespace ICSharpCode.ILSpy string surrogatePair; escapeSequence = ReadEscapeSequence(out chValue, out surrogatePair); if (surrogatePair != null) { - + Error(y, x, "The unicode character must be represented by a surrogate pair and does not fit into a System.Char"); } } unchecked { if ((char)ReaderRead() != '\'') { - + Error(y, x, "Char not terminated"); } } return new Literal("'" + ch + escapeSequence + "'", chValue, LiteralFormat.CharLiteral); } + + void Error(int y, int x, string message) + { + } } } From 0f0109424adb773185d59b26118e1ef8fa4847a8 Mon Sep 17 00:00:00 2001 From: Moritz Date: Sun, 8 Oct 2017 14:55:55 +0200 Subject: [PATCH 029/190] Fix base methods --- .../CSharp/CSharpDecompiler.cs | 3 +- .../ICSharpCode.Decompiler.csproj | 1 + .../IL/Transforms/ProxyCallReplacer.cs | 126 ++++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 1d3990401..55f20d3dc 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -122,7 +122,8 @@ namespace ICSharpCode.Decompiler.CSharp } }, new DelegateConstruction(), - new AssignVariableNames() + new AssignVariableNames(), + new ProxyCallReplacer(), }; } diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 912fa636d..e68291245 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -273,6 +273,7 @@ + diff --git a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs new file mode 100644 index 000000000..fac68c61e --- /dev/null +++ b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs @@ -0,0 +1,126 @@ +using System.Diagnostics; +using ICSharpCode.Decompiler.TypeSystem; +using Mono.Cecil; + +namespace ICSharpCode.Decompiler.IL.Transforms +{ + class ProxyCallReplacer : ILVisitor, IILTransform + { + ILTransformContext context; + + public void Run(ILFunction function, ILTransformContext context) + { + this.context = context; + function.AcceptVisitor(this); + } + + protected override void Default(ILInstruction inst) + { + foreach (var child in inst.Children) { + child.AcceptVisitor(this); + } + } + + protected internal override void VisitCallVirt(CallVirt inst) + { + VisitCally(inst); + } + + protected internal override void VisitCall(Call inst) + { + VisitCally(inst); + } + + protected internal void VisitCally(CallInstruction inst) + { + if (inst.Method.DeclaringTypeDefinition == null) // TODO: investigate why + return; + foreach (IMethod method in inst.Method.DeclaringTypeDefinition.Methods) { + if (method.FullName.Equals(inst.Method.FullName)) { + MethodDefinition methodDef = context.TypeSystem.GetCecil(method) as MethodDefinition; + if (methodDef != null && methodDef.Body != null) { + if (method.IsCompilerGeneratedOrIsInCompilerGeneratedClass()) { + // partially copied from CSharpDecompiler + var specializingTypeSystem = this.context.TypeSystem.GetSpecializingTypeSystem(this.context.TypeSystem.Compilation.TypeResolveContext); + var ilReader = new ILReader(specializingTypeSystem); + System.Threading.CancellationToken cancellationToken = new System.Threading.CancellationToken(); + var function = ilReader.ReadIL(methodDef.Body, cancellationToken); + var context = new ILTransformContext(function, specializingTypeSystem, this.context.Settings) { + CancellationToken = cancellationToken + }; + foreach (var transform in CSharp.CSharpDecompiler.GetILTransforms()) { + if (transform.GetType() != typeof(ProxyCallReplacer)) { // don't call itself on itself + cancellationToken.ThrowIfCancellationRequested(); + transform.Run(function, context); + } + } + Call currentCall = new ProxyMethodVisitor().GetCalledMethod(function, context); + if (currentCall != null) { + Call newInst = (Call)currentCall.Clone(); + newInst.Arguments.Clear(); + + ILInstruction thisArg = inst.Arguments.ElementAtOrDefault(0).Clone(); + + // special handling for first argument (this) - the underlying issue may be somewhere else + // normally + // leave IL_0000(await(callvirt<> n__0(ldobj xxHandler(ldloca this), ldobj System.Net.Http.HttpRequestMessage(ldloca request), ldobj System.Threading.CancellationToken(ldloca cancellationToken)))) + // would be decompiled to + // return await((DelegatingHandler)this).SendAsync(request, cancellationToken); + // this changes it to + // return await base.SendAsync(request, cancellationToken); + if (thisArg.OpCode == OpCode.LdObj && thisArg.Children.Count > 0 && thisArg.Children[0].OpCode == OpCode.LdLoca) { + thisArg = new LdLoc(((LdLoca)thisArg.Children[0]).Variable); + } + + newInst.Arguments.Add(thisArg); + + // add everything except first argument + for (int i = 1; i < inst.Arguments.Count; i++) { + newInst.Arguments.Add(inst.Arguments.ElementAtOrDefault(i).Clone()); + } + inst.ReplaceWith(newInst); + } + } + } + } + } + } + + // Checks if the method is a proxy method by checking if it only contains a call instruction and if it has special compiler attributes. + private class ProxyMethodVisitor : ILVisitor + { + ILTransformContext context; + int invalidInstructions = 0; + Call currentCall; + + public Call GetCalledMethod(ILFunction function, ILTransformContext context) + { + this.context = context; + function.AcceptVisitor(this); + if (invalidInstructions == 0) { + return currentCall; + } + return null; + } + + protected override void Default(ILInstruction inst) + { + if (inst.OpCode != OpCode.ILFunction && + inst.OpCode != OpCode.BlockContainer && + inst.OpCode != OpCode.Block && + inst.OpCode != OpCode.Leave && + inst.OpCode != OpCode.Nop) { + invalidInstructions++; + } + foreach (var child in inst.Children) { + child.AcceptVisitor(this); + } + } + + protected internal override void VisitCall(Call inst) + { + currentCall = inst; + } + } + } +} From 75a65380f0fc7f15eaa7e3ec6aa16cb17499a61f Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 8 Oct 2017 16:09:53 +0200 Subject: [PATCH 030/190] BlockBuilder: avoid crash on invalid branches (#902) --- ICSharpCode.Decompiler/IL/BlockBuilder.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/IL/BlockBuilder.cs b/ICSharpCode.Decompiler/IL/BlockBuilder.cs index 2ba957cb4..40ded7446 100644 --- a/ICSharpCode.Decompiler/IL/BlockBuilder.cs +++ b/ICSharpCode.Decompiler/IL/BlockBuilder.cs @@ -175,6 +175,12 @@ namespace ICSharpCode.Decompiler.IL cancellationToken.ThrowIfCancellationRequested(); Debug.Assert(branch.TargetBlock == null); branch.TargetBlock = FindBranchTarget(branch.TargetILOffset); + if (branch.TargetBlock == null) { + branch.ReplaceWith(new InvalidBranch("Could not find block for branch target " + + Disassembler.DisassemblerHelpers.OffsetToString(branch.TargetILOffset)) { + ILRange = branch.ILRange + }); + } break; case Leave leave: // ret (in void method) = leave(mainContainer) @@ -210,7 +216,7 @@ namespace ICSharpCode.Decompiler.IL return block; } } - throw new InvalidOperationException("Could not find block for branch target"); + return null; } } } From 1486cd4b620ab2101fd67c2f23e547231a238ebf Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Sun, 8 Oct 2017 18:08:24 +0200 Subject: [PATCH 031/190] Check that it only matches if the method performs one call and only with arguments without modification --- .../IL/Transforms/ProxyCallReplacer.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs index fac68c61e..18549fd6c 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs @@ -57,6 +57,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms Call currentCall = new ProxyMethodVisitor().GetCalledMethod(function, context); if (currentCall != null) { Call newInst = (Call)currentCall.Clone(); + + // check if original arguments are only correct ldloc calls + for (int i = 0; i < currentCall.Arguments.Count; i++) { + var originalArg = currentCall.Arguments.ElementAtOrDefault(i); + if (originalArg.OpCode != OpCode.LdLoc || + originalArg.Children.Count != 0 || + ((LdLoc)originalArg).Variable.Kind != VariableKind.Parameter || + ((LdLoc)originalArg).Variable.Index != i-1) { + return; + } + } newInst.Arguments.Clear(); ILInstruction thisArg = inst.Arguments.ElementAtOrDefault(0).Clone(); @@ -119,7 +130,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms protected internal override void VisitCall(Call inst) { - currentCall = inst; + if (currentCall == null) { + currentCall = inst; + } else { + invalidInstructions++; // more than one call in the function + } } } } From 131233627c55083842fe7728b65f41db277892f6 Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Sun, 8 Oct 2017 18:13:40 +0200 Subject: [PATCH 032/190] Remove unneccessary loop --- .../IL/Transforms/ProxyCallReplacer.cs | 98 +++++++++---------- 1 file changed, 47 insertions(+), 51 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs index 18549fd6c..8fac9e258 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs @@ -35,63 +35,59 @@ namespace ICSharpCode.Decompiler.IL.Transforms { if (inst.Method.DeclaringTypeDefinition == null) // TODO: investigate why return; - foreach (IMethod method in inst.Method.DeclaringTypeDefinition.Methods) { - if (method.FullName.Equals(inst.Method.FullName)) { - MethodDefinition methodDef = context.TypeSystem.GetCecil(method) as MethodDefinition; - if (methodDef != null && methodDef.Body != null) { - if (method.IsCompilerGeneratedOrIsInCompilerGeneratedClass()) { - // partially copied from CSharpDecompiler - var specializingTypeSystem = this.context.TypeSystem.GetSpecializingTypeSystem(this.context.TypeSystem.Compilation.TypeResolveContext); - var ilReader = new ILReader(specializingTypeSystem); - System.Threading.CancellationToken cancellationToken = new System.Threading.CancellationToken(); - var function = ilReader.ReadIL(methodDef.Body, cancellationToken); - var context = new ILTransformContext(function, specializingTypeSystem, this.context.Settings) { - CancellationToken = cancellationToken - }; - foreach (var transform in CSharp.CSharpDecompiler.GetILTransforms()) { - if (transform.GetType() != typeof(ProxyCallReplacer)) { // don't call itself on itself - cancellationToken.ThrowIfCancellationRequested(); - transform.Run(function, context); - } + MethodDefinition methodDef = context.TypeSystem.GetCecil(inst.Method) as MethodDefinition; + if (methodDef != null && methodDef.Body != null) { + if (inst.Method.IsCompilerGeneratedOrIsInCompilerGeneratedClass()) { + // partially copied from CSharpDecompiler + var specializingTypeSystem = this.context.TypeSystem.GetSpecializingTypeSystem(this.context.TypeSystem.Compilation.TypeResolveContext); + var ilReader = new ILReader(specializingTypeSystem); + System.Threading.CancellationToken cancellationToken = new System.Threading.CancellationToken(); + var function = ilReader.ReadIL(methodDef.Body, cancellationToken); + var context = new ILTransformContext(function, specializingTypeSystem, this.context.Settings) { + CancellationToken = cancellationToken + }; + foreach (var transform in CSharp.CSharpDecompiler.GetILTransforms()) { + if (transform.GetType() != typeof(ProxyCallReplacer)) { // don't call itself on itself + cancellationToken.ThrowIfCancellationRequested(); + transform.Run(function, context); + } + } + Call currentCall = new ProxyMethodVisitor().GetCalledMethod(function, context); + if (currentCall != null) { + Call newInst = (Call)currentCall.Clone(); + + // check if original arguments are only correct ldloc calls + for (int i = 0; i < currentCall.Arguments.Count; i++) { + var originalArg = currentCall.Arguments.ElementAtOrDefault(i); + if (originalArg.OpCode != OpCode.LdLoc || + originalArg.Children.Count != 0 || + ((LdLoc)originalArg).Variable.Kind != VariableKind.Parameter || + ((LdLoc)originalArg).Variable.Index != i - 1) { + return; } - Call currentCall = new ProxyMethodVisitor().GetCalledMethod(function, context); - if (currentCall != null) { - Call newInst = (Call)currentCall.Clone(); - - // check if original arguments are only correct ldloc calls - for (int i = 0; i < currentCall.Arguments.Count; i++) { - var originalArg = currentCall.Arguments.ElementAtOrDefault(i); - if (originalArg.OpCode != OpCode.LdLoc || - originalArg.Children.Count != 0 || - ((LdLoc)originalArg).Variable.Kind != VariableKind.Parameter || - ((LdLoc)originalArg).Variable.Index != i-1) { - return; - } - } - newInst.Arguments.Clear(); + } + newInst.Arguments.Clear(); - ILInstruction thisArg = inst.Arguments.ElementAtOrDefault(0).Clone(); + ILInstruction thisArg = inst.Arguments.ElementAtOrDefault(0).Clone(); - // special handling for first argument (this) - the underlying issue may be somewhere else - // normally - // leave IL_0000(await(callvirt<> n__0(ldobj xxHandler(ldloca this), ldobj System.Net.Http.HttpRequestMessage(ldloca request), ldobj System.Threading.CancellationToken(ldloca cancellationToken)))) - // would be decompiled to - // return await((DelegatingHandler)this).SendAsync(request, cancellationToken); - // this changes it to - // return await base.SendAsync(request, cancellationToken); - if (thisArg.OpCode == OpCode.LdObj && thisArg.Children.Count > 0 && thisArg.Children[0].OpCode == OpCode.LdLoca) { - thisArg = new LdLoc(((LdLoca)thisArg.Children[0]).Variable); - } + // special handling for first argument (this) - the underlying issue may be somewhere else + // normally + // leave IL_0000(await(callvirt<> n__0(ldobj xxHandler(ldloca this), ldobj System.Net.Http.HttpRequestMessage(ldloca request), ldobj System.Threading.CancellationToken(ldloca cancellationToken)))) + // would be decompiled to + // return await((DelegatingHandler)this).SendAsync(request, cancellationToken); + // this changes it to + // return await base.SendAsync(request, cancellationToken); + if (thisArg.OpCode == OpCode.LdObj && thisArg.Children.Count > 0 && thisArg.Children[0].OpCode == OpCode.LdLoca) { + thisArg = new LdLoc(((LdLoca)thisArg.Children[0]).Variable); + } - newInst.Arguments.Add(thisArg); + newInst.Arguments.Add(thisArg); - // add everything except first argument - for (int i = 1; i < inst.Arguments.Count; i++) { - newInst.Arguments.Add(inst.Arguments.ElementAtOrDefault(i).Clone()); - } - inst.ReplaceWith(newInst); - } + // add everything except first argument + for (int i = 1; i < inst.Arguments.Count; i++) { + newInst.Arguments.Add(inst.Arguments.ElementAtOrDefault(i).Clone()); } + inst.ReplaceWith(newInst); } } } From 509b69f685b776f2053a6ae228d3aa3ae7767c39 Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Sun, 8 Oct 2017 18:36:00 +0200 Subject: [PATCH 033/190] Add test case. --- .../ICSharpCode.Decompiler.Tests.csproj | 2 + .../ILPrettyTestRunner.cs | 6 + .../TestCases/ILPretty/FixProxyCalls.cs | 17 + .../TestCases/ILPretty/FixProxyCalls.il | 297 ++++++++++++++++++ 4 files changed, 322 insertions(+) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.cs create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.il diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index f39ff4d6d..ff1e11d41 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -62,7 +62,9 @@ + + diff --git a/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs index 7d2f9ed47..0cedaf647 100644 --- a/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs @@ -42,6 +42,12 @@ namespace ICSharpCode.Decompiler.Tests Run(); } + [Test] + public void FixProxyCalls() + { + Run(); + } + void Run([CallerMemberName] string testName = null) { var ilFile = Path.Combine(TestCasePath, testName + ".il"); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.cs b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.cs new file mode 100644 index 000000000..071052f1d --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.cs @@ -0,0 +1,17 @@ +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty +{ + internal class FixProxyCalls + { + public class TestHandler : DelegatingHandler + { + protected override async Task SendAsync(HttpRequestMessage r, CancellationToken c) + { + return await base.SendAsync(r, c); + } + } + } +} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.il b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.il new file mode 100644 index 000000000..e9d503e37 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.il @@ -0,0 +1,297 @@ +// C:\Users\M.Hedtke\Documents\FixProxyCalls\FixProxyCalls\bin\Debug\netstandard2.0\FixProxyCalls.dll + +.assembly extern netstandard +{ + .publickeytoken = ( + cc 7b 13 ff cd 2d dd 51 + ) + .ver 2:0:0:0 +} +.assembly FixProxyCalls +{ + .hash algorithm 0x00008004 // SHA1 + .ver 1:0:0:0 +} + +.module FixProxyCalls.dll +// MVID: {1C9C9ED2-FBF8-44D2-9699-305E3CFD7A94} +.corflags 0x00000001 // ILOnly + + +.class private auto ansi '' +{ +} // end of class + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls + extends [netstandard]System.Object +{ + // Nested Types + .class nested public auto ansi beforefieldinit TestHandler + extends [netstandard]System.Net.Http.DelegatingHandler + { + // Nested Types + .class nested private auto ansi sealed beforefieldinit 'd__0' + extends [netstandard]System.Object + implements [netstandard]System.Runtime.CompilerServices.IAsyncStateMachine + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( + 01 00 00 00 + ) + // Fields + .field public int32 '<>1__state' + .field public valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 '<>t__builder' + .field public class [netstandard]System.Net.Http.HttpRequestMessage r + .field public valuetype [netstandard]System.Threading.CancellationToken c + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler '<>4__this' + .field private class [netstandard]System.Net.Http.HttpResponseMessage '<>s__1' + .field private valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1 '<>u__1' + + // Methods + .method public hidebysig specialname rtspecialname + instance void .ctor () cil managed + { + // Method begins at RVA 0x20c4 + // Code size 8 (0x8) + .maxstack 8 + + IL_0000: ldarg.0 + IL_0001: call instance void [netstandard]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method 'd__0'::.ctor + + .method private final hidebysig newslot virtual + instance void MoveNext () cil managed + { + .override method instance void [netstandard]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext() + // Method begins at RVA 0x20d0 + // Code size 187 (0xbb) + .maxstack 3 + .locals init ( + [0] int32, + [1] class [netstandard]System.Net.Http.HttpResponseMessage, + [2] valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1, + [3] class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0', + [4] class [netstandard]System.Exception + ) + + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>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_0059 + + IL_000e: nop + IL_000f: ldarg.0 + IL_0010: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>4__this' + IL_0015: ldarg.0 + IL_0016: ldfld class [netstandard]System.Net.Http.HttpRequestMessage ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::r + IL_001b: ldarg.0 + IL_001c: ldfld valuetype [netstandard]System.Threading.CancellationToken ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::c + IL_0021: call instance class [netstandard]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler::'<>n__0'(class [netstandard]System.Net.Http.HttpRequestMessage, valuetype [netstandard]System.Threading.CancellationToken) + IL_0026: callvirt instance valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1 class [netstandard]System.Threading.Tasks.Task`1::GetAwaiter() + IL_002b: stloc.2 + IL_002c: ldloca.s 2 + IL_002e: call instance bool valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1::get_IsCompleted() + IL_0033: brtrue.s IL_0075 + + IL_0035: ldarg.0 + IL_0036: ldc.i4.0 + IL_0037: dup + IL_0038: stloc.0 + IL_0039: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>1__state' + IL_003e: ldarg.0 + IL_003f: ldloc.2 + IL_0040: stfld valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>u__1' + IL_0045: ldarg.0 + IL_0046: stloc.3 + IL_0047: ldarg.0 + IL_0048: ldflda valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>t__builder' + IL_004d: ldloca.s 2 + IL_004f: ldloca.s 3 + IL_0051: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted, class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'>(!!0&, !!1&) + IL_0056: nop + IL_0057: leave.s IL_00ba + + IL_0059: ldarg.0 + IL_005a: ldfld valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>u__1' + IL_005f: stloc.2 + IL_0060: ldarg.0 + IL_0061: ldflda valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>u__1' + IL_0066: initobj valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1 + IL_006c: ldarg.0 + IL_006d: ldc.i4.m1 + IL_006e: dup + IL_006f: stloc.0 + IL_0070: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>1__state' + + IL_0075: ldarg.0 + IL_0076: ldloca.s 2 + IL_0078: call instance !0 valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() + IL_007d: stfld class [netstandard]System.Net.Http.HttpResponseMessage ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>s__1' + IL_0082: ldarg.0 + IL_0083: ldfld class [netstandard]System.Net.Http.HttpResponseMessage ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>s__1' + IL_0088: stloc.1 + IL_0089: leave.s IL_00a5 + } // end .try + catch [netstandard]System.Exception + { + IL_008b: stloc.s 4 + IL_008d: ldarg.0 + IL_008e: ldc.i4.s -2 + IL_0090: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>1__state' + IL_0095: ldarg.0 + IL_0096: ldflda valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>t__builder' + IL_009b: ldloc.s 4 + IL_009d: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetException(class [netstandard]System.Exception) + IL_00a2: nop + IL_00a3: leave.s IL_00ba + } // end handler + + IL_00a5: ldarg.0 + IL_00a6: ldc.i4.s -2 + IL_00a8: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>1__state' + IL_00ad: ldarg.0 + IL_00ae: ldflda valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>t__builder' + IL_00b3: ldloc.1 + IL_00b4: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) + IL_00b9: nop + + IL_00ba: ret + } // end of method 'd__0'::MoveNext + + .method private final hidebysig newslot virtual + instance void SetStateMachine ( + class [netstandard]System.Runtime.CompilerServices.IAsyncStateMachine stateMachine + ) cil managed + { + .custom instance void [netstandard]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( + 01 00 00 00 + ) + .override method instance void [netstandard]System.Runtime.CompilerServices.IAsyncStateMachine::SetStateMachine(class [netstandard]System.Runtime.CompilerServices.IAsyncStateMachine) + // Method begins at RVA 0x21a8 + // Code size 1 (0x1) + .maxstack 8 + + IL_0000: ret + } // end of method 'd__0'::SetStateMachine + + } // end of class d__0 + + + // Methods + .method family hidebysig virtual + instance class [netstandard]System.Threading.Tasks.Task`1 SendAsync ( + class [netstandard]System.Net.Http.HttpRequestMessage r, + valuetype [netstandard]System.Threading.CancellationToken c + ) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [netstandard]System.Type) = ( + 01 00 59 49 43 53 68 61 72 70 43 6f 64 65 2e 44 + 65 63 6f 6d 70 69 6c 65 72 2e 54 65 73 74 73 2e + 54 65 73 74 43 61 73 65 73 2e 49 4c 50 72 65 74 + 74 79 2e 46 69 78 50 72 6f 78 79 43 61 6c 6c 73 + 2b 54 65 73 74 48 61 6e 64 6c 65 72 2b 3c 53 65 + 6e 64 41 73 79 6e 63 3e 64 5f 5f 30 00 00 + ) + .custom instance void [netstandard]System.Diagnostics.DebuggerStepThroughAttribute::.ctor() = ( + 01 00 00 00 + ) + // Method begins at RVA 0x205c + // Code size 73 (0x49) + .maxstack 2 + .locals init ( + [0] class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0', + [1] valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 + ) + + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>4__this' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld class [netstandard]System.Net.Http.HttpRequestMessage ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::r + IL_0014: ldloc.0 + IL_0015: ldarg.2 + IL_0016: stfld valuetype [netstandard]System.Threading.CancellationToken ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::c + IL_001b: ldloc.0 + IL_001c: call valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() + IL_0021: stfld valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>t__builder' + IL_0026: ldloc.0 + IL_0027: ldc.i4.m1 + IL_0028: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>1__state' + IL_002d: ldloc.0 + IL_002e: ldfld valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>t__builder' + IL_0033: stloc.1 + IL_0034: ldloca.s 1 + IL_0036: ldloca.s 0 + IL_0038: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Startd__0'>(!!0&) + IL_003d: ldloc.0 + IL_003e: ldflda valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>t__builder' + IL_0043: call instance class [netstandard]System.Threading.Tasks.Task`1 valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() + IL_0048: ret + } // end of method TestHandler::SendAsync + + .method public hidebysig specialname rtspecialname + instance void .ctor () cil managed + { + // Method begins at RVA 0x20b1 + // Code size 8 (0x8) + .maxstack 8 + + IL_0000: ldarg.0 + IL_0001: call instance void [netstandard]System.Net.Http.DelegatingHandler::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method TestHandler::.ctor + + .method private hidebysig + instance class [netstandard]System.Threading.Tasks.Task`1 '<>n__0' ( + class [netstandard]System.Net.Http.HttpRequestMessage 'request', + valuetype [netstandard]System.Threading.CancellationToken cancellationToken + ) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( + 01 00 00 00 + ) + .custom instance void [netstandard]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( + 01 00 00 00 + ) + // Method begins at RVA 0x20ba + // Code size 9 (0x9) + .maxstack 8 + + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance class [netstandard]System.Threading.Tasks.Task`1 [netstandard]System.Net.Http.DelegatingHandler::SendAsync(class [netstandard]System.Net.Http.HttpRequestMessage, valuetype [netstandard]System.Threading.CancellationToken) + IL_0008: ret + } // end of method TestHandler::'<>n__0' + + } // end of class TestHandler + + + // Methods + .method public hidebysig specialname rtspecialname + instance void .ctor () cil managed + { + // Method begins at RVA 0x2050 + // Code size 8 (0x8) + .maxstack 8 + + IL_0000: ldarg.0 + IL_0001: call instance void [netstandard]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method FixProxyCalls::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls + From 5b3adbd4fda4a86657e1534af4f4e3d887ddb4a1 Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Sun, 8 Oct 2017 19:31:20 +0200 Subject: [PATCH 034/190] Better check if the call can be replaced. Don't clone arguments. --- .../IL/Transforms/ProxyCallReplacer.cs | 119 ++++++++---------- 1 file changed, 50 insertions(+), 69 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs index 8fac9e258..8313e82c1 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs @@ -52,84 +52,65 @@ namespace ICSharpCode.Decompiler.IL.Transforms transform.Run(function, context); } } - Call currentCall = new ProxyMethodVisitor().GetCalledMethod(function, context); - if (currentCall != null) { - Call newInst = (Call)currentCall.Clone(); - // check if original arguments are only correct ldloc calls - for (int i = 0; i < currentCall.Arguments.Count; i++) { - var originalArg = currentCall.Arguments.ElementAtOrDefault(i); - if (originalArg.OpCode != OpCode.LdLoc || - originalArg.Children.Count != 0 || - ((LdLoc)originalArg).Variable.Kind != VariableKind.Parameter || - ((LdLoc)originalArg).Variable.Index != i - 1) { - return; - } - } - newInst.Arguments.Clear(); - - ILInstruction thisArg = inst.Arguments.ElementAtOrDefault(0).Clone(); - // special handling for first argument (this) - the underlying issue may be somewhere else - // normally - // leave IL_0000(await(callvirt<> n__0(ldobj xxHandler(ldloca this), ldobj System.Net.Http.HttpRequestMessage(ldloca request), ldobj System.Threading.CancellationToken(ldloca cancellationToken)))) - // would be decompiled to - // return await((DelegatingHandler)this).SendAsync(request, cancellationToken); - // this changes it to - // return await base.SendAsync(request, cancellationToken); - if (thisArg.OpCode == OpCode.LdObj && thisArg.Children.Count > 0 && thisArg.Children[0].OpCode == OpCode.LdLoca) { - thisArg = new LdLoc(((LdLoca)thisArg.Children[0]).Variable); + if (function.Children.Count != 1) + return; + var blockContainer = function.Children[0]; + if (blockContainer.OpCode != OpCode.BlockContainer) + return; + if (blockContainer.Children.Count != 1) + return; + var block = blockContainer.Children[0]; + if (block.OpCode != OpCode.Block) + return; + if (block.Children.Count > 2) + return; + if (block.Children.Count == 2 && block.Children[1].OpCode != OpCode.Nop) + return; + var leave = block.Children[0]; + if (leave.OpCode != OpCode.Leave) + return; + if (leave.Children.Count != 1) + return; + Call call = leave.Children[0] as Call; + if (call == null) + 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.OpCode != OpCode.LdLoc || + originalArg.Children.Count != 0 || + ((LdLoc)originalArg).Variable.Kind != VariableKind.Parameter || + ((LdLoc)originalArg).Variable.Index != i - 1) { + return; } + } - newInst.Arguments.Add(thisArg); + Call newInst = (Call)call.Clone(); - // add everything except first argument - for (int i = 1; i < inst.Arguments.Count; i++) { - newInst.Arguments.Add(inst.Arguments.ElementAtOrDefault(i).Clone()); - } - inst.ReplaceWith(newInst); - } - } - } - } + newInst.Arguments.Clear(); - // Checks if the method is a proxy method by checking if it only contains a call instruction and if it has special compiler attributes. - private class ProxyMethodVisitor : ILVisitor - { - ILTransformContext context; - int invalidInstructions = 0; - Call currentCall; + ILInstruction thisArg = inst.Arguments[0]; - public Call GetCalledMethod(ILFunction function, ILTransformContext context) - { - this.context = context; - function.AcceptVisitor(this); - if (invalidInstructions == 0) { - return currentCall; - } - return null; - } + // special handling for first argument (this) - the underlying issue may be somewhere else + // normally + // leave IL_0000(await(callvirt<> n__0(ldobj xxHandler(ldloca this), ldobj System.Net.Http.HttpRequestMessage(ldloca request), ldobj System.Threading.CancellationToken(ldloca cancellationToken)))) + // would be decompiled to + // return await((DelegatingHandler)this).SendAsync(request, cancellationToken); + // this changes it to + // return await base.SendAsync(request, cancellationToken); + if (thisArg.OpCode == OpCode.LdObj && thisArg.Children.Count > 0 && thisArg.Children[0].OpCode == OpCode.LdLoca) { + thisArg = new LdLoc(((LdLoca)thisArg.Children[0]).Variable); + } - protected override void Default(ILInstruction inst) - { - if (inst.OpCode != OpCode.ILFunction && - inst.OpCode != OpCode.BlockContainer && - inst.OpCode != OpCode.Block && - inst.OpCode != OpCode.Leave && - inst.OpCode != OpCode.Nop) { - invalidInstructions++; - } - foreach (var child in inst.Children) { - child.AcceptVisitor(this); - } - } + newInst.Arguments.Add(thisArg); - protected internal override void VisitCall(Call inst) - { - if (currentCall == null) { - currentCall = inst; - } else { - invalidInstructions++; // more than one call in the function + // add everything except first argument + for (int i = 1; i < inst.Arguments.Count; i++) { + newInst.Arguments.Add(inst.Arguments[i]); + } + inst.ReplaceWith(newInst); } } } From 9f6ea2f22d3eef50c01d80edc90d19193ea6f2b4 Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Sun, 8 Oct 2017 21:11:18 +0200 Subject: [PATCH 035/190] Add sdk path. --- .../Helpers/SdkUtility.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ICSharpCode.Decompiler.Tests/Helpers/SdkUtility.cs b/ICSharpCode.Decompiler.Tests/Helpers/SdkUtility.cs index 4ad1af0eb..d25d076c3 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/SdkUtility.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/SdkUtility.cs @@ -160,6 +160,19 @@ namespace ICSharpCode.Decompiler.Tests.Helpers return windowsSdk80InstallRoot; } } + + static string WindowsSdk461InstallRoot = null; + /// + /// Location of the .NET 4.6.1 SDK install root. + /// + public static string WindowsSdk461NetFxTools { + get { + if (WindowsSdk461InstallRoot == null) { + WindowsSdk461InstallRoot = GetPathFromRegistryX86(@"SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\NETFXSDK\4.6.1\WinSDK-NetFx40Tools", "InstallationFolder") ?? string.Empty; + } + return WindowsSdk461InstallRoot; + } + } #endregion /// @@ -170,6 +183,10 @@ namespace ICSharpCode.Decompiler.Tests.Helpers /// The path of the executable, or null if the exe is not found. public static string GetSdkPath(string exeName) { string execPath; + if (!string.IsNullOrEmpty(WindowsSdk461NetFxTools)) { + execPath = Path.Combine(WindowsSdk461NetFxTools, exeName); + if (File.Exists(execPath)) { return execPath; } + } if (!string.IsNullOrEmpty(WindowsSdk80NetFxTools)) { execPath = Path.Combine(WindowsSdk80NetFxTools, exeName); if (File.Exists(execPath)) { return execPath; } From 71349ba11ecb2d4504327267ff3cffe6319b2fa6 Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Sun, 8 Oct 2017 21:12:11 +0200 Subject: [PATCH 036/190] Implement pretty test. - Does not work with roslyn --- .../ICSharpCode.Decompiler.Tests.csproj | 3 +- .../ILPrettyTestRunner.cs | 8 +- .../PrettyTestRunner.cs | 6 + .../TestCases/ILPretty/FixProxyCalls.cs | 17 - .../TestCases/ILPretty/FixProxyCalls.il | 297 ------- .../TestCases/Pretty/FixProxyCalls.cs | 55 ++ .../TestCases/Pretty/FixProxyCalls.il | 781 ++++++++++++++++++ .../TestCases/Pretty/FixProxyCalls.opt.il | 664 +++++++++++++++ .../Pretty/FixProxyCalls.opt.roslyn.il | 660 +++++++++++++++ .../TestCases/Pretty/FixProxyCalls.roslyn.il | 737 +++++++++++++++++ 10 files changed, 2905 insertions(+), 323 deletions(-) delete mode 100644 ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.cs delete mode 100644 ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index ff1e11d41..08acdc774 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -62,9 +62,8 @@ - - + diff --git a/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs index 0cedaf647..6b5a1aaec 100644 --- a/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs @@ -41,13 +41,7 @@ namespace ICSharpCode.Decompiler.Tests { Run(); } - - [Test] - public void FixProxyCalls() - { - Run(); - } - + void Run([CallerMemberName] string testName = null) { var ilFile = Path.Combine(TestCasePath, testName + ".il"); diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index f0033e239..83314cdea 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -176,6 +176,12 @@ namespace ICSharpCode.Decompiler.Tests Run(cscOptions: cscOptions, asmOptions: AssemblerOptions.UseOwnDisassembler); } + [Test] + public void FixProxyCalls([ValueSource("defaultOptions")] CompilerOptions cscOptions) + { + Run(cscOptions: cscOptions); + } + void Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None) { var ilFile = Path.Combine(TestCasePath, testName); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.cs b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.cs deleted file mode 100644 index 071052f1d..000000000 --- a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty -{ - internal class FixProxyCalls - { - public class TestHandler : DelegatingHandler - { - protected override async Task SendAsync(HttpRequestMessage r, CancellationToken c) - { - return await base.SendAsync(r, c); - } - } - } -} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.il b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.il deleted file mode 100644 index e9d503e37..000000000 --- a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FixProxyCalls.il +++ /dev/null @@ -1,297 +0,0 @@ -// C:\Users\M.Hedtke\Documents\FixProxyCalls\FixProxyCalls\bin\Debug\netstandard2.0\FixProxyCalls.dll - -.assembly extern netstandard -{ - .publickeytoken = ( - cc 7b 13 ff cd 2d dd 51 - ) - .ver 2:0:0:0 -} -.assembly FixProxyCalls -{ - .hash algorithm 0x00008004 // SHA1 - .ver 1:0:0:0 -} - -.module FixProxyCalls.dll -// MVID: {1C9C9ED2-FBF8-44D2-9699-305E3CFD7A94} -.corflags 0x00000001 // ILOnly - - -.class private auto ansi '' -{ -} // end of class - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls - extends [netstandard]System.Object -{ - // Nested Types - .class nested public auto ansi beforefieldinit TestHandler - extends [netstandard]System.Net.Http.DelegatingHandler - { - // Nested Types - .class nested private auto ansi sealed beforefieldinit 'd__0' - extends [netstandard]System.Object - implements [netstandard]System.Runtime.CompilerServices.IAsyncStateMachine - { - .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( - 01 00 00 00 - ) - // Fields - .field public int32 '<>1__state' - .field public valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 '<>t__builder' - .field public class [netstandard]System.Net.Http.HttpRequestMessage r - .field public valuetype [netstandard]System.Threading.CancellationToken c - .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler '<>4__this' - .field private class [netstandard]System.Net.Http.HttpResponseMessage '<>s__1' - .field private valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1 '<>u__1' - - // Methods - .method public hidebysig specialname rtspecialname - instance void .ctor () cil managed - { - // Method begins at RVA 0x20c4 - // Code size 8 (0x8) - .maxstack 8 - - IL_0000: ldarg.0 - IL_0001: call instance void [netstandard]System.Object::.ctor() - IL_0006: nop - IL_0007: ret - } // end of method 'd__0'::.ctor - - .method private final hidebysig newslot virtual - instance void MoveNext () cil managed - { - .override method instance void [netstandard]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext() - // Method begins at RVA 0x20d0 - // Code size 187 (0xbb) - .maxstack 3 - .locals init ( - [0] int32, - [1] class [netstandard]System.Net.Http.HttpResponseMessage, - [2] valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1, - [3] class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0', - [4] class [netstandard]System.Exception - ) - - IL_0000: ldarg.0 - IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>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_0059 - - IL_000e: nop - IL_000f: ldarg.0 - IL_0010: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>4__this' - IL_0015: ldarg.0 - IL_0016: ldfld class [netstandard]System.Net.Http.HttpRequestMessage ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::r - IL_001b: ldarg.0 - IL_001c: ldfld valuetype [netstandard]System.Threading.CancellationToken ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::c - IL_0021: call instance class [netstandard]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler::'<>n__0'(class [netstandard]System.Net.Http.HttpRequestMessage, valuetype [netstandard]System.Threading.CancellationToken) - IL_0026: callvirt instance valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1 class [netstandard]System.Threading.Tasks.Task`1::GetAwaiter() - IL_002b: stloc.2 - IL_002c: ldloca.s 2 - IL_002e: call instance bool valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1::get_IsCompleted() - IL_0033: brtrue.s IL_0075 - - IL_0035: ldarg.0 - IL_0036: ldc.i4.0 - IL_0037: dup - IL_0038: stloc.0 - IL_0039: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>1__state' - IL_003e: ldarg.0 - IL_003f: ldloc.2 - IL_0040: stfld valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>u__1' - IL_0045: ldarg.0 - IL_0046: stloc.3 - IL_0047: ldarg.0 - IL_0048: ldflda valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>t__builder' - IL_004d: ldloca.s 2 - IL_004f: ldloca.s 3 - IL_0051: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted, class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'>(!!0&, !!1&) - IL_0056: nop - IL_0057: leave.s IL_00ba - - IL_0059: ldarg.0 - IL_005a: ldfld valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>u__1' - IL_005f: stloc.2 - IL_0060: ldarg.0 - IL_0061: ldflda valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>u__1' - IL_0066: initobj valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1 - IL_006c: ldarg.0 - IL_006d: ldc.i4.m1 - IL_006e: dup - IL_006f: stloc.0 - IL_0070: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>1__state' - - IL_0075: ldarg.0 - IL_0076: ldloca.s 2 - IL_0078: call instance !0 valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() - IL_007d: stfld class [netstandard]System.Net.Http.HttpResponseMessage ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>s__1' - IL_0082: ldarg.0 - IL_0083: ldfld class [netstandard]System.Net.Http.HttpResponseMessage ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>s__1' - IL_0088: stloc.1 - IL_0089: leave.s IL_00a5 - } // end .try - catch [netstandard]System.Exception - { - IL_008b: stloc.s 4 - IL_008d: ldarg.0 - IL_008e: ldc.i4.s -2 - IL_0090: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>1__state' - IL_0095: ldarg.0 - IL_0096: ldflda valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>t__builder' - IL_009b: ldloc.s 4 - IL_009d: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetException(class [netstandard]System.Exception) - IL_00a2: nop - IL_00a3: leave.s IL_00ba - } // end handler - - IL_00a5: ldarg.0 - IL_00a6: ldc.i4.s -2 - IL_00a8: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>1__state' - IL_00ad: ldarg.0 - IL_00ae: ldflda valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>t__builder' - IL_00b3: ldloc.1 - IL_00b4: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) - IL_00b9: nop - - IL_00ba: ret - } // end of method 'd__0'::MoveNext - - .method private final hidebysig newslot virtual - instance void SetStateMachine ( - class [netstandard]System.Runtime.CompilerServices.IAsyncStateMachine stateMachine - ) cil managed - { - .custom instance void [netstandard]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( - 01 00 00 00 - ) - .override method instance void [netstandard]System.Runtime.CompilerServices.IAsyncStateMachine::SetStateMachine(class [netstandard]System.Runtime.CompilerServices.IAsyncStateMachine) - // Method begins at RVA 0x21a8 - // Code size 1 (0x1) - .maxstack 8 - - IL_0000: ret - } // end of method 'd__0'::SetStateMachine - - } // end of class d__0 - - - // Methods - .method family hidebysig virtual - instance class [netstandard]System.Threading.Tasks.Task`1 SendAsync ( - class [netstandard]System.Net.Http.HttpRequestMessage r, - valuetype [netstandard]System.Threading.CancellationToken c - ) cil managed - { - .custom instance void [netstandard]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [netstandard]System.Type) = ( - 01 00 59 49 43 53 68 61 72 70 43 6f 64 65 2e 44 - 65 63 6f 6d 70 69 6c 65 72 2e 54 65 73 74 73 2e - 54 65 73 74 43 61 73 65 73 2e 49 4c 50 72 65 74 - 74 79 2e 46 69 78 50 72 6f 78 79 43 61 6c 6c 73 - 2b 54 65 73 74 48 61 6e 64 6c 65 72 2b 3c 53 65 - 6e 64 41 73 79 6e 63 3e 64 5f 5f 30 00 00 - ) - .custom instance void [netstandard]System.Diagnostics.DebuggerStepThroughAttribute::.ctor() = ( - 01 00 00 00 - ) - // Method begins at RVA 0x205c - // Code size 73 (0x49) - .maxstack 2 - .locals init ( - [0] class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0', - [1] valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 - ) - - IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::.ctor() - IL_0005: stloc.0 - IL_0006: ldloc.0 - IL_0007: ldarg.0 - IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>4__this' - IL_000d: ldloc.0 - IL_000e: ldarg.1 - IL_000f: stfld class [netstandard]System.Net.Http.HttpRequestMessage ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::r - IL_0014: ldloc.0 - IL_0015: ldarg.2 - IL_0016: stfld valuetype [netstandard]System.Threading.CancellationToken ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::c - IL_001b: ldloc.0 - IL_001c: call valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() - IL_0021: stfld valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>t__builder' - IL_0026: ldloc.0 - IL_0027: ldc.i4.m1 - IL_0028: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>1__state' - IL_002d: ldloc.0 - IL_002e: ldfld valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>t__builder' - IL_0033: stloc.1 - IL_0034: ldloca.s 1 - IL_0036: ldloca.s 0 - IL_0038: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Startd__0'>(!!0&) - IL_003d: ldloc.0 - IL_003e: ldflda valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls/TestHandler/'d__0'::'<>t__builder' - IL_0043: call instance class [netstandard]System.Threading.Tasks.Task`1 valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() - IL_0048: ret - } // end of method TestHandler::SendAsync - - .method public hidebysig specialname rtspecialname - instance void .ctor () cil managed - { - // Method begins at RVA 0x20b1 - // Code size 8 (0x8) - .maxstack 8 - - IL_0000: ldarg.0 - IL_0001: call instance void [netstandard]System.Net.Http.DelegatingHandler::.ctor() - IL_0006: nop - IL_0007: ret - } // end of method TestHandler::.ctor - - .method private hidebysig - instance class [netstandard]System.Threading.Tasks.Task`1 '<>n__0' ( - class [netstandard]System.Net.Http.HttpRequestMessage 'request', - valuetype [netstandard]System.Threading.CancellationToken cancellationToken - ) cil managed - { - .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( - 01 00 00 00 - ) - .custom instance void [netstandard]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( - 01 00 00 00 - ) - // Method begins at RVA 0x20ba - // Code size 9 (0x9) - .maxstack 8 - - IL_0000: ldarg.0 - IL_0001: ldarg.1 - IL_0002: ldarg.2 - IL_0003: call instance class [netstandard]System.Threading.Tasks.Task`1 [netstandard]System.Net.Http.DelegatingHandler::SendAsync(class [netstandard]System.Net.Http.HttpRequestMessage, valuetype [netstandard]System.Threading.CancellationToken) - IL_0008: ret - } // end of method TestHandler::'<>n__0' - - } // end of class TestHandler - - - // Methods - .method public hidebysig specialname rtspecialname - instance void .ctor () cil managed - { - // Method begins at RVA 0x2050 - // Code size 8 (0x8) - .maxstack 8 - - IL_0000: ldarg.0 - IL_0001: call instance void [netstandard]System.Object::.ctor() - IL_0006: nop - IL_0007: ret - } // end of method FixProxyCalls::.ctor - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.FixProxyCalls - diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs new file mode 100644 index 000000000..f4d85b597 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty +{ + internal class AwaitDelegatingHandler + { + protected internal virtual Task Test(string test) + { + return Task.Run((Func)(() => test.ToUpper())); + } + } + + internal class AwaitTestHandler : AwaitDelegatingHandler + { + protected internal override async Task Test(string test) + { + return await base.Test(test); + } + } + + internal class YieldDelegatingHandler + { + protected internal virtual string Test(string test) + { + return string.Join(test, "fsdf"); + } + } + + internal class YieldTestHandler : YieldDelegatingHandler + { + protected internal IEnumerable Test2(string test) + { + yield return base.Test(test); + } + } + + internal class LambdaDelegatingHandler + { + protected internal virtual string Test(string test) + { + return string.Join(test, "fsdf"); + } + } + + internal class LambdaHandler : LambdaDelegatingHandler + { + protected internal override string Test(string test) + { + Func func = (Func)(() => base.Test(test)); + return func(); + } + } +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il new file mode 100644 index 000000000..48af1c00a --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il @@ -0,0 +1,781 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly '3b3jnobf' +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module '3b3jnobf.dll' +// MVID: {49E27949-DBA3-4290-A606-8A8CBA8C564E} +.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: 0x00FC0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public string 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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1'::.ctor + + .method public hidebysig instance string + 'b__0'() cil managed + { + // Code size 17 (0x11) + .maxstack 1 + .locals init (string V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::test + IL_0007: callvirt instance string [mscorlib]System.String::ToUpper() + IL_000c: stloc.0 + IL_000d: br.s IL_000f + + IL_000f: ldloc.0 + IL_0010: ret + } // end of method '<>c__DisplayClass1'::'b__0' + + } // end of class '<>c__DisplayClass1' + + .method famorassem hidebysig newslot virtual + instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + // Code size 36 (0x24) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1' V_0, + class [mscorlib]System.Threading.Tasks.Task`1 V_1) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.1 + IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::test + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::'b__0'() + IL_0015: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_001a: call class [mscorlib]System.Threading.Tasks.Task`1 [mscorlib]System.Threading.Tasks.Task::Run(class [mscorlib]System.Func`1) + IL_001f: stloc.1 + IL_0020: br.s IL_0022 + + IL_0022: ldloc.1 + IL_0023: ret + } // end of method AwaitDelegatingHandler::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method AwaitDelegatingHandler::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler +{ + .class auto ansi sealed nested private beforefieldinit 'd__3' + 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 '<>t__builder' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler '<>4__this' + .field public string test + .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 '<>u__$awaiter4' + .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 V_4, + valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 V_5) + .try + { + IL_0000: ldc.i4.1 + IL_0001: stloc.0 + IL_0002: ldarg.0 + IL_0003: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>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.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>4__this' + IL_001a: ldarg.0 + IL_001b: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::test + IL_0020: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler::'<>n__FabricatedMethod5'(string) + IL_0025: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::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::get_IsCompleted() + IL_0033: brtrue.s IL_0076 + + IL_0035: ldarg.0 + IL_0036: ldc.i4.0 + IL_0037: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' + IL_003c: ldarg.0 + IL_003d: ldloc.s V_4 + IL_003f: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>u__$awaiter4' + IL_0044: ldarg.0 + IL_0045: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' + IL_004a: ldloca.s V_4 + IL_004c: ldarg.0 + IL_004d: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted,valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'>(!!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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>u__$awaiter4' + 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 + IL_0068: ldloc.s V_5 + IL_006a: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>u__$awaiter4' + IL_006f: ldarg.0 + IL_0070: ldc.i4.m1 + IL_0071: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' + IL_0076: ldloca.s V_4 + IL_0078: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() + IL_007d: ldloca.s V_4 + IL_007f: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 + 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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' + IL_0091: ldarg.0 + IL_0092: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' + IL_0097: ldloc.2 + IL_0098: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' + IL_00a9: ldarg.0 + IL_00aa: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' + IL_00af: ldloc.1 + IL_00b0: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) + IL_00b5: nop + IL_00b6: nop + IL_00b7: ret + } // end of method 'd__3'::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' + IL_0006: ldarg.1 + IL_0007: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine) + IL_000c: ret + } // end of method 'd__3'::SetStateMachine + + } // end of class 'd__3' + + .method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 4B 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..KICSharpCode.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 41 77 61 69 74 54 65 73 74 48 61 6E 64 // ty.AwaitTestHand + 6C 65 72 2B 3C 54 65 73 74 3E 64 5F 5F 33 00 00 ) // ler+d__3.. + .custom instance void [mscorlib]System.Diagnostics.DebuggerStepThroughAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 70 (0x46) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3' V_0, + class [mscorlib]System.Threading.Tasks.Task`1 V_1, + valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 V_2) + IL_0000: ldloca.s V_0 + IL_0002: ldarg.0 + IL_0003: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>4__this' + IL_0008: ldloca.s V_0 + IL_000a: ldarg.1 + IL_000b: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::test + IL_0010: ldloca.s V_0 + IL_0012: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() + IL_0017: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' + IL_001c: ldloca.s V_0 + IL_001e: ldc.i4.m1 + IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' + IL_0024: ldloca.s V_0 + IL_0026: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>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::Startd__3'>(!!0&) + IL_0035: ldloca.s V_0 + IL_0037: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' + IL_003c: call instance class [mscorlib]System.Threading.Tasks.Task`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() + IL_0041: stloc.1 + IL_0042: br.s IL_0044 + + IL_0044: ldloc.1 + IL_0045: ret + } // end of method AwaitTestHandler::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.AwaitDelegatingHandler::.ctor() + IL_0006: ret + } // end of method AwaitTestHandler::.ctor + + .method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1 + '<>n__FabricatedMethod5'(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 V_0) + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler::Test(string) + IL_0007: stloc.0 + IL_0008: br.s IL_000a + + IL_000a: ldloc.0 + IL_000b: ret + } // end of method AwaitTestHandler::'<>n__FabricatedMethod5' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 28 (0x1c) + .maxstack 4 + .locals init (string V_0, + string[] V_1) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldc.i4.1 + IL_0003: newarr [mscorlib]System.String + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldc.i4.0 + IL_000b: ldstr "fsdf" + IL_0010: stelem.ref + IL_0011: ldloc.1 + IL_0012: call string [mscorlib]System.String::Join(string, + string[]) + IL_0017: stloc.0 + IL_0018: br.s IL_001a + + IL_001a: ldloc.0 + IL_001b: ret + } // end of method YieldDelegatingHandler::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method YieldDelegatingHandler::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.Collections.IEnumerator, + [mscorlib]System.IDisposable + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private string '<>2__current' + .field private int32 '<>1__state' + .field private int32 '<>l__initialThreadId' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler '<>4__this' + .field public string test + .field public string '<>3__test' + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 82 (0x52) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0' V_0, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, + bool V_2) + IL_0000: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0005: ldarg.0 + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' + IL_000b: bne.un.s IL_001c + + IL_000d: ldarg.0 + IL_000e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0013: ldc.i4.s -2 + IL_0015: ceq + IL_0017: ldc.i4.0 + IL_0018: ceq + IL_001a: br.s IL_001d + + IL_001c: ldc.i4.1 + IL_001d: nop + IL_001e: stloc.2 + IL_001f: ldloc.2 + IL_0020: brtrue.s IL_002d + + IL_0022: ldarg.0 + IL_0023: ldc.i4.0 + IL_0024: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0029: ldarg.0 + IL_002a: stloc.0 + IL_002b: br.s IL_0040 + + IL_002d: ldc.i4.0 + IL_002e: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) + IL_0033: stloc.0 + IL_0034: ldloc.0 + IL_0035: ldarg.0 + IL_0036: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_003b: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_0040: ldloc.0 + IL_0041: ldarg.0 + IL_0042: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' + IL_0047: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test + IL_004c: ldloc.0 + IL_004d: stloc.1 + IL_004e: br.s IL_0050 + + IL_0050: ldloc.1 + IL_0051: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 11 (0xb) + .maxstack 1 + .locals init (class [mscorlib]System.Collections.IEnumerator V_0) + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 85 (0x55) + .maxstack 3 + .locals init (bool V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0006: stloc.1 + IL_0007: ldloc.1 + IL_0008: switch ( + IL_0019, + IL_0017) + IL_0015: br.s IL_001b + + IL_0017: br.s IL_0047 + + IL_0019: br.s IL_001d + + IL_001b: br.s IL_004f + + IL_001d: ldarg.0 + IL_001e: ldc.i4.m1 + IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0024: nop + IL_0025: ldarg.0 + IL_0026: ldarg.0 + IL_0027: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_002c: ldarg.0 + IL_002d: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test + IL_0032: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler::'<>n__FabricatedMethod1'(string) + IL_0037: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' + IL_003c: ldarg.0 + IL_003d: ldc.i4.1 + IL_003e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0043: ldc.i4.1 + IL_0044: stloc.0 + IL_0045: br.s IL_0053 + + IL_0047: ldarg.0 + IL_0048: ldc.i4.m1 + IL_0049: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_004e: nop + IL_004f: ldc.i4.0 + IL_0050: stloc.0 + IL_0051: br.s IL_0053 + + IL_0053: ldloc.0 + IL_0054: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance string 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 11 (0xb) + .maxstack 1 + .locals init (string V_0) + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .override [mscorlib]System.IDisposable::Dispose + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 11 (0xb) + .maxstack 1 + .locals init (object V_0) + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 25 (0x19) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_000d: ldarg.0 + IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' + IL_0018: ret + } // end of method 'd__0'::.ctor + + .property instance string 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test2(string test) cil managed + { + // Code size 28 (0x1c) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0' V_0, + class [mscorlib]System.Collections.Generic.IEnumerable`1 V_1) + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldarg.0 + IL_000a: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_000f: ldloc.0 + IL_0010: ldarg.1 + IL_0011: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' + IL_0016: ldloc.0 + IL_0017: stloc.1 + IL_0018: br.s IL_001a + + IL_001a: ldloc.1 + IL_001b: ret + } // end of method YieldTestHandler::Test2 + + .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.YieldDelegatingHandler::.ctor() + IL_0006: ret + } // end of method YieldTestHandler::.ctor + + .method private hidebysig instance string + '<>n__FabricatedMethod1'(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 (string V_0) + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler::Test(string) + IL_0007: stloc.0 + IL_0008: br.s IL_000a + + IL_000a: ldloc.0 + IL_000b: ret + } // end of method YieldTestHandler::'<>n__FabricatedMethod1' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 28 (0x1c) + .maxstack 4 + .locals init (string V_0, + string[] V_1) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldc.i4.1 + IL_0003: newarr [mscorlib]System.String + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldc.i4.0 + IL_000b: ldstr "fsdf" + IL_0010: stelem.ref + IL_0011: ldloc.1 + IL_0012: call string [mscorlib]System.String::Join(string, + string[]) + IL_0017: stloc.0 + IL_0018: br.s IL_001a + + IL_001a: ldloc.0 + IL_001b: ret + } // end of method LambdaDelegatingHandler::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method LambdaDelegatingHandler::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler '<>4__this' + .field public string 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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1'::.ctor + + .method public hidebysig instance string + 'b__0'() cil managed + { + // Code size 22 (0x16) + .maxstack 2 + .locals init (string V_0) + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::'<>4__this' + IL_0006: ldarg.0 + IL_0007: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::test + IL_000c: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler::'<>n__FabricatedMethod3'(string) + IL_0011: stloc.0 + IL_0012: br.s IL_0014 + + IL_0014: ldloc.0 + IL_0015: ret + } // end of method '<>c__DisplayClass1'::'b__0' + + } // end of class '<>c__DisplayClass1' + + .method famorassem hidebysig virtual instance string + Test(string test) cil managed + { + // Code size 45 (0x2d) + .maxstack 2 + .locals init (class [mscorlib]System.Func`1 V_0, + class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1' V_1, + string V_2) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::.ctor() + IL_0005: stloc.1 + IL_0006: ldloc.1 + IL_0007: ldarg.1 + IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::test + IL_000d: ldloc.1 + IL_000e: ldarg.0 + IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::'<>4__this' + IL_0014: nop + IL_0015: ldloc.1 + IL_0016: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::'b__0'() + IL_001c: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0021: stloc.0 + IL_0022: ldloc.0 + IL_0023: callvirt instance !0 class [mscorlib]System.Func`1::Invoke() + IL_0028: stloc.2 + IL_0029: br.s IL_002b + + IL_002b: ldloc.2 + IL_002c: ret + } // end of method LambdaHandler::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.LambdaDelegatingHandler::.ctor() + IL_0006: ret + } // end of method LambdaHandler::.ctor + + .method private hidebysig instance string + '<>n__FabricatedMethod3'(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 (string V_0) + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler::Test(string) + IL_0007: stloc.0 + IL_0008: br.s IL_000a + + IL_000a: ldloc.0 + IL_000b: ret + } // end of method LambdaHandler::'<>n__FabricatedMethod3' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\FixProxyCalls.res" wurde erstellt. diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il new file mode 100644 index 000000000..b25155b92 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il @@ -0,0 +1,664 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly '5o3fsn2p' +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module '5o3fsn2p.dll' +// MVID: {E4036E18-E1B6-438A-BE9C-9D698FD43CAD} +.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: 0x012C0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public string 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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1'::.ctor + + .method public hidebysig instance string + 'b__0'() cil managed + { + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::test + IL_0006: callvirt instance string [mscorlib]System.String::ToUpper() + IL_000b: ret + } // end of method '<>c__DisplayClass1'::'b__0' + + } // end of class '<>c__DisplayClass1' + + .method famorassem hidebysig newslot virtual + instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + // Code size 31 (0x1f) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.1 + IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::test + IL_000d: ldloc.0 + IL_000e: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::'b__0'() + IL_0014: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0019: call class [mscorlib]System.Threading.Tasks.Task`1 [mscorlib]System.Threading.Tasks.Task::Run(class [mscorlib]System.Func`1) + IL_001e: ret + } // end of method AwaitDelegatingHandler::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method AwaitDelegatingHandler::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler +{ + .class auto ansi sealed nested private beforefieldinit 'd__3' + 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 '<>t__builder' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler '<>4__this' + .field public string test + .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 '<>u__$awaiter4' + .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 V_4, + valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 V_5) + .try + { + IL_0000: ldc.i4.1 + IL_0001: stloc.0 + IL_0002: ldarg.0 + IL_0003: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>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.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>4__this' + IL_0013: ldarg.0 + IL_0014: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::test + IL_0019: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler::'<>n__FabricatedMethod5'(string) + IL_001e: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::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::get_IsCompleted() + IL_002c: brtrue.s IL_006e + + IL_002e: ldarg.0 + IL_002f: ldc.i4.0 + IL_0030: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' + IL_0035: ldarg.0 + IL_0036: ldloc.s V_4 + IL_0038: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>u__$awaiter4' + IL_003d: ldarg.0 + IL_003e: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' + IL_0043: ldloca.s V_4 + IL_0045: ldarg.0 + IL_0046: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted,valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'>(!!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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>u__$awaiter4' + 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 + IL_0060: ldloc.s V_5 + IL_0062: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>u__$awaiter4' + IL_0067: ldarg.0 + IL_0068: ldc.i4.m1 + IL_0069: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' + IL_006e: ldloca.s V_4 + IL_0070: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() + IL_0075: ldloca.s V_4 + IL_0077: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 + 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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' + IL_0089: ldarg.0 + IL_008a: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' + IL_008f: ldloc.2 + IL_0090: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' + IL_009f: ldarg.0 + IL_00a0: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' + IL_00a5: ldloc.1 + IL_00a6: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) + IL_00ab: ret + } // end of method 'd__3'::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' + IL_0006: ldarg.1 + IL_0007: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine) + IL_000c: ret + } // end of method 'd__3'::SetStateMachine + + } // end of class 'd__3' + + .method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 4B 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..KICSharpCode.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 41 77 61 69 74 54 65 73 74 48 61 6E 64 // ty.AwaitTestHand + 6C 65 72 2B 3C 54 65 73 74 3E 64 5F 5F 33 00 00 ) // ler+d__3.. + .custom instance void [mscorlib]System.Diagnostics.DebuggerStepThroughAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 66 (0x42) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3' V_0, + valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 V_1) + IL_0000: ldloca.s V_0 + IL_0002: ldarg.0 + IL_0003: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>4__this' + IL_0008: ldloca.s V_0 + IL_000a: ldarg.1 + IL_000b: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::test + IL_0010: ldloca.s V_0 + IL_0012: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() + IL_0017: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' + IL_001c: ldloca.s V_0 + IL_001e: ldc.i4.m1 + IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' + IL_0024: ldloca.s V_0 + IL_0026: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>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::Startd__3'>(!!0&) + IL_0035: ldloca.s V_0 + IL_0037: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' + IL_003c: call instance class [mscorlib]System.Threading.Tasks.Task`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() + IL_0041: ret + } // end of method AwaitTestHandler::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.AwaitDelegatingHandler::.ctor() + IL_0006: ret + } // end of method AwaitTestHandler::.ctor + + .method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1 + '<>n__FabricatedMethod5'(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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler::Test(string) + IL_0007: ret + } // end of method AwaitTestHandler::'<>n__FabricatedMethod5' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 23 (0x17) + .maxstack 4 + .locals init (string[] V_0) + IL_0000: ldarg.1 + IL_0001: ldc.i4.1 + IL_0002: newarr [mscorlib]System.String + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldc.i4.0 + IL_000a: ldstr "fsdf" + IL_000f: stelem.ref + IL_0010: ldloc.0 + IL_0011: call string [mscorlib]System.String::Join(string, + string[]) + IL_0016: ret + } // end of method YieldDelegatingHandler::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method YieldDelegatingHandler::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.Collections.IEnumerator, + [mscorlib]System.IDisposable + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private string '<>2__current' + .field private int32 '<>1__state' + .field private int32 '<>l__initialThreadId' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler '<>4__this' + .field public string test + .field public string '<>3__test' + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 67 (0x43) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0' V_0) + IL_0000: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0005: ldarg.0 + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' + IL_000b: bne.un.s IL_0022 + + IL_000d: ldarg.0 + IL_000e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0013: ldc.i4.s -2 + IL_0015: bne.un.s IL_0022 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.0 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: stloc.0 + IL_0020: br.s IL_0035 + + IL_0022: ldc.i4.0 + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) + IL_0028: stloc.0 + IL_0029: ldloc.0 + IL_002a: ldarg.0 + IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_0035: ldloc.0 + IL_0036: ldarg.0 + IL_0037: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' + IL_003c: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test + IL_0041: ldloc.0 + IL_0042: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 71 (0x47) + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: switch ( + IL_0017, + IL_003e) + IL_0015: br.s IL_0045 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.m1 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: ldarg.0 + IL_0020: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_0025: ldarg.0 + IL_0026: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test + IL_002b: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler::'<>n__FabricatedMethod1'(string) + IL_0030: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' + IL_0035: ldarg.0 + IL_0036: ldc.i4.1 + IL_0037: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_003c: ldc.i4.1 + IL_003d: ret + + IL_003e: ldarg.0 + IL_003f: ldc.i4.m1 + IL_0040: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0045: ldc.i4.0 + IL_0046: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance string 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .override [mscorlib]System.IDisposable::Dispose + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 25 (0x19) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_000d: ldarg.0 + IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' + IL_0018: ret + } // end of method 'd__0'::.ctor + + .property instance string 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test2(string test) cil managed + { + // Code size 24 (0x18) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0' V_0) + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldarg.0 + IL_000a: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_000f: ldloc.0 + IL_0010: ldarg.1 + IL_0011: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' + IL_0016: ldloc.0 + IL_0017: ret + } // end of method YieldTestHandler::Test2 + + .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.YieldDelegatingHandler::.ctor() + IL_0006: ret + } // end of method YieldTestHandler::.ctor + + .method private hidebysig instance string + '<>n__FabricatedMethod1'(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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler::Test(string) + IL_0007: ret + } // end of method YieldTestHandler::'<>n__FabricatedMethod1' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 23 (0x17) + .maxstack 4 + .locals init (string[] V_0) + IL_0000: ldarg.1 + IL_0001: ldc.i4.1 + IL_0002: newarr [mscorlib]System.String + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldc.i4.0 + IL_000a: ldstr "fsdf" + IL_000f: stelem.ref + IL_0010: ldloc.0 + IL_0011: call string [mscorlib]System.String::Join(string, + string[]) + IL_0016: ret + } // end of method LambdaDelegatingHandler::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method LambdaDelegatingHandler::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler '<>4__this' + .field public string 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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1'::.ctor + + .method public hidebysig instance string + 'b__0'() cil managed + { + // Code size 18 (0x12) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::'<>4__this' + IL_0006: ldarg.0 + IL_0007: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::test + IL_000c: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler::'<>n__FabricatedMethod3'(string) + IL_0011: ret + } // end of method '<>c__DisplayClass1'::'b__0' + + } // end of class '<>c__DisplayClass1' + + .method famorassem hidebysig virtual instance string + Test(string test) cil managed + { + // Code size 40 (0x28) + .maxstack 2 + .locals init (class [mscorlib]System.Func`1 V_0, + class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1' V_1) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::.ctor() + IL_0005: stloc.1 + IL_0006: ldloc.1 + IL_0007: ldarg.1 + IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::test + IL_000d: ldloc.1 + IL_000e: ldarg.0 + IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::'<>4__this' + IL_0014: ldloc.1 + IL_0015: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::'b__0'() + IL_001b: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0020: stloc.0 + IL_0021: ldloc.0 + IL_0022: callvirt instance !0 class [mscorlib]System.Func`1::Invoke() + IL_0027: ret + } // end of method LambdaHandler::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.LambdaDelegatingHandler::.ctor() + IL_0006: ret + } // end of method LambdaHandler::.ctor + + .method private hidebysig instance string + '<>n__FabricatedMethod3'(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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler::Test(string) + IL_0007: ret + } // end of method LambdaHandler::'<>n__FabricatedMethod3' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\FixProxyCalls.opt.res" wurde erstellt. diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il new file mode 100644 index 000000000..18067c1bc --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il @@ -0,0 +1,660 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly FixProxyCalls +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module FixProxyCalls.dll +// MVID: {01B4F59A-A47C-4AAE-8629-51C35A57DB9D} +.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: 0x004A0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + 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 '<>t__builder' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler '<>4__this' + .field public string test + .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 '<>u__1' + .method private hidebysig newslot virtual final + instance void MoveNext() cil managed + { + .override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext + // Code size 160 (0xa0) + .maxstack 3 + .locals init (int32 V_0, + class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler V_1, + string V_2, + valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 V_3, + class [mscorlib]System.Exception V_4) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldarg.0 + IL_0008: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>4__this' + IL_000d: stloc.1 + .try + { + IL_000e: ldloc.0 + IL_000f: brfalse.s IL_004c + + IL_0011: ldloc.1 + IL_0012: ldarg.0 + IL_0013: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::test + IL_0018: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler::'<>n__0'(string) + IL_001d: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::GetAwaiter() + IL_0022: stloc.3 + IL_0023: ldloca.s V_3 + IL_0025: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::get_IsCompleted() + IL_002a: brtrue.s IL_0068 + + IL_002c: ldarg.0 + IL_002d: ldc.i4.0 + IL_002e: dup + IL_002f: stloc.0 + IL_0030: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' + IL_0035: ldarg.0 + IL_0036: ldloc.3 + IL_0037: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>u__1' + IL_003c: ldarg.0 + IL_003d: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' + IL_0042: ldloca.s V_3 + IL_0044: ldarg.0 + IL_0045: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted,valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'>(!!0&, + !!1&) + IL_004a: leave.s IL_009f + + IL_004c: ldarg.0 + IL_004d: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>u__1' + IL_0052: stloc.3 + IL_0053: ldarg.0 + IL_0054: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>u__1' + IL_0059: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 + IL_005f: ldarg.0 + IL_0060: ldc.i4.m1 + IL_0061: dup + IL_0062: stloc.0 + IL_0063: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' + IL_0068: ldloca.s V_3 + IL_006a: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() + IL_006f: stloc.2 + IL_0070: leave.s IL_008b + + } // end .try + catch [mscorlib]System.Exception + { + IL_0072: stloc.s V_4 + IL_0074: ldarg.0 + IL_0075: ldc.i4.s -2 + IL_0077: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' + IL_007c: ldarg.0 + IL_007d: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' + IL_0082: ldloc.s V_4 + IL_0084: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetException(class [mscorlib]System.Exception) + IL_0089: leave.s IL_009f + + } // end handler + IL_008b: ldarg.0 + IL_008c: ldc.i4.s -2 + IL_008e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' + IL_0093: ldarg.0 + IL_0094: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' + IL_0099: ldloc.2 + IL_009a: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) + IL_009f: ret + } // end of method '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 13 (0xd) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' + IL_0006: ldarg.1 + IL_0007: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine) + IL_000c: ret + } // end of method 'd__0'::SetStateMachine + + } // end of class 'd__0' + + .method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 4B 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..KICSharpCode.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 41 77 61 69 74 54 65 73 74 48 61 6E 64 // ty.AwaitTestHand + 6C 65 72 2B 3C 54 65 73 74 3E 64 5F 5F 30 00 00 ) // ler+d__0.. + // Code size 65 (0x41) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0' V_0, + valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 V_1) + IL_0000: ldloca.s V_0 + IL_0002: ldarg.0 + IL_0003: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>4__this' + IL_0008: ldloca.s V_0 + IL_000a: ldarg.1 + IL_000b: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::test + IL_0010: ldloca.s V_0 + IL_0012: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() + IL_0017: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' + IL_001c: ldloca.s V_0 + IL_001e: ldc.i4.m1 + IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' + IL_0024: ldloc.0 + IL_0025: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' + IL_002a: stloc.1 + IL_002b: ldloca.s V_1 + IL_002d: ldloca.s V_0 + IL_002f: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Startd__0'>(!!0&) + IL_0034: ldloca.s V_0 + IL_0036: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' + IL_003b: call instance class [mscorlib]System.Threading.Tasks.Task`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() + IL_0040: ret + } // end of method AwaitTestHandler::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.AwaitDelegatingHandler::.ctor() + IL_0006: ret + } // end of method AwaitTestHandler::.ctor + + .method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1 + '<>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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler::Test(string) + IL_0007: ret + } // end of method AwaitTestHandler::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass0_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public string 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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass0_0'::.ctor + + .method assembly hidebysig instance string + 'b__0'() cil managed + { + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::test + IL_0006: callvirt instance string [mscorlib]System.String::ToUpper() + IL_000b: ret + } // end of method '<>c__DisplayClass0_0'::'b__0' + + } // end of class '<>c__DisplayClass0_0' + + .method famorassem hidebysig newslot virtual + instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + // Code size 29 (0x1d) + .maxstack 8 + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::.ctor() + IL_0005: dup + IL_0006: ldarg.1 + IL_0007: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::test + IL_000c: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::'b__0'() + IL_0012: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0017: call class [mscorlib]System.Threading.Tasks.Task`1 [mscorlib]System.Threading.Tasks.Task::Run(class [mscorlib]System.Func`1) + IL_001c: ret + } // end of method AwaitDelegatingHandler::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method AwaitDelegatingHandler::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.IDisposable, + [mscorlib]System.Collections.IEnumerator + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private int32 '<>1__state' + .field private string '<>2__current' + .field private int32 '<>l__initialThreadId' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler '<>4__this' + .field private string test + .field public string '<>3__test' + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 25 (0x19) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_000d: ldarg.0 + IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' + IL_0018: ret + } // end of method 'd__0'::.ctor + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.IDisposable::Dispose + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 66 (0x42) + .maxstack 3 + .locals init (int32 V_0, + class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler V_1) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldarg.0 + IL_0008: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_000d: stloc.1 + IL_000e: ldloc.0 + IL_000f: brfalse.s IL_0017 + + IL_0011: ldloc.0 + IL_0012: ldc.i4.1 + IL_0013: beq.s IL_0039 + + IL_0015: ldc.i4.0 + IL_0016: ret + + IL_0017: ldarg.0 + IL_0018: ldc.i4.m1 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: ldloc.1 + IL_0020: ldarg.0 + IL_0021: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test + IL_0026: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler::'<>n__0'(string) + IL_002b: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' + IL_0030: ldarg.0 + IL_0031: ldc.i4.1 + IL_0032: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0037: ldc.i4.1 + IL_0038: ret + + IL_0039: ldarg.0 + IL_003a: ldc.i4.m1 + IL_003b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0040: ldc.i4.0 + IL_0041: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance string 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 67 (0x43) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0' V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0006: ldc.i4.s -2 + IL_0008: bne.un.s IL_0022 + + IL_000a: ldarg.0 + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' + IL_0010: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0015: bne.un.s IL_0022 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.0 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: stloc.0 + IL_0020: br.s IL_0035 + + IL_0022: ldc.i4.0 + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) + IL_0028: stloc.0 + IL_0029: ldloc.0 + IL_002a: ldarg.0 + IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_0035: ldloc.0 + IL_0036: ldarg.0 + IL_0037: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' + IL_003c: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test + IL_0041: ldloc.0 + IL_0042: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .property instance string 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test2(string test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.IteratorStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 4C 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..LICSharpCode.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 59 69 65 6C 64 54 65 73 74 48 61 6E 64 // ty.YieldTestHand + 6C 65 72 2B 3C 54 65 73 74 32 3E 64 5F 5F 30 00 // ler+d__0. + 00 ) + // Code size 22 (0x16) + .maxstack 8 + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) + IL_0007: dup + IL_0008: ldarg.0 + IL_0009: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_000e: dup + IL_000f: ldarg.1 + IL_0010: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' + IL_0015: ret + } // end of method YieldTestHandler::Test2 + + .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.YieldDelegatingHandler::.ctor() + IL_0006: ret + } // end of method YieldTestHandler::.ctor + + .method private hidebysig instance 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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler::Test(string) + IL_0007: ret + } // end of method YieldTestHandler::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 21 (0x15) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldc.i4.1 + IL_0002: newarr [mscorlib]System.String + IL_0007: dup + IL_0008: ldc.i4.0 + IL_0009: ldstr "fsdf" + IL_000e: stelem.ref + IL_000f: call string [mscorlib]System.String::Join(string, + string[]) + IL_0014: ret + } // end of method YieldDelegatingHandler::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method YieldDelegatingHandler::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass0_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public string test + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler '<>4__this' + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass0_0'::.ctor + + .method assembly hidebysig instance string + 'b__0'() cil managed + { + // Code size 18 (0x12) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::'<>4__this' + IL_0006: ldarg.0 + IL_0007: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::test + IL_000c: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler::'<>n__0'(string) + IL_0011: ret + } // end of method '<>c__DisplayClass0_0'::'b__0' + + } // end of class '<>c__DisplayClass0_0' + + .method famorassem hidebysig virtual instance string + Test(string test) cil managed + { + // Code size 36 (0x24) + .maxstack 8 + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::.ctor() + IL_0005: dup + IL_0006: ldarg.0 + IL_0007: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::'<>4__this' + IL_000c: dup + IL_000d: ldarg.1 + IL_000e: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::test + IL_0013: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::'b__0'() + IL_0019: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_001e: callvirt instance !0 class [mscorlib]System.Func`1::Invoke() + IL_0023: ret + } // end of method LambdaHandler::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.LambdaDelegatingHandler::.ctor() + IL_0006: ret + } // end of method LambdaHandler::.ctor + + .method private hidebysig instance 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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler::Test(string) + IL_0007: ret + } // end of method LambdaHandler::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 21 (0x15) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldc.i4.1 + IL_0002: newarr [mscorlib]System.String + IL_0007: dup + IL_0008: ldc.i4.0 + IL_0009: ldstr "fsdf" + IL_000e: stelem.ref + IL_000f: call string [mscorlib]System.String::Join(string, + string[]) + IL_0014: ret + } // end of method LambdaDelegatingHandler::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method LambdaDelegatingHandler::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il new file mode 100644 index 000000000..696f3ea51 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il @@ -0,0 +1,737 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly FixProxyCalls +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module FixProxyCalls.dll +// MVID: {33B12B9F-34E5-4EDD-B8C4-0A47397C1BC1} +.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: 0x01280000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + 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 '<>t__builder' + .field public string test + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler '<>4__this' + .field private string '<>s__1' + .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 '<>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 '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 V_2, + class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0' V_3, + class [mscorlib]System.Exception V_4) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>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.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>4__this' + IL_0015: ldarg.0 + IL_0016: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::test + IL_001b: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler::'<>n__0'(string) + IL_0020: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::GetAwaiter() + IL_0025: stloc.2 + IL_0026: ldloca.s V_2 + IL_0028: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' + IL_0038: ldarg.0 + IL_0039: ldloc.2 + IL_003a: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>u__1' + IL_003f: ldarg.0 + IL_0040: stloc.3 + IL_0041: ldarg.0 + IL_0042: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>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::AwaitUnsafeOnCompleted,class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>u__1' + IL_0059: stloc.2 + IL_005a: ldarg.0 + IL_005b: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>u__1' + IL_0060: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 + IL_0066: ldarg.0 + IL_0067: ldc.i4.m1 + IL_0068: dup + IL_0069: stloc.0 + IL_006a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' + IL_006f: ldarg.0 + IL_0070: ldloca.s V_2 + IL_0072: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() + IL_0077: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>s__1' + IL_007c: ldarg.0 + IL_007d: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' + IL_008f: ldarg.0 + IL_0090: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' + IL_0095: ldloc.s V_4 + IL_0097: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' + IL_00a7: ldarg.0 + IL_00a8: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' + IL_00ad: ldloc.1 + IL_00ae: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) + IL_00b3: nop + IL_00b4: ret + } // end of method '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 'd__0'::SetStateMachine + + } // end of class 'd__0' + + .method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 4B 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..KICSharpCode.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 41 77 61 69 74 54 65 73 74 48 61 6E 64 // ty.AwaitTestHand + 6C 65 72 2B 3C 54 65 73 74 3E 64 5F 5F 30 00 00 ) // ler+d__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.AwaitTestHandler/'d__0' V_0, + valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 V_1) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>4__this' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::test + IL_0014: ldloc.0 + IL_0015: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() + IL_001a: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' + IL_001f: ldloc.0 + IL_0020: ldc.i4.m1 + IL_0021: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' + IL_0026: ldloc.0 + IL_0027: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>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::Startd__0'>(!!0&) + IL_0036: ldloc.0 + IL_0037: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' + IL_003c: call instance class [mscorlib]System.Threading.Tasks.Task`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() + IL_0041: ret + } // end of method AwaitTestHandler::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.AwaitDelegatingHandler::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method AwaitTestHandler::.ctor + + .method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1 + '<>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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler::Test(string) + IL_0007: ret + } // end of method AwaitTestHandler::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass0_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public string 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 [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method '<>c__DisplayClass0_0'::.ctor + + .method assembly hidebysig instance string + 'b__0'() cil managed + { + // Code size 17 (0x11) + .maxstack 1 + .locals init (string V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::test + IL_0007: callvirt instance string [mscorlib]System.String::ToUpper() + IL_000c: stloc.0 + IL_000d: br.s IL_000f + + IL_000f: ldloc.0 + IL_0010: ret + } // end of method '<>c__DisplayClass0_0'::'b__0' + + } // end of class '<>c__DisplayClass0_0' + + .method famorassem hidebysig newslot virtual + instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + // Code size 36 (0x24) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0' V_0, + class [mscorlib]System.Threading.Tasks.Task`1 V_1) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.1 + IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::test + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::'b__0'() + IL_0015: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_001a: call class [mscorlib]System.Threading.Tasks.Task`1 [mscorlib]System.Threading.Tasks.Task::Run(class [mscorlib]System.Func`1) + IL_001f: stloc.1 + IL_0020: br.s IL_0022 + + IL_0022: ldloc.1 + IL_0023: ret + } // end of method AwaitDelegatingHandler::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 [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method AwaitDelegatingHandler::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.IDisposable, + [mscorlib]System.Collections.IEnumerator + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private int32 '<>1__state' + .field private string '<>2__current' + .field private int32 '<>l__initialThreadId' + .field private string test + .field public string '<>3__test' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler '<>4__this' + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 26 (0x1a) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ldarg.0 + IL_0008: ldarg.1 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_000e: ldarg.0 + IL_000f: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' + IL_0019: ret + } // end of method 'd__0'::.ctor + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.IDisposable::Dispose + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 73 (0x49) + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: brfalse.s IL_0012 + + IL_000a: br.s IL_000c + + IL_000c: ldloc.0 + IL_000d: ldc.i4.1 + IL_000e: beq.s IL_0014 + + IL_0010: br.s IL_0016 + + IL_0012: br.s IL_0018 + + IL_0014: br.s IL_0040 + + IL_0016: ldc.i4.0 + IL_0017: ret + + IL_0018: ldarg.0 + IL_0019: ldc.i4.m1 + IL_001a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_001f: nop + IL_0020: ldarg.0 + IL_0021: ldarg.0 + IL_0022: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_0027: ldarg.0 + IL_0028: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test + IL_002d: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler::'<>n__0'(string) + IL_0032: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' + IL_0037: ldarg.0 + IL_0038: ldc.i4.1 + IL_0039: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_003e: ldc.i4.1 + IL_003f: ret + + IL_0040: ldarg.0 + IL_0041: ldc.i4.m1 + IL_0042: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0047: ldc.i4.0 + IL_0048: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance string 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 67 (0x43) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0' V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_0006: ldc.i4.s -2 + IL_0008: bne.un.s IL_0022 + + IL_000a: ldarg.0 + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' + IL_0010: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0015: bne.un.s IL_0022 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.0 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: stloc.0 + IL_0020: br.s IL_0035 + + IL_0022: ldc.i4.0 + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) + IL_0028: stloc.0 + IL_0029: ldloc.0 + IL_002a: ldarg.0 + IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_0035: ldloc.0 + IL_0036: ldarg.0 + IL_0037: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' + IL_003c: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test + IL_0041: ldloc.0 + IL_0042: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .property instance string 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test2(string test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.IteratorStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 4C 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..LICSharpCode.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 59 69 65 6C 64 54 65 73 74 48 61 6E 64 // ty.YieldTestHand + 6C 65 72 2B 3C 54 65 73 74 32 3E 64 5F 5F 30 00 // ler+d__0. + 00 ) + // Code size 22 (0x16) + .maxstack 8 + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) + IL_0007: dup + IL_0008: ldarg.0 + IL_0009: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' + IL_000e: dup + IL_000f: ldarg.1 + IL_0010: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' + IL_0015: ret + } // end of method YieldTestHandler::Test2 + + .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.YieldDelegatingHandler::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method YieldTestHandler::.ctor + + .method private hidebysig instance 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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler::Test(string) + IL_0007: ret + } // end of method YieldTestHandler::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 26 (0x1a) + .maxstack 5 + .locals init (string V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldc.i4.1 + IL_0003: newarr [mscorlib]System.String + IL_0008: dup + IL_0009: ldc.i4.0 + IL_000a: ldstr "fsdf" + IL_000f: stelem.ref + IL_0010: call string [mscorlib]System.String::Join(string, + string[]) + IL_0015: stloc.0 + IL_0016: br.s IL_0018 + + IL_0018: ldloc.0 + IL_0019: ret + } // end of method YieldDelegatingHandler::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 [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method YieldDelegatingHandler::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass0_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public string test + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler '<>4__this' + .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 '<>c__DisplayClass0_0'::.ctor + + .method assembly hidebysig instance string + 'b__0'() cil managed + { + // Code size 18 (0x12) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::'<>4__this' + IL_0006: ldarg.0 + IL_0007: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::test + IL_000c: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler::'<>n__0'(string) + IL_0011: ret + } // end of method '<>c__DisplayClass0_0'::'b__0' + + } // end of class '<>c__DisplayClass0_0' + + .method famorassem hidebysig virtual instance string + Test(string test) cil managed + { + // Code size 45 (0x2d) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0' V_0, + class [mscorlib]System.Func`1 V_1, + string V_2) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::'<>4__this' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::test + IL_0014: nop + IL_0015: ldloc.0 + IL_0016: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::'b__0'() + IL_001c: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0021: stloc.1 + IL_0022: ldloc.1 + IL_0023: callvirt instance !0 class [mscorlib]System.Func`1::Invoke() + IL_0028: stloc.2 + IL_0029: br.s IL_002b + + IL_002b: ldloc.2 + IL_002c: ret + } // end of method LambdaHandler::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.LambdaDelegatingHandler::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method LambdaHandler::.ctor + + .method private hidebysig instance 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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler::Test(string) + IL_0007: ret + } // end of method LambdaHandler::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 26 (0x1a) + .maxstack 5 + .locals init (string V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldc.i4.1 + IL_0003: newarr [mscorlib]System.String + IL_0008: dup + IL_0009: ldc.i4.0 + IL_000a: ldstr "fsdf" + IL_000f: stelem.ref + IL_0010: call string [mscorlib]System.String::Join(string, + string[]) + IL_0015: stloc.0 + IL_0016: br.s IL_0018 + + IL_0018: ldloc.0 + IL_0019: ret + } // end of method LambdaDelegatingHandler::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 [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method LambdaDelegatingHandler::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** From 69b64481283165cae3a7f44475b81e00979f13f4 Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Sun, 8 Oct 2017 22:05:05 +0200 Subject: [PATCH 037/190] Fix order of transforms --- ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 55f20d3dc..5810602fe 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -121,9 +121,9 @@ namespace ICSharpCode.Decompiler.CSharp ) } }, + new ProxyCallReplacer(), new DelegateConstruction(), new AssignVariableNames(), - new ProxyCallReplacer(), }; } From d5a1d8df02bfe0883828bef5a79b982663a50fff Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Sun, 8 Oct 2017 22:12:16 +0200 Subject: [PATCH 038/190] Fix test --- .../TestCases/Pretty/FixProxyCalls.cs | 17 +- .../TestCases/Pretty/FixProxyCalls.il | 781 ------------------ .../TestCases/Pretty/FixProxyCalls.opt.il | 664 --------------- .../Pretty/FixProxyCalls.opt.roslyn.il | 660 --------------- .../TestCases/Pretty/FixProxyCalls.roslyn.il | 737 ----------------- 5 files changed, 9 insertions(+), 2850 deletions(-) delete mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il delete mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il delete mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il delete mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs index f4d85b597..7e9f18456 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty { - internal class AwaitDelegatingHandler + internal class A { protected internal virtual Task Test(string test) { @@ -12,7 +12,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty } } - internal class AwaitTestHandler : AwaitDelegatingHandler + internal class B : A { protected internal override async Task Test(string test) { @@ -20,7 +20,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty } } - internal class YieldDelegatingHandler + internal class C { protected internal virtual string Test(string test) { @@ -28,7 +28,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty } } - internal class YieldTestHandler : YieldDelegatingHandler + internal class D : C { protected internal IEnumerable Test2(string test) { @@ -36,7 +36,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty } } - internal class LambdaDelegatingHandler + internal class E { protected internal virtual string Test(string test) { @@ -44,12 +44,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty } } - internal class LambdaHandler : LambdaDelegatingHandler + internal class F : E { protected internal override string Test(string test) { - Func func = (Func)(() => base.Test(test)); - return func(); + Func func = (Func)((string a) => base.Test(a)); + test = string.Join(test, "aa"); + return func(test); } } } \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il deleted file mode 100644 index 48af1c00a..000000000 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il +++ /dev/null @@ -1,781 +0,0 @@ - -// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 -// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. - - - -// Metadata version: v4.0.30319 -.assembly extern mscorlib -{ - .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. - .ver 4:0:0:0 -} -.assembly '3b3jnobf' -{ - .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 - 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. - .permissionset reqmin - = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} - .hash algorithm 0x00008004 - .ver 0:0:0:0 -} -.module '3b3jnobf.dll' -// MVID: {49E27949-DBA3-4290-A606-8A8CBA8C564E} -.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: 0x00FC0000 - - -// =============== CLASS MEMBERS DECLARATION =================== - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler - extends [mscorlib]System.Object -{ - .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' - extends [mscorlib]System.Object - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public string 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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method '<>c__DisplayClass1'::.ctor - - .method public hidebysig instance string - 'b__0'() cil managed - { - // Code size 17 (0x11) - .maxstack 1 - .locals init (string V_0) - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::test - IL_0007: callvirt instance string [mscorlib]System.String::ToUpper() - IL_000c: stloc.0 - IL_000d: br.s IL_000f - - IL_000f: ldloc.0 - IL_0010: ret - } // end of method '<>c__DisplayClass1'::'b__0' - - } // end of class '<>c__DisplayClass1' - - .method famorassem hidebysig newslot virtual - instance class [mscorlib]System.Threading.Tasks.Task`1 - Test(string test) cil managed - { - // Code size 36 (0x24) - .maxstack 2 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1' V_0, - class [mscorlib]System.Threading.Tasks.Task`1 V_1) - IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::.ctor() - IL_0005: stloc.0 - IL_0006: ldloc.0 - IL_0007: ldarg.1 - IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::test - IL_000d: nop - IL_000e: ldloc.0 - IL_000f: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::'b__0'() - IL_0015: newobj instance void class [mscorlib]System.Func`1::.ctor(object, - native int) - IL_001a: call class [mscorlib]System.Threading.Tasks.Task`1 [mscorlib]System.Threading.Tasks.Task::Run(class [mscorlib]System.Func`1) - IL_001f: stloc.1 - IL_0020: br.s IL_0022 - - IL_0022: ldloc.1 - IL_0023: ret - } // end of method AwaitDelegatingHandler::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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method AwaitDelegatingHandler::.ctor - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler - extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler -{ - .class auto ansi sealed nested private beforefieldinit 'd__3' - 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 '<>t__builder' - .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler '<>4__this' - .field public string test - .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 '<>u__$awaiter4' - .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 V_4, - valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 V_5) - .try - { - IL_0000: ldc.i4.1 - IL_0001: stloc.0 - IL_0002: ldarg.0 - IL_0003: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>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.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>4__this' - IL_001a: ldarg.0 - IL_001b: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::test - IL_0020: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler::'<>n__FabricatedMethod5'(string) - IL_0025: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::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::get_IsCompleted() - IL_0033: brtrue.s IL_0076 - - IL_0035: ldarg.0 - IL_0036: ldc.i4.0 - IL_0037: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' - IL_003c: ldarg.0 - IL_003d: ldloc.s V_4 - IL_003f: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>u__$awaiter4' - IL_0044: ldarg.0 - IL_0045: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' - IL_004a: ldloca.s V_4 - IL_004c: ldarg.0 - IL_004d: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted,valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'>(!!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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>u__$awaiter4' - 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 - IL_0068: ldloc.s V_5 - IL_006a: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>u__$awaiter4' - IL_006f: ldarg.0 - IL_0070: ldc.i4.m1 - IL_0071: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' - IL_0076: ldloca.s V_4 - IL_0078: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() - IL_007d: ldloca.s V_4 - IL_007f: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 - 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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' - IL_0091: ldarg.0 - IL_0092: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' - IL_0097: ldloc.2 - IL_0098: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' - IL_00a9: ldarg.0 - IL_00aa: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' - IL_00af: ldloc.1 - IL_00b0: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) - IL_00b5: nop - IL_00b6: nop - IL_00b7: ret - } // end of method 'd__3'::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' - IL_0006: ldarg.1 - IL_0007: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine) - IL_000c: ret - } // end of method 'd__3'::SetStateMachine - - } // end of class 'd__3' - - .method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1 - Test(string test) cil managed - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 4B 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..KICSharpCode.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 41 77 61 69 74 54 65 73 74 48 61 6E 64 // ty.AwaitTestHand - 6C 65 72 2B 3C 54 65 73 74 3E 64 5F 5F 33 00 00 ) // ler+d__3.. - .custom instance void [mscorlib]System.Diagnostics.DebuggerStepThroughAttribute::.ctor() = ( 01 00 00 00 ) - // Code size 70 (0x46) - .maxstack 2 - .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3' V_0, - class [mscorlib]System.Threading.Tasks.Task`1 V_1, - valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 V_2) - IL_0000: ldloca.s V_0 - IL_0002: ldarg.0 - IL_0003: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>4__this' - IL_0008: ldloca.s V_0 - IL_000a: ldarg.1 - IL_000b: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::test - IL_0010: ldloca.s V_0 - IL_0012: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() - IL_0017: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' - IL_001c: ldloca.s V_0 - IL_001e: ldc.i4.m1 - IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' - IL_0024: ldloca.s V_0 - IL_0026: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>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::Startd__3'>(!!0&) - IL_0035: ldloca.s V_0 - IL_0037: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' - IL_003c: call instance class [mscorlib]System.Threading.Tasks.Task`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() - IL_0041: stloc.1 - IL_0042: br.s IL_0044 - - IL_0044: ldloc.1 - IL_0045: ret - } // end of method AwaitTestHandler::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.AwaitDelegatingHandler::.ctor() - IL_0006: ret - } // end of method AwaitTestHandler::.ctor - - .method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1 - '<>n__FabricatedMethod5'(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 V_0) - IL_0000: ldarg.0 - IL_0001: ldarg.1 - IL_0002: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler::Test(string) - IL_0007: stloc.0 - IL_0008: br.s IL_000a - - IL_000a: ldloc.0 - IL_000b: ret - } // end of method AwaitTestHandler::'<>n__FabricatedMethod5' - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler - extends [mscorlib]System.Object -{ - .method famorassem hidebysig newslot virtual - instance string Test(string test) cil managed - { - // Code size 28 (0x1c) - .maxstack 4 - .locals init (string V_0, - string[] V_1) - IL_0000: nop - IL_0001: ldarg.1 - IL_0002: ldc.i4.1 - IL_0003: newarr [mscorlib]System.String - IL_0008: stloc.1 - IL_0009: ldloc.1 - IL_000a: ldc.i4.0 - IL_000b: ldstr "fsdf" - IL_0010: stelem.ref - IL_0011: ldloc.1 - IL_0012: call string [mscorlib]System.String::Join(string, - string[]) - IL_0017: stloc.0 - IL_0018: br.s IL_001a - - IL_001a: ldloc.0 - IL_001b: ret - } // end of method YieldDelegatingHandler::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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method YieldDelegatingHandler::.ctor - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler - extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler -{ - .class auto ansi sealed nested private beforefieldinit 'd__0' - extends [mscorlib]System.Object - implements class [mscorlib]System.Collections.Generic.IEnumerable`1, - [mscorlib]System.Collections.IEnumerable, - class [mscorlib]System.Collections.Generic.IEnumerator`1, - [mscorlib]System.Collections.IEnumerator, - [mscorlib]System.IDisposable - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field private string '<>2__current' - .field private int32 '<>1__state' - .field private int32 '<>l__initialThreadId' - .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler '<>4__this' - .field public string test - .field public string '<>3__test' - .method private hidebysig newslot virtual final - instance class [mscorlib]System.Collections.Generic.IEnumerator`1 - 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() - // Code size 82 (0x52) - .maxstack 2 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0' V_0, - class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, - bool V_2) - IL_0000: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() - IL_0005: ldarg.0 - IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' - IL_000b: bne.un.s IL_001c - - IL_000d: ldarg.0 - IL_000e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0013: ldc.i4.s -2 - IL_0015: ceq - IL_0017: ldc.i4.0 - IL_0018: ceq - IL_001a: br.s IL_001d - - IL_001c: ldc.i4.1 - IL_001d: nop - IL_001e: stloc.2 - IL_001f: ldloc.2 - IL_0020: brtrue.s IL_002d - - IL_0022: ldarg.0 - IL_0023: ldc.i4.0 - IL_0024: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0029: ldarg.0 - IL_002a: stloc.0 - IL_002b: br.s IL_0040 - - IL_002d: ldc.i4.0 - IL_002e: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) - IL_0033: stloc.0 - IL_0034: ldloc.0 - IL_0035: ldarg.0 - IL_0036: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_003b: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_0040: ldloc.0 - IL_0041: ldarg.0 - IL_0042: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' - IL_0047: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test - IL_004c: ldloc.0 - IL_004d: stloc.1 - IL_004e: br.s IL_0050 - - IL_0050: ldloc.1 - IL_0051: ret - } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' - - .method private hidebysig newslot virtual final - instance class [mscorlib]System.Collections.IEnumerator - System.Collections.IEnumerable.GetEnumerator() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.Collections.IEnumerable::GetEnumerator - // Code size 11 (0xb) - .maxstack 1 - .locals init (class [mscorlib]System.Collections.IEnumerator V_0) - IL_0000: ldarg.0 - IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() - IL_0006: stloc.0 - IL_0007: br.s IL_0009 - - IL_0009: ldloc.0 - IL_000a: ret - } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator - - .method private hidebysig newslot virtual final - instance bool MoveNext() cil managed - { - .override [mscorlib]System.Collections.IEnumerator::MoveNext - // Code size 85 (0x55) - .maxstack 3 - .locals init (bool V_0, - int32 V_1) - IL_0000: ldarg.0 - IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0006: stloc.1 - IL_0007: ldloc.1 - IL_0008: switch ( - IL_0019, - IL_0017) - IL_0015: br.s IL_001b - - IL_0017: br.s IL_0047 - - IL_0019: br.s IL_001d - - IL_001b: br.s IL_004f - - IL_001d: ldarg.0 - IL_001e: ldc.i4.m1 - IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0024: nop - IL_0025: ldarg.0 - IL_0026: ldarg.0 - IL_0027: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_002c: ldarg.0 - IL_002d: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test - IL_0032: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler::'<>n__FabricatedMethod1'(string) - IL_0037: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' - IL_003c: ldarg.0 - IL_003d: ldc.i4.1 - IL_003e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0043: ldc.i4.1 - IL_0044: stloc.0 - IL_0045: br.s IL_0053 - - IL_0047: ldarg.0 - IL_0048: ldc.i4.m1 - IL_0049: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_004e: nop - IL_004f: ldc.i4.0 - IL_0050: stloc.0 - IL_0051: br.s IL_0053 - - IL_0053: ldloc.0 - IL_0054: ret - } // end of method 'd__0'::MoveNext - - .method private hidebysig newslot specialname virtual final - instance string 'System.Collections.Generic.IEnumerator.get_Current'() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() - // Code size 11 (0xb) - .maxstack 1 - .locals init (string V_0) - IL_0000: ldarg.0 - IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' - IL_0006: stloc.0 - IL_0007: br.s IL_0009 - - IL_0009: ldloc.0 - IL_000a: ret - } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' - - .method private hidebysig newslot virtual final - instance void System.Collections.IEnumerator.Reset() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.Collections.IEnumerator::Reset - // Code size 6 (0x6) - .maxstack 8 - IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() - IL_0005: throw - } // end of method 'd__0'::System.Collections.IEnumerator.Reset - - .method private hidebysig newslot virtual final - instance void System.IDisposable.Dispose() cil managed - { - .override [mscorlib]System.IDisposable::Dispose - // Code size 2 (0x2) - .maxstack 8 - IL_0000: nop - IL_0001: ret - } // end of method 'd__0'::System.IDisposable.Dispose - - .method private hidebysig newslot specialname virtual final - instance object System.Collections.IEnumerator.get_Current() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.Collections.IEnumerator::get_Current - // Code size 11 (0xb) - .maxstack 1 - .locals init (object V_0) - IL_0000: ldarg.0 - IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' - IL_0006: stloc.0 - IL_0007: br.s IL_0009 - - IL_0009: ldloc.0 - IL_000a: ret - } // end of method 'd__0'::System.Collections.IEnumerator.get_Current - - .method public hidebysig specialname rtspecialname - instance void .ctor(int32 '<>1__state') cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - // Code size 25 (0x19) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void [mscorlib]System.Object::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_000d: ldarg.0 - IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() - IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' - IL_0018: ret - } // end of method 'd__0'::.ctor - - .property instance string 'System.Collections.Generic.IEnumerator.Current'() - { - .get instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() - } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' - .property instance object System.Collections.IEnumerator.Current() - { - .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::System.Collections.IEnumerator.get_Current() - } // end of property 'd__0'::System.Collections.IEnumerator.Current - } // end of class 'd__0' - - .method famorassem hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 - Test2(string test) cil managed - { - // Code size 28 (0x1c) - .maxstack 2 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0' V_0, - class [mscorlib]System.Collections.Generic.IEnumerable`1 V_1) - IL_0000: ldc.i4.s -2 - IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) - IL_0007: stloc.0 - IL_0008: ldloc.0 - IL_0009: ldarg.0 - IL_000a: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_000f: ldloc.0 - IL_0010: ldarg.1 - IL_0011: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' - IL_0016: ldloc.0 - IL_0017: stloc.1 - IL_0018: br.s IL_001a - - IL_001a: ldloc.1 - IL_001b: ret - } // end of method YieldTestHandler::Test2 - - .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.YieldDelegatingHandler::.ctor() - IL_0006: ret - } // end of method YieldTestHandler::.ctor - - .method private hidebysig instance string - '<>n__FabricatedMethod1'(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 (string V_0) - IL_0000: ldarg.0 - IL_0001: ldarg.1 - IL_0002: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler::Test(string) - IL_0007: stloc.0 - IL_0008: br.s IL_000a - - IL_000a: ldloc.0 - IL_000b: ret - } // end of method YieldTestHandler::'<>n__FabricatedMethod1' - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler - extends [mscorlib]System.Object -{ - .method famorassem hidebysig newslot virtual - instance string Test(string test) cil managed - { - // Code size 28 (0x1c) - .maxstack 4 - .locals init (string V_0, - string[] V_1) - IL_0000: nop - IL_0001: ldarg.1 - IL_0002: ldc.i4.1 - IL_0003: newarr [mscorlib]System.String - IL_0008: stloc.1 - IL_0009: ldloc.1 - IL_000a: ldc.i4.0 - IL_000b: ldstr "fsdf" - IL_0010: stelem.ref - IL_0011: ldloc.1 - IL_0012: call string [mscorlib]System.String::Join(string, - string[]) - IL_0017: stloc.0 - IL_0018: br.s IL_001a - - IL_001a: ldloc.0 - IL_001b: ret - } // end of method LambdaDelegatingHandler::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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method LambdaDelegatingHandler::.ctor - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler - extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler -{ - .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' - extends [mscorlib]System.Object - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler '<>4__this' - .field public string 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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method '<>c__DisplayClass1'::.ctor - - .method public hidebysig instance string - 'b__0'() cil managed - { - // Code size 22 (0x16) - .maxstack 2 - .locals init (string V_0) - IL_0000: ldarg.0 - IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::'<>4__this' - IL_0006: ldarg.0 - IL_0007: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::test - IL_000c: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler::'<>n__FabricatedMethod3'(string) - IL_0011: stloc.0 - IL_0012: br.s IL_0014 - - IL_0014: ldloc.0 - IL_0015: ret - } // end of method '<>c__DisplayClass1'::'b__0' - - } // end of class '<>c__DisplayClass1' - - .method famorassem hidebysig virtual instance string - Test(string test) cil managed - { - // Code size 45 (0x2d) - .maxstack 2 - .locals init (class [mscorlib]System.Func`1 V_0, - class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1' V_1, - string V_2) - IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::.ctor() - IL_0005: stloc.1 - IL_0006: ldloc.1 - IL_0007: ldarg.1 - IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::test - IL_000d: ldloc.1 - IL_000e: ldarg.0 - IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::'<>4__this' - IL_0014: nop - IL_0015: ldloc.1 - IL_0016: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::'b__0'() - IL_001c: newobj instance void class [mscorlib]System.Func`1::.ctor(object, - native int) - IL_0021: stloc.0 - IL_0022: ldloc.0 - IL_0023: callvirt instance !0 class [mscorlib]System.Func`1::Invoke() - IL_0028: stloc.2 - IL_0029: br.s IL_002b - - IL_002b: ldloc.2 - IL_002c: ret - } // end of method LambdaHandler::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.LambdaDelegatingHandler::.ctor() - IL_0006: ret - } // end of method LambdaHandler::.ctor - - .method private hidebysig instance string - '<>n__FabricatedMethod3'(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 (string V_0) - IL_0000: ldarg.0 - IL_0001: ldarg.1 - IL_0002: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler::Test(string) - IL_0007: stloc.0 - IL_0008: br.s IL_000a - - IL_000a: ldloc.0 - IL_000b: ret - } // end of method LambdaHandler::'<>n__FabricatedMethod3' - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler - - -// ============================================================= - -// *********** DISASSEMBLY COMPLETE *********************** -// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\FixProxyCalls.res" wurde erstellt. diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il deleted file mode 100644 index b25155b92..000000000 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il +++ /dev/null @@ -1,664 +0,0 @@ - -// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 -// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. - - - -// Metadata version: v4.0.30319 -.assembly extern mscorlib -{ - .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. - .ver 4:0:0:0 -} -.assembly '5o3fsn2p' -{ - .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 - 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. - .permissionset reqmin - = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} - .hash algorithm 0x00008004 - .ver 0:0:0:0 -} -.module '5o3fsn2p.dll' -// MVID: {E4036E18-E1B6-438A-BE9C-9D698FD43CAD} -.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: 0x012C0000 - - -// =============== CLASS MEMBERS DECLARATION =================== - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler - extends [mscorlib]System.Object -{ - .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' - extends [mscorlib]System.Object - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public string 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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method '<>c__DisplayClass1'::.ctor - - .method public hidebysig instance string - 'b__0'() cil managed - { - // Code size 12 (0xc) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::test - IL_0006: callvirt instance string [mscorlib]System.String::ToUpper() - IL_000b: ret - } // end of method '<>c__DisplayClass1'::'b__0' - - } // end of class '<>c__DisplayClass1' - - .method famorassem hidebysig newslot virtual - instance class [mscorlib]System.Threading.Tasks.Task`1 - Test(string test) cil managed - { - // Code size 31 (0x1f) - .maxstack 2 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1' V_0) - IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::.ctor() - IL_0005: stloc.0 - IL_0006: ldloc.0 - IL_0007: ldarg.1 - IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::test - IL_000d: ldloc.0 - IL_000e: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass1'::'b__0'() - IL_0014: newobj instance void class [mscorlib]System.Func`1::.ctor(object, - native int) - IL_0019: call class [mscorlib]System.Threading.Tasks.Task`1 [mscorlib]System.Threading.Tasks.Task::Run(class [mscorlib]System.Func`1) - IL_001e: ret - } // end of method AwaitDelegatingHandler::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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method AwaitDelegatingHandler::.ctor - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler - extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler -{ - .class auto ansi sealed nested private beforefieldinit 'd__3' - 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 '<>t__builder' - .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler '<>4__this' - .field public string test - .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 '<>u__$awaiter4' - .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 V_4, - valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 V_5) - .try - { - IL_0000: ldc.i4.1 - IL_0001: stloc.0 - IL_0002: ldarg.0 - IL_0003: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>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.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>4__this' - IL_0013: ldarg.0 - IL_0014: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::test - IL_0019: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler::'<>n__FabricatedMethod5'(string) - IL_001e: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::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::get_IsCompleted() - IL_002c: brtrue.s IL_006e - - IL_002e: ldarg.0 - IL_002f: ldc.i4.0 - IL_0030: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' - IL_0035: ldarg.0 - IL_0036: ldloc.s V_4 - IL_0038: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>u__$awaiter4' - IL_003d: ldarg.0 - IL_003e: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' - IL_0043: ldloca.s V_4 - IL_0045: ldarg.0 - IL_0046: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted,valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'>(!!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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>u__$awaiter4' - 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 - IL_0060: ldloc.s V_5 - IL_0062: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>u__$awaiter4' - IL_0067: ldarg.0 - IL_0068: ldc.i4.m1 - IL_0069: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' - IL_006e: ldloca.s V_4 - IL_0070: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() - IL_0075: ldloca.s V_4 - IL_0077: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 - 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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' - IL_0089: ldarg.0 - IL_008a: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' - IL_008f: ldloc.2 - IL_0090: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' - IL_009f: ldarg.0 - IL_00a0: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' - IL_00a5: ldloc.1 - IL_00a6: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) - IL_00ab: ret - } // end of method 'd__3'::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' - IL_0006: ldarg.1 - IL_0007: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine) - IL_000c: ret - } // end of method 'd__3'::SetStateMachine - - } // end of class 'd__3' - - .method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1 - Test(string test) cil managed - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 4B 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..KICSharpCode.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 41 77 61 69 74 54 65 73 74 48 61 6E 64 // ty.AwaitTestHand - 6C 65 72 2B 3C 54 65 73 74 3E 64 5F 5F 33 00 00 ) // ler+d__3.. - .custom instance void [mscorlib]System.Diagnostics.DebuggerStepThroughAttribute::.ctor() = ( 01 00 00 00 ) - // Code size 66 (0x42) - .maxstack 2 - .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3' V_0, - valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 V_1) - IL_0000: ldloca.s V_0 - IL_0002: ldarg.0 - IL_0003: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>4__this' - IL_0008: ldloca.s V_0 - IL_000a: ldarg.1 - IL_000b: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::test - IL_0010: ldloca.s V_0 - IL_0012: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() - IL_0017: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' - IL_001c: ldloca.s V_0 - IL_001e: ldc.i4.m1 - IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>1__state' - IL_0024: ldloca.s V_0 - IL_0026: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>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::Startd__3'>(!!0&) - IL_0035: ldloca.s V_0 - IL_0037: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__3'::'<>t__builder' - IL_003c: call instance class [mscorlib]System.Threading.Tasks.Task`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() - IL_0041: ret - } // end of method AwaitTestHandler::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.AwaitDelegatingHandler::.ctor() - IL_0006: ret - } // end of method AwaitTestHandler::.ctor - - .method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1 - '<>n__FabricatedMethod5'(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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler::Test(string) - IL_0007: ret - } // end of method AwaitTestHandler::'<>n__FabricatedMethod5' - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler - extends [mscorlib]System.Object -{ - .method famorassem hidebysig newslot virtual - instance string Test(string test) cil managed - { - // Code size 23 (0x17) - .maxstack 4 - .locals init (string[] V_0) - IL_0000: ldarg.1 - IL_0001: ldc.i4.1 - IL_0002: newarr [mscorlib]System.String - IL_0007: stloc.0 - IL_0008: ldloc.0 - IL_0009: ldc.i4.0 - IL_000a: ldstr "fsdf" - IL_000f: stelem.ref - IL_0010: ldloc.0 - IL_0011: call string [mscorlib]System.String::Join(string, - string[]) - IL_0016: ret - } // end of method YieldDelegatingHandler::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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method YieldDelegatingHandler::.ctor - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler - extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler -{ - .class auto ansi sealed nested private beforefieldinit 'd__0' - extends [mscorlib]System.Object - implements class [mscorlib]System.Collections.Generic.IEnumerable`1, - [mscorlib]System.Collections.IEnumerable, - class [mscorlib]System.Collections.Generic.IEnumerator`1, - [mscorlib]System.Collections.IEnumerator, - [mscorlib]System.IDisposable - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field private string '<>2__current' - .field private int32 '<>1__state' - .field private int32 '<>l__initialThreadId' - .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler '<>4__this' - .field public string test - .field public string '<>3__test' - .method private hidebysig newslot virtual final - instance class [mscorlib]System.Collections.Generic.IEnumerator`1 - 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() - // Code size 67 (0x43) - .maxstack 2 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0' V_0) - IL_0000: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() - IL_0005: ldarg.0 - IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' - IL_000b: bne.un.s IL_0022 - - IL_000d: ldarg.0 - IL_000e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0013: ldc.i4.s -2 - IL_0015: bne.un.s IL_0022 - - IL_0017: ldarg.0 - IL_0018: ldc.i4.0 - IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_001e: ldarg.0 - IL_001f: stloc.0 - IL_0020: br.s IL_0035 - - IL_0022: ldc.i4.0 - IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) - IL_0028: stloc.0 - IL_0029: ldloc.0 - IL_002a: ldarg.0 - IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_0035: ldloc.0 - IL_0036: ldarg.0 - IL_0037: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' - IL_003c: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test - IL_0041: ldloc.0 - IL_0042: ret - } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' - - .method private hidebysig newslot virtual final - instance class [mscorlib]System.Collections.IEnumerator - System.Collections.IEnumerable.GetEnumerator() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.Collections.IEnumerable::GetEnumerator - // Code size 7 (0x7) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() - IL_0006: ret - } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator - - .method private hidebysig newslot virtual final - instance bool MoveNext() cil managed - { - .override [mscorlib]System.Collections.IEnumerator::MoveNext - // Code size 71 (0x47) - .maxstack 3 - .locals init (int32 V_0) - IL_0000: ldarg.0 - IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0006: stloc.0 - IL_0007: ldloc.0 - IL_0008: switch ( - IL_0017, - IL_003e) - IL_0015: br.s IL_0045 - - IL_0017: ldarg.0 - IL_0018: ldc.i4.m1 - IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_001e: ldarg.0 - IL_001f: ldarg.0 - IL_0020: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_0025: ldarg.0 - IL_0026: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test - IL_002b: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler::'<>n__FabricatedMethod1'(string) - IL_0030: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' - IL_0035: ldarg.0 - IL_0036: ldc.i4.1 - IL_0037: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_003c: ldc.i4.1 - IL_003d: ret - - IL_003e: ldarg.0 - IL_003f: ldc.i4.m1 - IL_0040: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0045: ldc.i4.0 - IL_0046: ret - } // end of method 'd__0'::MoveNext - - .method private hidebysig newslot specialname virtual final - instance string 'System.Collections.Generic.IEnumerator.get_Current'() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() - // Code size 7 (0x7) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' - IL_0006: ret - } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' - - .method private hidebysig newslot virtual final - instance void System.Collections.IEnumerator.Reset() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.Collections.IEnumerator::Reset - // Code size 6 (0x6) - .maxstack 8 - IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() - IL_0005: throw - } // end of method 'd__0'::System.Collections.IEnumerator.Reset - - .method private hidebysig newslot virtual final - instance void System.IDisposable.Dispose() cil managed - { - .override [mscorlib]System.IDisposable::Dispose - // Code size 1 (0x1) - .maxstack 8 - IL_0000: ret - } // end of method 'd__0'::System.IDisposable.Dispose - - .method private hidebysig newslot specialname virtual final - instance object System.Collections.IEnumerator.get_Current() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.Collections.IEnumerator::get_Current - // Code size 7 (0x7) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' - IL_0006: ret - } // end of method 'd__0'::System.Collections.IEnumerator.get_Current - - .method public hidebysig specialname rtspecialname - instance void .ctor(int32 '<>1__state') cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - // Code size 25 (0x19) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void [mscorlib]System.Object::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_000d: ldarg.0 - IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() - IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' - IL_0018: ret - } // end of method 'd__0'::.ctor - - .property instance string 'System.Collections.Generic.IEnumerator.Current'() - { - .get instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() - } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' - .property instance object System.Collections.IEnumerator.Current() - { - .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::System.Collections.IEnumerator.get_Current() - } // end of property 'd__0'::System.Collections.IEnumerator.Current - } // end of class 'd__0' - - .method famorassem hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 - Test2(string test) cil managed - { - // Code size 24 (0x18) - .maxstack 2 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0' V_0) - IL_0000: ldc.i4.s -2 - IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) - IL_0007: stloc.0 - IL_0008: ldloc.0 - IL_0009: ldarg.0 - IL_000a: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_000f: ldloc.0 - IL_0010: ldarg.1 - IL_0011: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' - IL_0016: ldloc.0 - IL_0017: ret - } // end of method YieldTestHandler::Test2 - - .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.YieldDelegatingHandler::.ctor() - IL_0006: ret - } // end of method YieldTestHandler::.ctor - - .method private hidebysig instance string - '<>n__FabricatedMethod1'(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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler::Test(string) - IL_0007: ret - } // end of method YieldTestHandler::'<>n__FabricatedMethod1' - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler - extends [mscorlib]System.Object -{ - .method famorassem hidebysig newslot virtual - instance string Test(string test) cil managed - { - // Code size 23 (0x17) - .maxstack 4 - .locals init (string[] V_0) - IL_0000: ldarg.1 - IL_0001: ldc.i4.1 - IL_0002: newarr [mscorlib]System.String - IL_0007: stloc.0 - IL_0008: ldloc.0 - IL_0009: ldc.i4.0 - IL_000a: ldstr "fsdf" - IL_000f: stelem.ref - IL_0010: ldloc.0 - IL_0011: call string [mscorlib]System.String::Join(string, - string[]) - IL_0016: ret - } // end of method LambdaDelegatingHandler::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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method LambdaDelegatingHandler::.ctor - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler - extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler -{ - .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' - extends [mscorlib]System.Object - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler '<>4__this' - .field public string 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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method '<>c__DisplayClass1'::.ctor - - .method public hidebysig instance string - 'b__0'() cil managed - { - // Code size 18 (0x12) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::'<>4__this' - IL_0006: ldarg.0 - IL_0007: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::test - IL_000c: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler::'<>n__FabricatedMethod3'(string) - IL_0011: ret - } // end of method '<>c__DisplayClass1'::'b__0' - - } // end of class '<>c__DisplayClass1' - - .method famorassem hidebysig virtual instance string - Test(string test) cil managed - { - // Code size 40 (0x28) - .maxstack 2 - .locals init (class [mscorlib]System.Func`1 V_0, - class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1' V_1) - IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::.ctor() - IL_0005: stloc.1 - IL_0006: ldloc.1 - IL_0007: ldarg.1 - IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::test - IL_000d: ldloc.1 - IL_000e: ldarg.0 - IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::'<>4__this' - IL_0014: ldloc.1 - IL_0015: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass1'::'b__0'() - IL_001b: newobj instance void class [mscorlib]System.Func`1::.ctor(object, - native int) - IL_0020: stloc.0 - IL_0021: ldloc.0 - IL_0022: callvirt instance !0 class [mscorlib]System.Func`1::Invoke() - IL_0027: ret - } // end of method LambdaHandler::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.LambdaDelegatingHandler::.ctor() - IL_0006: ret - } // end of method LambdaHandler::.ctor - - .method private hidebysig instance string - '<>n__FabricatedMethod3'(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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler::Test(string) - IL_0007: ret - } // end of method LambdaHandler::'<>n__FabricatedMethod3' - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler - - -// ============================================================= - -// *********** DISASSEMBLY COMPLETE *********************** -// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\FixProxyCalls.opt.res" wurde erstellt. diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il deleted file mode 100644 index 18067c1bc..000000000 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il +++ /dev/null @@ -1,660 +0,0 @@ - -// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 -// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. - - - -// Metadata version: v4.0.30319 -.assembly extern mscorlib -{ - .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. - .ver 4:0:0:0 -} -.assembly FixProxyCalls -{ - .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 - 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. - - // --- The following custom attribute is added automatically, do not uncomment ------- - // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 ) - - .permissionset reqmin - = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} - .hash algorithm 0x00008004 - .ver 0:0:0:0 -} -.module FixProxyCalls.dll -// MVID: {01B4F59A-A47C-4AAE-8629-51C35A57DB9D} -.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: 0x004A0000 - - -// =============== CLASS MEMBERS DECLARATION =================== - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler - extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler -{ - .class auto ansi sealed nested private beforefieldinit 'd__0' - 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 '<>t__builder' - .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler '<>4__this' - .field public string test - .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 '<>u__1' - .method private hidebysig newslot virtual final - instance void MoveNext() cil managed - { - .override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext - // Code size 160 (0xa0) - .maxstack 3 - .locals init (int32 V_0, - class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler V_1, - string V_2, - valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 V_3, - class [mscorlib]System.Exception V_4) - IL_0000: ldarg.0 - IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' - IL_0006: stloc.0 - IL_0007: ldarg.0 - IL_0008: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>4__this' - IL_000d: stloc.1 - .try - { - IL_000e: ldloc.0 - IL_000f: brfalse.s IL_004c - - IL_0011: ldloc.1 - IL_0012: ldarg.0 - IL_0013: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::test - IL_0018: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler::'<>n__0'(string) - IL_001d: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::GetAwaiter() - IL_0022: stloc.3 - IL_0023: ldloca.s V_3 - IL_0025: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::get_IsCompleted() - IL_002a: brtrue.s IL_0068 - - IL_002c: ldarg.0 - IL_002d: ldc.i4.0 - IL_002e: dup - IL_002f: stloc.0 - IL_0030: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' - IL_0035: ldarg.0 - IL_0036: ldloc.3 - IL_0037: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>u__1' - IL_003c: ldarg.0 - IL_003d: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' - IL_0042: ldloca.s V_3 - IL_0044: ldarg.0 - IL_0045: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted,valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'>(!!0&, - !!1&) - IL_004a: leave.s IL_009f - - IL_004c: ldarg.0 - IL_004d: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>u__1' - IL_0052: stloc.3 - IL_0053: ldarg.0 - IL_0054: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>u__1' - IL_0059: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 - IL_005f: ldarg.0 - IL_0060: ldc.i4.m1 - IL_0061: dup - IL_0062: stloc.0 - IL_0063: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' - IL_0068: ldloca.s V_3 - IL_006a: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() - IL_006f: stloc.2 - IL_0070: leave.s IL_008b - - } // end .try - catch [mscorlib]System.Exception - { - IL_0072: stloc.s V_4 - IL_0074: ldarg.0 - IL_0075: ldc.i4.s -2 - IL_0077: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' - IL_007c: ldarg.0 - IL_007d: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' - IL_0082: ldloc.s V_4 - IL_0084: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetException(class [mscorlib]System.Exception) - IL_0089: leave.s IL_009f - - } // end handler - IL_008b: ldarg.0 - IL_008c: ldc.i4.s -2 - IL_008e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' - IL_0093: ldarg.0 - IL_0094: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' - IL_0099: ldloc.2 - IL_009a: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) - IL_009f: ret - } // end of method '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 13 (0xd) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' - IL_0006: ldarg.1 - IL_0007: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine) - IL_000c: ret - } // end of method 'd__0'::SetStateMachine - - } // end of class 'd__0' - - .method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1 - Test(string test) cil managed - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 4B 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..KICSharpCode.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 41 77 61 69 74 54 65 73 74 48 61 6E 64 // ty.AwaitTestHand - 6C 65 72 2B 3C 54 65 73 74 3E 64 5F 5F 30 00 00 ) // ler+d__0.. - // Code size 65 (0x41) - .maxstack 2 - .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0' V_0, - valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 V_1) - IL_0000: ldloca.s V_0 - IL_0002: ldarg.0 - IL_0003: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>4__this' - IL_0008: ldloca.s V_0 - IL_000a: ldarg.1 - IL_000b: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::test - IL_0010: ldloca.s V_0 - IL_0012: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() - IL_0017: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' - IL_001c: ldloca.s V_0 - IL_001e: ldc.i4.m1 - IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' - IL_0024: ldloc.0 - IL_0025: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' - IL_002a: stloc.1 - IL_002b: ldloca.s V_1 - IL_002d: ldloca.s V_0 - IL_002f: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Startd__0'>(!!0&) - IL_0034: ldloca.s V_0 - IL_0036: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' - IL_003b: call instance class [mscorlib]System.Threading.Tasks.Task`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() - IL_0040: ret - } // end of method AwaitTestHandler::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.AwaitDelegatingHandler::.ctor() - IL_0006: ret - } // end of method AwaitTestHandler::.ctor - - .method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1 - '<>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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler::Test(string) - IL_0007: ret - } // end of method AwaitTestHandler::'<>n__0' - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler - extends [mscorlib]System.Object -{ - .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass0_0' - extends [mscorlib]System.Object - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public string 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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method '<>c__DisplayClass0_0'::.ctor - - .method assembly hidebysig instance string - 'b__0'() cil managed - { - // Code size 12 (0xc) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::test - IL_0006: callvirt instance string [mscorlib]System.String::ToUpper() - IL_000b: ret - } // end of method '<>c__DisplayClass0_0'::'b__0' - - } // end of class '<>c__DisplayClass0_0' - - .method famorassem hidebysig newslot virtual - instance class [mscorlib]System.Threading.Tasks.Task`1 - Test(string test) cil managed - { - // Code size 29 (0x1d) - .maxstack 8 - IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::.ctor() - IL_0005: dup - IL_0006: ldarg.1 - IL_0007: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::test - IL_000c: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::'b__0'() - IL_0012: newobj instance void class [mscorlib]System.Func`1::.ctor(object, - native int) - IL_0017: call class [mscorlib]System.Threading.Tasks.Task`1 [mscorlib]System.Threading.Tasks.Task::Run(class [mscorlib]System.Func`1) - IL_001c: ret - } // end of method AwaitDelegatingHandler::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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method AwaitDelegatingHandler::.ctor - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler - extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler -{ - .class auto ansi sealed nested private beforefieldinit 'd__0' - extends [mscorlib]System.Object - implements class [mscorlib]System.Collections.Generic.IEnumerable`1, - [mscorlib]System.Collections.IEnumerable, - class [mscorlib]System.Collections.Generic.IEnumerator`1, - [mscorlib]System.IDisposable, - [mscorlib]System.Collections.IEnumerator - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field private int32 '<>1__state' - .field private string '<>2__current' - .field private int32 '<>l__initialThreadId' - .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler '<>4__this' - .field private string test - .field public string '<>3__test' - .method public hidebysig specialname rtspecialname - instance void .ctor(int32 '<>1__state') cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - // Code size 25 (0x19) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void [mscorlib]System.Object::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_000d: ldarg.0 - IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() - IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' - IL_0018: ret - } // end of method 'd__0'::.ctor - - .method private hidebysig newslot virtual final - instance void System.IDisposable.Dispose() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.IDisposable::Dispose - // Code size 1 (0x1) - .maxstack 8 - IL_0000: ret - } // end of method 'd__0'::System.IDisposable.Dispose - - .method private hidebysig newslot virtual final - instance bool MoveNext() cil managed - { - .override [mscorlib]System.Collections.IEnumerator::MoveNext - // Code size 66 (0x42) - .maxstack 3 - .locals init (int32 V_0, - class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler V_1) - IL_0000: ldarg.0 - IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0006: stloc.0 - IL_0007: ldarg.0 - IL_0008: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_000d: stloc.1 - IL_000e: ldloc.0 - IL_000f: brfalse.s IL_0017 - - IL_0011: ldloc.0 - IL_0012: ldc.i4.1 - IL_0013: beq.s IL_0039 - - IL_0015: ldc.i4.0 - IL_0016: ret - - IL_0017: ldarg.0 - IL_0018: ldc.i4.m1 - IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_001e: ldarg.0 - IL_001f: ldloc.1 - IL_0020: ldarg.0 - IL_0021: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test - IL_0026: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler::'<>n__0'(string) - IL_002b: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' - IL_0030: ldarg.0 - IL_0031: ldc.i4.1 - IL_0032: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0037: ldc.i4.1 - IL_0038: ret - - IL_0039: ldarg.0 - IL_003a: ldc.i4.m1 - IL_003b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0040: ldc.i4.0 - IL_0041: ret - } // end of method 'd__0'::MoveNext - - .method private hidebysig newslot specialname virtual final - instance string 'System.Collections.Generic.IEnumerator.get_Current'() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() - // Code size 7 (0x7) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' - IL_0006: ret - } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' - - .method private hidebysig newslot virtual final - instance void System.Collections.IEnumerator.Reset() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.Collections.IEnumerator::Reset - // Code size 6 (0x6) - .maxstack 8 - IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() - IL_0005: throw - } // end of method 'd__0'::System.Collections.IEnumerator.Reset - - .method private hidebysig newslot specialname virtual final - instance object System.Collections.IEnumerator.get_Current() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.Collections.IEnumerator::get_Current - // Code size 7 (0x7) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' - IL_0006: ret - } // end of method 'd__0'::System.Collections.IEnumerator.get_Current - - .method private hidebysig newslot virtual final - instance class [mscorlib]System.Collections.Generic.IEnumerator`1 - 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() - // Code size 67 (0x43) - .maxstack 2 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0' V_0) - IL_0000: ldarg.0 - IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0006: ldc.i4.s -2 - IL_0008: bne.un.s IL_0022 - - IL_000a: ldarg.0 - IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' - IL_0010: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() - IL_0015: bne.un.s IL_0022 - - IL_0017: ldarg.0 - IL_0018: ldc.i4.0 - IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_001e: ldarg.0 - IL_001f: stloc.0 - IL_0020: br.s IL_0035 - - IL_0022: ldc.i4.0 - IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) - IL_0028: stloc.0 - IL_0029: ldloc.0 - IL_002a: ldarg.0 - IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_0035: ldloc.0 - IL_0036: ldarg.0 - IL_0037: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' - IL_003c: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test - IL_0041: ldloc.0 - IL_0042: ret - } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' - - .method private hidebysig newslot virtual final - instance class [mscorlib]System.Collections.IEnumerator - System.Collections.IEnumerable.GetEnumerator() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.Collections.IEnumerable::GetEnumerator - // Code size 7 (0x7) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() - IL_0006: ret - } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator - - .property instance string 'System.Collections.Generic.IEnumerator.Current'() - { - .get instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() - } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' - .property instance object System.Collections.IEnumerator.Current() - { - .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::System.Collections.IEnumerator.get_Current() - } // end of property 'd__0'::System.Collections.IEnumerator.Current - } // end of class 'd__0' - - .method famorassem hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 - Test2(string test) cil managed - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.IteratorStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 4C 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..LICSharpCode.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 59 69 65 6C 64 54 65 73 74 48 61 6E 64 // ty.YieldTestHand - 6C 65 72 2B 3C 54 65 73 74 32 3E 64 5F 5F 30 00 // ler+d__0. - 00 ) - // Code size 22 (0x16) - .maxstack 8 - IL_0000: ldc.i4.s -2 - IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) - IL_0007: dup - IL_0008: ldarg.0 - IL_0009: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_000e: dup - IL_000f: ldarg.1 - IL_0010: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' - IL_0015: ret - } // end of method YieldTestHandler::Test2 - - .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.YieldDelegatingHandler::.ctor() - IL_0006: ret - } // end of method YieldTestHandler::.ctor - - .method private hidebysig instance 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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler::Test(string) - IL_0007: ret - } // end of method YieldTestHandler::'<>n__0' - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler - extends [mscorlib]System.Object -{ - .method famorassem hidebysig newslot virtual - instance string Test(string test) cil managed - { - // Code size 21 (0x15) - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ldc.i4.1 - IL_0002: newarr [mscorlib]System.String - IL_0007: dup - IL_0008: ldc.i4.0 - IL_0009: ldstr "fsdf" - IL_000e: stelem.ref - IL_000f: call string [mscorlib]System.String::Join(string, - string[]) - IL_0014: ret - } // end of method YieldDelegatingHandler::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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method YieldDelegatingHandler::.ctor - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler - extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler -{ - .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass0_0' - extends [mscorlib]System.Object - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public string test - .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler '<>4__this' - .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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method '<>c__DisplayClass0_0'::.ctor - - .method assembly hidebysig instance string - 'b__0'() cil managed - { - // Code size 18 (0x12) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::'<>4__this' - IL_0006: ldarg.0 - IL_0007: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::test - IL_000c: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler::'<>n__0'(string) - IL_0011: ret - } // end of method '<>c__DisplayClass0_0'::'b__0' - - } // end of class '<>c__DisplayClass0_0' - - .method famorassem hidebysig virtual instance string - Test(string test) cil managed - { - // Code size 36 (0x24) - .maxstack 8 - IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::.ctor() - IL_0005: dup - IL_0006: ldarg.0 - IL_0007: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::'<>4__this' - IL_000c: dup - IL_000d: ldarg.1 - IL_000e: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::test - IL_0013: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::'b__0'() - IL_0019: newobj instance void class [mscorlib]System.Func`1::.ctor(object, - native int) - IL_001e: callvirt instance !0 class [mscorlib]System.Func`1::Invoke() - IL_0023: ret - } // end of method LambdaHandler::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.LambdaDelegatingHandler::.ctor() - IL_0006: ret - } // end of method LambdaHandler::.ctor - - .method private hidebysig instance 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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler::Test(string) - IL_0007: ret - } // end of method LambdaHandler::'<>n__0' - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler - extends [mscorlib]System.Object -{ - .method famorassem hidebysig newslot virtual - instance string Test(string test) cil managed - { - // Code size 21 (0x15) - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ldc.i4.1 - IL_0002: newarr [mscorlib]System.String - IL_0007: dup - IL_0008: ldc.i4.0 - IL_0009: ldstr "fsdf" - IL_000e: stelem.ref - IL_000f: call string [mscorlib]System.String::Join(string, - string[]) - IL_0014: ret - } // end of method LambdaDelegatingHandler::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 [mscorlib]System.Object::.ctor() - IL_0006: ret - } // end of method LambdaDelegatingHandler::.ctor - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler - - -// ============================================================= - -// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il deleted file mode 100644 index 696f3ea51..000000000 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il +++ /dev/null @@ -1,737 +0,0 @@ - -// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 -// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. - - - -// Metadata version: v4.0.30319 -.assembly extern mscorlib -{ - .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. - .ver 4:0:0:0 -} -.assembly FixProxyCalls -{ - .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 - 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. - - // --- The following custom attribute is added automatically, do not uncomment ------- - // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) - - .permissionset reqmin - = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} - .hash algorithm 0x00008004 - .ver 0:0:0:0 -} -.module FixProxyCalls.dll -// MVID: {33B12B9F-34E5-4EDD-B8C4-0A47397C1BC1} -.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: 0x01280000 - - -// =============== CLASS MEMBERS DECLARATION =================== - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler - extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler -{ - .class auto ansi sealed nested private beforefieldinit 'd__0' - 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 '<>t__builder' - .field public string test - .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler '<>4__this' - .field private string '<>s__1' - .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 '<>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 '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 V_2, - class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0' V_3, - class [mscorlib]System.Exception V_4) - IL_0000: ldarg.0 - IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>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.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>4__this' - IL_0015: ldarg.0 - IL_0016: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::test - IL_001b: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler::'<>n__0'(string) - IL_0020: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::GetAwaiter() - IL_0025: stloc.2 - IL_0026: ldloca.s V_2 - IL_0028: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' - IL_0038: ldarg.0 - IL_0039: ldloc.2 - IL_003a: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>u__1' - IL_003f: ldarg.0 - IL_0040: stloc.3 - IL_0041: ldarg.0 - IL_0042: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>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::AwaitUnsafeOnCompleted,class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>u__1' - IL_0059: stloc.2 - IL_005a: ldarg.0 - IL_005b: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>u__1' - IL_0060: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 - IL_0066: ldarg.0 - IL_0067: ldc.i4.m1 - IL_0068: dup - IL_0069: stloc.0 - IL_006a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' - IL_006f: ldarg.0 - IL_0070: ldloca.s V_2 - IL_0072: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() - IL_0077: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>s__1' - IL_007c: ldarg.0 - IL_007d: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' - IL_008f: ldarg.0 - IL_0090: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' - IL_0095: ldloc.s V_4 - IL_0097: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' - IL_00a7: ldarg.0 - IL_00a8: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' - IL_00ad: ldloc.1 - IL_00ae: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) - IL_00b3: nop - IL_00b4: ret - } // end of method '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 'd__0'::SetStateMachine - - } // end of class 'd__0' - - .method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1 - Test(string test) cil managed - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 4B 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..KICSharpCode.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 41 77 61 69 74 54 65 73 74 48 61 6E 64 // ty.AwaitTestHand - 6C 65 72 2B 3C 54 65 73 74 3E 64 5F 5F 30 00 00 ) // ler+d__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.AwaitTestHandler/'d__0' V_0, - valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 V_1) - IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::.ctor() - IL_0005: stloc.0 - IL_0006: ldloc.0 - IL_0007: ldarg.0 - IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>4__this' - IL_000d: ldloc.0 - IL_000e: ldarg.1 - IL_000f: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::test - IL_0014: ldloc.0 - IL_0015: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() - IL_001a: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' - IL_001f: ldloc.0 - IL_0020: ldc.i4.m1 - IL_0021: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>1__state' - IL_0026: ldloc.0 - IL_0027: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>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::Startd__0'>(!!0&) - IL_0036: ldloc.0 - IL_0037: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler/'d__0'::'<>t__builder' - IL_003c: call instance class [mscorlib]System.Threading.Tasks.Task`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() - IL_0041: ret - } // end of method AwaitTestHandler::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.AwaitDelegatingHandler::.ctor() - IL_0006: nop - IL_0007: ret - } // end of method AwaitTestHandler::.ctor - - .method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1 - '<>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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler::Test(string) - IL_0007: ret - } // end of method AwaitTestHandler::'<>n__0' - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitTestHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler - extends [mscorlib]System.Object -{ - .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass0_0' - extends [mscorlib]System.Object - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public string 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 [mscorlib]System.Object::.ctor() - IL_0006: nop - IL_0007: ret - } // end of method '<>c__DisplayClass0_0'::.ctor - - .method assembly hidebysig instance string - 'b__0'() cil managed - { - // Code size 17 (0x11) - .maxstack 1 - .locals init (string V_0) - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::test - IL_0007: callvirt instance string [mscorlib]System.String::ToUpper() - IL_000c: stloc.0 - IL_000d: br.s IL_000f - - IL_000f: ldloc.0 - IL_0010: ret - } // end of method '<>c__DisplayClass0_0'::'b__0' - - } // end of class '<>c__DisplayClass0_0' - - .method famorassem hidebysig newslot virtual - instance class [mscorlib]System.Threading.Tasks.Task`1 - Test(string test) cil managed - { - // Code size 36 (0x24) - .maxstack 2 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0' V_0, - class [mscorlib]System.Threading.Tasks.Task`1 V_1) - IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::.ctor() - IL_0005: stloc.0 - IL_0006: ldloc.0 - IL_0007: ldarg.1 - IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::test - IL_000d: nop - IL_000e: ldloc.0 - IL_000f: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler/'<>c__DisplayClass0_0'::'b__0'() - IL_0015: newobj instance void class [mscorlib]System.Func`1::.ctor(object, - native int) - IL_001a: call class [mscorlib]System.Threading.Tasks.Task`1 [mscorlib]System.Threading.Tasks.Task::Run(class [mscorlib]System.Func`1) - IL_001f: stloc.1 - IL_0020: br.s IL_0022 - - IL_0022: ldloc.1 - IL_0023: ret - } // end of method AwaitDelegatingHandler::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 [mscorlib]System.Object::.ctor() - IL_0006: nop - IL_0007: ret - } // end of method AwaitDelegatingHandler::.ctor - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AwaitDelegatingHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler - extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler -{ - .class auto ansi sealed nested private beforefieldinit 'd__0' - extends [mscorlib]System.Object - implements class [mscorlib]System.Collections.Generic.IEnumerable`1, - [mscorlib]System.Collections.IEnumerable, - class [mscorlib]System.Collections.Generic.IEnumerator`1, - [mscorlib]System.IDisposable, - [mscorlib]System.Collections.IEnumerator - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field private int32 '<>1__state' - .field private string '<>2__current' - .field private int32 '<>l__initialThreadId' - .field private string test - .field public string '<>3__test' - .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler '<>4__this' - .method public hidebysig specialname rtspecialname - instance void .ctor(int32 '<>1__state') cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - // Code size 26 (0x1a) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void [mscorlib]System.Object::.ctor() - IL_0006: nop - IL_0007: ldarg.0 - IL_0008: ldarg.1 - IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_000e: ldarg.0 - IL_000f: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() - IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' - IL_0019: ret - } // end of method 'd__0'::.ctor - - .method private hidebysig newslot virtual final - instance void System.IDisposable.Dispose() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.IDisposable::Dispose - // Code size 1 (0x1) - .maxstack 8 - IL_0000: ret - } // end of method 'd__0'::System.IDisposable.Dispose - - .method private hidebysig newslot virtual final - instance bool MoveNext() cil managed - { - .override [mscorlib]System.Collections.IEnumerator::MoveNext - // Code size 73 (0x49) - .maxstack 3 - .locals init (int32 V_0) - IL_0000: ldarg.0 - IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0006: stloc.0 - IL_0007: ldloc.0 - IL_0008: brfalse.s IL_0012 - - IL_000a: br.s IL_000c - - IL_000c: ldloc.0 - IL_000d: ldc.i4.1 - IL_000e: beq.s IL_0014 - - IL_0010: br.s IL_0016 - - IL_0012: br.s IL_0018 - - IL_0014: br.s IL_0040 - - IL_0016: ldc.i4.0 - IL_0017: ret - - IL_0018: ldarg.0 - IL_0019: ldc.i4.m1 - IL_001a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_001f: nop - IL_0020: ldarg.0 - IL_0021: ldarg.0 - IL_0022: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_0027: ldarg.0 - IL_0028: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test - IL_002d: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler::'<>n__0'(string) - IL_0032: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' - IL_0037: ldarg.0 - IL_0038: ldc.i4.1 - IL_0039: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_003e: ldc.i4.1 - IL_003f: ret - - IL_0040: ldarg.0 - IL_0041: ldc.i4.m1 - IL_0042: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0047: ldc.i4.0 - IL_0048: ret - } // end of method 'd__0'::MoveNext - - .method private hidebysig newslot specialname virtual final - instance string 'System.Collections.Generic.IEnumerator.get_Current'() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() - // Code size 7 (0x7) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' - IL_0006: ret - } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' - - .method private hidebysig newslot virtual final - instance void System.Collections.IEnumerator.Reset() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.Collections.IEnumerator::Reset - // Code size 6 (0x6) - .maxstack 8 - IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() - IL_0005: throw - } // end of method 'd__0'::System.Collections.IEnumerator.Reset - - .method private hidebysig newslot specialname virtual final - instance object System.Collections.IEnumerator.get_Current() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.Collections.IEnumerator::get_Current - // Code size 7 (0x7) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>2__current' - IL_0006: ret - } // end of method 'd__0'::System.Collections.IEnumerator.get_Current - - .method private hidebysig newslot virtual final - instance class [mscorlib]System.Collections.Generic.IEnumerator`1 - 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() - // Code size 67 (0x43) - .maxstack 2 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0' V_0) - IL_0000: ldarg.0 - IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_0006: ldc.i4.s -2 - IL_0008: bne.un.s IL_0022 - - IL_000a: ldarg.0 - IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>l__initialThreadId' - IL_0010: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() - IL_0015: bne.un.s IL_0022 - - IL_0017: ldarg.0 - IL_0018: ldc.i4.0 - IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>1__state' - IL_001e: ldarg.0 - IL_001f: stloc.0 - IL_0020: br.s IL_0035 - - IL_0022: ldc.i4.0 - IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) - IL_0028: stloc.0 - IL_0029: ldloc.0 - IL_002a: ldarg.0 - IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_0035: ldloc.0 - IL_0036: ldarg.0 - IL_0037: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' - IL_003c: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::test - IL_0041: ldloc.0 - IL_0042: ret - } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' - - .method private hidebysig newslot virtual final - instance class [mscorlib]System.Collections.IEnumerator - System.Collections.IEnumerable.GetEnumerator() cil managed - { - .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) - .override [mscorlib]System.Collections.IEnumerable::GetEnumerator - // Code size 7 (0x7) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() - IL_0006: ret - } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator - - .property instance string 'System.Collections.Generic.IEnumerator.Current'() - { - .get instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() - } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' - .property instance object System.Collections.IEnumerator.Current() - { - .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::System.Collections.IEnumerator.get_Current() - } // end of property 'd__0'::System.Collections.IEnumerator.Current - } // end of class 'd__0' - - .method famorassem hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 - Test2(string test) cil managed - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.IteratorStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 4C 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..LICSharpCode.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 59 69 65 6C 64 54 65 73 74 48 61 6E 64 // ty.YieldTestHand - 6C 65 72 2B 3C 54 65 73 74 32 3E 64 5F 5F 30 00 // ler+d__0. - 00 ) - // Code size 22 (0x16) - .maxstack 8 - IL_0000: ldc.i4.s -2 - IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::.ctor(int32) - IL_0007: dup - IL_0008: ldarg.0 - IL_0009: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>4__this' - IL_000e: dup - IL_000f: ldarg.1 - IL_0010: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler/'d__0'::'<>3__test' - IL_0015: ret - } // end of method YieldTestHandler::Test2 - - .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.YieldDelegatingHandler::.ctor() - IL_0006: nop - IL_0007: ret - } // end of method YieldTestHandler::.ctor - - .method private hidebysig instance 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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler::Test(string) - IL_0007: ret - } // end of method YieldTestHandler::'<>n__0' - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldTestHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler - extends [mscorlib]System.Object -{ - .method famorassem hidebysig newslot virtual - instance string Test(string test) cil managed - { - // Code size 26 (0x1a) - .maxstack 5 - .locals init (string V_0) - IL_0000: nop - IL_0001: ldarg.1 - IL_0002: ldc.i4.1 - IL_0003: newarr [mscorlib]System.String - IL_0008: dup - IL_0009: ldc.i4.0 - IL_000a: ldstr "fsdf" - IL_000f: stelem.ref - IL_0010: call string [mscorlib]System.String::Join(string, - string[]) - IL_0015: stloc.0 - IL_0016: br.s IL_0018 - - IL_0018: ldloc.0 - IL_0019: ret - } // end of method YieldDelegatingHandler::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 [mscorlib]System.Object::.ctor() - IL_0006: nop - IL_0007: ret - } // end of method YieldDelegatingHandler::.ctor - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.YieldDelegatingHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler - extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler -{ - .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass0_0' - extends [mscorlib]System.Object - { - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public string test - .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler '<>4__this' - .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 '<>c__DisplayClass0_0'::.ctor - - .method assembly hidebysig instance string - 'b__0'() cil managed - { - // Code size 18 (0x12) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::'<>4__this' - IL_0006: ldarg.0 - IL_0007: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::test - IL_000c: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler::'<>n__0'(string) - IL_0011: ret - } // end of method '<>c__DisplayClass0_0'::'b__0' - - } // end of class '<>c__DisplayClass0_0' - - .method famorassem hidebysig virtual instance string - Test(string test) cil managed - { - // Code size 45 (0x2d) - .maxstack 2 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0' V_0, - class [mscorlib]System.Func`1 V_1, - string V_2) - IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::.ctor() - IL_0005: stloc.0 - IL_0006: ldloc.0 - IL_0007: ldarg.0 - IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::'<>4__this' - IL_000d: ldloc.0 - IL_000e: ldarg.1 - IL_000f: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::test - IL_0014: nop - IL_0015: ldloc.0 - IL_0016: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler/'<>c__DisplayClass0_0'::'b__0'() - IL_001c: newobj instance void class [mscorlib]System.Func`1::.ctor(object, - native int) - IL_0021: stloc.1 - IL_0022: ldloc.1 - IL_0023: callvirt instance !0 class [mscorlib]System.Func`1::Invoke() - IL_0028: stloc.2 - IL_0029: br.s IL_002b - - IL_002b: ldloc.2 - IL_002c: ret - } // end of method LambdaHandler::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.LambdaDelegatingHandler::.ctor() - IL_0006: nop - IL_0007: ret - } // end of method LambdaHandler::.ctor - - .method private hidebysig instance 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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler::Test(string) - IL_0007: ret - } // end of method LambdaHandler::'<>n__0' - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaHandler - -.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler - extends [mscorlib]System.Object -{ - .method famorassem hidebysig newslot virtual - instance string Test(string test) cil managed - { - // Code size 26 (0x1a) - .maxstack 5 - .locals init (string V_0) - IL_0000: nop - IL_0001: ldarg.1 - IL_0002: ldc.i4.1 - IL_0003: newarr [mscorlib]System.String - IL_0008: dup - IL_0009: ldc.i4.0 - IL_000a: ldstr "fsdf" - IL_000f: stelem.ref - IL_0010: call string [mscorlib]System.String::Join(string, - string[]) - IL_0015: stloc.0 - IL_0016: br.s IL_0018 - - IL_0018: ldloc.0 - IL_0019: ret - } // end of method LambdaDelegatingHandler::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 [mscorlib]System.Object::.ctor() - IL_0006: nop - IL_0007: ret - } // end of method LambdaDelegatingHandler::.ctor - -} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.LambdaDelegatingHandler - - -// ============================================================= - -// *********** DISASSEMBLY COMPLETE *********************** From 1821a0fb92d21e5feeba9b89acaa6e915f6d5c75 Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Sun, 8 Oct 2017 22:18:42 +0200 Subject: [PATCH 039/190] Add il files --- .../TestCases/Pretty/FixProxyCalls.il | 766 ++++++++++++++++++ .../TestCases/Pretty/FixProxyCalls.opt.il | 650 +++++++++++++++ .../Pretty/FixProxyCalls.opt.roslyn.il | 635 +++++++++++++++ .../TestCases/Pretty/FixProxyCalls.roslyn.il | 699 ++++++++++++++++ 4 files changed, 2750 insertions(+) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il new file mode 100644 index 000000000..e2db82f72 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il @@ -0,0 +1,766 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly '3zqosgit' +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module '3zqosgit.dll' +// MVID: {6F515237-D053-4A08-B075-52009B7D06CA} +.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: 0x01410000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public string 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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1'::.ctor + + .method public hidebysig instance string + 'b__0'() cil managed + { + // Code size 16 (0x10) + .maxstack 1 + .locals init (string V_0) + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass1'::test + IL_0006: callvirt instance string [mscorlib]System.String::ToUpper() + IL_000b: stloc.0 + IL_000c: br.s IL_000e + + IL_000e: ldloc.0 + IL_000f: ret + } // end of method '<>c__DisplayClass1'::'b__0' + + } // end of class '<>c__DisplayClass1' + + .method famorassem hidebysig newslot virtual + instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + // Code size 36 (0x24) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass1' V_0, + class [mscorlib]System.Threading.Tasks.Task`1 V_1) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass1'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.1 + IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass1'::test + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass1'::'b__0'() + IL_0015: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_001a: call class [mscorlib]System.Threading.Tasks.Task`1 [mscorlib]System.Threading.Tasks.Task::Run(class [mscorlib]System.Func`1) + IL_001f: stloc.1 + IL_0020: br.s IL_0022 + + IL_0022: ldloc.1 + IL_0023: ret + } // end of method A::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method A::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + 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 '<>t__builder' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B '<>4__this' + .field public string test + .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 '<>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 V_4, + valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 V_5) + .try + { + IL_0000: ldc.i4.1 + IL_0001: stloc.0 + IL_0002: ldarg.0 + IL_0003: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>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.B ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>4__this' + IL_001a: ldarg.0 + IL_001b: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::test + IL_0020: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B::'<>n__FabricatedMethod2'(string) + IL_0025: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::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::get_IsCompleted() + IL_0033: brtrue.s IL_0076 + + IL_0035: ldarg.0 + IL_0036: ldc.i4.0 + IL_0037: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_003c: ldarg.0 + IL_003d: ldloc.s V_4 + IL_003f: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>u__$awaiter1' + IL_0044: ldarg.0 + IL_0045: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_004a: ldloca.s V_4 + IL_004c: ldarg.0 + IL_004d: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted,valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>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 + IL_0068: ldloc.s V_5 + IL_006a: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>u__$awaiter1' + IL_006f: ldarg.0 + IL_0070: ldc.i4.m1 + IL_0071: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_0076: ldloca.s V_4 + IL_0078: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() + IL_007d: ldloca.s V_4 + IL_007f: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 + 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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_0091: ldarg.0 + IL_0092: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_0097: ldloc.2 + IL_0098: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_00a9: ldarg.0 + IL_00aa: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_00af: ldloc.1 + IL_00b0: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) + IL_00b5: nop + IL_00b6: nop + IL_00b7: ret + } // end of method '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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_0006: ldarg.1 + IL_0007: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine) + IL_000c: ret + } // end of method 'd__0'::SetStateMachine + + } // end of class 'd__0' + + .method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 3C 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..d__0. + 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerStepThroughAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 70 (0x46) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0' V_0, + class [mscorlib]System.Threading.Tasks.Task`1 V_1, + valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 V_2) + IL_0000: ldloca.s V_0 + IL_0002: ldarg.0 + IL_0003: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>4__this' + IL_0008: ldloca.s V_0 + IL_000a: ldarg.1 + IL_000b: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::test + IL_0010: ldloca.s V_0 + IL_0012: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() + IL_0017: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_001c: ldloca.s V_0 + IL_001e: ldc.i4.m1 + IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_0024: ldloca.s V_0 + IL_0026: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>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::Startd__0'>(!!0&) + IL_0035: ldloca.s V_0 + IL_0037: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_003c: call instance class [mscorlib]System.Threading.Tasks.Task`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() + IL_0041: stloc.1 + IL_0042: br.s IL_0044 + + IL_0044: ldloc.1 + IL_0045: ret + } // end of method B::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 B::.ctor + + .method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1 + '<>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 V_0) + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call instance class [mscorlib]System.Threading.Tasks.Task`1 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 B::'<>n__FabricatedMethod2' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 28 (0x1c) + .maxstack 4 + .locals init (string V_0, + string[] V_1) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldc.i4.1 + IL_0003: newarr [mscorlib]System.String + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldc.i4.0 + IL_000b: ldstr "fsdf" + IL_0010: stelem.ref + IL_0011: ldloc.1 + IL_0012: call string [mscorlib]System.String::Join(string, + string[]) + IL_0017: stloc.0 + IL_0018: br.s IL_001a + + IL_001a: ldloc.0 + IL_001b: ret + } // end of method C::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method C::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.Collections.IEnumerator, + [mscorlib]System.IDisposable + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private string '<>2__current' + .field private int32 '<>1__state' + .field private int32 '<>l__initialThreadId' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D '<>4__this' + .field public string test + .field public string '<>3__test' + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 82 (0x52) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0' V_0, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, + bool V_2) + IL_0000: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0005: ldarg.0 + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>l__initialThreadId' + IL_000b: bne.un.s IL_001c + + IL_000d: ldarg.0 + IL_000e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0013: ldc.i4.s -2 + IL_0015: ceq + IL_0017: ldc.i4.0 + IL_0018: ceq + IL_001a: br.s IL_001d + + IL_001c: ldc.i4.1 + IL_001d: nop + IL_001e: stloc.2 + IL_001f: ldloc.2 + IL_0020: brtrue.s IL_002d + + IL_0022: ldarg.0 + IL_0023: ldc.i4.0 + IL_0024: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0029: ldarg.0 + IL_002a: stloc.0 + IL_002b: br.s IL_0040 + + IL_002d: ldc.i4.0 + IL_002e: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::.ctor(int32) + IL_0033: stloc.0 + IL_0034: ldloc.0 + IL_0035: ldarg.0 + IL_0036: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_003b: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_0040: ldloc.0 + IL_0041: ldarg.0 + IL_0042: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>3__test' + IL_0047: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::test + IL_004c: ldloc.0 + IL_004d: stloc.1 + IL_004e: br.s IL_0050 + + IL_0050: ldloc.1 + IL_0051: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 11 (0xb) + .maxstack 1 + .locals init (class [mscorlib]System.Collections.IEnumerator V_0) + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 85 (0x55) + .maxstack 3 + .locals init (bool V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0006: stloc.1 + IL_0007: ldloc.1 + IL_0008: switch ( + IL_0019, + IL_0017) + IL_0015: br.s IL_001b + + IL_0017: br.s IL_0047 + + IL_0019: br.s IL_001d + + IL_001b: br.s IL_004f + + IL_001d: ldarg.0 + IL_001e: ldc.i4.m1 + IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0024: nop + IL_0025: ldarg.0 + IL_0026: ldarg.0 + IL_0027: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_002c: ldarg.0 + IL_002d: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::test + IL_0032: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D::'<>n__FabricatedMethod1'(string) + IL_0037: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>2__current' + IL_003c: ldarg.0 + IL_003d: ldc.i4.1 + IL_003e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0043: ldc.i4.1 + IL_0044: stloc.0 + IL_0045: br.s IL_0053 + + IL_0047: ldarg.0 + IL_0048: ldc.i4.m1 + IL_0049: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_004e: nop + IL_004f: ldc.i4.0 + IL_0050: stloc.0 + IL_0051: br.s IL_0053 + + IL_0053: ldloc.0 + IL_0054: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance string 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 11 (0xb) + .maxstack 1 + .locals init (string V_0) + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>2__current' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .override [mscorlib]System.IDisposable::Dispose + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 11 (0xb) + .maxstack 1 + .locals init (object V_0) + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>2__current' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 25 (0x19) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_000d: ldarg.0 + IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>l__initialThreadId' + IL_0018: ret + } // end of method 'd__0'::.ctor + + .property instance string 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test2(string test) cil managed + { + // Code size 28 (0x1c) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0' V_0, + class [mscorlib]System.Collections.Generic.IEnumerable`1 V_1) + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::.ctor(int32) + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldarg.0 + IL_000a: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_000f: ldloc.0 + IL_0010: ldarg.1 + IL_0011: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>3__test' + IL_0016: ldloc.0 + IL_0017: stloc.1 + IL_0018: br.s IL_001a + + IL_001a: ldloc.1 + IL_001b: ret + } // end of method D::Test2 + + .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.C::.ctor() + IL_0006: ret + } // end of method D::.ctor + + .method private hidebysig instance string + '<>n__FabricatedMethod1'(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 (string V_0) + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C::Test(string) + IL_0007: stloc.0 + IL_0008: br.s IL_000a + + IL_000a: ldloc.0 + IL_000b: ret + } // end of method D::'<>n__FabricatedMethod1' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 28 (0x1c) + .maxstack 4 + .locals init (string V_0, + string[] V_1) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldc.i4.1 + IL_0003: newarr [mscorlib]System.String + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldc.i4.0 + IL_000b: ldstr "fsdf" + IL_0010: stelem.ref + IL_0011: ldloc.1 + IL_0012: call string [mscorlib]System.String::Join(string, + string[]) + IL_0017: stloc.0 + IL_0018: br.s IL_001a + + IL_001a: ldloc.0 + IL_001b: ret + } // end of method E::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method E::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E +{ + .method famorassem hidebysig virtual instance string + Test(string test) cil managed + { + // Code size 50 (0x32) + .maxstack 4 + .locals init (class [mscorlib]System.Func`2 V_0, + string V_1, + string[] V_2) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F::'b__0'(string) + IL_0008: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: ldarg.1 + IL_000f: ldc.i4.1 + IL_0010: newarr [mscorlib]System.String + IL_0015: stloc.2 + IL_0016: ldloc.2 + IL_0017: ldc.i4.0 + IL_0018: ldstr "aa" + IL_001d: stelem.ref + IL_001e: ldloc.2 + IL_001f: call string [mscorlib]System.String::Join(string, + string[]) + IL_0024: starg.s test + IL_0026: ldloc.0 + IL_0027: ldarg.1 + IL_0028: callvirt instance !1 class [mscorlib]System.Func`2::Invoke(!0) + IL_002d: stloc.1 + IL_002e: br.s IL_0030 + + IL_0030: ldloc.1 + IL_0031: ret + } // end of method F::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.E::.ctor() + IL_0006: ret + } // end of method F::.ctor + + .method private hidebysig instance string + '<>n__FabricatedMethod1'(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 (string V_0) + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E::Test(string) + IL_0007: stloc.0 + IL_0008: br.s IL_000a + + IL_000a: ldloc.0 + IL_000b: ret + } // end of method F::'<>n__FabricatedMethod1' + + .method private hidebysig instance string + 'b__0'(string a) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 12 (0xc) + .maxstack 2 + .locals init (string V_0) + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F::'<>n__FabricatedMethod1'(string) + IL_0007: stloc.0 + IL_0008: br.s IL_000a + + IL_000a: ldloc.0 + IL_000b: ret + } // end of method F::'b__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\FixProxyCalls.res" wurde erstellt. diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il new file mode 100644 index 000000000..e0ded2980 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il @@ -0,0 +1,650 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly jub0alhf +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module jub0alhf.dll +// MVID: {B209562F-4B42-47D5-8725-45EAB5E79932} +.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: 0x004E0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public string 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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1'::.ctor + + .method public hidebysig instance string + 'b__0'() cil managed + { + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass1'::test + IL_0006: callvirt instance string [mscorlib]System.String::ToUpper() + IL_000b: ret + } // end of method '<>c__DisplayClass1'::'b__0' + + } // end of class '<>c__DisplayClass1' + + .method famorassem hidebysig newslot virtual + instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + // Code size 31 (0x1f) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass1' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass1'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.1 + IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass1'::test + IL_000d: ldloc.0 + IL_000e: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass1'::'b__0'() + IL_0014: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0019: call class [mscorlib]System.Threading.Tasks.Task`1 [mscorlib]System.Threading.Tasks.Task::Run(class [mscorlib]System.Func`1) + IL_001e: ret + } // end of method A::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method A::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + 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 '<>t__builder' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B '<>4__this' + .field public string test + .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 '<>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 V_4, + valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 V_5) + .try + { + IL_0000: ldc.i4.1 + IL_0001: stloc.0 + IL_0002: ldarg.0 + IL_0003: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>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.B ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>4__this' + IL_0013: ldarg.0 + IL_0014: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::test + IL_0019: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B::'<>n__FabricatedMethod2'(string) + IL_001e: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::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::get_IsCompleted() + IL_002c: brtrue.s IL_006e + + IL_002e: ldarg.0 + IL_002f: ldc.i4.0 + IL_0030: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_0035: ldarg.0 + IL_0036: ldloc.s V_4 + IL_0038: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>u__$awaiter1' + IL_003d: ldarg.0 + IL_003e: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_0043: ldloca.s V_4 + IL_0045: ldarg.0 + IL_0046: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted,valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>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 + IL_0060: ldloc.s V_5 + IL_0062: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>u__$awaiter1' + IL_0067: ldarg.0 + IL_0068: ldc.i4.m1 + IL_0069: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_006e: ldloca.s V_4 + IL_0070: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() + IL_0075: ldloca.s V_4 + IL_0077: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 + 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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_0089: ldarg.0 + IL_008a: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_008f: ldloc.2 + IL_0090: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_009f: ldarg.0 + IL_00a0: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_00a5: ldloc.1 + IL_00a6: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) + IL_00ab: ret + } // end of method '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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_0006: ldarg.1 + IL_0007: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine) + IL_000c: ret + } // end of method 'd__0'::SetStateMachine + + } // end of class 'd__0' + + .method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 3C 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..d__0. + 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerStepThroughAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 66 (0x42) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0' V_0, + valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 V_1) + IL_0000: ldloca.s V_0 + IL_0002: ldarg.0 + IL_0003: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>4__this' + IL_0008: ldloca.s V_0 + IL_000a: ldarg.1 + IL_000b: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::test + IL_0010: ldloca.s V_0 + IL_0012: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() + IL_0017: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_001c: ldloca.s V_0 + IL_001e: ldc.i4.m1 + IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_0024: ldloca.s V_0 + IL_0026: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>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::Startd__0'>(!!0&) + IL_0035: ldloca.s V_0 + IL_0037: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_003c: call instance class [mscorlib]System.Threading.Tasks.Task`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() + IL_0041: ret + } // end of method B::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 B::.ctor + + .method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1 + '<>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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A::Test(string) + IL_0007: ret + } // end of method B::'<>n__FabricatedMethod2' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 23 (0x17) + .maxstack 4 + .locals init (string[] V_0) + IL_0000: ldarg.1 + IL_0001: ldc.i4.1 + IL_0002: newarr [mscorlib]System.String + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldc.i4.0 + IL_000a: ldstr "fsdf" + IL_000f: stelem.ref + IL_0010: ldloc.0 + IL_0011: call string [mscorlib]System.String::Join(string, + string[]) + IL_0016: ret + } // end of method C::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method C::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.Collections.IEnumerator, + [mscorlib]System.IDisposable + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private string '<>2__current' + .field private int32 '<>1__state' + .field private int32 '<>l__initialThreadId' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D '<>4__this' + .field public string test + .field public string '<>3__test' + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 67 (0x43) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0' V_0) + IL_0000: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0005: ldarg.0 + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>l__initialThreadId' + IL_000b: bne.un.s IL_0022 + + IL_000d: ldarg.0 + IL_000e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0013: ldc.i4.s -2 + IL_0015: bne.un.s IL_0022 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.0 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: stloc.0 + IL_0020: br.s IL_0035 + + IL_0022: ldc.i4.0 + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::.ctor(int32) + IL_0028: stloc.0 + IL_0029: ldloc.0 + IL_002a: ldarg.0 + IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_0035: ldloc.0 + IL_0036: ldarg.0 + IL_0037: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>3__test' + IL_003c: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::test + IL_0041: ldloc.0 + IL_0042: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 71 (0x47) + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: switch ( + IL_0017, + IL_003e) + IL_0015: br.s IL_0045 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.m1 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: ldarg.0 + IL_0020: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_0025: ldarg.0 + IL_0026: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::test + IL_002b: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D::'<>n__FabricatedMethod1'(string) + IL_0030: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>2__current' + IL_0035: ldarg.0 + IL_0036: ldc.i4.1 + IL_0037: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_003c: ldc.i4.1 + IL_003d: ret + + IL_003e: ldarg.0 + IL_003f: ldc.i4.m1 + IL_0040: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0045: ldc.i4.0 + IL_0046: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance string 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .override [mscorlib]System.IDisposable::Dispose + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 25 (0x19) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_000d: ldarg.0 + IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>l__initialThreadId' + IL_0018: ret + } // end of method 'd__0'::.ctor + + .property instance string 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test2(string test) cil managed + { + // Code size 24 (0x18) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0' V_0) + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::.ctor(int32) + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldarg.0 + IL_000a: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_000f: ldloc.0 + IL_0010: ldarg.1 + IL_0011: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>3__test' + IL_0016: ldloc.0 + IL_0017: ret + } // end of method D::Test2 + + .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.C::.ctor() + IL_0006: ret + } // end of method D::.ctor + + .method private hidebysig instance string + '<>n__FabricatedMethod1'(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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C::Test(string) + IL_0007: ret + } // end of method D::'<>n__FabricatedMethod1' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 23 (0x17) + .maxstack 4 + .locals init (string[] V_0) + IL_0000: ldarg.1 + IL_0001: ldc.i4.1 + IL_0002: newarr [mscorlib]System.String + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldc.i4.0 + IL_000a: ldstr "fsdf" + IL_000f: stelem.ref + IL_0010: ldloc.0 + IL_0011: call string [mscorlib]System.String::Join(string, + string[]) + IL_0016: ret + } // end of method E::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method E::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E +{ + .method famorassem hidebysig virtual instance string + Test(string test) cil managed + { + // Code size 45 (0x2d) + .maxstack 4 + .locals init (class [mscorlib]System.Func`2 V_0, + string[] V_1) + IL_0000: ldarg.0 + IL_0001: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F::'b__0'(string) + IL_0007: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_000c: stloc.0 + IL_000d: ldarg.1 + IL_000e: ldc.i4.1 + IL_000f: newarr [mscorlib]System.String + IL_0014: stloc.1 + IL_0015: ldloc.1 + IL_0016: ldc.i4.0 + IL_0017: ldstr "aa" + IL_001c: stelem.ref + IL_001d: ldloc.1 + IL_001e: call string [mscorlib]System.String::Join(string, + string[]) + IL_0023: starg.s test + IL_0025: ldloc.0 + IL_0026: ldarg.1 + IL_0027: callvirt instance !1 class [mscorlib]System.Func`2::Invoke(!0) + IL_002c: ret + } // end of method F::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.E::.ctor() + IL_0006: ret + } // end of method F::.ctor + + .method private hidebysig instance string + '<>n__FabricatedMethod1'(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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E::Test(string) + IL_0007: ret + } // end of method F::'<>n__FabricatedMethod1' + + .method private hidebysig instance string + 'b__0'(string a) 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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F::'<>n__FabricatedMethod1'(string) + IL_0007: ret + } // end of method F::'b__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\FixProxyCalls.opt.res" wurde erstellt. diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il new file mode 100644 index 000000000..d2c17f01b --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il @@ -0,0 +1,635 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly FixProxyCalls +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module FixProxyCalls.dll +// MVID: {4ED058B3-70DA-4FB5-B699-61DBE42057C4} +.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: 0x009D0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass0_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public string 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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass0_0'::.ctor + + .method assembly hidebysig instance string + 'b__0'() cil managed + { + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass0_0'::test + IL_0006: callvirt instance string [mscorlib]System.String::ToUpper() + IL_000b: ret + } // end of method '<>c__DisplayClass0_0'::'b__0' + + } // end of class '<>c__DisplayClass0_0' + + .method famorassem hidebysig newslot virtual + instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + // Code size 29 (0x1d) + .maxstack 8 + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass0_0'::.ctor() + IL_0005: dup + IL_0006: ldarg.1 + IL_0007: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass0_0'::test + IL_000c: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass0_0'::'b__0'() + IL_0012: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0017: call class [mscorlib]System.Threading.Tasks.Task`1 [mscorlib]System.Threading.Tasks.Task::Run(class [mscorlib]System.Func`1) + IL_001c: ret + } // end of method A::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method A::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + 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 '<>t__builder' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B '<>4__this' + .field public string test + .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 '<>u__1' + .method private hidebysig newslot virtual final + instance void MoveNext() cil managed + { + .override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext + // Code size 160 (0xa0) + .maxstack 3 + .locals init (int32 V_0, + class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B V_1, + string V_2, + valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 V_3, + class [mscorlib]System.Exception V_4) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldarg.0 + IL_0008: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>4__this' + IL_000d: stloc.1 + .try + { + IL_000e: ldloc.0 + IL_000f: brfalse.s IL_004c + + IL_0011: ldloc.1 + IL_0012: ldarg.0 + IL_0013: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::test + IL_0018: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B::'<>n__0'(string) + IL_001d: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::GetAwaiter() + IL_0022: stloc.3 + IL_0023: ldloca.s V_3 + IL_0025: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::get_IsCompleted() + IL_002a: brtrue.s IL_0068 + + IL_002c: ldarg.0 + IL_002d: ldc.i4.0 + IL_002e: dup + IL_002f: stloc.0 + IL_0030: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_0035: ldarg.0 + IL_0036: ldloc.3 + IL_0037: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>u__1' + IL_003c: ldarg.0 + IL_003d: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_0042: ldloca.s V_3 + IL_0044: ldarg.0 + IL_0045: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted,valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'>(!!0&, + !!1&) + IL_004a: leave.s IL_009f + + IL_004c: ldarg.0 + IL_004d: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>u__1' + IL_0052: stloc.3 + IL_0053: ldarg.0 + IL_0054: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>u__1' + IL_0059: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 + IL_005f: ldarg.0 + IL_0060: ldc.i4.m1 + IL_0061: dup + IL_0062: stloc.0 + IL_0063: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_0068: ldloca.s V_3 + IL_006a: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() + IL_006f: stloc.2 + IL_0070: leave.s IL_008b + + } // end .try + catch [mscorlib]System.Exception + { + IL_0072: stloc.s V_4 + IL_0074: ldarg.0 + IL_0075: ldc.i4.s -2 + IL_0077: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_007c: ldarg.0 + IL_007d: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_0082: ldloc.s V_4 + IL_0084: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetException(class [mscorlib]System.Exception) + IL_0089: leave.s IL_009f + + } // end handler + IL_008b: ldarg.0 + IL_008c: ldc.i4.s -2 + IL_008e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_0093: ldarg.0 + IL_0094: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_0099: ldloc.2 + IL_009a: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) + IL_009f: ret + } // end of method '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 13 (0xd) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_0006: ldarg.1 + IL_0007: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine) + IL_000c: ret + } // end of method 'd__0'::SetStateMachine + + } // end of class 'd__0' + + .method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 3C 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..d__0. + 00 ) + // Code size 65 (0x41) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0' V_0, + valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 V_1) + IL_0000: ldloca.s V_0 + IL_0002: ldarg.0 + IL_0003: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>4__this' + IL_0008: ldloca.s V_0 + IL_000a: ldarg.1 + IL_000b: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::test + IL_0010: ldloca.s V_0 + IL_0012: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() + IL_0017: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_001c: ldloca.s V_0 + IL_001e: ldc.i4.m1 + IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_0024: ldloc.0 + IL_0025: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_002a: stloc.1 + IL_002b: ldloca.s V_1 + IL_002d: ldloca.s V_0 + IL_002f: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Startd__0'>(!!0&) + IL_0034: ldloca.s V_0 + IL_0036: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_003b: call instance class [mscorlib]System.Threading.Tasks.Task`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() + IL_0040: ret + } // end of method B::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 B::.ctor + + .method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1 + '<>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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A::Test(string) + IL_0007: ret + } // end of method B::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 21 (0x15) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldc.i4.1 + IL_0002: newarr [mscorlib]System.String + IL_0007: dup + IL_0008: ldc.i4.0 + IL_0009: ldstr "fsdf" + IL_000e: stelem.ref + IL_000f: call string [mscorlib]System.String::Join(string, + string[]) + IL_0014: ret + } // end of method C::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method C::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.IDisposable, + [mscorlib]System.Collections.IEnumerator + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private int32 '<>1__state' + .field private string '<>2__current' + .field private int32 '<>l__initialThreadId' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D '<>4__this' + .field private string test + .field public string '<>3__test' + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 25 (0x19) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_000d: ldarg.0 + IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>l__initialThreadId' + IL_0018: ret + } // end of method 'd__0'::.ctor + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.IDisposable::Dispose + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 66 (0x42) + .maxstack 3 + .locals init (int32 V_0, + class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D V_1) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldarg.0 + IL_0008: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_000d: stloc.1 + IL_000e: ldloc.0 + IL_000f: brfalse.s IL_0017 + + IL_0011: ldloc.0 + IL_0012: ldc.i4.1 + IL_0013: beq.s IL_0039 + + IL_0015: ldc.i4.0 + IL_0016: ret + + IL_0017: ldarg.0 + IL_0018: ldc.i4.m1 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: ldloc.1 + IL_0020: ldarg.0 + IL_0021: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::test + IL_0026: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D::'<>n__0'(string) + IL_002b: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>2__current' + IL_0030: ldarg.0 + IL_0031: ldc.i4.1 + IL_0032: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0037: ldc.i4.1 + IL_0038: ret + + IL_0039: ldarg.0 + IL_003a: ldc.i4.m1 + IL_003b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0040: ldc.i4.0 + IL_0041: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance string 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 67 (0x43) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0' V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0006: ldc.i4.s -2 + IL_0008: bne.un.s IL_0022 + + IL_000a: ldarg.0 + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>l__initialThreadId' + IL_0010: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0015: bne.un.s IL_0022 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.0 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: stloc.0 + IL_0020: br.s IL_0035 + + IL_0022: ldc.i4.0 + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::.ctor(int32) + IL_0028: stloc.0 + IL_0029: ldloc.0 + IL_002a: ldarg.0 + IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_0035: ldloc.0 + IL_0036: ldarg.0 + IL_0037: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>3__test' + IL_003c: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::test + IL_0041: ldloc.0 + IL_0042: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .property instance string 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test2(string test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.IteratorStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 3D 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 44 2B 3C 54 65 73 74 32 3E 64 5F 5F 30 // ty.D+d__0 + 00 00 ) + // Code size 22 (0x16) + .maxstack 8 + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::.ctor(int32) + IL_0007: dup + IL_0008: ldarg.0 + IL_0009: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_000e: dup + IL_000f: ldarg.1 + IL_0010: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>3__test' + IL_0015: ret + } // end of method D::Test2 + + .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.C::.ctor() + IL_0006: ret + } // end of method D::.ctor + + .method private hidebysig instance 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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C::Test(string) + IL_0007: ret + } // end of method D::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 21 (0x15) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldc.i4.1 + IL_0002: newarr [mscorlib]System.String + IL_0007: dup + IL_0008: ldc.i4.0 + IL_0009: ldstr "fsdf" + IL_000e: stelem.ref + IL_000f: call string [mscorlib]System.String::Join(string, + string[]) + IL_0014: ret + } // end of method E::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method E::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E +{ + .method famorassem hidebysig virtual instance string + Test(string test) cil managed + { + // Code size 43 (0x2b) + .maxstack 5 + .locals init (class [mscorlib]System.Func`2 V_0) + IL_0000: ldarg.0 + IL_0001: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F::'b__0_0'(string) + IL_0007: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_000c: stloc.0 + IL_000d: ldarg.1 + IL_000e: ldc.i4.1 + IL_000f: newarr [mscorlib]System.String + IL_0014: dup + IL_0015: ldc.i4.0 + IL_0016: ldstr "aa" + IL_001b: stelem.ref + IL_001c: call string [mscorlib]System.String::Join(string, + string[]) + IL_0021: starg.s test + IL_0023: ldloc.0 + IL_0024: ldarg.1 + IL_0025: callvirt instance !1 class [mscorlib]System.Func`2::Invoke(!0) + IL_002a: ret + } // end of method F::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.E::.ctor() + IL_0006: ret + } // end of method F::.ctor + + .method private hidebysig instance string + 'b__0_0'(string a) 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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E::Test(string) + IL_0007: ret + } // end of method F::'b__0_0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il new file mode 100644 index 000000000..df84e9a1f --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il @@ -0,0 +1,699 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly FixProxyCalls +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module FixProxyCalls.dll +// MVID: {7BB86323-1120-4703-BABC-BC12F69CE2C1} +.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: 0x00E50000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass0_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public string 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 [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method '<>c__DisplayClass0_0'::.ctor + + .method assembly hidebysig instance string + 'b__0'() cil managed + { + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass0_0'::test + IL_0006: callvirt instance string [mscorlib]System.String::ToUpper() + IL_000b: ret + } // end of method '<>c__DisplayClass0_0'::'b__0' + + } // end of class '<>c__DisplayClass0_0' + + .method famorassem hidebysig newslot virtual + instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + // Code size 36 (0x24) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass0_0' V_0, + class [mscorlib]System.Threading.Tasks.Task`1 V_1) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass0_0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.1 + IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass0_0'::test + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A/'<>c__DisplayClass0_0'::'b__0'() + IL_0015: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_001a: call class [mscorlib]System.Threading.Tasks.Task`1 [mscorlib]System.Threading.Tasks.Task::Run(class [mscorlib]System.Func`1) + IL_001f: stloc.1 + IL_0020: br.s IL_0022 + + IL_0022: ldloc.1 + IL_0023: ret + } // end of method A::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 [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method A::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + 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 '<>t__builder' + .field public string test + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B '<>4__this' + .field private string '<>s__1' + .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 '<>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 '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 V_2, + class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0' V_3, + class [mscorlib]System.Exception V_4) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>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.B ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>4__this' + IL_0015: ldarg.0 + IL_0016: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::test + IL_001b: call instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B::'<>n__0'(string) + IL_0020: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::GetAwaiter() + IL_0025: stloc.2 + IL_0026: ldloca.s V_2 + IL_0028: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_0038: ldarg.0 + IL_0039: ldloc.2 + IL_003a: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>u__1' + IL_003f: ldarg.0 + IL_0040: stloc.3 + IL_0041: ldarg.0 + IL_0042: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>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::AwaitUnsafeOnCompleted,class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>u__1' + IL_0059: stloc.2 + IL_005a: ldarg.0 + IL_005b: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>u__1' + IL_0060: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 + IL_0066: ldarg.0 + IL_0067: ldc.i4.m1 + IL_0068: dup + IL_0069: stloc.0 + IL_006a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_006f: ldarg.0 + IL_0070: ldloca.s V_2 + IL_0072: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() + IL_0077: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>s__1' + IL_007c: ldarg.0 + IL_007d: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_008f: ldarg.0 + IL_0090: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_0095: ldloc.s V_4 + IL_0097: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_00a7: ldarg.0 + IL_00a8: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_00ad: ldloc.1 + IL_00ae: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) + IL_00b3: nop + IL_00b4: ret + } // end of method '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 'd__0'::SetStateMachine + + } // end of class 'd__0' + + .method famorassem hidebysig virtual instance class [mscorlib]System.Threading.Tasks.Task`1 + Test(string test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 3C 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..d__0. + 00 ) + .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.B/'d__0' V_0, + valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 V_1) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>4__this' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::test + IL_0014: ldloc.0 + IL_0015: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::Create() + IL_001a: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_001f: ldloc.0 + IL_0020: ldc.i4.m1 + IL_0021: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>1__state' + IL_0026: ldloc.0 + IL_0027: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>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::Startd__0'>(!!0&) + IL_0036: ldloc.0 + IL_0037: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B/'d__0'::'<>t__builder' + IL_003c: call instance class [mscorlib]System.Threading.Tasks.Task`1 valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::get_Task() + IL_0041: ret + } // end of method B::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 B::.ctor + + .method private hidebysig instance class [mscorlib]System.Threading.Tasks.Task`1 + '<>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 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.A::Test(string) + IL_0007: ret + } // end of method B::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.B + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 26 (0x1a) + .maxstack 5 + .locals init (string V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldc.i4.1 + IL_0003: newarr [mscorlib]System.String + IL_0008: dup + IL_0009: ldc.i4.0 + IL_000a: ldstr "fsdf" + IL_000f: stelem.ref + IL_0010: call string [mscorlib]System.String::Join(string, + string[]) + IL_0015: stloc.0 + IL_0016: br.s IL_0018 + + IL_0018: ldloc.0 + IL_0019: ret + } // end of method C::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 [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method C::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.IDisposable, + [mscorlib]System.Collections.IEnumerator + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private int32 '<>1__state' + .field private string '<>2__current' + .field private int32 '<>l__initialThreadId' + .field private string test + .field public string '<>3__test' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D '<>4__this' + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 26 (0x1a) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ldarg.0 + IL_0008: ldarg.1 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_000e: ldarg.0 + IL_000f: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>l__initialThreadId' + IL_0019: ret + } // end of method 'd__0'::.ctor + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.IDisposable::Dispose + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 73 (0x49) + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: brfalse.s IL_0012 + + IL_000a: br.s IL_000c + + IL_000c: ldloc.0 + IL_000d: ldc.i4.1 + IL_000e: beq.s IL_0014 + + IL_0010: br.s IL_0016 + + IL_0012: br.s IL_0018 + + IL_0014: br.s IL_0040 + + IL_0016: ldc.i4.0 + IL_0017: ret + + IL_0018: ldarg.0 + IL_0019: ldc.i4.m1 + IL_001a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_001f: nop + IL_0020: ldarg.0 + IL_0021: ldarg.0 + IL_0022: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_0027: ldarg.0 + IL_0028: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::test + IL_002d: call instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D::'<>n__0'(string) + IL_0032: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>2__current' + IL_0037: ldarg.0 + IL_0038: ldc.i4.1 + IL_0039: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_003e: ldc.i4.1 + IL_003f: ret + + IL_0040: ldarg.0 + IL_0041: ldc.i4.m1 + IL_0042: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0047: ldc.i4.0 + IL_0048: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance string 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 67 (0x43) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0' V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_0006: ldc.i4.s -2 + IL_0008: bne.un.s IL_0022 + + IL_000a: ldarg.0 + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>l__initialThreadId' + IL_0010: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0015: bne.un.s IL_0022 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.0 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: stloc.0 + IL_0020: br.s IL_0035 + + IL_0022: ldc.i4.0 + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::.ctor(int32) + IL_0028: stloc.0 + IL_0029: ldloc.0 + IL_002a: ldarg.0 + IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_0035: ldloc.0 + IL_0036: ldarg.0 + IL_0037: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>3__test' + IL_003c: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::test + IL_0041: ldloc.0 + IL_0042: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .property instance string 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test2(string test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.IteratorStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 3D 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 44 2B 3C 54 65 73 74 32 3E 64 5F 5F 30 // ty.D+d__0 + 00 00 ) + // Code size 22 (0x16) + .maxstack 8 + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::.ctor(int32) + IL_0007: dup + IL_0008: ldarg.0 + IL_0009: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>4__this' + IL_000e: dup + IL_000f: ldarg.1 + IL_0010: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D/'d__0'::'<>3__test' + IL_0015: ret + } // end of method D::Test2 + + .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.C::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method D::.ctor + + .method private hidebysig instance 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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.C::Test(string) + IL_0007: ret + } // end of method D::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.D + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance string Test(string test) cil managed + { + // Code size 26 (0x1a) + .maxstack 5 + .locals init (string V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldc.i4.1 + IL_0003: newarr [mscorlib]System.String + IL_0008: dup + IL_0009: ldc.i4.0 + IL_000a: ldstr "fsdf" + IL_000f: stelem.ref + IL_0010: call string [mscorlib]System.String::Join(string, + string[]) + IL_0015: stloc.0 + IL_0016: br.s IL_0018 + + IL_0018: ldloc.0 + IL_0019: ret + } // end of method E::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 [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method E::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E +{ + .method famorassem hidebysig virtual instance string + Test(string test) cil managed + { + // Code size 48 (0x30) + .maxstack 5 + .locals init (class [mscorlib]System.Func`2 V_0, + string V_1) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldftn instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F::'b__0_0'(string) + IL_0008: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: ldarg.1 + IL_000f: ldc.i4.1 + IL_0010: newarr [mscorlib]System.String + IL_0015: dup + IL_0016: ldc.i4.0 + IL_0017: ldstr "aa" + IL_001c: stelem.ref + IL_001d: call string [mscorlib]System.String::Join(string, + string[]) + IL_0022: starg.s test + IL_0024: ldloc.0 + IL_0025: ldarg.1 + IL_0026: callvirt instance !1 class [mscorlib]System.Func`2::Invoke(!0) + IL_002b: stloc.1 + IL_002c: br.s IL_002e + + IL_002e: ldloc.1 + IL_002f: ret + } // end of method F::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.E::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method F::.ctor + + .method private hidebysig instance string + 'b__0_0'(string a) 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 string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.E::Test(string) + IL_0007: ret + } // end of method F::'b__0_0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** From 102729cfde299da70bfc278bbaad1f4d992da72f Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 8 Oct 2017 23:06:38 +0200 Subject: [PATCH 040/190] Put switch instructions into their own BlockContainer. This removes the need for "goto case" in the ILAst as we can just branch to the appropriate block. It also means we can support "break;" within switch using the "leave" instruction (otherwise we'd have to introduce yet another special kind of jump). --- .../CSharp/StatementBuilder.cs | 35 ++++++++- .../FlowAnalysis/DataFlowVisitor.cs | 12 +--- .../IL/ControlFlow/ConditionDetection.cs | 22 +----- .../IL/ControlFlow/LoopDetection.cs | 72 ++++++++++++++++--- ICSharpCode.Decompiler/IL/Instructions.cs | 49 ------------- ICSharpCode.Decompiler/IL/Instructions.tt | 3 - .../IL/Instructions/Block.cs | 3 + .../IL/Instructions/BlockContainer.cs | 2 +- .../IL/Instructions/SwitchInstruction.cs | 33 --------- 9 files changed, 102 insertions(+), 129 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 3ddb00fe9..12ba474aa 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -98,11 +98,17 @@ namespace ICSharpCode.Decompiler.CSharp } return new CaseLabel(exprBuilder.ConvertConstantValue(new ConstantResolveResult(type, value), allowImplicitConversion: true)); } - + protected internal override Statement VisitSwitchInstruction(SwitchInstruction inst) { + return TranslateSwitch(null, inst); + } + + SwitchStatement TranslateSwitch(BlockContainer switchContainer, SwitchInstruction inst) + { + Debug.Assert(switchContainer.EntryPoint.IncomingEdgeCount == 1); var oldBreakTarget = breakTarget; - breakTarget = null; // 'break' within a switch would only leave the switch + breakTarget = switchContainer; // 'break' within a switch would only leave the switch TranslatedExpression value; var strToInt = inst.Value as StringToInt; @@ -134,7 +140,28 @@ namespace ICSharpCode.Decompiler.CSharp ConvertSwitchSectionBody(astSection, section.Body); stmt.SwitchSections.Add(astSection); } - + if (switchContainer != null) { + // Translate any remaining blocks: + var lastSectionStatements = stmt.SwitchSections.Last().Statements; + foreach (var block in switchContainer.Blocks.Skip(1)) { + lastSectionStatements.Add(new LabelStatement { Label = block.Label }); + foreach (var nestedInst in block.Instructions) { + var nestedStmt = Convert(nestedInst); + if (nestedStmt is BlockStatement b) { + foreach (var nested in b.Statements) + lastSectionStatements.Add(nested.Detach()); + } else { + lastSectionStatements.Add(nestedStmt); + } + } + Debug.Assert(block.FinalInstruction.OpCode == OpCode.Nop); + } + if (endContainerLabels.TryGetValue(switchContainer, out string label)) { + lastSectionStatements.Add(new LabelStatement { Label = label }); + lastSectionStatements.Add(new BreakStatement()); + } + } + breakTarget = oldBreakTarget; return stmt; } @@ -471,6 +498,8 @@ namespace ICSharpCode.Decompiler.CSharp continueCount = oldContinueCount; breakTarget = oldBreakTarget; return loop; + } else if (container.EntryPoint.Instructions.Count == 1 && container.EntryPoint.Instructions[0] is SwitchInstruction switchInst) { + return TranslateSwitch(container, switchInst); } else { return ConvertBlockContainer(container, false); } diff --git a/ICSharpCode.Decompiler/FlowAnalysis/DataFlowVisitor.cs b/ICSharpCode.Decompiler/FlowAnalysis/DataFlowVisitor.cs index 0632edc79..034e33798 100644 --- a/ICSharpCode.Decompiler/FlowAnalysis/DataFlowVisitor.cs +++ b/ICSharpCode.Decompiler/FlowAnalysis/DataFlowVisitor.cs @@ -624,17 +624,7 @@ namespace ICSharpCode.Decompiler.FlowAnalysis state = afterSections; DebugEndPoint(inst); } - - protected internal override void VisitGotoCase(GotoCase inst) - { - // Handling goto case here is tricky: - // We'll need a fixed-point iteration for SwitchInstruction similar to BlockContainer, - // and we'll need to handle GotoCase like Branch, including stuff like ProcessBranchesLeavingTryFinally(). - // Hopefully we won't need a data-flow analysis in the decompiler pipeline after 'goto case' instructions - // are already introduced. - throw new NotImplementedException(); - } - + protected internal override void VisitYieldReturn(YieldReturn inst) { DebugStartPoint(inst); diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs index 21da91022..954120bbf 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs @@ -65,10 +65,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow Debug.Assert(block.Instructions.Last().HasFlag(InstructionFlags.EndPointUnreachable)); ILInstruction exitInst = block.Instructions.Last(); - if (exitInst is SwitchInstruction switchInst) { - HandleSwitchInstruction(cfgNode, block, switchInst); - } - + // Previous-to-last instruction might have conditional control flow, // usually an IfInstruction with a branch: IfInstruction ifInst = block.Instructions.SecondToLastOrDefault() as IfInstruction; @@ -287,22 +284,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow && targetBlock.IncomingEdgeCount == 1 && targetBlock.FinalInstruction.OpCode == OpCode.Nop && cfgNode.Dominates(context.ControlFlowGraph.GetNode(targetBlock)); } - - private void HandleSwitchInstruction(ControlFlowNode cfgNode, Block block, SwitchInstruction sw) - { - // First, move blocks into the switch section - foreach (var section in sw.Sections) { - if (IsUsableBranchToChild(cfgNode, section.Body)) { - // case ...: goto targetBlock; - var targetBlock = ((Branch)section.Body).TargetBlock; - targetBlock.Remove(); - section.Body = targetBlock; - } - } - // TODO: find a common exit point among the cases, and if possible inline that into this block. - sw.Sections.ReplaceList(sw.Sections.OrderBy(s => s.Body.ILRange.Start)); - } - + private bool IsBranchOrLeave(ILInstruction inst) { switch (inst) { diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs index b8086bee0..322543b05 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs @@ -16,6 +16,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -57,6 +58,11 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow // Because this is a post-order block transform, we can assume that // any nested loops within this loop have already been constructed. + if (block.Instructions.Last() is SwitchInstruction switchInst) { + // Switch instructions support "break;" just like loops + DetectSwitchBody(block, switchInst); + } + ControlFlowNode h = context.ControlFlowNode; // CFG node for our potential loop head Debug.Assert(h.UserData == block); Debug.Assert(!TreeTraversal.PreOrder(h, n => n.DominatorTreeChildren).Any(n => n.Visited)); @@ -101,7 +107,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow ConstructLoop(loop, exitPoint); } } - + /// /// Recurse into the dominator tree and find back edges/natural loops. /// @@ -412,13 +418,25 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow // Move contents of oldEntryPoint to newEntryPoint // (we can't move the block itself because it might be the target of branch instructions outside the loop) newEntryPoint.Instructions.ReplaceList(oldEntryPoint.Instructions); - newEntryPoint.FinalInstruction = oldEntryPoint.FinalInstruction; newEntryPoint.ILRange = oldEntryPoint.ILRange; oldEntryPoint.Instructions.ReplaceList(new[] { loopContainer }); if (exitTargetBlock != null) oldEntryPoint.Instructions.Add(new Branch(exitTargetBlock)); - oldEntryPoint.FinalInstruction = new Nop(); - + + MoveBlocksIntoContainer(loop, loopContainer); + + // Rewrite branches within the loop from oldEntryPoint to newEntryPoint: + foreach (var branch in loopContainer.Descendants.OfType()) { + if (branch.TargetBlock == oldEntryPoint) { + branch.TargetBlock = newEntryPoint; + } else if (branch.TargetBlock == exitTargetBlock) { + branch.ReplaceWith(new Leave(loopContainer) { ILRange = branch.ILRange }); + } + } + } + + private void MoveBlocksIntoContainer(List loop, BlockContainer loopContainer) + { // Move other blocks into the loop body: they're all dominated by the loop header, // and thus cannot be the target of branch instructions outside the loop. for (int i = 1; i < loop.Count; i++) { @@ -440,12 +458,48 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow Block block = (Block)loop[i].UserData; Debug.Assert(block.IsDescendantOf(loopContainer)); } + } + + private void DetectSwitchBody(Block block, SwitchInstruction switchInst) + { + Debug.Assert(block.Instructions.Last() == switchInst); + ControlFlowNode h = context.ControlFlowNode; // CFG node for our potential loop head + Debug.Assert(h.UserData == block); + Debug.Assert(!TreeTraversal.PreOrder(h, n => n.DominatorTreeChildren).Any(n => n.Visited)); + + var nodesInSwitch = new List(); + nodesInSwitch.Add(h); + h.Visited = true; + ExtendLoop(h, nodesInSwitch, out var exitPoint); + + context.Step("Create BlockContainer for switch", switchInst); + // Sort blocks in the loop in reverse post-order to make the output look a bit nicer. + // (if the loop doesn't contain nested loops, this is a topological sort) + nodesInSwitch.Sort((a, b) => b.PostOrderNumber.CompareTo(a.PostOrderNumber)); + Debug.Assert(nodesInSwitch[0] == h); + foreach (var node in nodesInSwitch) { + node.Visited = false; // reset visited flag so that we can find outer loops + Debug.Assert(h.Dominates(node) || !node.IsReachable, "The switch body must be dominated by the switch head"); + } + + BlockContainer switchContainer = new BlockContainer(); + Block newEntryPoint = new Block(); + newEntryPoint.ILRange = switchInst.ILRange; + switchContainer.Blocks.Add(newEntryPoint); + newEntryPoint.Instructions.Add(switchInst); + block.Instructions[block.Instructions.Count - 1] = switchContainer; + + Block exitTargetBlock = (Block)exitPoint?.UserData; + if (exitTargetBlock != null) { + block.Instructions.Add(new Branch(exitTargetBlock)); + } + + MoveBlocksIntoContainer(nodesInSwitch, switchContainer); + // Rewrite branches within the loop from oldEntryPoint to newEntryPoint: - foreach (var branch in loopContainer.Descendants.OfType()) { - if (branch.TargetBlock == oldEntryPoint) { - branch.TargetBlock = newEntryPoint; - } else if (branch.TargetBlock == exitTargetBlock) { - branch.ReplaceWith(new Leave(loopContainer) { ILRange = branch.ILRange }); + foreach (var branch in switchContainer.Descendants.OfType()) { + if (branch.TargetBlock == exitTargetBlock) { + branch.ReplaceWith(new Leave(switchContainer) { ILRange = branch.ILRange }); } } } diff --git a/ICSharpCode.Decompiler/IL/Instructions.cs b/ICSharpCode.Decompiler/IL/Instructions.cs index ccb7bdedf..0ae8a6815 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.cs +++ b/ICSharpCode.Decompiler/IL/Instructions.cs @@ -63,8 +63,6 @@ namespace ICSharpCode.Decompiler.IL SwitchInstruction, /// Switch section within a switch statement SwitchSection, - /// Unconditional branch to switch section. goto case target; - GotoCase, /// Try-catch statement. TryCatch, /// Catch handler within a try-catch statement. @@ -1407,40 +1405,6 @@ namespace ICSharpCode.Decompiler.IL } } namespace ICSharpCode.Decompiler.IL -{ - /// Unconditional branch to switch section. goto case target; - public sealed partial class GotoCase : SimpleInstruction - { - public override StackType ResultType { get { return StackType.Void; } } - protected override InstructionFlags ComputeFlags() - { - return InstructionFlags.EndPointUnreachable | InstructionFlags.MayBranch; - } - public override InstructionFlags DirectFlags { - get { - return InstructionFlags.EndPointUnreachable | InstructionFlags.MayBranch; - } - } - public override void AcceptVisitor(ILVisitor visitor) - { - visitor.VisitGotoCase(this); - } - public override T AcceptVisitor(ILVisitor visitor) - { - return visitor.VisitGotoCase(this); - } - public override T AcceptVisitor(ILVisitor visitor, C context) - { - return visitor.VisitGotoCase(this, context); - } - protected internal override bool PerformMatch(ILInstruction other, ref Patterns.Match match) - { - var o = other as GotoCase; - return o != null && this.TargetSection == o.TargetSection; - } - } -} -namespace ICSharpCode.Decompiler.IL { /// Try-catch statement. public sealed partial class TryCatch : TryInstruction @@ -4573,10 +4537,6 @@ namespace ICSharpCode.Decompiler.IL { Default(inst); } - protected internal virtual void VisitGotoCase(GotoCase inst) - { - Default(inst); - } protected internal virtual void VisitTryCatch(TryCatch inst) { Default(inst); @@ -4867,10 +4827,6 @@ namespace ICSharpCode.Decompiler.IL { return Default(inst); } - protected internal virtual T VisitGotoCase(GotoCase inst) - { - return Default(inst); - } protected internal virtual T VisitTryCatch(TryCatch inst) { return Default(inst); @@ -5161,10 +5117,6 @@ namespace ICSharpCode.Decompiler.IL { return Default(inst, context); } - protected internal virtual T VisitGotoCase(GotoCase inst, C context) - { - return Default(inst, context); - } protected internal virtual T VisitTryCatch(TryCatch inst, C context) { return Default(inst, context); @@ -5399,7 +5351,6 @@ namespace ICSharpCode.Decompiler.IL "if.notnull", "switch", "switch.section", - "goto.case", "try.catch", "try.catch.handler", "try.finally", diff --git a/ICSharpCode.Decompiler/IL/Instructions.tt b/ICSharpCode.Decompiler/IL/Instructions.tt index c75172ddf..ca7590811 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.tt +++ b/ICSharpCode.Decompiler/IL/Instructions.tt @@ -98,9 +98,6 @@ CustomClassName("SwitchSection"), CustomChildren(new [] { new ChildInfo("body") }), CustomConstructor, CustomComputeFlags, CustomWriteTo, ResultType("Void"), MatchCondition("this.Labels.SetEquals(o.Labels) && this.HasNullLabel == o.HasNullLabel")), - new OpCode("goto.case", "Unconditional branch to switch section. goto case target;", - CustomClassName("GotoCase"), NoArguments, CustomConstructor, UnconditionalBranch, MayBranch, - MatchCondition("this.TargetSection == o.TargetSection")), new OpCode("try.catch", "Try-catch statement.", BaseClass("TryInstruction"), CustomConstructor, CustomComputeFlags, CustomWriteTo, MatchCondition("TryBlock.PerformMatch(o.TryBlock, ref match)"), diff --git a/ICSharpCode.Decompiler/IL/Instructions/Block.cs b/ICSharpCode.Decompiler/IL/Instructions/Block.cs index 3931beece..0c5f9b7cc 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/Block.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/Block.cs @@ -108,6 +108,9 @@ namespace ICSharpCode.Decompiler.IL // only the last instruction may have an unreachable endpoint Debug.Assert(!Instructions[i].HasFlag(InstructionFlags.EndPointUnreachable)); } + if (this.Type == BlockType.ControlFlow) { + Debug.Assert(finalInstruction.OpCode == OpCode.Nop); + } } public override StackType ResultType { diff --git a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs index 5cf84221c..c48021ac7 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs @@ -154,7 +154,7 @@ namespace ICSharpCode.Decompiler.IL Debug.Assert(EntryPoint == Blocks[0]); Debug.Assert(!IsConnected || EntryPoint.IncomingEdgeCount >= 1); Debug.Assert(Blocks.All(b => b.HasFlag(InstructionFlags.EndPointUnreachable))); - Debug.Assert(Blocks.All(b => b.FinalInstruction.OpCode == OpCode.Nop)); + Debug.Assert(Blocks.All(b => b.Type == BlockType.ControlFlow)); // this also implies that the blocks don't use FinalInstruction } protected override InstructionFlags ComputeFlags() diff --git a/ICSharpCode.Decompiler/IL/Instructions/SwitchInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/SwitchInstruction.cs index 5de07f592..ae828983f 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/SwitchInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/SwitchInstruction.cs @@ -196,37 +196,4 @@ namespace ICSharpCode.Decompiler.IL body.WriteTo(output, options); } } - - /// - /// Unconditional branch to switch section. goto case target;/goto default; - /// - /// - /// Like normal branches, can trigger finally blocks. - /// - partial class GotoCase // : IBranchOrLeaveInstruction - { - public SwitchSection TargetSection { get; } - - public GotoCase(SwitchSection target) : base(OpCode.GotoCase) - { - this.TargetSection = target ?? throw new ArgumentNullException(nameof(target)); - } - - internal override void CheckInvariant(ILPhase phase) - { - base.CheckInvariant(phase); - var parentSwitch = this.Ancestors.OfType().First(); - Debug.Assert(parentSwitch == TargetSection.Parent); - } - - public override void WriteTo(ITextOutput output, ILAstWritingOptions options) - { - output.Write("goto.case "); - if (TargetSection.HasNullLabel) { - output.WriteReference("null", TargetSection, isLocal: true); - } else { - output.WriteReference(TargetSection.Labels.Values.First().ToString(), TargetSection, isLocal: true); - } - } - } } From 105ff744b336111c6214552c4451619b2e6e6d35 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 8 Oct 2017 23:55:08 +0200 Subject: [PATCH 041/190] Fix bug that could cause nodes reachable from the exit point to be moved into the loop/switch. --- .../IL/ControlFlow/LoopDetection.cs | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs index 322543b05..2e49db446 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs @@ -101,7 +101,6 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow loop.Sort((a, b) => b.PostOrderNumber.CompareTo(a.PostOrderNumber)); Debug.Assert(loop[0] == h); foreach (var node in loop) { - node.Visited = false; // reset visited flag so that we can find outer loops Debug.Assert(h.Dominates(node) || !node.IsReachable, "The loop body must be dominated by the loop head"); } ConstructLoop(loop, exitPoint); @@ -207,6 +206,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow /// used by the post-dominance analysis. In this case, we fall back to the old heuristic algorithm. /// /// Precondition: Requires that a node is marked as visited iff it is contained in the loop. + /// Postcondition: loop is subset of nodes that are only reachable from each other, + /// exit-point (if non-null) is not in this set, + /// nodes are no longer marked as visited in the CFG /// void ExtendLoop(ControlFlowNode loopHead, List loop, out ControlFlowNode exitPoint) { @@ -215,9 +217,16 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow if (exitPoint != null) { // Either we are in case 1 and just picked an exit that maximizes the amount of code // outside the loop, or we are in case 2 and found an exit point via post-dominance. - var ep = exitPoint; - foreach (var node in TreeTraversal.PreOrder(loopHead, n => (n != ep) ? n.DominatorTreeChildren : null)) { - if (node != exitPoint && !node.Visited) { + + // We'll move all blocks dominated by the loop head into the loop, except for those that + // are reachable from the exit point. + MarkReachableWithinBlocksDominatedByLoop(exitPoint, loopHead); + foreach (var node in TreeTraversal.PreOrder(loopHead, n => n.DominatorTreeChildren)) { + if (node.Visited) { + // node.Visited means that the node is already part of the loop, + // or that it is reachable from the exit point. + node.Visited = false; + } else { loop.Add(node); } } @@ -226,9 +235,25 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow // Heuristically try to minimize the number of exit points // (but we'll always end up with more than 1 exit and will require goto statements). ExtendLoopHeuristic(loopHead, loop, loopHead); + // Reset Visited flag: + foreach (var node in loop) { + node.Visited = false; + } } } - + + void MarkReachableWithinBlocksDominatedByLoop(ControlFlowNode node, ControlFlowNode loopHead) + { + if (node.Visited) + return; // already visited + if (!loopHead.Dominates(node)) + return; + node.Visited = true; + foreach (var successor in node.Successors) { + MarkReachableWithinBlocksDominatedByLoop(successor, loopHead); + } + } + /// /// Finds a suitable single exit point for the specified loop. /// @@ -478,7 +503,6 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow nodesInSwitch.Sort((a, b) => b.PostOrderNumber.CompareTo(a.PostOrderNumber)); Debug.Assert(nodesInSwitch[0] == h); foreach (var node in nodesInSwitch) { - node.Visited = false; // reset visited flag so that we can find outer loops Debug.Assert(h.Dominates(node) || !node.IsReachable, "The switch body must be dominated by the switch head"); } From 180f5341784b7455c2598561ade9952740395f5b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 7 Oct 2017 23:20:16 +0200 Subject: [PATCH 042/190] Fix #778: Errors about decompiling local variables and default for switch-cases --- .../IL/Transforms/DelegateConstruction.cs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs index 130349971..f90a57aff 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs @@ -228,6 +228,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms public TransformDisplayClassUsages(IInstructionWithVariableOperand targetLoad, BlockContainer captureScope, List orphanedVariableInits) { + this.currentFunction = captureScope.Ancestors.OfType().First(); this.targetLoad = targetLoad; this.captureScope = captureScope; this.orphanedVariableInits = orphanedVariableInits; @@ -241,17 +242,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms } } - protected internal override void VisitILFunction(ILFunction function) - { - var old = currentFunction; - currentFunction = function; - try { - base.VisitILFunction(function); - } finally { - currentFunction = old; - } - } - protected internal override void VisitStLoc(StLoc inst) { base.VisitStLoc(inst); From 155b97b32e5d046421ae9bd3458f938e793d1298 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 8 Oct 2017 23:26:36 +0200 Subject: [PATCH 043/190] SwitchOnStringTransform: fix Roslyn transform --- .../IL/Transforms/SwitchOnStringTransform.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 96836b3db..0c8e6ef45 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -417,12 +417,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms var stringValues = new List<(int, string, Block)>(); int index = 0; - Block defaultBlock = null; + ILInstruction defaultBranch = null; foreach (var section in switchInst.Sections) { - if (!section.Body.MatchBranch(out Block target)) + if (!section.Body.MatchBranch(out Block target)) { + if (section.Body is Leave leave) { + defaultBranch = leave; + continue; + } return false; + } if (target.IncomingEdgeCount > 1) { - defaultBlock = target; + defaultBranch = new Branch(target); continue; } if (target.Instructions.Count != 2) @@ -445,8 +450,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms var value = new StringToInt(switchValue.Clone(), stringValues.Select(item => item.Item2).ToArray()); inst = new SwitchInstruction(value); inst.Sections.AddRange(stringValues.Select(section => new SwitchSection { Labels = new Util.LongSet(section.Item1), Body = new Branch(section.Item3) })); - inst.Sections.Add(new SwitchSection { Labels = defaultLabel, Body = new Branch(defaultBlock) }); - + inst.Sections.Add(new SwitchSection { Labels = defaultLabel, Body = defaultBranch }); return true; } From 2021152b7d16a62c307e9e1fd8c4a429773b013a Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Mon, 9 Oct 2017 09:31:40 +0200 Subject: [PATCH 044/190] Replace ILVisitor with foreach OfType --- .../IL/Transforms/ProxyCallReplacer.cs | 157 ++++++++---------- 1 file changed, 68 insertions(+), 89 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs index 8313e82c1..e095aa916 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs @@ -1,116 +1,95 @@ using System.Diagnostics; +using System.Linq; using ICSharpCode.Decompiler.TypeSystem; using Mono.Cecil; namespace ICSharpCode.Decompiler.IL.Transforms { - class ProxyCallReplacer : ILVisitor, IILTransform + class ProxyCallReplacer : IILTransform { ILTransformContext context; public void Run(ILFunction function, ILTransformContext context) { this.context = context; - function.AcceptVisitor(this); - } - - protected override void Default(ILInstruction inst) - { - foreach (var child in inst.Children) { - child.AcceptVisitor(this); - } - } - - protected internal override void VisitCallVirt(CallVirt inst) - { - VisitCally(inst); - } - - protected internal override void VisitCall(Call inst) - { - VisitCally(inst); - } - - protected internal void VisitCally(CallInstruction inst) - { - if (inst.Method.DeclaringTypeDefinition == null) // TODO: investigate why - return; - MethodDefinition methodDef = context.TypeSystem.GetCecil(inst.Method) as MethodDefinition; - if (methodDef != null && methodDef.Body != null) { - if (inst.Method.IsCompilerGeneratedOrIsInCompilerGeneratedClass()) { - // partially copied from CSharpDecompiler - var specializingTypeSystem = this.context.TypeSystem.GetSpecializingTypeSystem(this.context.TypeSystem.Compilation.TypeResolveContext); - var ilReader = new ILReader(specializingTypeSystem); - System.Threading.CancellationToken cancellationToken = new System.Threading.CancellationToken(); - var function = ilReader.ReadIL(methodDef.Body, cancellationToken); - var context = new ILTransformContext(function, specializingTypeSystem, this.context.Settings) { - CancellationToken = cancellationToken - }; - foreach (var transform in CSharp.CSharpDecompiler.GetILTransforms()) { - if (transform.GetType() != typeof(ProxyCallReplacer)) { // don't call itself on itself - cancellationToken.ThrowIfCancellationRequested(); - transform.Run(function, context); + foreach (var inst in function.Descendants.OfType()) { + MethodDefinition methodDef = context.TypeSystem.GetCecil(inst.Method) as MethodDefinition; + if (methodDef != null && methodDef.Body != null) { + if (inst.Method.IsCompilerGeneratedOrIsInCompilerGeneratedClass()) { + // partially copied from CSharpDecompiler + var specializingTypeSystem = this.context.TypeSystem.GetSpecializingTypeSystem(this.context.TypeSystem.Compilation.TypeResolveContext); + var ilReader = new ILReader(specializingTypeSystem); + System.Threading.CancellationToken cancellationToken = new System.Threading.CancellationToken(); + var proxyFunction = ilReader.ReadIL(methodDef.Body, cancellationToken); + var transformContext = new ILTransformContext(proxyFunction, specializingTypeSystem, this.context.Settings) { + CancellationToken = cancellationToken + }; + 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 (function.Children.Count != 1) - return; - var blockContainer = function.Children[0]; - if (blockContainer.OpCode != OpCode.BlockContainer) - return; - if (blockContainer.Children.Count != 1) - return; - var block = blockContainer.Children[0]; - if (block.OpCode != OpCode.Block) - return; - if (block.Children.Count > 2) - return; - if (block.Children.Count == 2 && block.Children[1].OpCode != OpCode.Nop) - return; - var leave = block.Children[0]; - if (leave.OpCode != OpCode.Leave) - return; - if (leave.Children.Count != 1) - return; - Call call = leave.Children[0] as Call; - if (call == null) - 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.OpCode != OpCode.LdLoc || - originalArg.Children.Count != 0 || - ((LdLoc)originalArg).Variable.Kind != VariableKind.Parameter || - ((LdLoc)originalArg).Variable.Index != i - 1) { + if (proxyFunction.Children.Count != 1) + return; + var blockContainer = proxyFunction.Children[0]; + if (blockContainer.OpCode != OpCode.BlockContainer) + return; + if (blockContainer.Children.Count != 1) + return; + var block = blockContainer.Children[0]; + if (block.OpCode != OpCode.Block) + return; + if (block.Children.Count > 2) + return; + if (block.Children.Count == 2 && block.Children[1].OpCode != OpCode.Nop) + return; + var leave = block.Children[0]; + if (leave.OpCode != OpCode.Leave) return; + if (leave.Children.Count != 1) + return; + Call call = leave.Children[0] as Call; + if (call == null) + 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.OpCode != OpCode.LdLoc || + originalArg.Children.Count != 0 || + ((LdLoc)originalArg).Variable.Kind != VariableKind.Parameter || + ((LdLoc)originalArg).Variable.Index != i - 1) { + return; + } } - } - Call newInst = (Call)call.Clone(); + Call newInst = (Call)call.Clone(); - newInst.Arguments.Clear(); + newInst.Arguments.Clear(); - ILInstruction thisArg = inst.Arguments[0]; + ILInstruction thisArg = inst.Arguments[0]; - // special handling for first argument (this) - the underlying issue may be somewhere else - // normally - // leave IL_0000(await(callvirt<> n__0(ldobj xxHandler(ldloca this), ldobj System.Net.Http.HttpRequestMessage(ldloca request), ldobj System.Threading.CancellationToken(ldloca cancellationToken)))) - // would be decompiled to - // return await((DelegatingHandler)this).SendAsync(request, cancellationToken); - // this changes it to - // return await base.SendAsync(request, cancellationToken); - if (thisArg.OpCode == OpCode.LdObj && thisArg.Children.Count > 0 && thisArg.Children[0].OpCode == OpCode.LdLoca) { - thisArg = new LdLoc(((LdLoca)thisArg.Children[0]).Variable); - } + // special handling for first argument (this) - the underlying issue may be somewhere else + // normally + // leave IL_0000(await(callvirt<> n__0(ldobj xxHandler(ldloca this), ldobj System.Net.Http.HttpRequestMessage(ldloca request), ldobj System.Threading.CancellationToken(ldloca cancellationToken)))) + // would be decompiled to + // return await((DelegatingHandler)this).SendAsync(request, cancellationToken); + // this changes it to + // return await base.SendAsync(request, cancellationToken); + if (thisArg.OpCode == OpCode.LdObj && thisArg.Children.Count > 0 && thisArg.Children[0].OpCode == OpCode.LdLoca) { + thisArg = new LdLoc(((LdLoca)thisArg.Children[0]).Variable); + } - newInst.Arguments.Add(thisArg); + newInst.Arguments.Add(thisArg); - // add everything except first argument - for (int i = 1; i < inst.Arguments.Count; i++) { - newInst.Arguments.Add(inst.Arguments[i]); + // add everything except first argument + for (int i = 1; i < inst.Arguments.Count; i++) { + newInst.Arguments.Add(inst.Arguments[i]); + } + inst.ReplaceWith(newInst); } - inst.ReplaceWith(newInst); } } } From a323210346fa09627ac2725388b92e46c6de5b19 Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Mon, 9 Oct 2017 09:53:48 +0200 Subject: [PATCH 045/190] Clean up the check a little bit. --- .../IL/Transforms/ProxyCallReplacer.cs | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs index e095aa916..4e2c0eb68 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs @@ -31,28 +31,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms } } - - if (proxyFunction.Children.Count != 1) - return; - var blockContainer = proxyFunction.Children[0]; - if (blockContainer.OpCode != OpCode.BlockContainer) - return; - if (blockContainer.Children.Count != 1) - return; - var block = blockContainer.Children[0]; - if (block.OpCode != OpCode.Block) - return; - if (block.Children.Count > 2) + if (!(proxyFunction.Body is BlockContainer blockContainer)) return; - if (block.Children.Count == 2 && block.Children[1].OpCode != OpCode.Nop) + if (blockContainer.Blocks.Count != 1) return; - var leave = block.Children[0]; - if (leave.OpCode != OpCode.Leave) + var block = blockContainer.Blocks[0]; + if (block.Instructions.Count != 1) return; - if (leave.Children.Count != 1) + if (!block.Instructions[0].MatchLeave(blockContainer, out ILInstruction returnValue)) return; - Call call = leave.Children[0] as Call; - if (call == null) + if (!(returnValue is Call call)) return; // check if original arguments are only correct ldloc calls for (int i = 0; i < call.Arguments.Count; i++) { From a36cbcc427a1d91a827c3078e0295c59a1f10aeb Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Mon, 9 Oct 2017 10:04:21 +0200 Subject: [PATCH 046/190] Simplify a little bit more --- .../IL/Transforms/ProxyCallReplacer.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs index 4e2c0eb68..f3f7c552f 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs @@ -45,10 +45,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms // 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.OpCode != OpCode.LdLoc || - originalArg.Children.Count != 0 || - ((LdLoc)originalArg).Variable.Kind != VariableKind.Parameter || - ((LdLoc)originalArg).Variable.Index != i - 1) { + if (!originalArg.MatchLdLoc(out ILVariable var) || + var.Kind != VariableKind.Parameter || + var.Index != i - 1) { return; } } @@ -66,8 +65,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms // return await((DelegatingHandler)this).SendAsync(request, cancellationToken); // this changes it to // return await base.SendAsync(request, cancellationToken); - if (thisArg.OpCode == OpCode.LdObj && thisArg.Children.Count > 0 && thisArg.Children[0].OpCode == OpCode.LdLoca) { - thisArg = new LdLoc(((LdLoca)thisArg.Children[0]).Variable); + if (thisArg.MatchLdObj(out ILInstruction loadedObject, out IType objectType) && + loadedObject.MatchLdLoca(out ILVariable loadedVar)) { + thisArg = new LdLoc(loadedVar); } newInst.Arguments.Add(thisArg); From d95d131071bb25f36f1f6e607d6042690bbc075b Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Mon, 9 Oct 2017 10:46:20 +0200 Subject: [PATCH 047/190] Fix void and no-arguments methods --- .../IL/Transforms/ProxyCallReplacer.cs | 57 ++++++++++++------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs index f3f7c552f..b021fb840 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs @@ -36,12 +36,25 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (blockContainer.Blocks.Count != 1) return; var block = blockContainer.Blocks[0]; - if (block.Instructions.Count != 1) - return; - if (!block.Instructions[0].MatchLeave(blockContainer, out ILInstruction returnValue)) - return; - if (!(returnValue is Call call)) + 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; + } + // check if original arguments are only correct ldloc calls for (int i = 0; i < call.Arguments.Count; i++) { var originalArg = call.Arguments[i]; @@ -56,25 +69,27 @@ namespace ICSharpCode.Decompiler.IL.Transforms newInst.Arguments.Clear(); - ILInstruction thisArg = inst.Arguments[0]; + if (inst.Arguments.Count > 0) { + ILInstruction thisArg = inst.Arguments[0]; - // special handling for first argument (this) - the underlying issue may be somewhere else - // normally - // leave IL_0000(await(callvirt<> n__0(ldobj xxHandler(ldloca this), ldobj System.Net.Http.HttpRequestMessage(ldloca request), ldobj System.Threading.CancellationToken(ldloca cancellationToken)))) - // would be decompiled to - // return await((DelegatingHandler)this).SendAsync(request, cancellationToken); - // this changes it to - // return await base.SendAsync(request, cancellationToken); - if (thisArg.MatchLdObj(out ILInstruction loadedObject, out IType objectType) && - loadedObject.MatchLdLoca(out ILVariable loadedVar)) { - thisArg = new LdLoc(loadedVar); - } + // special handling for first argument (this) - the underlying issue may be somewhere else + // normally + // leave IL_0000(await(callvirt<> n__0(ldobj xxHandler(ldloca this), ldobj System.Net.Http.HttpRequestMessage(ldloca request), ldobj System.Threading.CancellationToken(ldloca cancellationToken)))) + // would be decompiled to + // return await((DelegatingHandler)this).SendAsync(request, cancellationToken); + // this changes it to + // return await base.SendAsync(request, cancellationToken); + if (thisArg.MatchLdObj(out ILInstruction loadedObject, out IType objectType) && + loadedObject.MatchLdLoca(out ILVariable loadedVar)) { + thisArg = new LdLoc(loadedVar); + } - newInst.Arguments.Add(thisArg); + newInst.Arguments.Add(thisArg); - // add everything except first argument - for (int i = 1; i < inst.Arguments.Count; i++) { - newInst.Arguments.Add(inst.Arguments[i]); + // add everything except first argument + for (int i = 1; i < inst.Arguments.Count; i++) { + newInst.Arguments.Add(inst.Arguments[i]); + } } inst.ReplaceWith(newInst); } From 33a7e2bf1d6f9450578d35fdcc751d168d25498b Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Mon, 9 Oct 2017 10:51:34 +0200 Subject: [PATCH 048/190] Add more tests. --- .../TestCases/Pretty/FixProxyCalls.cs | 62 ++ .../TestCases/Pretty/FixProxyCalls.il | 823 +++++++++++++++++- .../TestCases/Pretty/FixProxyCalls.opt.il | 683 ++++++++++++++- .../Pretty/FixProxyCalls.opt.roslyn.il | 663 +++++++++++++- .../TestCases/Pretty/FixProxyCalls.roslyn.il | 729 +++++++++++++++- 5 files changed, 2946 insertions(+), 14 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs index 7e9f18456..ae0b87b2d 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs @@ -53,4 +53,66 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty return func(test); } } + + internal class G + { + protected internal virtual void Test(string test) + { + string.Join(test, "fsdf"); + } + } + + internal class H : G + { + protected internal override void Test(string test) + { + Action action = (Action)delegate(string a) { + base.Test(a); + }; + if (test.Equals(1)) { + throw new Exception("roslyn optimize is inlining the assignment which lets the test fail"); + } + action(test); + } + } + + internal class I + { + protected internal virtual void Test(int a) + { + + } + } + + internal class J : I + { + protected internal override void Test(int a) + { + Action action = (Action)delegate() { + base.Test(a); + }; + if (a.Equals(1)) { + throw new Exception("roslyn optimize is inlining the assignment which lets the test fail"); + } + action(); + + } + } + + internal class K + { + protected internal virtual IEnumerable Test(int p) + { + yield return p + 1; + yield return p + 2; + } + } + + internal class L : K + { + protected internal override IEnumerable Test(int p) + { + yield return base.Test(base.Test(0).GetEnumerator().Current).GetEnumerator().Current; + } + } } \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il index e2db82f72..69f149030 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.il @@ -10,25 +10,25 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly '3zqosgit' +.assembly kjibydgt { - .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .permissionset reqmin = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module '3zqosgit.dll' -// MVID: {6F515237-D053-4A08-B075-52009B7D06CA} +.module kjibydgt.dll +// MVID: {7F7E319E-D28C-421B-B3A6-A5F71C1BC3A5} .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: 0x01410000 +// Image base: 0x02700000 // =============== CLASS MEMBERS DECLARATION =================== @@ -759,6 +759,819 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance void Test(string test) cil managed + { + // Code size 25 (0x19) + .maxstack 4 + .locals init (string[] V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldc.i4.1 + IL_0003: newarr [mscorlib]System.String + IL_0008: stloc.0 + IL_0009: ldloc.0 + IL_000a: ldc.i4.0 + IL_000b: ldstr "fsdf" + IL_0010: stelem.ref + IL_0011: ldloc.0 + IL_0012: call string [mscorlib]System.String::Join(string, + string[]) + IL_0017: pop + IL_0018: ret + } // end of method G::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method G::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G +{ + .method famorassem hidebysig virtual instance void + Test(string test) cil managed + { + // Code size 54 (0x36) + .maxstack 2 + .locals init (class [mscorlib]System.Action`1 V_0, + bool V_1) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H::'b__0'(string) + IL_0008: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: ldarg.1 + IL_000f: ldc.i4.1 + IL_0010: box [mscorlib]System.Int32 + IL_0015: callvirt instance bool [mscorlib]System.Object::Equals(object) + IL_001a: ldc.i4.0 + IL_001b: ceq + IL_001d: stloc.1 + IL_001e: ldloc.1 + IL_001f: brtrue.s IL_002d + + IL_0021: nop + IL_0022: ldstr "roslyn optimize is inlining the assignment which l" + + "ets the test fail" + IL_0027: newobj instance void [mscorlib]System.Exception::.ctor(string) + IL_002c: throw + + IL_002d: ldloc.0 + IL_002e: ldarg.1 + IL_002f: callvirt instance void class [mscorlib]System.Action`1::Invoke(!0) + IL_0034: nop + IL_0035: ret + } // end of method H::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.G::.ctor() + IL_0006: ret + } // end of method H::.ctor + + .method private hidebysig instance void + '<>n__FabricatedMethod1'(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 void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G::Test(string) + IL_0007: ret + } // end of method H::'<>n__FabricatedMethod1' + + .method private hidebysig instance void + 'b__0'(string a) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 10 (0xa) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: call instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H::'<>n__FabricatedMethod1'(string) + IL_0008: nop + IL_0009: ret + } // end of method H::'b__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance void Test(int32 a) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method I::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method I::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J '<>4__this' + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1'::.ctor + + .method public hidebysig instance void + 'b__0'() cil managed + { + // Code size 20 (0x14) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::'<>4__this' + IL_0007: ldarg.0 + IL_0008: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::a + IL_000d: call instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J::'<>n__FabricatedMethod3'(int32) + IL_0012: nop + IL_0013: ret + } // end of method '<>c__DisplayClass1'::'b__0' + + } // end of class '<>c__DisplayClass1' + + .method famorassem hidebysig virtual instance void + Test(int32 a) cil managed + { + // Code size 74 (0x4a) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0, + class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1' V_1, + bool V_2) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::.ctor() + IL_0005: stloc.1 + IL_0006: ldloc.1 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::a + IL_000d: ldloc.1 + IL_000e: ldarg.0 + IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::'<>4__this' + IL_0014: nop + IL_0015: ldloc.1 + IL_0016: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::'b__0'() + IL_001c: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0021: stloc.0 + IL_0022: ldloc.1 + IL_0023: ldflda int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::a + IL_0028: ldc.i4.1 + IL_0029: call instance bool [mscorlib]System.Int32::Equals(int32) + IL_002e: ldc.i4.0 + IL_002f: ceq + IL_0031: stloc.2 + IL_0032: ldloc.2 + IL_0033: brtrue.s IL_0041 + + IL_0035: nop + IL_0036: ldstr "roslyn optimize is inlining the assignment which l" + + "ets the test fail" + IL_003b: newobj instance void [mscorlib]System.Exception::.ctor(string) + IL_0040: throw + + IL_0041: ldloc.0 + IL_0042: callvirt instance void [mscorlib]System.Action::Invoke() + IL_0047: nop + IL_0048: nop + IL_0049: ret + } // end of method J::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.I::.ctor() + IL_0006: ret + } // end of method J::.ctor + + .method private hidebysig instance void + '<>n__FabricatedMethod3'(int32 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 void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I::Test(int32) + IL_0007: ret + } // end of method J::'<>n__FabricatedMethod3' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.Collections.IEnumerator, + [mscorlib]System.IDisposable + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private int32 '<>2__current' + .field private int32 '<>1__state' + .field private int32 '<>l__initialThreadId' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K '<>4__this' + .field public int32 p + .field public int32 '<>3__p' + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 82 (0x52) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0' V_0, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, + bool V_2) + IL_0000: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0005: ldarg.0 + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>l__initialThreadId' + IL_000b: bne.un.s IL_001c + + IL_000d: ldarg.0 + IL_000e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0013: ldc.i4.s -2 + IL_0015: ceq + IL_0017: ldc.i4.0 + IL_0018: ceq + IL_001a: br.s IL_001d + + IL_001c: ldc.i4.1 + IL_001d: nop + IL_001e: stloc.2 + IL_001f: ldloc.2 + IL_0020: brtrue.s IL_002d + + IL_0022: ldarg.0 + IL_0023: ldc.i4.0 + IL_0024: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0029: ldarg.0 + IL_002a: stloc.0 + IL_002b: br.s IL_0040 + + IL_002d: ldc.i4.0 + IL_002e: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::.ctor(int32) + IL_0033: stloc.0 + IL_0034: ldloc.0 + IL_0035: ldarg.0 + IL_0036: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>4__this' + IL_003b: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>4__this' + IL_0040: ldloc.0 + IL_0041: ldarg.0 + IL_0042: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>3__p' + IL_0047: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::p + IL_004c: ldloc.0 + IL_004d: stloc.1 + IL_004e: br.s IL_0050 + + IL_0050: ldloc.1 + IL_0051: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 11 (0xb) + .maxstack 1 + .locals init (class [mscorlib]System.Collections.IEnumerator V_0) + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 114 (0x72) + .maxstack 3 + .locals init (bool V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0006: stloc.1 + IL_0007: ldloc.1 + IL_0008: switch ( + IL_001f, + IL_001b, + IL_001d) + IL_0019: br.s IL_0021 + + IL_001b: br.s IL_0044 + + IL_001d: br.s IL_0064 + + IL_001f: br.s IL_0023 + + IL_0021: br.s IL_006c + + IL_0023: ldarg.0 + IL_0024: ldc.i4.m1 + IL_0025: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_002a: nop + IL_002b: ldarg.0 + IL_002c: ldarg.0 + IL_002d: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::p + IL_0032: ldc.i4.1 + IL_0033: add + IL_0034: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0039: ldarg.0 + IL_003a: ldc.i4.1 + IL_003b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0040: ldc.i4.1 + IL_0041: stloc.0 + IL_0042: br.s IL_0070 + + IL_0044: ldarg.0 + IL_0045: ldc.i4.m1 + IL_0046: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_004b: ldarg.0 + IL_004c: ldarg.0 + IL_004d: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::p + IL_0052: ldc.i4.2 + IL_0053: add + IL_0054: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0059: ldarg.0 + IL_005a: ldc.i4.2 + IL_005b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0060: ldc.i4.1 + IL_0061: stloc.0 + IL_0062: br.s IL_0070 + + IL_0064: ldarg.0 + IL_0065: ldc.i4.m1 + IL_0066: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_006b: nop + IL_006c: ldc.i4.0 + IL_006d: stloc.0 + IL_006e: br.s IL_0070 + + IL_0070: ldloc.0 + IL_0071: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance int32 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 11 (0xb) + .maxstack 1 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .override [mscorlib]System.IDisposable::Dispose + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 16 (0x10) + .maxstack 1 + .locals init (object V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0006: box [mscorlib]System.Int32 + IL_000b: stloc.0 + IL_000c: br.s IL_000e + + IL_000e: ldloc.0 + IL_000f: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 25 (0x19) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_000d: ldarg.0 + IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>l__initialThreadId' + IL_0018: ret + } // end of method 'd__0'::.ctor + + .property instance int32 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig newslot virtual + instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test(int32 p) cil managed + { + // Code size 28 (0x1c) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0' V_0, + class [mscorlib]System.Collections.Generic.IEnumerable`1 V_1) + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::.ctor(int32) + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldarg.0 + IL_000a: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>4__this' + IL_000f: ldloc.0 + IL_0010: ldarg.1 + IL_0011: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>3__p' + IL_0016: ldloc.0 + IL_0017: stloc.1 + IL_0018: br.s IL_001a + + IL_001a: ldloc.1 + IL_001b: ret + } // end of method K::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method K::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.Collections.IEnumerator, + [mscorlib]System.IDisposable + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private int32 '<>2__current' + .field private int32 '<>1__state' + .field private int32 '<>l__initialThreadId' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L '<>4__this' + .field public int32 p + .field public int32 '<>3__p' + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 82 (0x52) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0' V_0, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, + bool V_2) + IL_0000: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0005: ldarg.0 + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>l__initialThreadId' + IL_000b: bne.un.s IL_001c + + IL_000d: ldarg.0 + IL_000e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0013: ldc.i4.s -2 + IL_0015: ceq + IL_0017: ldc.i4.0 + IL_0018: ceq + IL_001a: br.s IL_001d + + IL_001c: ldc.i4.1 + IL_001d: nop + IL_001e: stloc.2 + IL_001f: ldloc.2 + IL_0020: brtrue.s IL_002d + + IL_0022: ldarg.0 + IL_0023: ldc.i4.0 + IL_0024: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0029: ldarg.0 + IL_002a: stloc.0 + IL_002b: br.s IL_0040 + + IL_002d: ldc.i4.0 + IL_002e: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::.ctor(int32) + IL_0033: stloc.0 + IL_0034: ldloc.0 + IL_0035: ldarg.0 + IL_0036: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_003b: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_0040: ldloc.0 + IL_0041: ldarg.0 + IL_0042: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>3__p' + IL_0047: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::p + IL_004c: ldloc.0 + IL_004d: stloc.1 + IL_004e: br.s IL_0050 + + IL_0050: ldloc.1 + IL_0051: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 11 (0xb) + .maxstack 1 + .locals init (class [mscorlib]System.Collections.IEnumerator V_0) + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 111 (0x6f) + .maxstack 4 + .locals init (bool V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0006: stloc.1 + IL_0007: ldloc.1 + IL_0008: switch ( + IL_0019, + IL_0017) + IL_0015: br.s IL_001b + + IL_0017: br.s IL_0061 + + IL_0019: br.s IL_001d + + IL_001b: br.s IL_0069 + + IL_001d: ldarg.0 + IL_001e: ldc.i4.m1 + IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0024: nop + IL_0025: ldarg.0 + IL_0026: ldarg.0 + IL_0027: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_002c: ldarg.0 + IL_002d: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_0032: ldc.i4.0 + IL_0033: call instance class [mscorlib]System.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L::'<>n__FabricatedMethod1'(int32) + IL_0038: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_003d: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0042: call instance class [mscorlib]System.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L::'<>n__FabricatedMethod1'(int32) + IL_0047: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_004c: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0051: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>2__current' + IL_0056: ldarg.0 + IL_0057: ldc.i4.1 + IL_0058: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_005d: ldc.i4.1 + IL_005e: stloc.0 + IL_005f: br.s IL_006d + + IL_0061: ldarg.0 + IL_0062: ldc.i4.m1 + IL_0063: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0068: nop + IL_0069: ldc.i4.0 + IL_006a: stloc.0 + IL_006b: br.s IL_006d + + IL_006d: ldloc.0 + IL_006e: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance int32 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 11 (0xb) + .maxstack 1 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>2__current' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .override [mscorlib]System.IDisposable::Dispose + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 16 (0x10) + .maxstack 1 + .locals init (object V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>2__current' + IL_0006: box [mscorlib]System.Int32 + IL_000b: stloc.0 + IL_000c: br.s IL_000e + + IL_000e: ldloc.0 + IL_000f: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 25 (0x19) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_000d: ldarg.0 + IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>l__initialThreadId' + IL_0018: ret + } // end of method 'd__0'::.ctor + + .property instance int32 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig virtual instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test(int32 p) cil managed + { + // Code size 28 (0x1c) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0' V_0, + class [mscorlib]System.Collections.Generic.IEnumerable`1 V_1) + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::.ctor(int32) + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldarg.0 + IL_000a: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_000f: ldloc.0 + IL_0010: ldarg.1 + IL_0011: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>3__p' + IL_0016: ldloc.0 + IL_0017: stloc.1 + IL_0018: br.s IL_001a + + IL_001a: ldloc.1 + IL_001b: ret + } // end of method L::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.K::.ctor() + IL_0006: ret + } // end of method L::.ctor + + .method private hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + '<>n__FabricatedMethod1'(int32 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.Collections.Generic.IEnumerable`1 V_0) + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call instance class [mscorlib]System.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K::Test(int32) + IL_0007: stloc.0 + IL_0008: br.s IL_000a + + IL_000a: ldloc.0 + IL_000b: ret + } // end of method L::'<>n__FabricatedMethod1' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L + // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il index e0ded2980..b26753120 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.il @@ -10,25 +10,25 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly jub0alhf +.assembly b0rqcnnq { - .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .permissionset reqmin = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module jub0alhf.dll -// MVID: {B209562F-4B42-47D5-8725-45EAB5E79932} +.module b0rqcnnq.dll +// MVID: {D8989CD1-06F3-4E8C-8C4C-7F7B95ACB488} .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: 0x004E0000 +// Image base: 0x00810000 // =============== CLASS MEMBERS DECLARATION =================== @@ -643,6 +643,679 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance void Test(string test) cil managed + { + // Code size 24 (0x18) + .maxstack 4 + .locals init (string[] V_0) + IL_0000: ldarg.1 + IL_0001: ldc.i4.1 + IL_0002: newarr [mscorlib]System.String + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldc.i4.0 + IL_000a: ldstr "fsdf" + IL_000f: stelem.ref + IL_0010: ldloc.0 + IL_0011: call string [mscorlib]System.String::Join(string, + string[]) + IL_0016: pop + IL_0017: ret + } // end of method G::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method G::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G +{ + .method famorassem hidebysig virtual instance void + Test(string test) cil managed + { + // Code size 46 (0x2e) + .maxstack 2 + .locals init (class [mscorlib]System.Action`1 V_0) + IL_0000: ldarg.0 + IL_0001: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H::'b__0'(string) + IL_0007: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000c: stloc.0 + IL_000d: ldarg.1 + IL_000e: ldc.i4.1 + IL_000f: box [mscorlib]System.Int32 + IL_0014: callvirt instance bool [mscorlib]System.Object::Equals(object) + IL_0019: brfalse.s IL_0026 + + IL_001b: ldstr "roslyn optimize is inlining the assignment which l" + + "ets the test fail" + IL_0020: newobj instance void [mscorlib]System.Exception::.ctor(string) + IL_0025: throw + + IL_0026: ldloc.0 + IL_0027: ldarg.1 + IL_0028: callvirt instance void class [mscorlib]System.Action`1::Invoke(!0) + IL_002d: ret + } // end of method H::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.G::.ctor() + IL_0006: ret + } // end of method H::.ctor + + .method private hidebysig instance void + '<>n__FabricatedMethod1'(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 void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G::Test(string) + IL_0007: ret + } // end of method H::'<>n__FabricatedMethod1' + + .method private hidebysig instance void + 'b__0'(string a) 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 void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H::'<>n__FabricatedMethod1'(string) + IL_0007: ret + } // end of method H::'b__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance void Test(int32 a) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method I::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method I::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J '<>4__this' + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1'::.ctor + + .method public hidebysig instance void + 'b__0'() cil managed + { + // Code size 18 (0x12) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::'<>4__this' + IL_0006: ldarg.0 + IL_0007: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::a + IL_000c: call instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J::'<>n__FabricatedMethod3'(int32) + IL_0011: ret + } // end of method '<>c__DisplayClass1'::'b__0' + + } // end of class '<>c__DisplayClass1' + + .method famorassem hidebysig virtual instance void + Test(int32 a) cil managed + { + // Code size 65 (0x41) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0, + class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1' V_1) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::.ctor() + IL_0005: stloc.1 + IL_0006: ldloc.1 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::a + IL_000d: ldloc.1 + IL_000e: ldarg.0 + IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::'<>4__this' + IL_0014: ldloc.1 + IL_0015: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::'b__0'() + IL_001b: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0020: stloc.0 + IL_0021: ldloc.1 + IL_0022: ldflda int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass1'::a + IL_0027: ldc.i4.1 + IL_0028: call instance bool [mscorlib]System.Int32::Equals(int32) + IL_002d: brfalse.s IL_003a + + IL_002f: ldstr "roslyn optimize is inlining the assignment which l" + + "ets the test fail" + IL_0034: newobj instance void [mscorlib]System.Exception::.ctor(string) + IL_0039: throw + + IL_003a: ldloc.0 + IL_003b: callvirt instance void [mscorlib]System.Action::Invoke() + IL_0040: ret + } // end of method J::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.I::.ctor() + IL_0006: ret + } // end of method J::.ctor + + .method private hidebysig instance void + '<>n__FabricatedMethod3'(int32 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 void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I::Test(int32) + IL_0007: ret + } // end of method J::'<>n__FabricatedMethod3' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.Collections.IEnumerator, + [mscorlib]System.IDisposable + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private int32 '<>2__current' + .field private int32 '<>1__state' + .field private int32 '<>l__initialThreadId' + .field public int32 p + .field public int32 '<>3__p' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K '<>4__this' + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 67 (0x43) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0' V_0) + IL_0000: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0005: ldarg.0 + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>l__initialThreadId' + IL_000b: bne.un.s IL_0022 + + IL_000d: ldarg.0 + IL_000e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0013: ldc.i4.s -2 + IL_0015: bne.un.s IL_0022 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.0 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: stloc.0 + IL_0020: br.s IL_0035 + + IL_0022: ldc.i4.0 + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::.ctor(int32) + IL_0028: stloc.0 + IL_0029: ldloc.0 + IL_002a: ldarg.0 + IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>4__this' + IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>4__this' + IL_0035: ldloc.0 + IL_0036: ldarg.0 + IL_0037: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>3__p' + IL_003c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::p + IL_0041: ldloc.0 + IL_0042: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 96 (0x60) + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: switch ( + IL_001b, + IL_0039, + IL_0057) + IL_0019: br.s IL_005e + + IL_001b: ldarg.0 + IL_001c: ldc.i4.m1 + IL_001d: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0022: ldarg.0 + IL_0023: ldarg.0 + IL_0024: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::p + IL_0029: ldc.i4.1 + IL_002a: add + IL_002b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0030: ldarg.0 + IL_0031: ldc.i4.1 + IL_0032: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0037: ldc.i4.1 + IL_0038: ret + + IL_0039: ldarg.0 + IL_003a: ldc.i4.m1 + IL_003b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0040: ldarg.0 + IL_0041: ldarg.0 + IL_0042: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::p + IL_0047: ldc.i4.2 + IL_0048: add + IL_0049: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_004e: ldarg.0 + IL_004f: ldc.i4.2 + IL_0050: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0055: ldc.i4.1 + IL_0056: ret + + IL_0057: ldarg.0 + IL_0058: ldc.i4.m1 + IL_0059: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_005e: ldc.i4.0 + IL_005f: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance int32 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .override [mscorlib]System.IDisposable::Dispose + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0006: box [mscorlib]System.Int32 + IL_000b: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 25 (0x19) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_000d: ldarg.0 + IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>l__initialThreadId' + IL_0018: ret + } // end of method 'd__0'::.ctor + + .property instance int32 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig newslot virtual + instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test(int32 p) cil managed + { + // Code size 24 (0x18) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0' V_0) + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::.ctor(int32) + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldarg.0 + IL_000a: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>4__this' + IL_000f: ldloc.0 + IL_0010: ldarg.1 + IL_0011: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>3__p' + IL_0016: ldloc.0 + IL_0017: ret + } // end of method K::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method K::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.Collections.IEnumerator, + [mscorlib]System.IDisposable + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private int32 '<>2__current' + .field private int32 '<>1__state' + .field private int32 '<>l__initialThreadId' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L '<>4__this' + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 55 (0x37) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0' V_0) + IL_0000: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0005: ldarg.0 + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>l__initialThreadId' + IL_000b: bne.un.s IL_0022 + + IL_000d: ldarg.0 + IL_000e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0013: ldc.i4.s -2 + IL_0015: bne.un.s IL_0022 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.0 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: stloc.0 + IL_0020: br.s IL_0035 + + IL_0022: ldc.i4.0 + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::.ctor(int32) + IL_0028: stloc.0 + IL_0029: ldloc.0 + IL_002a: ldarg.0 + IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_0035: ldloc.0 + IL_0036: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 97 (0x61) + .maxstack 4 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: switch ( + IL_0017, + IL_0058) + IL_0015: br.s IL_005f + + IL_0017: ldarg.0 + IL_0018: ldc.i4.m1 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: ldarg.0 + IL_0020: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_0025: ldarg.0 + IL_0026: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_002b: ldc.i4.0 + IL_002c: call instance class [mscorlib]System.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L::'<>n__FabricatedMethod1'(int32) + IL_0031: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0036: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_003b: call instance class [mscorlib]System.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L::'<>n__FabricatedMethod1'(int32) + IL_0040: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0045: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_004a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>2__current' + IL_004f: ldarg.0 + IL_0050: ldc.i4.1 + IL_0051: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0056: ldc.i4.1 + IL_0057: ret + + IL_0058: ldarg.0 + IL_0059: ldc.i4.m1 + IL_005a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_005f: ldc.i4.0 + IL_0060: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance int32 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .override [mscorlib]System.IDisposable::Dispose + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>2__current' + IL_0006: box [mscorlib]System.Int32 + IL_000b: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 25 (0x19) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_000d: ldarg.0 + IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>l__initialThreadId' + IL_0018: ret + } // end of method 'd__0'::.ctor + + .property instance int32 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig virtual instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test(int32 p) cil managed + { + // Code size 17 (0x11) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0' V_0) + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::.ctor(int32) + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldarg.0 + IL_000a: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_000f: ldloc.0 + IL_0010: ret + } // end of method L::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.K::.ctor() + IL_0006: ret + } // end of method L::.ctor + + .method private hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + '<>n__FabricatedMethod1'(int32 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.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K::Test(int32) + IL_0007: ret + } // end of method L::'<>n__FabricatedMethod1' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L + // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il index d2c17f01b..d4c7d8f22 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module FixProxyCalls.dll -// MVID: {4ED058B3-70DA-4FB5-B699-61DBE42057C4} +// MVID: {68453617-6425-4063-8DF9-B48E31C1B6A2} .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: 0x009D0000 +// Image base: 0x00D00000 // =============== CLASS MEMBERS DECLARATION =================== @@ -629,6 +629,665 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance void Test(string test) cil managed + { + // Code size 22 (0x16) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldc.i4.1 + IL_0002: newarr [mscorlib]System.String + IL_0007: dup + IL_0008: ldc.i4.0 + IL_0009: ldstr "fsdf" + IL_000e: stelem.ref + IL_000f: call string [mscorlib]System.String::Join(string, + string[]) + IL_0014: pop + IL_0015: ret + } // end of method G::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method G::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G +{ + .method famorassem hidebysig virtual instance void + Test(string test) cil managed + { + // Code size 44 (0x2c) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H::'b__0_0'(string) + IL_0007: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000c: ldarg.1 + IL_000d: ldc.i4.1 + IL_000e: box [mscorlib]System.Int32 + IL_0013: callvirt instance bool [mscorlib]System.Object::Equals(object) + IL_0018: brfalse.s IL_0025 + + IL_001a: ldstr "roslyn optimize is inlining the assignment which l" + + "ets the test fail" + IL_001f: newobj instance void [mscorlib]System.Exception::.ctor(string) + IL_0024: throw + + IL_0025: ldarg.1 + IL_0026: callvirt instance void class [mscorlib]System.Action`1::Invoke(!0) + IL_002b: ret + } // end of method H::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.G::.ctor() + IL_0006: ret + } // end of method H::.ctor + + .method private hidebysig instance void + 'b__0_0'(string a) 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 void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G::Test(string) + IL_0007: ret + } // end of method H::'b__0_0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance void Test(int32 a) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method I::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method I::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass0_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 a + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J '<>4__this' + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass0_0'::.ctor + + .method assembly hidebysig instance void + 'b__0'() cil managed + { + // Code size 18 (0x12) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::'<>4__this' + IL_0006: ldarg.0 + IL_0007: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::a + IL_000c: call instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J::'<>n__0'(int32) + IL_0011: ret + } // end of method '<>c__DisplayClass0_0'::'b__0' + + } // end of class '<>c__DisplayClass0_0' + + .method famorassem hidebysig virtual instance void + Test(int32 a) cil managed + { + // Code size 63 (0x3f) + .maxstack 3 + .locals init (class [mscorlib]System.Action V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::.ctor() + IL_0005: dup + IL_0006: ldarg.0 + IL_0007: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::'<>4__this' + IL_000c: dup + IL_000d: ldarg.1 + IL_000e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::a + IL_0013: dup + IL_0014: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::'b__0'() + IL_001a: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_001f: stloc.0 + IL_0020: ldflda int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::a + IL_0025: ldc.i4.1 + IL_0026: call instance bool [mscorlib]System.Int32::Equals(int32) + IL_002b: brfalse.s IL_0038 + + IL_002d: ldstr "roslyn optimize is inlining the assignment which l" + + "ets the test fail" + IL_0032: newobj instance void [mscorlib]System.Exception::.ctor(string) + IL_0037: throw + + IL_0038: ldloc.0 + IL_0039: callvirt instance void [mscorlib]System.Action::Invoke() + IL_003e: ret + } // end of method J::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.I::.ctor() + IL_0006: ret + } // end of method J::.ctor + + .method private hidebysig instance void + '<>n__0'(int32 a) 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 void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I::Test(int32) + IL_0007: ret + } // end of method J::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.IDisposable, + [mscorlib]System.Collections.IEnumerator + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private int32 '<>1__state' + .field private int32 '<>2__current' + .field private int32 '<>l__initialThreadId' + .field private int32 p + .field public int32 '<>3__p' + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 25 (0x19) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_000d: ldarg.0 + IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>l__initialThreadId' + IL_0018: ret + } // end of method 'd__0'::.ctor + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.IDisposable::Dispose + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 96 (0x60) + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: switch ( + IL_001b, + IL_0039, + IL_0057) + IL_0019: ldc.i4.0 + IL_001a: ret + + IL_001b: ldarg.0 + IL_001c: ldc.i4.m1 + IL_001d: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0022: ldarg.0 + IL_0023: ldarg.0 + IL_0024: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::p + IL_0029: ldc.i4.1 + IL_002a: add + IL_002b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0030: ldarg.0 + IL_0031: ldc.i4.1 + IL_0032: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0037: ldc.i4.1 + IL_0038: ret + + IL_0039: ldarg.0 + IL_003a: ldc.i4.m1 + IL_003b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0040: ldarg.0 + IL_0041: ldarg.0 + IL_0042: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::p + IL_0047: ldc.i4.2 + IL_0048: add + IL_0049: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_004e: ldarg.0 + IL_004f: ldc.i4.2 + IL_0050: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0055: ldc.i4.1 + IL_0056: ret + + IL_0057: ldarg.0 + IL_0058: ldc.i4.m1 + IL_0059: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_005e: ldc.i4.0 + IL_005f: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance int32 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0006: box [mscorlib]System.Int32 + IL_000b: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 55 (0x37) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0' V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0006: ldc.i4.s -2 + IL_0008: bne.un.s IL_0022 + + IL_000a: ldarg.0 + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>l__initialThreadId' + IL_0010: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0015: bne.un.s IL_0022 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.0 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: stloc.0 + IL_0020: br.s IL_0029 + + IL_0022: ldc.i4.0 + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::.ctor(int32) + IL_0028: stloc.0 + IL_0029: ldloc.0 + IL_002a: ldarg.0 + IL_002b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>3__p' + IL_0030: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::p + IL_0035: ldloc.0 + IL_0036: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .property instance int32 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig newslot virtual + instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test(int32 p) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.IteratorStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 3C 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..d__0. + 00 ) + // Code size 15 (0xf) + .maxstack 8 + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::.ctor(int32) + IL_0007: dup + IL_0008: ldarg.1 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>3__p' + IL_000e: ret + } // end of method K::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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method K::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.IDisposable, + [mscorlib]System.Collections.IEnumerator + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private int32 '<>1__state' + .field private int32 '<>2__current' + .field private int32 '<>l__initialThreadId' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L '<>4__this' + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 25 (0x19) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_000d: ldarg.0 + IL_000e: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>l__initialThreadId' + IL_0018: ret + } // end of method 'd__0'::.ctor + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.IDisposable::Dispose + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 87 (0x57) + .maxstack 4 + .locals init (int32 V_0, + class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L V_1) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldarg.0 + IL_0008: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_000d: stloc.1 + IL_000e: ldloc.0 + IL_000f: brfalse.s IL_0017 + + IL_0011: ldloc.0 + IL_0012: ldc.i4.1 + IL_0013: beq.s IL_004e + + IL_0015: ldc.i4.0 + IL_0016: ret + + IL_0017: ldarg.0 + IL_0018: ldc.i4.m1 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: ldloc.1 + IL_0020: ldloc.1 + IL_0021: ldc.i4.0 + IL_0022: call instance class [mscorlib]System.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L::'<>n__0'(int32) + IL_0027: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_002c: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0031: call instance class [mscorlib]System.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L::'<>n__0'(int32) + IL_0036: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_003b: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0040: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>2__current' + IL_0045: ldarg.0 + IL_0046: ldc.i4.1 + IL_0047: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_004c: ldc.i4.1 + IL_004d: ret + + IL_004e: ldarg.0 + IL_004f: ldc.i4.m1 + IL_0050: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0055: ldc.i4.0 + IL_0056: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance int32 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>2__current' + IL_0006: box [mscorlib]System.Int32 + IL_000b: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 55 (0x37) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0' V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0006: ldc.i4.s -2 + IL_0008: bne.un.s IL_0022 + + IL_000a: ldarg.0 + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>l__initialThreadId' + IL_0010: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0015: bne.un.s IL_0022 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.0 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: stloc.0 + IL_0020: br.s IL_0035 + + IL_0022: ldc.i4.0 + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::.ctor(int32) + IL_0028: stloc.0 + IL_0029: ldloc.0 + IL_002a: ldarg.0 + IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_0035: ldloc.0 + IL_0036: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .property instance int32 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig virtual instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test(int32 p) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.IteratorStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 3C 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..d__0. + 00 ) + // Code size 15 (0xf) + .maxstack 8 + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::.ctor(int32) + IL_0007: dup + IL_0008: ldarg.0 + IL_0009: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_000e: ret + } // end of method L::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.K::.ctor() + IL_0006: ret + } // end of method L::.ctor + + .method private hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + '<>n__0'(int32 p) 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.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K::Test(int32) + IL_0007: ret + } // end of method L::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L + // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il index df84e9a1f..a902d0a07 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module FixProxyCalls.dll -// MVID: {7BB86323-1120-4703-BABC-BC12F69CE2C1} +// MVID: {337B20CD-03F0-410E-9868-F4B4F95C9AEF} .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: 0x00E50000 +// Image base: 0x00DC0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -693,6 +693,731 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.F +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance void Test(string test) cil managed + { + // Code size 23 (0x17) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldc.i4.1 + IL_0003: newarr [mscorlib]System.String + IL_0008: dup + IL_0009: ldc.i4.0 + IL_000a: ldstr "fsdf" + IL_000f: stelem.ref + IL_0010: call string [mscorlib]System.String::Join(string, + string[]) + IL_0015: pop + IL_0016: ret + } // end of method G::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 [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method G::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G +{ + .method famorassem hidebysig virtual instance void + Test(string test) cil managed + { + // Code size 51 (0x33) + .maxstack 2 + .locals init (class [mscorlib]System.Action`1 V_0, + bool V_1) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H::'b__0_0'(string) + IL_0008: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: ldarg.1 + IL_000f: ldc.i4.1 + IL_0010: box [mscorlib]System.Int32 + IL_0015: callvirt instance bool [mscorlib]System.Object::Equals(object) + IL_001a: stloc.1 + IL_001b: ldloc.1 + IL_001c: brfalse.s IL_002a + + IL_001e: nop + IL_001f: ldstr "roslyn optimize is inlining the assignment which l" + + "ets the test fail" + IL_0024: newobj instance void [mscorlib]System.Exception::.ctor(string) + IL_0029: throw + + IL_002a: ldloc.0 + IL_002b: ldarg.1 + IL_002c: callvirt instance void class [mscorlib]System.Action`1::Invoke(!0) + IL_0031: nop + IL_0032: ret + } // end of method H::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.G::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method H::.ctor + + .method private hidebysig instance void + 'b__0_0'(string a) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 10 (0xa) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: call instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.G::Test(string) + IL_0008: nop + IL_0009: ret + } // end of method H::'b__0_0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.H + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I + extends [mscorlib]System.Object +{ + .method famorassem hidebysig newslot virtual + instance void Test(int32 a) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method I::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 [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method I::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I +{ + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass0_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 a + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J '<>4__this' + .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 '<>c__DisplayClass0_0'::.ctor + + .method assembly hidebysig instance void + 'b__0'() cil managed + { + // Code size 20 (0x14) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::'<>4__this' + IL_0007: ldarg.0 + IL_0008: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::a + IL_000d: call instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J::'<>n__0'(int32) + IL_0012: nop + IL_0013: ret + } // end of method '<>c__DisplayClass0_0'::'b__0' + + } // end of class '<>c__DisplayClass0_0' + + .method famorassem hidebysig virtual instance void + Test(int32 a) cil managed + { + // Code size 70 (0x46) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0' V_0, + class [mscorlib]System.Action V_1, + bool V_2) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::'<>4__this' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::a + IL_0014: nop + IL_0015: ldloc.0 + IL_0016: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::'b__0'() + IL_001c: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0021: stloc.1 + IL_0022: ldloc.0 + IL_0023: ldflda int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J/'<>c__DisplayClass0_0'::a + IL_0028: ldc.i4.1 + IL_0029: call instance bool [mscorlib]System.Int32::Equals(int32) + IL_002e: stloc.2 + IL_002f: ldloc.2 + IL_0030: brfalse.s IL_003e + + IL_0032: nop + IL_0033: ldstr "roslyn optimize is inlining the assignment which l" + + "ets the test fail" + IL_0038: newobj instance void [mscorlib]System.Exception::.ctor(string) + IL_003d: throw + + IL_003e: ldloc.1 + IL_003f: callvirt instance void [mscorlib]System.Action::Invoke() + IL_0044: nop + IL_0045: ret + } // end of method J::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.I::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method J::.ctor + + .method private hidebysig instance void + '<>n__0'(int32 a) 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 void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.I::Test(int32) + IL_0007: ret + } // end of method J::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.J + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.IDisposable, + [mscorlib]System.Collections.IEnumerator + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private int32 '<>1__state' + .field private int32 '<>2__current' + .field private int32 '<>l__initialThreadId' + .field private int32 p + .field public int32 '<>3__p' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K '<>4__this' + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 26 (0x1a) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ldarg.0 + IL_0008: ldarg.1 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_000e: ldarg.0 + IL_000f: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>l__initialThreadId' + IL_0019: ret + } // end of method 'd__0'::.ctor + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.IDisposable::Dispose + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 105 (0x69) + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: switch ( + IL_001b, + IL_001d, + IL_001f) + IL_0019: br.s IL_0021 + + IL_001b: br.s IL_0023 + + IL_001d: br.s IL_0042 + + IL_001f: br.s IL_0060 + + IL_0021: ldc.i4.0 + IL_0022: ret + + IL_0023: ldarg.0 + IL_0024: ldc.i4.m1 + IL_0025: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_002a: nop + IL_002b: ldarg.0 + IL_002c: ldarg.0 + IL_002d: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::p + IL_0032: ldc.i4.1 + IL_0033: add + IL_0034: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0039: ldarg.0 + IL_003a: ldc.i4.1 + IL_003b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0040: ldc.i4.1 + IL_0041: ret + + IL_0042: ldarg.0 + IL_0043: ldc.i4.m1 + IL_0044: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0049: ldarg.0 + IL_004a: ldarg.0 + IL_004b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::p + IL_0050: ldc.i4.2 + IL_0051: add + IL_0052: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0057: ldarg.0 + IL_0058: ldc.i4.2 + IL_0059: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_005e: ldc.i4.1 + IL_005f: ret + + IL_0060: ldarg.0 + IL_0061: ldc.i4.m1 + IL_0062: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0067: ldc.i4.0 + IL_0068: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance int32 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>2__current' + IL_0006: box [mscorlib]System.Int32 + IL_000b: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 67 (0x43) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0' V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_0006: ldc.i4.s -2 + IL_0008: bne.un.s IL_0022 + + IL_000a: ldarg.0 + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>l__initialThreadId' + IL_0010: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0015: bne.un.s IL_0022 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.0 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: stloc.0 + IL_0020: br.s IL_0035 + + IL_0022: ldc.i4.0 + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::.ctor(int32) + IL_0028: stloc.0 + IL_0029: ldloc.0 + IL_002a: ldarg.0 + IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>4__this' + IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>4__this' + IL_0035: ldloc.0 + IL_0036: ldarg.0 + IL_0037: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>3__p' + IL_003c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::p + IL_0041: ldloc.0 + IL_0042: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .property instance int32 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig newslot virtual + instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test(int32 p) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.IteratorStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 3C 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..d__0. + 00 ) + // Code size 22 (0x16) + .maxstack 8 + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::.ctor(int32) + IL_0007: dup + IL_0008: ldarg.0 + IL_0009: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>4__this' + IL_000e: dup + IL_000f: ldarg.1 + IL_0010: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K/'d__0'::'<>3__p' + IL_0015: ret + } // end of method K::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 [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method K::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L + extends ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K +{ + .class auto ansi sealed nested private beforefieldinit 'd__0' + extends [mscorlib]System.Object + implements class [mscorlib]System.Collections.Generic.IEnumerable`1, + [mscorlib]System.Collections.IEnumerable, + class [mscorlib]System.Collections.Generic.IEnumerator`1, + [mscorlib]System.IDisposable, + [mscorlib]System.Collections.IEnumerator + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private int32 '<>1__state' + .field private int32 '<>2__current' + .field private int32 '<>l__initialThreadId' + .field private int32 p + .field public int32 '<>3__p' + .field public class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L '<>4__this' + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 '<>1__state') cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 26 (0x1a) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ldarg.0 + IL_0008: ldarg.1 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_000e: ldarg.0 + IL_000f: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>l__initialThreadId' + IL_0019: ret + } // end of method 'd__0'::.ctor + + .method private hidebysig newslot virtual final + instance void System.IDisposable.Dispose() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.IDisposable::Dispose + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method 'd__0'::System.IDisposable.Dispose + + .method private hidebysig newslot virtual final + instance bool MoveNext() cil managed + { + .override [mscorlib]System.Collections.IEnumerator::MoveNext + // Code size 99 (0x63) + .maxstack 4 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: brfalse.s IL_0012 + + IL_000a: br.s IL_000c + + IL_000c: ldloc.0 + IL_000d: ldc.i4.1 + IL_000e: beq.s IL_0014 + + IL_0010: br.s IL_0016 + + IL_0012: br.s IL_0018 + + IL_0014: br.s IL_005a + + IL_0016: ldc.i4.0 + IL_0017: ret + + IL_0018: ldarg.0 + IL_0019: ldc.i4.m1 + IL_001a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_001f: nop + IL_0020: ldarg.0 + IL_0021: ldarg.0 + IL_0022: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_0027: ldarg.0 + IL_0028: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_002d: ldc.i4.0 + IL_002e: call instance class [mscorlib]System.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L::'<>n__0'(int32) + IL_0033: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0038: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_003d: call instance class [mscorlib]System.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L::'<>n__0'(int32) + IL_0042: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0047: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_004c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>2__current' + IL_0051: ldarg.0 + IL_0052: ldc.i4.1 + IL_0053: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0058: ldc.i4.1 + IL_0059: ret + + IL_005a: ldarg.0 + IL_005b: ldc.i4.m1 + IL_005c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0061: ldc.i4.0 + IL_0062: ret + } // end of method 'd__0'::MoveNext + + .method private hidebysig newslot specialname virtual final + instance int32 'System.Collections.Generic.IEnumerator.get_Current'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>2__current' + IL_0006: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerator.get_Current' + + .method private hidebysig newslot virtual final + instance void System.Collections.IEnumerator.Reset() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::Reset + // Code size 6 (0x6) + .maxstack 8 + IL_0000: newobj instance void [mscorlib]System.NotSupportedException::.ctor() + IL_0005: throw + } // end of method 'd__0'::System.Collections.IEnumerator.Reset + + .method private hidebysig newslot specialname virtual final + instance object System.Collections.IEnumerator.get_Current() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerator::get_Current + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>2__current' + IL_0006: box [mscorlib]System.Int32 + IL_000b: ret + } // end of method 'd__0'::System.Collections.IEnumerator.get_Current + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.Generic.IEnumerator`1 + 'System.Collections.Generic.IEnumerable.GetEnumerator'() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + // Code size 67 (0x43) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0' V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_0006: ldc.i4.s -2 + IL_0008: bne.un.s IL_0022 + + IL_000a: ldarg.0 + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>l__initialThreadId' + IL_0010: call int32 [mscorlib]System.Environment::get_CurrentManagedThreadId() + IL_0015: bne.un.s IL_0022 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.0 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>1__state' + IL_001e: ldarg.0 + IL_001f: stloc.0 + IL_0020: br.s IL_0035 + + IL_0022: ldc.i4.0 + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::.ctor(int32) + IL_0028: stloc.0 + IL_0029: ldloc.0 + IL_002a: ldarg.0 + IL_002b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_0030: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_0035: ldloc.0 + IL_0036: ldarg.0 + IL_0037: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>3__p' + IL_003c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::p + IL_0041: ldloc.0 + IL_0042: ret + } // end of method 'd__0'::'System.Collections.Generic.IEnumerable.GetEnumerator' + + .method private hidebysig newslot virtual final + instance class [mscorlib]System.Collections.IEnumerator + System.Collections.IEnumerable.GetEnumerator() cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Collections.IEnumerable::GetEnumerator + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'System.Collections.Generic.IEnumerable.GetEnumerator'() + IL_0006: ret + } // end of method 'd__0'::System.Collections.IEnumerable.GetEnumerator + + .property instance int32 'System.Collections.Generic.IEnumerator.Current'() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'System.Collections.Generic.IEnumerator.get_Current'() + } // end of property 'd__0'::'System.Collections.Generic.IEnumerator.Current' + .property instance object System.Collections.IEnumerator.Current() + { + .get instance object ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::System.Collections.IEnumerator.get_Current() + } // end of property 'd__0'::System.Collections.IEnumerator.Current + } // end of class 'd__0' + + .method famorassem hidebysig virtual instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + Test(int32 p) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.IteratorStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 3C 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..d__0. + 00 ) + // Code size 22 (0x16) + .maxstack 8 + IL_0000: ldc.i4.s -2 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::.ctor(int32) + IL_0007: dup + IL_0008: ldarg.0 + IL_0009: stfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>4__this' + IL_000e: dup + IL_000f: ldarg.1 + IL_0010: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L/'d__0'::'<>3__p' + IL_0015: ret + } // end of method L::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.K::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method L::.ctor + + .method private hidebysig instance class [mscorlib]System.Collections.Generic.IEnumerable`1 + '<>n__0'(int32 p) 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.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.K::Test(int32) + IL_0007: ret + } // end of method L::'<>n__0' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.L + // ============================================================= From 041c3603d25b342b861ccf56819adff1219ee118 Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Mon, 9 Oct 2017 11:16:53 +0200 Subject: [PATCH 049/190] Don't inline contructors. --- ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs index b021fb840..1ea28340d 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs @@ -54,6 +54,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms 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++) { From 69dae9d5c20f924cefc031d3c0b8223cd235eeeb Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Mon, 9 Oct 2017 12:06:39 +0200 Subject: [PATCH 050/190] Don't run test with [roslyn optimize]. --- ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index 83314cdea..91c84a9db 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -177,7 +177,7 @@ namespace ICSharpCode.Decompiler.Tests } [Test] - public void FixProxyCalls([ValueSource("defaultOptions")] CompilerOptions cscOptions) + public void FixProxyCall([Values(CompilerOptions.None, CompilerOptions.Optimize, CompilerOptions.UseRoslyn)] CompilerOptions cscOptions) { Run(cscOptions: cscOptions); } From e2efd3014c243575534392a2b16e659169ef9b26 Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Mon, 9 Oct 2017 12:24:59 +0200 Subject: [PATCH 051/190] Fix name --- ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index 91c84a9db..48fc036ff 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -177,7 +177,7 @@ namespace ICSharpCode.Decompiler.Tests } [Test] - public void FixProxyCall([Values(CompilerOptions.None, CompilerOptions.Optimize, CompilerOptions.UseRoslyn)] CompilerOptions cscOptions) + public void FixProxyCalls([Values(CompilerOptions.None, CompilerOptions.Optimize, CompilerOptions.UseRoslyn)] CompilerOptions cscOptions) { Run(cscOptions: cscOptions); } From f3679e7df099837114c6b52e265dce95ec332029 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 7 Oct 2017 23:20:16 +0200 Subject: [PATCH 052/190] Fix #778: Errors about decompiling local variables and default for switch-cases --- .../IL/Transforms/DelegateConstruction.cs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs index 130349971..f90a57aff 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs @@ -228,6 +228,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms public TransformDisplayClassUsages(IInstructionWithVariableOperand targetLoad, BlockContainer captureScope, List orphanedVariableInits) { + this.currentFunction = captureScope.Ancestors.OfType().First(); this.targetLoad = targetLoad; this.captureScope = captureScope; this.orphanedVariableInits = orphanedVariableInits; @@ -241,17 +242,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms } } - protected internal override void VisitILFunction(ILFunction function) - { - var old = currentFunction; - currentFunction = function; - try { - base.VisitILFunction(function); - } finally { - currentFunction = old; - } - } - protected internal override void VisitStLoc(StLoc inst) { base.VisitStLoc(inst); From 46fdfd4b4117ee36f94a84e80e649b8909e757c3 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 8 Oct 2017 23:27:32 +0200 Subject: [PATCH 053/190] Fix bug in DelegateConstruction: ILVariables were added to the wrong ILFunction --- .../IL/Transforms/DelegateConstruction.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs index f90a57aff..1f955ce8b 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs @@ -65,7 +65,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms } } foreach (var target in targetsToReplace.OrderByDescending(t => ((ILInstruction)t).ILRange.Start)) { - function.AcceptVisitor(new TransformDisplayClassUsages(target, target.Variable.CaptureScope, orphanedVariableInits)); + function.AcceptVisitor(new TransformDisplayClassUsages(function, target, target.Variable.CaptureScope, orphanedVariableInits)); } foreach (var store in orphanedVariableInits) { if (store.Parent is Block containingBlock) @@ -226,9 +226,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms public ILInstruction value; } - public TransformDisplayClassUsages(IInstructionWithVariableOperand targetLoad, BlockContainer captureScope, List orphanedVariableInits) + public TransformDisplayClassUsages(ILFunction function, IInstructionWithVariableOperand targetLoad, BlockContainer captureScope, List orphanedVariableInits) { - this.currentFunction = captureScope.Ancestors.OfType().First(); + this.currentFunction = function; this.targetLoad = targetLoad; this.captureScope = captureScope; this.orphanedVariableInits = orphanedVariableInits; From 3f886414b0aca6ec7eda21d00c170f434339694c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 9 Oct 2017 18:55:02 +0200 Subject: [PATCH 054/190] Do not add parentheses to AnonymousMethodExpression if there are no parameters. --- ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 4528bece8..f05f0b85b 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -1033,7 +1033,7 @@ namespace ICSharpCode.Decompiler.CSharp AnonymousMethodExpression ame = new AnonymousMethodExpression(); ame.IsAsync = function.IsAsync; ame.Parameters.AddRange(MakeParameters(method, function)); - ame.HasParameterList = true; + ame.HasParameterList = ame.Parameters.Count > 0; StatementBuilder builder = new StatementBuilder(typeSystem.GetSpecializingTypeSystem(new SimpleTypeResolveContext(method)), this.decompilationContext, method, function, settings, cancellationToken); var body = builder.ConvertAsBlock(function.Body); bool isLambda = false; From f4882017625338a3fa9f038e80a9701896fc1acf Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 9 Oct 2017 18:56:36 +0200 Subject: [PATCH 055/190] Fix bug in for-loop detection: Could not detect for-loops when the condition used multiple variables. --- ICSharpCode.Decompiler/IL/DetectedLoop.cs | 26 +++++++++-------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/DetectedLoop.cs b/ICSharpCode.Decompiler/IL/DetectedLoop.cs index 276ca2657..933d7e7d1 100644 --- a/ICSharpCode.Decompiler/IL/DetectedLoop.cs +++ b/ICSharpCode.Decompiler/IL/DetectedLoop.cs @@ -116,10 +116,10 @@ namespace ICSharpCode.Decompiler.IL AdditionalBlocks = Container.Blocks.Skip(1).Where(b => b != IncrementBlock).ToArray(); return this; } else if (trueInst is Block block) { - var variable = GetVariableFromCondition(conditionInst); var last = block.Instructions.LastOrDefault(); var secondToLast = block.Instructions.SecondToLastOrDefault(); - if (variable != null && last != null && secondToLast != null && last.MatchBranch(Container.EntryPoint) && MatchIncrement(secondToLast, variable)) { + if (last != null && secondToLast != null && last.MatchBranch(Container.EntryPoint) && + MatchIncrement(secondToLast, out var variable) && conditionInst.Children.Any(c => c.MatchLdLoc(variable))) { Kind = LoopKind.For; IncrementTarget = variable; AdditionalBlocks = Container.Blocks.Skip(1).ToArray(); @@ -144,22 +144,16 @@ namespace ICSharpCode.Decompiler.IL return this; } - static ILVariable GetVariableFromCondition(ILInstruction conditionInst) + static bool MatchIncrement(ILInstruction inst, out ILVariable variable) { - var ldLocs = conditionInst.Children.OfType().ToArray(); - if (ldLocs.Length == 1) - return ldLocs[0].Variable; - else - return null; - } - - static bool MatchIncrement(ILInstruction inst, ILVariable variable) - { - if (!inst.MatchStLoc(variable, out var value)) + if (!inst.MatchStLoc(out variable, out var value)) return false; - if (!value.MatchBinaryNumericInstruction(BinaryNumericOperator.Add, out var left, out var right)) - return false; - return left.MatchLdLoc(variable) && right.MatchLdcI(out var val) && val == 1; + if (!value.MatchBinaryNumericInstruction(BinaryNumericOperator.Add, out var left, out var right)) { + if (value is CompoundAssignmentInstruction cai) { + left = cai.Target; + } else return false; + } + return left.MatchLdLoc(variable); } } } From bf8a6b9ff290e4d0c9d4e32964c915b3955a3ae0 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 9 Oct 2017 19:01:57 +0200 Subject: [PATCH 056/190] CachedDelegateInitialization: Remove dead init-store in loops --- .../IL/Transforms/CachedDelegateInitialization.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/CachedDelegateInitialization.cs b/ICSharpCode.Decompiler/IL/Transforms/CachedDelegateInitialization.cs index 6d3b833e1..725f75e8f 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/CachedDelegateInitialization.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/CachedDelegateInitialization.cs @@ -101,9 +101,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!DelegateConstruction.IsDelegateConstruction(value as NewObj, true)) return false; // do not transform if there are other stores/loads of this variable - if (v.StoreCount != 2 || v.LoadCount != 2 || v.AddressCount != 0) + if (v.StoreCount != 2 || v.StoreInstructions.Count != 2 || v.LoadCount != 2 || v.AddressCount != 0) return false; - // do not transform if there is no usage directly aftewards + // do not transform if the first assignment is not assigning null: + var otherStore = v.StoreInstructions.OfType().SingleOrDefault(store => store != storeInst); + if (otherStore == null || !otherStore.Value.MatchLdNull() || !(otherStore.Parent is Block)) + return false; + // do not transform if there is no usage directly afterwards var nextInstruction = inst.Parent.Children.ElementAtOrDefault(inst.ChildIndex + 1); if (nextInstruction == null) return false; @@ -111,6 +115,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (usages.Length != 1) return false; context.Step("CachedDelegateInitializationWithLocal", inst); + ((Block)otherStore.Parent).Instructions.Remove(otherStore); inst.ReplaceWith(new StLoc(v, value)); return true; } From 4636c0b038eceebee654bb8ae12e9353c4ea1911 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 9 Oct 2017 19:03:38 +0200 Subject: [PATCH 057/190] DelegateConstruction: only remove copies of parameter values that are part of the outer function. --- ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs index 1f955ce8b..6b0150216 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs @@ -271,7 +271,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (initValues.TryGetValue(field, out info)) { inst.ReplaceWith(new StLoc(info.variable, inst.Value)); } else { - if (inst.Value.MatchLdLoc(out var v) && v.Kind == VariableKind.Parameter) { + if (inst.Value.MatchLdLoc(out var v) && v.Kind == VariableKind.Parameter && currentFunction == v.Function) { // special case for parameters: remove copies of parameter values. orphanedVariableInits.Add(inst); value = inst.Value; From 911cdbca661071f8c24637de87c9e6e5297361a4 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 9 Oct 2017 20:52:36 +0200 Subject: [PATCH 058/190] Add DelegateConstruction tests --- .../ICSharpCode.Decompiler.Tests.csproj | 1 + .../PrettyTestRunner.cs | 6 + .../Pretty}/DelegateConstruction.cs | 61 +- .../TestCases/Pretty/DelegateConstruction.il | 1400 +++++++++++++++++ .../Pretty/DelegateConstruction.opt.il | 1150 ++++++++++++++ .../Pretty/DelegateConstruction.opt.roslyn.il | 1144 ++++++++++++++ .../Pretty/DelegateConstruction.roslyn.il | 1362 ++++++++++++++++ 7 files changed, 5089 insertions(+), 35 deletions(-) rename ICSharpCode.Decompiler.Tests/{ => TestCases/Pretty}/DelegateConstruction.cs (77%) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.roslyn.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.roslyn.il diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index f39ff4d6d..0480c2533 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -51,6 +51,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index f0033e239..47d253dab 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -97,6 +97,12 @@ namespace ICSharpCode.Decompiler.Tests Run(cscOptions: cscOptions); } + [Test, Ignore] + public void DelegateConstruction([ValueSource("defaultOptions")] CompilerOptions cscOptions) + { + Run(cscOptions: cscOptions); + } + [Test] public void AnonymousTypes([Values(CompilerOptions.None, CompilerOptions.Optimize)] CompilerOptions cscOptions) { diff --git a/ICSharpCode.Decompiler.Tests/DelegateConstruction.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs similarity index 77% rename from ICSharpCode.Decompiler.Tests/DelegateConstruction.cs rename to ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs index 70c00fc65..283a89acc 100644 --- a/ICSharpCode.Decompiler.Tests/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs @@ -22,19 +22,19 @@ using System.Linq; public static class DelegateConstruction { - class InstanceTests + private class InstanceTests { public Action CaptureOfThis() { - return delegate { - CaptureOfThis(); + return (Action)delegate { + this.CaptureOfThis(); }; } public Action CaptureOfThisAndParameter(int a) { - return delegate { - CaptureOfThisAndParameter(a); + return (Action)delegate { + this.CaptureOfThisAndParameter(a); }; } @@ -42,8 +42,8 @@ public static class DelegateConstruction { foreach (int item in Enumerable.Empty()) { if (item > 0) { - return delegate { - CaptureOfThisAndParameter(item + a); + return (Action)delegate { + this.CaptureOfThisAndParameter(item + a); }; } } @@ -55,8 +55,8 @@ public static class DelegateConstruction foreach (int item in Enumerable.Empty()) { int copyOfItem = item; if (item > 0) { - return delegate { - CaptureOfThisAndParameter(item + a + copyOfItem); + return (Action)delegate { + this.CaptureOfThisAndParameter(item + a + copyOfItem); }; } } @@ -66,7 +66,7 @@ public static class DelegateConstruction public void LambdaInForLoop() { for (int i = 0; i < 100000; i++) { - Bar(() => Foo()); + this.Bar((Func)(() => this.Foo())); } } @@ -117,14 +117,11 @@ public static class DelegateConstruction public static List> AnonymousMethodStoreWithinLoop() { List> list = new List>(); - for (int i = 0; i < 10; i++) - { + for (int i = 0; i < 10; i++) { int counter; - list.Add(delegate(int x) - { + list.Add((Action)delegate(int x) { counter = x; - } - ); + }); } return list; } @@ -133,21 +130,17 @@ public static class DelegateConstruction { List> list = new List>(); int counter; - for (int i = 0; i < 10; i++) - { - list.Add(delegate(int x) - { + for (int i = 0; i < 10; i++) { + list.Add((Action)delegate(int x) { counter = x; - } - ); + }); } return list; } public static Action StaticAnonymousMethodNoClosure() { - return delegate - { + return (Action)delegate { Console.WriteLine(); }; } @@ -156,16 +149,15 @@ public static class DelegateConstruction { // i is captured variable, // j is parameter in anonymous method - // k is local in anonymous method, - // l is local in main method + // l is local in anonymous method, + // k is local in main method // Ensure that the decompiler doesn't introduce name conflicts List> list = new List>(); - for (int l = 0; l < 10; l++) { + for (int k = 0; k < 10; k++) { int i; for (i = 0; i < 10; i++) { - list.Add( - delegate (int j) { - for (int k = 0; k < i; k += j) { + list.Add((Action)delegate(int j) { + for (int l = 0; l < i; l += j) { Console.WriteLine(); } }); @@ -177,8 +169,7 @@ public static class DelegateConstruction { List> list = new List>(); for (int k = 0; k < 10; k++) { - list.Add( - delegate(int i) { + list.Add((Action)delegate(int i) { Console.WriteLine(i); }); } @@ -186,7 +177,7 @@ public static class DelegateConstruction public static Action NameConflict3(int i) { - return delegate(int j) { + return (Action)delegate(int j) { for (int k = 0; k < j; k++) { Console.WriteLine(k); } @@ -195,11 +186,11 @@ public static class DelegateConstruction public static Func> CurriedAddition(int a) { - return b => c => a + b + c; + return (Func>)((int b) => (Func)((int c) => a + b + c)); } public static Func>> CurriedAddition2(int a) { - return b => c => d => a + b + c + d; + return (Func>>)((int b) => (Func>)((int c) => (Func)((int d) => a + b + c + d))); } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.il new file mode 100644 index 000000000..b783a086b --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.il @@ -0,0 +1,1400 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly extern System.Core +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly bmq55mnq +{ + .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.ExtensionAttribute::.ctor() = ( 01 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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module bmq55mnq.dll +// MVID: {F2F10218-F242-427C-ADE5-E367B0EA41E3} +.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: 0x02B40000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public abstract auto ansi sealed beforefieldinit DelegateConstruction + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .class auto ansi nested private beforefieldinit InstanceTests + extends [mscorlib]System.Object + { + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass22' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass22'::.ctor + + .method public hidebysig instance void + 'b__21'() cil managed + { + // Code size 20 (0x14) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'<>4__this' + IL_0007: ldarg.0 + IL_0008: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::a + IL_000d: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0012: pop + IL_0013: ret + } // end of method '<>c__DisplayClass22'::'b__21' + + } // end of class '<>c__DisplayClass22' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass25' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass25'::.ctor + + } // end of class '<>c__DisplayClass25' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass28' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' 'CS$<>8__locals26' + .field public int32 item + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass28'::.ctor + + .method public hidebysig instance void + 'b__24'() cil managed + { + // Code size 37 (0x25) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' + IL_0007: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::'<>4__this' + IL_000c: ldarg.0 + IL_000d: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item + IL_0012: ldarg.0 + IL_0013: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' + IL_0018: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::a + IL_001d: add + IL_001e: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0023: pop + IL_0024: ret + } // end of method '<>c__DisplayClass28'::'b__24' + + } // end of class '<>c__DisplayClass28' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass2b' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass2b'::.ctor + + } // end of class '<>c__DisplayClass2b' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass2d' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 item + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass2d'::.ctor + + } // end of class '<>c__DisplayClass2d' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass30' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' 'CS$<>8__locals2e' + .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' 'CS$<>8__locals2c' + .field public int32 copyOfItem + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass30'::.ctor + + .method public hidebysig instance void + 'b__2a'() cil managed + { + // Code size 49 (0x31) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' + IL_0007: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::'<>4__this' + IL_000c: ldarg.0 + IL_000d: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2e' + IL_0012: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_0017: ldarg.0 + IL_0018: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' + IL_001d: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::a + IL_0022: add + IL_0023: ldarg.0 + IL_0024: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::copyOfItem + IL_0029: add + IL_002a: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_002f: pop + IL_0030: ret + } // end of method '<>c__DisplayClass30'::'b__2a' + + } // end of class '<>c__DisplayClass30' + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThis() cil managed + { + // Code size 18 (0x12) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldftn instance void DelegateConstruction/InstanceTests::'b__20'() + IL_0008: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: br.s IL_0010 + + IL_0010: ldloc.0 + IL_0011: ret + } // end of method InstanceTests::CaptureOfThis + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThisAndParameter(int32 a) cil managed + { + // Code size 38 (0x26) + .maxstack 2 + .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass22' V_0, + class [mscorlib]System.Action V_1) + IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::a + IL_000d: ldloc.0 + IL_000e: ldarg.0 + IL_000f: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'<>4__this' + IL_0014: nop + IL_0015: ldloc.0 + IL_0016: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'b__21'() + IL_001c: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0021: stloc.1 + IL_0022: br.s IL_0024 + + IL_0024: ldloc.1 + IL_0025: ret + } // end of method InstanceTests::CaptureOfThisAndParameter + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThisAndParameterInForEach(int32 a) cil managed + { + // Code size 150 (0x96) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass28' V_1, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' V_2, + class [mscorlib]System.Action V_3, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_4, + bool V_5) + IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::.ctor() + IL_0005: stloc.2 + IL_0006: ldloc.2 + IL_0007: ldarg.1 + IL_0008: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::a + IL_000d: ldloc.2 + IL_000e: ldarg.0 + IL_000f: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::'<>4__this' + IL_0014: nop + IL_0015: nop + IL_0016: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() + IL_001b: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0020: stloc.s V_4 + .try + { + IL_0022: br.s IL_006b + + IL_0024: ldnull + IL_0025: stloc.0 + IL_0026: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::.ctor() + IL_002b: stloc.1 + IL_002c: ldloc.1 + IL_002d: ldloc.2 + IL_002e: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' + IL_0033: ldloc.1 + IL_0034: ldloc.s V_4 + IL_0036: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_003b: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item + IL_0040: nop + IL_0041: ldloc.1 + IL_0042: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item + IL_0047: ldc.i4.0 + IL_0048: cgt + IL_004a: ldc.i4.0 + IL_004b: ceq + IL_004d: stloc.s V_5 + IL_004f: ldloc.s V_5 + IL_0051: brtrue.s IL_006a + + IL_0053: nop + IL_0054: ldloc.0 + IL_0055: brtrue.s IL_0066 + + IL_0057: ldloc.1 + IL_0058: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'b__24'() + IL_005e: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0063: stloc.0 + IL_0064: br.s IL_0066 + + IL_0066: ldloc.0 + IL_0067: stloc.3 + IL_0068: leave.s IL_0093 + + IL_006a: nop + IL_006b: ldloc.s V_4 + IL_006d: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() + IL_0072: stloc.s V_5 + IL_0074: ldloc.s V_5 + IL_0076: brtrue.s IL_0024 + + IL_0078: leave.s IL_008e + + } // end .try + finally + { + IL_007a: ldloc.s V_4 + IL_007c: ldnull + IL_007d: ceq + IL_007f: stloc.s V_5 + IL_0081: ldloc.s V_5 + IL_0083: brtrue.s IL_008d + + IL_0085: ldloc.s V_4 + IL_0087: callvirt instance void [mscorlib]System.IDisposable::Dispose() + IL_008c: nop + IL_008d: endfinally + } // end handler + IL_008e: nop + IL_008f: ldnull + IL_0090: stloc.3 + IL_0091: br.s IL_0093 + + IL_0093: nop + IL_0094: ldloc.3 + IL_0095: ret + } // end of method InstanceTests::CaptureOfThisAndParameterInForEach + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThisAndParameterInForEachWithItemCopy(int32 a) cil managed + { + // Code size 178 (0xb2) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass30' V_1, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' V_2, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' V_3, + class [mscorlib]System.Action V_4, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_5, + bool V_6) + IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::.ctor() + IL_0005: stloc.3 + IL_0006: ldloc.3 + IL_0007: ldarg.1 + IL_0008: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::a + IL_000d: ldloc.3 + IL_000e: ldarg.0 + IL_000f: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::'<>4__this' + IL_0014: nop + IL_0015: nop + IL_0016: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() + IL_001b: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0020: stloc.s V_5 + .try + { + IL_0022: br.s IL_0085 + + IL_0024: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::.ctor() + IL_0029: stloc.2 + IL_002a: ldloc.2 + IL_002b: ldloc.s V_5 + IL_002d: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0032: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_0037: ldnull + IL_0038: stloc.0 + IL_0039: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::.ctor() + IL_003e: stloc.1 + IL_003f: ldloc.1 + IL_0040: ldloc.2 + IL_0041: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2e' + IL_0046: ldloc.1 + IL_0047: ldloc.3 + IL_0048: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' + IL_004d: nop + IL_004e: ldloc.1 + IL_004f: ldloc.2 + IL_0050: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_0055: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::copyOfItem + IL_005a: ldloc.2 + IL_005b: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_0060: ldc.i4.0 + IL_0061: cgt + IL_0063: ldc.i4.0 + IL_0064: ceq + IL_0066: stloc.s V_6 + IL_0068: ldloc.s V_6 + IL_006a: brtrue.s IL_0084 + + IL_006c: nop + IL_006d: ldloc.0 + IL_006e: brtrue.s IL_007f + + IL_0070: ldloc.1 + IL_0071: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'b__2a'() + IL_0077: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_007c: stloc.0 + IL_007d: br.s IL_007f + + IL_007f: ldloc.0 + IL_0080: stloc.s V_4 + IL_0082: leave.s IL_00ae + + IL_0084: nop + IL_0085: ldloc.s V_5 + IL_0087: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() + IL_008c: stloc.s V_6 + IL_008e: ldloc.s V_6 + IL_0090: brtrue.s IL_0024 + + IL_0092: leave.s IL_00a8 + + } // end .try + finally + { + IL_0094: ldloc.s V_5 + IL_0096: ldnull + IL_0097: ceq + IL_0099: stloc.s V_6 + IL_009b: ldloc.s V_6 + IL_009d: brtrue.s IL_00a7 + + IL_009f: ldloc.s V_5 + IL_00a1: callvirt instance void [mscorlib]System.IDisposable::Dispose() + IL_00a6: nop + IL_00a7: endfinally + } // end handler + IL_00a8: nop + IL_00a9: ldnull + IL_00aa: stloc.s V_4 + IL_00ac: br.s IL_00ae + + IL_00ae: nop + IL_00af: ldloc.s V_4 + IL_00b1: ret + } // end of method InstanceTests::CaptureOfThisAndParameterInForEachWithItemCopy + + .method public hidebysig instance void + LambdaInForLoop() cil managed + { + // Code size 53 (0x35) + .maxstack 3 + .locals init (int32 V_0, + class [mscorlib]System.Func`1 V_1, + bool V_2) + IL_0000: ldnull + IL_0001: stloc.1 + IL_0002: nop + IL_0003: ldc.i4.0 + IL_0004: stloc.0 + IL_0005: br.s IL_0027 + + IL_0007: nop + IL_0008: ldarg.0 + IL_0009: ldloc.1 + IL_000a: brtrue.s IL_001b + + IL_000c: ldarg.0 + IL_000d: ldftn instance int32 DelegateConstruction/InstanceTests::'b__32'() + IL_0013: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0018: stloc.1 + IL_0019: br.s IL_001b + + IL_001b: ldloc.1 + IL_001c: call instance void DelegateConstruction/InstanceTests::Bar(class [mscorlib]System.Func`1) + IL_0021: nop + IL_0022: nop + IL_0023: ldloc.0 + IL_0024: ldc.i4.1 + IL_0025: add + IL_0026: stloc.0 + IL_0027: ldloc.0 + IL_0028: ldc.i4 0x186a0 + IL_002d: clt + IL_002f: stloc.2 + IL_0030: ldloc.2 + IL_0031: brtrue.s IL_0007 + + IL_0033: nop + IL_0034: ret + } // end of method InstanceTests::LambdaInForLoop + + .method public hidebysig instance int32 + Foo() cil managed + { + // Code size 7 (0x7) + .maxstack 1 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: stloc.0 + IL_0003: br.s IL_0005 + + IL_0005: ldloc.0 + IL_0006: ret + } // end of method InstanceTests::Foo + + .method public hidebysig instance void + Bar(class [mscorlib]System.Func`1 f) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method InstanceTests::Bar + + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method InstanceTests::.ctor + + .method private hidebysig instance void + 'b__20'() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 9 (0x9) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThis() + IL_0007: pop + IL_0008: ret + } // end of method InstanceTests::'b__20' + + .method private hidebysig instance int32 + 'b__32'() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 11 (0xb) + .maxstack 1 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: call instance int32 DelegateConstruction/InstanceTests::Foo() + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method InstanceTests::'b__32' + + } // end of class InstanceTests + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 counter + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1'::.ctor + + .method public hidebysig instance void + 'b__0'(int32 x) cil managed + { + // Code size 9 (0x9) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: stfld int32 DelegateConstruction/'<>c__DisplayClass1'::counter + IL_0008: ret + } // end of method '<>c__DisplayClass1'::'b__0' + + } // end of class '<>c__DisplayClass1' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass5' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 counter + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass5'::.ctor + + .method public hidebysig instance void + 'b__3'(int32 x) cil managed + { + // Code size 9 (0x9) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: stfld int32 DelegateConstruction/'<>c__DisplayClass5'::counter + IL_0008: ret + } // end of method '<>c__DisplayClass5'::'b__3' + + } // end of class '<>c__DisplayClass5' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClassb' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 i + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClassb'::.ctor + + .method public hidebysig instance void + 'b__9'(int32 j) cil managed + { + // Code size 31 (0x1f) + .maxstack 2 + .locals init (int32 V_0, + bool V_1) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: stloc.0 + IL_0003: br.s IL_0011 + + IL_0005: nop + IL_0006: call void [mscorlib]System.Console::WriteLine() + IL_000b: nop + IL_000c: nop + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: add + IL_0010: stloc.0 + IL_0011: ldloc.0 + IL_0012: ldarg.0 + IL_0013: ldfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0018: clt + IL_001a: stloc.1 + IL_001b: ldloc.1 + IL_001c: brtrue.s IL_0005 + + IL_001e: ret + } // end of method '<>c__DisplayClassb'::'b__9' + + } // end of class '<>c__DisplayClassb' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass13' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass15' + extends [mscorlib]System.Object + { + .field public class DelegateConstruction/'<>c__DisplayClass13' 'CS$<>8__locals14' + .field public int32 b + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass15'::.ctor + + .method public hidebysig instance int32 + 'b__12'(int32 c) cil managed + { + // Code size 25 (0x19) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass13' DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'CS$<>8__locals14' + IL_0006: ldfld int32 DelegateConstruction/'<>c__DisplayClass13'::a + IL_000b: ldarg.0 + IL_000c: ldfld int32 DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::b + IL_0011: add + IL_0012: ldarg.1 + IL_0013: add + IL_0014: stloc.0 + IL_0015: br.s IL_0017 + + IL_0017: ldloc.0 + IL_0018: ret + } // end of method '<>c__DisplayClass15'::'b__12' + + } // end of class '<>c__DisplayClass15' + + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass13'::.ctor + + .method public hidebysig instance class [mscorlib]System.Func`2 + 'b__11'(int32 b) cil managed + { + // Code size 37 (0x25) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15' V_0, + class [mscorlib]System.Func`2 V_1) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass13' DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'CS$<>8__locals14' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::b + IL_0014: ldloc.0 + IL_0015: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'b__12'(int32) + IL_001b: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0020: stloc.1 + IL_0021: br.s IL_0023 + + IL_0023: ldloc.1 + IL_0024: ret + } // end of method '<>c__DisplayClass13'::'b__11' + + } // end of class '<>c__DisplayClass13' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1a' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1c' + extends [mscorlib]System.Object + { + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1e' + extends [mscorlib]System.Object + { + .field public class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' 'CS$<>8__locals1d' + .field public class DelegateConstruction/'<>c__DisplayClass1a' 'CS$<>8__locals1b' + .field public int32 c + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1e'::.ctor + + .method public hidebysig instance int32 + 'b__19'(int32 d) cil managed + { + // Code size 37 (0x25) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1b' + IL_0006: ldfld int32 DelegateConstruction/'<>c__DisplayClass1a'::a + IL_000b: ldarg.0 + IL_000c: ldfld class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1d' + IL_0011: ldfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::b + IL_0016: add + IL_0017: ldarg.0 + IL_0018: ldfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::c + IL_001d: add + IL_001e: ldarg.1 + IL_001f: add + IL_0020: stloc.0 + IL_0021: br.s IL_0023 + + IL_0023: ldloc.0 + IL_0024: ret + } // end of method '<>c__DisplayClass1e'::'b__19' + + } // end of class '<>c__DisplayClass1e' + + .field public class DelegateConstruction/'<>c__DisplayClass1a' 'CS$<>8__locals1b' + .field public int32 b + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1c'::.ctor + + .method public hidebysig instance class [mscorlib]System.Func`2 + 'b__18'(int32 c) cil managed + { + // Code size 49 (0x31) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e' V_0, + class [mscorlib]System.Func`2 V_1) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1d' + IL_000d: ldloc.0 + IL_000e: ldarg.0 + IL_000f: ldfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'CS$<>8__locals1b' + IL_0014: stfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1b' + IL_0019: ldloc.0 + IL_001a: ldarg.1 + IL_001b: stfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::c + IL_0020: ldloc.0 + IL_0021: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'b__19'(int32) + IL_0027: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_002c: stloc.1 + IL_002d: br.s IL_002f + + IL_002f: ldloc.1 + IL_0030: ret + } // end of method '<>c__DisplayClass1c'::'b__18' + + } // end of class '<>c__DisplayClass1c' + + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1a'::.ctor + + .method public hidebysig instance class [mscorlib]System.Func`2> + 'b__17'(int32 b) cil managed + { + // Code size 37 (0x25) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' V_0, + class [mscorlib]System.Func`2> V_1) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'CS$<>8__locals1b' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::b + IL_0014: ldloc.0 + IL_0015: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'b__18'(int32) + IL_001b: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, + native int) + IL_0020: stloc.1 + IL_0021: br.s IL_0023 + + IL_0023: ldloc.1 + IL_0024: ret + } // end of method '<>c__DisplayClass1a'::'b__17' + + } // end of class '<>c__DisplayClass1a' + + .field private static class [mscorlib]System.Action 'CS$<>9__CachedAnonymousMethodDelegate8' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private static class [mscorlib]System.Action`1 'CS$<>9__CachedAnonymousMethodDelegatee' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private static class [mscorlib]System.Action`1 'CS$<>9__CachedAnonymousMethodDelegate10' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig static void Test(string a) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method DelegateConstruction::Test + + .method public hidebysig static class [mscorlib]System.Action`1 + ExtensionMethodUnbound() cil managed + { + // Code size 18 (0x12) + .maxstack 2 + .locals init (class [mscorlib]System.Action`1 V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: ldftn void DelegateConstruction::Test(string) + IL_0008: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: br.s IL_0010 + + IL_0010: ldloc.0 + IL_0011: ret + } // end of method DelegateConstruction::ExtensionMethodUnbound + + .method public hidebysig static class [mscorlib]System.Action + ExtensionMethodBound() cil managed + { + // Code size 22 (0x16) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0) + IL_0000: nop + IL_0001: ldstr "abc" + IL_0006: ldftn void DelegateConstruction::Test(string) + IL_000c: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0011: stloc.0 + IL_0012: br.s IL_0014 + + IL_0014: ldloc.0 + IL_0015: ret + } // end of method DelegateConstruction::ExtensionMethodBound + + .method public hidebysig static class [mscorlib]System.Action + ExtensionMethodBoundOnNull() cil managed + { + // Code size 18 (0x12) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: ldftn void DelegateConstruction::Test(string) + IL_0008: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: br.s IL_0010 + + IL_0010: ldloc.0 + IL_0011: ret + } // end of method DelegateConstruction::ExtensionMethodBoundOnNull + + .method public hidebysig static object + StaticMethod() cil managed + { + // Code size 18 (0x12) + .maxstack 2 + .locals init (object V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: ldftn class [mscorlib]System.Action DelegateConstruction::ExtensionMethodBound() + IL_0008: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: br.s IL_0010 + + IL_0010: ldloc.0 + IL_0011: ret + } // end of method DelegateConstruction::StaticMethod + + .method public hidebysig static object + InstanceMethod() cil managed + { + // Code size 22 (0x16) + .maxstack 2 + .locals init (object V_0) + IL_0000: nop + IL_0001: ldstr "hello" + IL_0006: ldftn instance string [mscorlib]System.String::ToUpper() + IL_000c: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0011: stloc.0 + IL_0012: br.s IL_0014 + + IL_0014: ldloc.0 + IL_0015: ret + } // end of method DelegateConstruction::InstanceMethod + + .method public hidebysig static object + InstanceMethodOnNull() cil managed + { + // Code size 18 (0x12) + .maxstack 2 + .locals init (object V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: ldftn instance string [mscorlib]System.String::ToUpper() + IL_0008: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: br.s IL_0010 + + IL_0010: ldloc.0 + IL_0011: ret + } // end of method DelegateConstruction::InstanceMethodOnNull + + .method public hidebysig static class [mscorlib]System.Collections.Generic.List`1> + AnonymousMethodStoreWithinLoop() cil managed + { + // Code size 59 (0x3b) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1, + class DelegateConstruction/'<>c__DisplayClass1' V_2, + class [mscorlib]System.Collections.Generic.List`1> V_3, + bool V_4) + IL_0000: nop + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: stloc.1 + IL_0009: br.s IL_002a + + IL_000b: newobj instance void DelegateConstruction/'<>c__DisplayClass1'::.ctor() + IL_0010: stloc.2 + IL_0011: nop + IL_0012: ldloc.0 + IL_0013: ldloc.2 + IL_0014: ldftn instance void DelegateConstruction/'<>c__DisplayClass1'::'b__0'(int32) + IL_001a: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_001f: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_0024: nop + IL_0025: nop + IL_0026: ldloc.1 + IL_0027: ldc.i4.1 + IL_0028: add + IL_0029: stloc.1 + IL_002a: ldloc.1 + IL_002b: ldc.i4.s 10 + IL_002d: clt + IL_002f: stloc.s V_4 + IL_0031: ldloc.s V_4 + IL_0033: brtrue.s IL_000b + + IL_0035: ldloc.0 + IL_0036: stloc.3 + IL_0037: br.s IL_0039 + + IL_0039: ldloc.3 + IL_003a: ret + } // end of method DelegateConstruction::AnonymousMethodStoreWithinLoop + + .method public hidebysig static class [mscorlib]System.Collections.Generic.List`1> + AnonymousMethodStoreOutsideLoop() cil managed + { + // Code size 70 (0x46) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1, + class [mscorlib]System.Action`1 V_2, + class DelegateConstruction/'<>c__DisplayClass5' V_3, + class [mscorlib]System.Collections.Generic.List`1> V_4, + bool V_5) + IL_0000: ldnull + IL_0001: stloc.2 + IL_0002: newobj instance void DelegateConstruction/'<>c__DisplayClass5'::.ctor() + IL_0007: stloc.3 + IL_0008: nop + IL_0009: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_000e: stloc.0 + IL_000f: ldc.i4.0 + IL_0010: stloc.1 + IL_0011: br.s IL_0033 + + IL_0013: nop + IL_0014: ldloc.0 + IL_0015: ldloc.2 + IL_0016: brtrue.s IL_0027 + + IL_0018: ldloc.3 + IL_0019: ldftn instance void DelegateConstruction/'<>c__DisplayClass5'::'b__3'(int32) + IL_001f: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0024: stloc.2 + IL_0025: br.s IL_0027 + + IL_0027: ldloc.2 + IL_0028: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_002d: nop + IL_002e: nop + IL_002f: ldloc.1 + IL_0030: ldc.i4.1 + IL_0031: add + IL_0032: stloc.1 + IL_0033: ldloc.1 + IL_0034: ldc.i4.s 10 + IL_0036: clt + IL_0038: stloc.s V_5 + IL_003a: ldloc.s V_5 + IL_003c: brtrue.s IL_0013 + + IL_003e: ldloc.0 + IL_003f: stloc.s V_4 + IL_0041: br.s IL_0043 + + IL_0043: ldloc.s V_4 + IL_0045: ret + } // end of method DelegateConstruction::AnonymousMethodStoreOutsideLoop + + .method public hidebysig static class [mscorlib]System.Action + StaticAnonymousMethodNoClosure() cil managed + { + // Code size 37 (0x25) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0) + IL_0000: nop + IL_0001: ldsfld class [mscorlib]System.Action DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_0006: brtrue.s IL_001b + + IL_0008: ldnull + IL_0009: ldftn void DelegateConstruction::'b__7'() + IL_000f: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0014: stsfld class [mscorlib]System.Action DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_0019: br.s IL_001b + + IL_001b: ldsfld class [mscorlib]System.Action DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_0020: stloc.0 + IL_0021: br.s IL_0023 + + IL_0023: ldloc.0 + IL_0024: ret + } // end of method DelegateConstruction::StaticAnonymousMethodNoClosure + + .method public hidebysig static void NameConflict() cil managed + { + // Code size 104 (0x68) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1, + class [mscorlib]System.Action`1 V_2, + class DelegateConstruction/'<>c__DisplayClassb' V_3, + bool V_4) + IL_0000: nop + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: stloc.1 + IL_0009: br.s IL_005c + + IL_000b: ldnull + IL_000c: stloc.2 + IL_000d: newobj instance void DelegateConstruction/'<>c__DisplayClassb'::.ctor() + IL_0012: stloc.3 + IL_0013: nop + IL_0014: ldloc.3 + IL_0015: ldc.i4.0 + IL_0016: stfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_001b: br.s IL_0047 + + IL_001d: nop + IL_001e: ldloc.0 + IL_001f: ldloc.2 + IL_0020: brtrue.s IL_0031 + + IL_0022: ldloc.3 + IL_0023: ldftn instance void DelegateConstruction/'<>c__DisplayClassb'::'b__9'(int32) + IL_0029: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_002e: stloc.2 + IL_002f: br.s IL_0031 + + IL_0031: ldloc.2 + IL_0032: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_0037: nop + IL_0038: nop + IL_0039: ldloc.3 + IL_003a: dup + IL_003b: ldfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0040: ldc.i4.1 + IL_0041: add + IL_0042: stfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0047: ldloc.3 + IL_0048: ldfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_004d: ldc.i4.s 10 + IL_004f: clt + IL_0051: stloc.s V_4 + IL_0053: ldloc.s V_4 + IL_0055: brtrue.s IL_001d + + IL_0057: nop + IL_0058: ldloc.1 + IL_0059: ldc.i4.1 + IL_005a: add + IL_005b: stloc.1 + IL_005c: ldloc.1 + IL_005d: ldc.i4.s 10 + IL_005f: clt + IL_0061: stloc.s V_4 + IL_0063: ldloc.s V_4 + IL_0065: brtrue.s IL_000b + + IL_0067: ret + } // end of method DelegateConstruction::NameConflict + + .method public hidebysig static void NameConflict2(int32 j) cil managed + { + // Code size 65 (0x41) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1, + bool V_2) + IL_0000: nop + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: stloc.1 + IL_0009: br.s IL_0037 + + IL_000b: nop + IL_000c: ldloc.0 + IL_000d: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' + IL_0012: brtrue.s IL_0027 + + IL_0014: ldnull + IL_0015: ldftn void DelegateConstruction::'b__d'(int32) + IL_001b: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0020: stsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' + IL_0025: br.s IL_0027 + + IL_0027: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' + IL_002c: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_0031: nop + IL_0032: nop + IL_0033: ldloc.1 + IL_0034: ldc.i4.1 + IL_0035: add + IL_0036: stloc.1 + IL_0037: ldloc.1 + IL_0038: ldc.i4.s 10 + IL_003a: clt + IL_003c: stloc.2 + IL_003d: ldloc.2 + IL_003e: brtrue.s IL_000b + + IL_0040: ret + } // end of method DelegateConstruction::NameConflict2 + + .method public hidebysig static class [mscorlib]System.Action`1 + NameConflict3(int32 i) cil managed + { + // Code size 37 (0x25) + .maxstack 2 + .locals init (class [mscorlib]System.Action`1 V_0) + IL_0000: nop + IL_0001: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' + IL_0006: brtrue.s IL_001b + + IL_0008: ldnull + IL_0009: ldftn void DelegateConstruction::'b__f'(int32) + IL_000f: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0014: stsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' + IL_0019: br.s IL_001b + + IL_001b: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' + IL_0020: stloc.0 + IL_0021: br.s IL_0023 + + IL_0023: ldloc.0 + IL_0024: ret + } // end of method DelegateConstruction::NameConflict3 + + .method public hidebysig static class [mscorlib]System.Func`2> + CurriedAddition(int32 a) cil managed + { + // Code size 31 (0x1f) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass13' V_0, + class [mscorlib]System.Func`2> V_1) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass13'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld int32 DelegateConstruction/'<>c__DisplayClass13'::a + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass13'::'b__11'(int32) + IL_0015: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, + native int) + IL_001a: stloc.1 + IL_001b: br.s IL_001d + + IL_001d: ldloc.1 + IL_001e: ret + } // end of method DelegateConstruction::CurriedAddition + + .method public hidebysig static class [mscorlib]System.Func`2>> + CurriedAddition2(int32 a) cil managed + { + // Code size 31 (0x1f) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass1a' V_0, + class [mscorlib]System.Func`2>> V_1) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass1a'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld int32 DelegateConstruction/'<>c__DisplayClass1a'::a + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldftn instance class [mscorlib]System.Func`2> DelegateConstruction/'<>c__DisplayClass1a'::'b__17'(int32) + IL_0015: newobj instance void class [mscorlib]System.Func`2>>::.ctor(object, + native int) + IL_001a: stloc.1 + IL_001b: br.s IL_001d + + IL_001d: ldloc.1 + IL_001e: ret + } // end of method DelegateConstruction::CurriedAddition2 + + .method private hidebysig static void 'b__7'() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 8 (0x8) + .maxstack 8 + IL_0000: nop + IL_0001: call void [mscorlib]System.Console::WriteLine() + IL_0006: nop + IL_0007: ret + } // end of method DelegateConstruction::'b__7' + + .method private hidebysig static void 'b__d'(int32 i) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 9 (0x9) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: call void [mscorlib]System.Console::WriteLine(int32) + IL_0007: nop + IL_0008: ret + } // end of method DelegateConstruction::'b__d' + + .method private hidebysig static void 'b__f'(int32 j) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 27 (0x1b) + .maxstack 2 + .locals init (int32 V_0, + bool V_1) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: stloc.0 + IL_0003: br.s IL_0012 + + IL_0005: nop + IL_0006: ldloc.0 + IL_0007: call void [mscorlib]System.Console::WriteLine(int32) + IL_000c: nop + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldc.i4.1 + IL_0010: add + IL_0011: stloc.0 + IL_0012: ldloc.0 + IL_0013: ldarg.0 + IL_0014: clt + IL_0016: stloc.1 + IL_0017: ldloc.1 + IL_0018: brtrue.s IL_0005 + + IL_001a: ret + } // end of method DelegateConstruction::'b__f' + +} // end of class DelegateConstruction + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// WARNING: Created Win32 resource file ../../../TestCases/Pretty\DelegateConstruction.res diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.il new file mode 100644 index 000000000..5ae47aa6a --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.il @@ -0,0 +1,1150 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly extern System.Core +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly xrchixjz +{ + .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.ExtensionAttribute::.ctor() = ( 01 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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module xrchixjz.dll +// MVID: {4764226C-6D0F-4413-9843-94B16795E6C2} +.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: 0x00C80000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public abstract auto ansi sealed beforefieldinit DelegateConstruction + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .class auto ansi nested private beforefieldinit InstanceTests + extends [mscorlib]System.Object + { + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass22' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass22'::.ctor + + .method public hidebysig instance void + 'b__21'() cil managed + { + // Code size 19 (0x13) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'<>4__this' + IL_0006: ldarg.0 + IL_0007: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::a + IL_000c: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0011: pop + IL_0012: ret + } // end of method '<>c__DisplayClass22'::'b__21' + + } // end of class '<>c__DisplayClass22' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass25' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass25'::.ctor + + } // end of class '<>c__DisplayClass25' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass28' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' 'CS$<>8__locals26' + .field public int32 item + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass28'::.ctor + + .method public hidebysig instance void + 'b__24'() cil managed + { + // Code size 36 (0x24) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' + IL_0006: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::'<>4__this' + IL_000b: ldarg.0 + IL_000c: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item + IL_0011: ldarg.0 + IL_0012: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' + IL_0017: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::a + IL_001c: add + IL_001d: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0022: pop + IL_0023: ret + } // end of method '<>c__DisplayClass28'::'b__24' + + } // end of class '<>c__DisplayClass28' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass2b' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass2b'::.ctor + + } // end of class '<>c__DisplayClass2b' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass2d' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 item + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass2d'::.ctor + + } // end of class '<>c__DisplayClass2d' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass30' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' 'CS$<>8__locals2e' + .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' 'CS$<>8__locals2c' + .field public int32 copyOfItem + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass30'::.ctor + + .method public hidebysig instance void + 'b__2a'() cil managed + { + // Code size 48 (0x30) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' + IL_0006: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::'<>4__this' + IL_000b: ldarg.0 + IL_000c: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2e' + IL_0011: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_0016: ldarg.0 + IL_0017: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' + IL_001c: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::a + IL_0021: add + IL_0022: ldarg.0 + IL_0023: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::copyOfItem + IL_0028: add + IL_0029: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_002e: pop + IL_002f: ret + } // end of method '<>c__DisplayClass30'::'b__2a' + + } // end of class '<>c__DisplayClass30' + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThis() cil managed + { + // Code size 13 (0xd) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance void DelegateConstruction/InstanceTests::'b__20'() + IL_0007: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_000c: ret + } // end of method InstanceTests::CaptureOfThis + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThisAndParameter(int32 a) cil managed + { + // Code size 33 (0x21) + .maxstack 2 + .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass22' V_0) + IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.1 + IL_0008: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::a + IL_000d: ldloc.0 + IL_000e: ldarg.0 + IL_000f: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'<>4__this' + IL_0014: ldloc.0 + IL_0015: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'b__21'() + IL_001b: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0020: ret + } // end of method InstanceTests::CaptureOfThisAndParameter + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThisAndParameterInForEach(int32 a) cil managed + { + // Code size 118 (0x76) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass28' V_1, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' V_2, + class [mscorlib]System.Action V_3, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_4) + IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::.ctor() + IL_0005: stloc.2 + IL_0006: ldloc.2 + IL_0007: ldarg.1 + IL_0008: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::a + IL_000d: ldloc.2 + IL_000e: ldarg.0 + IL_000f: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::'<>4__this' + IL_0014: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() + IL_0019: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_001e: stloc.s V_4 + .try + { + IL_0020: br.s IL_005b + + IL_0022: ldnull + IL_0023: stloc.0 + IL_0024: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::.ctor() + IL_0029: stloc.1 + IL_002a: ldloc.1 + IL_002b: ldloc.2 + IL_002c: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' + IL_0031: ldloc.1 + IL_0032: ldloc.s V_4 + IL_0034: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0039: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item + IL_003e: ldloc.1 + IL_003f: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item + IL_0044: ldc.i4.0 + IL_0045: ble.s IL_005b + + IL_0047: ldloc.0 + IL_0048: brtrue.s IL_0057 + + IL_004a: ldloc.1 + IL_004b: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'b__24'() + IL_0051: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0056: stloc.0 + IL_0057: ldloc.0 + IL_0058: stloc.3 + IL_0059: leave.s IL_0074 + + IL_005b: ldloc.s V_4 + IL_005d: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() + IL_0062: brtrue.s IL_0022 + + IL_0064: leave.s IL_0072 + + } // end .try + finally + { + IL_0066: ldloc.s V_4 + IL_0068: brfalse.s IL_0071 + + IL_006a: ldloc.s V_4 + IL_006c: callvirt instance void [mscorlib]System.IDisposable::Dispose() + IL_0071: endfinally + } // end handler + IL_0072: ldnull + IL_0073: ret + + IL_0074: ldloc.3 + IL_0075: ret + } // end of method InstanceTests::CaptureOfThisAndParameterInForEach + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThisAndParameterInForEachWithItemCopy(int32 a) cil managed + { + // Code size 145 (0x91) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass30' V_1, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' V_2, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' V_3, + class [mscorlib]System.Action V_4, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_5) + IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::.ctor() + IL_0005: stloc.3 + IL_0006: ldloc.3 + IL_0007: ldarg.1 + IL_0008: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::a + IL_000d: ldloc.3 + IL_000e: ldarg.0 + IL_000f: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::'<>4__this' + IL_0014: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() + IL_0019: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_001e: stloc.s V_5 + .try + { + IL_0020: br.s IL_0075 + + IL_0022: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::.ctor() + IL_0027: stloc.2 + IL_0028: ldloc.2 + IL_0029: ldloc.s V_5 + IL_002b: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0030: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_0035: ldnull + IL_0036: stloc.0 + IL_0037: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::.ctor() + IL_003c: stloc.1 + IL_003d: ldloc.1 + IL_003e: ldloc.2 + IL_003f: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2e' + IL_0044: ldloc.1 + IL_0045: ldloc.3 + IL_0046: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' + IL_004b: ldloc.1 + IL_004c: ldloc.2 + IL_004d: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_0052: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::copyOfItem + IL_0057: ldloc.2 + IL_0058: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_005d: ldc.i4.0 + IL_005e: ble.s IL_0075 + + IL_0060: ldloc.0 + IL_0061: brtrue.s IL_0070 + + IL_0063: ldloc.1 + IL_0064: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'b__2a'() + IL_006a: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_006f: stloc.0 + IL_0070: ldloc.0 + IL_0071: stloc.s V_4 + IL_0073: leave.s IL_008e + + IL_0075: ldloc.s V_5 + IL_0077: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() + IL_007c: brtrue.s IL_0022 + + IL_007e: leave.s IL_008c + + } // end .try + finally + { + IL_0080: ldloc.s V_5 + IL_0082: brfalse.s IL_008b + + IL_0084: ldloc.s V_5 + IL_0086: callvirt instance void [mscorlib]System.IDisposable::Dispose() + IL_008b: endfinally + } // end handler + IL_008c: ldnull + IL_008d: ret + + IL_008e: ldloc.s V_4 + IL_0090: ret + } // end of method InstanceTests::CaptureOfThisAndParameterInForEachWithItemCopy + + .method public hidebysig instance void + LambdaInForLoop() cil managed + { + // Code size 42 (0x2a) + .maxstack 3 + .locals init (int32 V_0, + class [mscorlib]System.Func`1 V_1) + IL_0000: ldnull + IL_0001: stloc.1 + IL_0002: ldc.i4.0 + IL_0003: stloc.0 + IL_0004: br.s IL_0021 + + IL_0006: ldarg.0 + IL_0007: ldloc.1 + IL_0008: brtrue.s IL_0017 + + IL_000a: ldarg.0 + IL_000b: ldftn instance int32 DelegateConstruction/InstanceTests::'b__32'() + IL_0011: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0016: stloc.1 + IL_0017: ldloc.1 + IL_0018: call instance void DelegateConstruction/InstanceTests::Bar(class [mscorlib]System.Func`1) + IL_001d: ldloc.0 + IL_001e: ldc.i4.1 + IL_001f: add + IL_0020: stloc.0 + IL_0021: ldloc.0 + IL_0022: ldc.i4 0x186a0 + IL_0027: blt.s IL_0006 + + IL_0029: ret + } // end of method InstanceTests::LambdaInForLoop + + .method public hidebysig instance int32 + Foo() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } // end of method InstanceTests::Foo + + .method public hidebysig instance void + Bar(class [mscorlib]System.Func`1 f) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method InstanceTests::Bar + + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method InstanceTests::.ctor + + .method private hidebysig instance void + 'b__20'() 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: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThis() + IL_0006: pop + IL_0007: ret + } // end of method InstanceTests::'b__20' + + .method private hidebysig instance int32 + 'b__32'() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance int32 DelegateConstruction/InstanceTests::Foo() + IL_0006: ret + } // end of method InstanceTests::'b__32' + + } // end of class InstanceTests + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 counter + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1'::.ctor + + .method public hidebysig instance void + 'b__0'(int32 x) cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 DelegateConstruction/'<>c__DisplayClass1'::counter + IL_0007: ret + } // end of method '<>c__DisplayClass1'::'b__0' + + } // end of class '<>c__DisplayClass1' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass5' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 counter + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass5'::.ctor + + .method public hidebysig instance void + 'b__3'(int32 x) cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 DelegateConstruction/'<>c__DisplayClass5'::counter + IL_0007: ret + } // end of method '<>c__DisplayClass5'::'b__3' + + } // end of class '<>c__DisplayClass5' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClassb' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 i + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClassb'::.ctor + + .method public hidebysig instance void + 'b__9'(int32 j) cil managed + { + // Code size 23 (0x17) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_000d + + IL_0004: call void [mscorlib]System.Console::WriteLine() + IL_0009: ldloc.0 + IL_000a: ldarg.1 + IL_000b: add + IL_000c: stloc.0 + IL_000d: ldloc.0 + IL_000e: ldarg.0 + IL_000f: ldfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0014: blt.s IL_0004 + + IL_0016: ret + } // end of method '<>c__DisplayClassb'::'b__9' + + } // end of class '<>c__DisplayClassb' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass13' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass15' + extends [mscorlib]System.Object + { + .field public class DelegateConstruction/'<>c__DisplayClass13' 'CS$<>8__locals14' + .field public int32 b + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass15'::.ctor + + .method public hidebysig instance int32 + 'b__12'(int32 c) cil managed + { + // Code size 21 (0x15) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass13' DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'CS$<>8__locals14' + IL_0006: ldfld int32 DelegateConstruction/'<>c__DisplayClass13'::a + IL_000b: ldarg.0 + IL_000c: ldfld int32 DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::b + IL_0011: add + IL_0012: ldarg.1 + IL_0013: add + IL_0014: ret + } // end of method '<>c__DisplayClass15'::'b__12' + + } // end of class '<>c__DisplayClass15' + + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass13'::.ctor + + .method public hidebysig instance class [mscorlib]System.Func`2 + 'b__11'(int32 b) cil managed + { + // Code size 33 (0x21) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15' V_0) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass13' DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'CS$<>8__locals14' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::b + IL_0014: ldloc.0 + IL_0015: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'b__12'(int32) + IL_001b: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0020: ret + } // end of method '<>c__DisplayClass13'::'b__11' + + } // end of class '<>c__DisplayClass13' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1a' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1c' + extends [mscorlib]System.Object + { + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1e' + extends [mscorlib]System.Object + { + .field public class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' 'CS$<>8__locals1d' + .field public class DelegateConstruction/'<>c__DisplayClass1a' 'CS$<>8__locals1b' + .field public int32 c + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1e'::.ctor + + .method public hidebysig instance int32 + 'b__19'(int32 d) cil managed + { + // Code size 33 (0x21) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1b' + IL_0006: ldfld int32 DelegateConstruction/'<>c__DisplayClass1a'::a + IL_000b: ldarg.0 + IL_000c: ldfld class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1d' + IL_0011: ldfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::b + IL_0016: add + IL_0017: ldarg.0 + IL_0018: ldfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::c + IL_001d: add + IL_001e: ldarg.1 + IL_001f: add + IL_0020: ret + } // end of method '<>c__DisplayClass1e'::'b__19' + + } // end of class '<>c__DisplayClass1e' + + .field public class DelegateConstruction/'<>c__DisplayClass1a' 'CS$<>8__locals1b' + .field public int32 b + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1c'::.ctor + + .method public hidebysig instance class [mscorlib]System.Func`2 + 'b__18'(int32 c) cil managed + { + // Code size 45 (0x2d) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e' V_0) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1d' + IL_000d: ldloc.0 + IL_000e: ldarg.0 + IL_000f: ldfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'CS$<>8__locals1b' + IL_0014: stfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1b' + IL_0019: ldloc.0 + IL_001a: ldarg.1 + IL_001b: stfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::c + IL_0020: ldloc.0 + IL_0021: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'b__19'(int32) + IL_0027: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_002c: ret + } // end of method '<>c__DisplayClass1c'::'b__18' + + } // end of class '<>c__DisplayClass1c' + + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1a'::.ctor + + .method public hidebysig instance class [mscorlib]System.Func`2> + 'b__17'(int32 b) cil managed + { + // Code size 33 (0x21) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' V_0) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'CS$<>8__locals1b' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::b + IL_0014: ldloc.0 + IL_0015: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'b__18'(int32) + IL_001b: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, + native int) + IL_0020: ret + } // end of method '<>c__DisplayClass1a'::'b__17' + + } // end of class '<>c__DisplayClass1a' + + .field private static class [mscorlib]System.Action 'CS$<>9__CachedAnonymousMethodDelegate8' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private static class [mscorlib]System.Action`1 'CS$<>9__CachedAnonymousMethodDelegatee' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private static class [mscorlib]System.Action`1 'CS$<>9__CachedAnonymousMethodDelegate10' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig static void Test(string a) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method DelegateConstruction::Test + + .method public hidebysig static class [mscorlib]System.Action`1 + ExtensionMethodUnbound() cil managed + { + // Code size 13 (0xd) + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void DelegateConstruction::Test(string) + IL_0007: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000c: ret + } // end of method DelegateConstruction::ExtensionMethodUnbound + + .method public hidebysig static class [mscorlib]System.Action + ExtensionMethodBound() cil managed + { + // Code size 17 (0x11) + .maxstack 8 + IL_0000: ldstr "abc" + IL_0005: ldftn void DelegateConstruction::Test(string) + IL_000b: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0010: ret + } // end of method DelegateConstruction::ExtensionMethodBound + + .method public hidebysig static class [mscorlib]System.Action + ExtensionMethodBoundOnNull() cil managed + { + // Code size 13 (0xd) + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void DelegateConstruction::Test(string) + IL_0007: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_000c: ret + } // end of method DelegateConstruction::ExtensionMethodBoundOnNull + + .method public hidebysig static object + StaticMethod() cil managed + { + // Code size 13 (0xd) + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn class [mscorlib]System.Action DelegateConstruction::ExtensionMethodBound() + IL_0007: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_000c: ret + } // end of method DelegateConstruction::StaticMethod + + .method public hidebysig static object + InstanceMethod() cil managed + { + // Code size 17 (0x11) + .maxstack 8 + IL_0000: ldstr "hello" + IL_0005: ldftn instance string [mscorlib]System.String::ToUpper() + IL_000b: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0010: ret + } // end of method DelegateConstruction::InstanceMethod + + .method public hidebysig static object + InstanceMethodOnNull() cil managed + { + // Code size 13 (0xd) + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn instance string [mscorlib]System.String::ToUpper() + IL_0007: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_000c: ret + } // end of method DelegateConstruction::InstanceMethodOnNull + + .method public hidebysig static class [mscorlib]System.Collections.Generic.List`1> + AnonymousMethodStoreWithinLoop() cil managed + { + // Code size 45 (0x2d) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1, + class DelegateConstruction/'<>c__DisplayClass1' V_2) + IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0005: stloc.0 + IL_0006: ldc.i4.0 + IL_0007: stloc.1 + IL_0008: br.s IL_0026 + + IL_000a: newobj instance void DelegateConstruction/'<>c__DisplayClass1'::.ctor() + IL_000f: stloc.2 + IL_0010: ldloc.0 + IL_0011: ldloc.2 + IL_0012: ldftn instance void DelegateConstruction/'<>c__DisplayClass1'::'b__0'(int32) + IL_0018: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_001d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_0022: ldloc.1 + IL_0023: ldc.i4.1 + IL_0024: add + IL_0025: stloc.1 + IL_0026: ldloc.1 + IL_0027: ldc.i4.s 10 + IL_0029: blt.s IL_000a + + IL_002b: ldloc.0 + IL_002c: ret + } // end of method DelegateConstruction::AnonymousMethodStoreWithinLoop + + .method public hidebysig static class [mscorlib]System.Collections.Generic.List`1> + AnonymousMethodStoreOutsideLoop() cil managed + { + // Code size 52 (0x34) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1, + class [mscorlib]System.Action`1 V_2, + class DelegateConstruction/'<>c__DisplayClass5' V_3) + IL_0000: ldnull + IL_0001: stloc.2 + IL_0002: newobj instance void DelegateConstruction/'<>c__DisplayClass5'::.ctor() + IL_0007: stloc.3 + IL_0008: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_000d: stloc.0 + IL_000e: ldc.i4.0 + IL_000f: stloc.1 + IL_0010: br.s IL_002d + + IL_0012: ldloc.0 + IL_0013: ldloc.2 + IL_0014: brtrue.s IL_0023 + + IL_0016: ldloc.3 + IL_0017: ldftn instance void DelegateConstruction/'<>c__DisplayClass5'::'b__3'(int32) + IL_001d: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0022: stloc.2 + IL_0023: ldloc.2 + IL_0024: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_0029: ldloc.1 + IL_002a: ldc.i4.1 + IL_002b: add + IL_002c: stloc.1 + IL_002d: ldloc.1 + IL_002e: ldc.i4.s 10 + IL_0030: blt.s IL_0012 + + IL_0032: ldloc.0 + IL_0033: ret + } // end of method DelegateConstruction::AnonymousMethodStoreOutsideLoop + + .method public hidebysig static class [mscorlib]System.Action + StaticAnonymousMethodNoClosure() cil managed + { + // Code size 30 (0x1e) + .maxstack 8 + IL_0000: ldsfld class [mscorlib]System.Action DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_0005: brtrue.s IL_0018 + + IL_0007: ldnull + IL_0008: ldftn void DelegateConstruction::'b__7'() + IL_000e: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0013: stsfld class [mscorlib]System.Action DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_0018: ldsfld class [mscorlib]System.Action DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_001d: ret + } // end of method DelegateConstruction::StaticAnonymousMethodNoClosure + + .method public hidebysig static void NameConflict() cil managed + { + // Code size 84 (0x54) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1, + class [mscorlib]System.Action`1 V_2, + class DelegateConstruction/'<>c__DisplayClassb' V_3) + IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0005: stloc.0 + IL_0006: ldc.i4.0 + IL_0007: stloc.1 + IL_0008: br.s IL_004e + + IL_000a: ldnull + IL_000b: stloc.2 + IL_000c: newobj instance void DelegateConstruction/'<>c__DisplayClassb'::.ctor() + IL_0011: stloc.3 + IL_0012: ldloc.3 + IL_0013: ldc.i4.0 + IL_0014: stfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0019: br.s IL_0040 + + IL_001b: ldloc.0 + IL_001c: ldloc.2 + IL_001d: brtrue.s IL_002c + + IL_001f: ldloc.3 + IL_0020: ldftn instance void DelegateConstruction/'<>c__DisplayClassb'::'b__9'(int32) + IL_0026: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_002b: stloc.2 + IL_002c: ldloc.2 + IL_002d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_0032: ldloc.3 + IL_0033: dup + IL_0034: ldfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0039: ldc.i4.1 + IL_003a: add + IL_003b: stfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0040: ldloc.3 + IL_0041: ldfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0046: ldc.i4.s 10 + IL_0048: blt.s IL_001b + + IL_004a: ldloc.1 + IL_004b: ldc.i4.1 + IL_004c: add + IL_004d: stloc.1 + IL_004e: ldloc.1 + IL_004f: ldc.i4.s 10 + IL_0051: blt.s IL_000a + + IL_0053: ret + } // end of method DelegateConstruction::NameConflict + + .method public hidebysig static void NameConflict2(int32 j) cil managed + { + // Code size 55 (0x37) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1) + IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0005: stloc.0 + IL_0006: ldc.i4.0 + IL_0007: stloc.1 + IL_0008: br.s IL_0031 + + IL_000a: ldloc.0 + IL_000b: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' + IL_0010: brtrue.s IL_0023 + + IL_0012: ldnull + IL_0013: ldftn void DelegateConstruction::'b__d'(int32) + IL_0019: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_001e: stsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' + IL_0023: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' + IL_0028: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_002d: ldloc.1 + IL_002e: ldc.i4.1 + IL_002f: add + IL_0030: stloc.1 + IL_0031: ldloc.1 + IL_0032: ldc.i4.s 10 + IL_0034: blt.s IL_000a + + IL_0036: ret + } // end of method DelegateConstruction::NameConflict2 + + .method public hidebysig static class [mscorlib]System.Action`1 + NameConflict3(int32 i) cil managed + { + // Code size 30 (0x1e) + .maxstack 8 + IL_0000: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' + IL_0005: brtrue.s IL_0018 + + IL_0007: ldnull + IL_0008: ldftn void DelegateConstruction::'b__f'(int32) + IL_000e: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0013: stsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' + IL_0018: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' + IL_001d: ret + } // end of method DelegateConstruction::NameConflict3 + + .method public hidebysig static class [mscorlib]System.Func`2> + CurriedAddition(int32 a) cil managed + { + // Code size 26 (0x1a) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass13' V_0) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass13'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld int32 DelegateConstruction/'<>c__DisplayClass13'::a + IL_000d: ldloc.0 + IL_000e: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass13'::'b__11'(int32) + IL_0014: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, + native int) + IL_0019: ret + } // end of method DelegateConstruction::CurriedAddition + + .method public hidebysig static class [mscorlib]System.Func`2>> + CurriedAddition2(int32 a) cil managed + { + // Code size 26 (0x1a) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass1a' V_0) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass1a'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld int32 DelegateConstruction/'<>c__DisplayClass1a'::a + IL_000d: ldloc.0 + IL_000e: ldftn instance class [mscorlib]System.Func`2> DelegateConstruction/'<>c__DisplayClass1a'::'b__17'(int32) + IL_0014: newobj instance void class [mscorlib]System.Func`2>>::.ctor(object, + native int) + IL_0019: ret + } // end of method DelegateConstruction::CurriedAddition2 + + .method private hidebysig static void 'b__7'() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 6 (0x6) + .maxstack 8 + IL_0000: call void [mscorlib]System.Console::WriteLine() + IL_0005: ret + } // end of method DelegateConstruction::'b__7' + + .method private hidebysig static void 'b__d'(int32 i) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call void [mscorlib]System.Console::WriteLine(int32) + IL_0006: ret + } // end of method DelegateConstruction::'b__d' + + .method private hidebysig static void 'b__f'(int32 j) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 19 (0x13) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_000e + + IL_0004: ldloc.0 + IL_0005: call void [mscorlib]System.Console::WriteLine(int32) + IL_000a: ldloc.0 + IL_000b: ldc.i4.1 + IL_000c: add + IL_000d: stloc.0 + IL_000e: ldloc.0 + IL_000f: ldarg.0 + IL_0010: blt.s IL_0004 + + IL_0012: ret + } // end of method DelegateConstruction::'b__f' + +} // end of class DelegateConstruction + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// WARNING: Created Win32 resource file ../../../TestCases/Pretty\DelegateConstruction.opt.res diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.roslyn.il new file mode 100644 index 000000000..afa8fe5da --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.roslyn.il @@ -0,0 +1,1144 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly extern System.Core +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly DelegateConstruction +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module DelegateConstruction.dll +// MVID: {D01DFE9F-2A31-46AA-8CBD-03D412485F40} +.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: 0x009F0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public abstract auto ansi sealed beforefieldinit DelegateConstruction + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .class auto ansi nested private beforefieldinit InstanceTests + extends [mscorlib]System.Object + { + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 a + .field public class DelegateConstruction/InstanceTests '<>4__this' + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass1_0'::.ctor + + .method assembly hidebysig instance void + 'b__0'() cil managed + { + // Code size 19 (0x13) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'<>4__this' + IL_0006: ldarg.0 + IL_0007: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::a + IL_000c: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0011: pop + IL_0012: ret + } // end of method '<>c__DisplayClass1_0'::'b__0' + + } // end of class '<>c__DisplayClass1_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass2_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 item + .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' 'CS$<>8__locals1' + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass2_0'::.ctor + + .method assembly hidebysig instance void + 'b__0'() cil managed + { + // Code size 36 (0x24) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' + IL_0006: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::'<>4__this' + IL_000b: ldarg.0 + IL_000c: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item + IL_0011: ldarg.0 + IL_0012: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' + IL_0017: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::a + IL_001c: add + IL_001d: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0022: pop + IL_0023: ret + } // end of method '<>c__DisplayClass2_0'::'b__0' + + } // end of class '<>c__DisplayClass2_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass2_1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 a + .field public class DelegateConstruction/InstanceTests '<>4__this' + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass2_1'::.ctor + + } // end of class '<>c__DisplayClass2_1' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass3_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 item + .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' 'CS$<>8__locals1' + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass3_0'::.ctor + + } // end of class '<>c__DisplayClass3_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass3_1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 a + .field public class DelegateConstruction/InstanceTests '<>4__this' + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass3_1'::.ctor + + } // end of class '<>c__DisplayClass3_1' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass3_2' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 copyOfItem + .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' 'CS$<>8__locals2' + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass3_2'::.ctor + + .method assembly hidebysig instance void + 'b__0'() cil managed + { + // Code size 58 (0x3a) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0006: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' + IL_000b: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::'<>4__this' + IL_0010: ldarg.0 + IL_0011: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0016: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_001b: ldarg.0 + IL_001c: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0021: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' + IL_0026: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::a + IL_002b: add + IL_002c: ldarg.0 + IL_002d: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::copyOfItem + IL_0032: add + IL_0033: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0038: pop + IL_0039: ret + } // end of method '<>c__DisplayClass3_2'::'b__0' + + } // end of class '<>c__DisplayClass3_2' + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThis() cil managed + { + // Code size 13 (0xd) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance void DelegateConstruction/InstanceTests::'b__0_0'() + IL_0007: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_000c: ret + } // end of method InstanceTests::CaptureOfThis + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThisAndParameter(int32 a) cil managed + { + // Code size 31 (0x1f) + .maxstack 8 + IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::.ctor() + IL_0005: dup + IL_0006: ldarg.0 + IL_0007: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'<>4__this' + IL_000c: dup + IL_000d: ldarg.1 + IL_000e: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::a + IL_0013: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'b__0'() + IL_0019: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_001e: ret + } // end of method InstanceTests::CaptureOfThisAndParameter + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThisAndParameterInForEach(int32 a) cil managed + { + // Code size 106 (0x6a) + .maxstack 2 + .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' V_0, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0' V_2, + class [mscorlib]System.Action V_3) + IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::'<>4__this' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::a + IL_0014: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() + IL_0019: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_001e: stloc.1 + .try + { + IL_001f: br.s IL_0052 + + IL_0021: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::.ctor() + IL_0026: stloc.2 + IL_0027: ldloc.2 + IL_0028: ldloc.0 + IL_0029: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' + IL_002e: ldloc.2 + IL_002f: ldloc.1 + IL_0030: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0035: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item + IL_003a: ldloc.2 + IL_003b: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item + IL_0040: ldc.i4.0 + IL_0041: ble.s IL_0052 + + IL_0043: ldloc.2 + IL_0044: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'b__0'() + IL_004a: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_004f: stloc.3 + IL_0050: leave.s IL_0068 + + IL_0052: ldloc.1 + IL_0053: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() + IL_0058: brtrue.s IL_0021 + + IL_005a: leave.s IL_0066 + + } // end .try + finally + { + IL_005c: ldloc.1 + IL_005d: brfalse.s IL_0065 + + IL_005f: ldloc.1 + IL_0060: callvirt instance void [mscorlib]System.IDisposable::Dispose() + IL_0065: endfinally + } // end handler + IL_0066: ldnull + IL_0067: ret + + IL_0068: ldloc.3 + IL_0069: ret + } // end of method InstanceTests::CaptureOfThisAndParameterInForEach + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThisAndParameterInForEachWithItemCopy(int32 a) cil managed + { + // Code size 143 (0x8f) + .maxstack 2 + .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' V_0, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' V_2, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2' V_3, + class [mscorlib]System.Action V_4) + IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::'<>4__this' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::a + IL_0014: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() + IL_0019: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_001e: stloc.1 + .try + { + IL_001f: br.s IL_0076 + + IL_0021: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::.ctor() + IL_0026: stloc.2 + IL_0027: ldloc.2 + IL_0028: ldloc.0 + IL_0029: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' + IL_002e: ldloc.2 + IL_002f: ldloc.1 + IL_0030: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0035: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_003a: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::.ctor() + IL_003f: stloc.3 + IL_0040: ldloc.3 + IL_0041: ldloc.2 + IL_0042: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0047: ldloc.3 + IL_0048: ldloc.3 + IL_0049: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_004e: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_0053: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::copyOfItem + IL_0058: ldloc.3 + IL_0059: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_005e: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_0063: ldc.i4.0 + IL_0064: ble.s IL_0076 + + IL_0066: ldloc.3 + IL_0067: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'b__0'() + IL_006d: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0072: stloc.s V_4 + IL_0074: leave.s IL_008c + + IL_0076: ldloc.1 + IL_0077: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() + IL_007c: brtrue.s IL_0021 + + IL_007e: leave.s IL_008a + + } // end .try + finally + { + IL_0080: ldloc.1 + IL_0081: brfalse.s IL_0089 + + IL_0083: ldloc.1 + IL_0084: callvirt instance void [mscorlib]System.IDisposable::Dispose() + IL_0089: endfinally + } // end handler + IL_008a: ldnull + IL_008b: ret + + IL_008c: ldloc.s V_4 + IL_008e: ret + } // end of method InstanceTests::CaptureOfThisAndParameterInForEachWithItemCopy + + .method public hidebysig instance void + LambdaInForLoop() cil managed + { + // Code size 35 (0x23) + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_001a + + IL_0004: ldarg.0 + IL_0005: ldarg.0 + IL_0006: ldftn instance int32 DelegateConstruction/InstanceTests::'b__4_0'() + IL_000c: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0011: call instance void DelegateConstruction/InstanceTests::Bar(class [mscorlib]System.Func`1) + IL_0016: ldloc.0 + IL_0017: ldc.i4.1 + IL_0018: add + IL_0019: stloc.0 + IL_001a: ldloc.0 + IL_001b: ldc.i4 0x186a0 + IL_0020: blt.s IL_0004 + + IL_0022: ret + } // end of method InstanceTests::LambdaInForLoop + + .method public hidebysig instance int32 + Foo() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } // end of method InstanceTests::Foo + + .method public hidebysig instance void + Bar(class [mscorlib]System.Func`1 f) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method InstanceTests::Bar + + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method InstanceTests::.ctor + + .method private hidebysig instance void + 'b__0_0'() 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: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThis() + IL_0006: pop + IL_0007: ret + } // end of method InstanceTests::'b__0_0' + + .method private hidebysig instance int32 + 'b__4_0'() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance int32 DelegateConstruction/InstanceTests::Foo() + IL_0006: ret + } // end of method InstanceTests::'b__4_0' + + } // end of class InstanceTests + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass8_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 counter + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass8_0'::.ctor + + .method assembly hidebysig instance void + 'b__0'(int32 x) cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 DelegateConstruction/'<>c__DisplayClass8_0'::counter + IL_0007: ret + } // end of method '<>c__DisplayClass8_0'::'b__0' + + } // end of class '<>c__DisplayClass8_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass9_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 counter + .field public class [mscorlib]System.Action`1 '<>9__0' + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass9_0'::.ctor + + .method assembly hidebysig instance void + 'b__0'(int32 x) cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 DelegateConstruction/'<>c__DisplayClass9_0'::counter + IL_0007: ret + } // end of method '<>c__DisplayClass9_0'::'b__0' + + } // end of class '<>c__DisplayClass9_0' + + .class auto ansi serializable sealed nested private beforefieldinit '<>c' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public static initonly class DelegateConstruction/'<>c' '<>9' + .field public static class [mscorlib]System.Action '<>9__10_0' + .field public static class [mscorlib]System.Action`1 '<>9__12_0' + .field public static class [mscorlib]System.Action`1 '<>9__13_0' + .method private hidebysig specialname rtspecialname static + void .cctor() cil managed + { + // Code size 11 (0xb) + .maxstack 8 + IL_0000: newobj instance void DelegateConstruction/'<>c'::.ctor() + IL_0005: stsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' + IL_000a: ret + } // end of method '<>c'::.cctor + + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c'::.ctor + + .method assembly hidebysig instance void + 'b__10_0'() cil managed + { + // Code size 6 (0x6) + .maxstack 8 + IL_0000: call void [mscorlib]System.Console::WriteLine() + IL_0005: ret + } // end of method '<>c'::'b__10_0' + + .method assembly hidebysig instance void + 'b__12_0'(int32 i) cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: call void [mscorlib]System.Console::WriteLine(int32) + IL_0006: ret + } // end of method '<>c'::'b__12_0' + + .method assembly hidebysig instance void + 'b__13_0'(int32 j) cil managed + { + // Code size 19 (0x13) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_000e + + IL_0004: ldloc.0 + IL_0005: call void [mscorlib]System.Console::WriteLine(int32) + IL_000a: ldloc.0 + IL_000b: ldc.i4.1 + IL_000c: add + IL_000d: stloc.0 + IL_000e: ldloc.0 + IL_000f: ldarg.1 + IL_0010: blt.s IL_0004 + + IL_0012: ret + } // end of method '<>c'::'b__13_0' + + } // end of class '<>c' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass11_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 i + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass11_0'::.ctor + + .method assembly hidebysig instance void + 'b__0'(int32 j) cil managed + { + // Code size 23 (0x17) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_000d + + IL_0004: call void [mscorlib]System.Console::WriteLine() + IL_0009: ldloc.0 + IL_000a: ldarg.1 + IL_000b: add + IL_000c: stloc.0 + IL_000d: ldloc.0 + IL_000e: ldarg.0 + IL_000f: ldfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0014: blt.s IL_0004 + + IL_0016: ret + } // end of method '<>c__DisplayClass11_0'::'b__0' + + } // end of class '<>c__DisplayClass11_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass14_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass14_0'::.ctor + + .method assembly hidebysig instance class [mscorlib]System.Func`2 + 'b__0'(int32 b) cil managed + { + // Code size 31 (0x1f) + .maxstack 8 + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass14_1'::.ctor() + IL_0005: dup + IL_0006: ldarg.0 + IL_0007: stfld class DelegateConstruction/'<>c__DisplayClass14_0' DelegateConstruction/'<>c__DisplayClass14_1'::'CS$<>8__locals1' + IL_000c: dup + IL_000d: ldarg.1 + IL_000e: stfld int32 DelegateConstruction/'<>c__DisplayClass14_1'::b + IL_0013: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass14_1'::'b__1'(int32) + IL_0019: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_001e: ret + } // end of method '<>c__DisplayClass14_0'::'b__0' + + } // end of class '<>c__DisplayClass14_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass14_1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 b + .field public class DelegateConstruction/'<>c__DisplayClass14_0' 'CS$<>8__locals1' + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass14_1'::.ctor + + .method assembly hidebysig instance int32 + 'b__1'(int32 c) cil managed + { + // Code size 21 (0x15) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass14_0' DelegateConstruction/'<>c__DisplayClass14_1'::'CS$<>8__locals1' + IL_0006: ldfld int32 DelegateConstruction/'<>c__DisplayClass14_0'::a + IL_000b: ldarg.0 + IL_000c: ldfld int32 DelegateConstruction/'<>c__DisplayClass14_1'::b + IL_0011: add + IL_0012: ldarg.1 + IL_0013: add + IL_0014: ret + } // end of method '<>c__DisplayClass14_1'::'b__1' + + } // end of class '<>c__DisplayClass14_1' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass15_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 a + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass15_0'::.ctor + + .method assembly hidebysig instance class [mscorlib]System.Func`2> + 'b__0'(int32 b) cil managed + { + // Code size 31 (0x1f) + .maxstack 8 + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass15_1'::.ctor() + IL_0005: dup + IL_0006: ldarg.0 + IL_0007: stfld class DelegateConstruction/'<>c__DisplayClass15_0' DelegateConstruction/'<>c__DisplayClass15_1'::'CS$<>8__locals1' + IL_000c: dup + IL_000d: ldarg.1 + IL_000e: stfld int32 DelegateConstruction/'<>c__DisplayClass15_1'::b + IL_0013: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass15_1'::'b__1'(int32) + IL_0019: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, + native int) + IL_001e: ret + } // end of method '<>c__DisplayClass15_0'::'b__0' + + } // end of class '<>c__DisplayClass15_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass15_1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 b + .field public class DelegateConstruction/'<>c__DisplayClass15_0' 'CS$<>8__locals1' + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass15_1'::.ctor + + .method assembly hidebysig instance class [mscorlib]System.Func`2 + 'b__1'(int32 c) cil managed + { + // Code size 31 (0x1f) + .maxstack 8 + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass15_2'::.ctor() + IL_0005: dup + IL_0006: ldarg.0 + IL_0007: stfld class DelegateConstruction/'<>c__DisplayClass15_1' DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' + IL_000c: dup + IL_000d: ldarg.1 + IL_000e: stfld int32 DelegateConstruction/'<>c__DisplayClass15_2'::c + IL_0013: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass15_2'::'b__2'(int32) + IL_0019: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_001e: ret + } // end of method '<>c__DisplayClass15_1'::'b__1' + + } // end of class '<>c__DisplayClass15_1' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass15_2' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 c + .field public class DelegateConstruction/'<>c__DisplayClass15_1' 'CS$<>8__locals2' + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c__DisplayClass15_2'::.ctor + + .method assembly hidebysig instance int32 + 'b__2'(int32 d) cil managed + { + // Code size 38 (0x26) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass15_1' DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' + IL_0006: ldfld class DelegateConstruction/'<>c__DisplayClass15_0' DelegateConstruction/'<>c__DisplayClass15_1'::'CS$<>8__locals1' + IL_000b: ldfld int32 DelegateConstruction/'<>c__DisplayClass15_0'::a + IL_0010: ldarg.0 + IL_0011: ldfld class DelegateConstruction/'<>c__DisplayClass15_1' DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' + IL_0016: ldfld int32 DelegateConstruction/'<>c__DisplayClass15_1'::b + IL_001b: add + IL_001c: ldarg.0 + IL_001d: ldfld int32 DelegateConstruction/'<>c__DisplayClass15_2'::c + IL_0022: add + IL_0023: ldarg.1 + IL_0024: add + IL_0025: ret + } // end of method '<>c__DisplayClass15_2'::'b__2' + + } // end of class '<>c__DisplayClass15_2' + + .method public hidebysig static void Test(string a) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method DelegateConstruction::Test + + .method public hidebysig static class [mscorlib]System.Action`1 + ExtensionMethodUnbound() cil managed + { + // Code size 13 (0xd) + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void DelegateConstruction::Test(string) + IL_0007: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000c: ret + } // end of method DelegateConstruction::ExtensionMethodUnbound + + .method public hidebysig static class [mscorlib]System.Action + ExtensionMethodBound() cil managed + { + // Code size 17 (0x11) + .maxstack 8 + IL_0000: ldstr "abc" + IL_0005: ldftn void DelegateConstruction::Test(string) + IL_000b: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0010: ret + } // end of method DelegateConstruction::ExtensionMethodBound + + .method public hidebysig static class [mscorlib]System.Action + ExtensionMethodBoundOnNull() cil managed + { + // Code size 13 (0xd) + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void DelegateConstruction::Test(string) + IL_0007: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_000c: ret + } // end of method DelegateConstruction::ExtensionMethodBoundOnNull + + .method public hidebysig static object + StaticMethod() cil managed + { + // Code size 13 (0xd) + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn class [mscorlib]System.Action DelegateConstruction::ExtensionMethodBound() + IL_0007: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_000c: ret + } // end of method DelegateConstruction::StaticMethod + + .method public hidebysig static object + InstanceMethod() cil managed + { + // Code size 17 (0x11) + .maxstack 8 + IL_0000: ldstr "hello" + IL_0005: ldftn instance string [mscorlib]System.String::ToUpper() + IL_000b: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0010: ret + } // end of method DelegateConstruction::InstanceMethod + + .method public hidebysig static object + InstanceMethodOnNull() cil managed + { + // Code size 13 (0xd) + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn instance string [mscorlib]System.String::ToUpper() + IL_0007: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_000c: ret + } // end of method DelegateConstruction::InstanceMethodOnNull + + .method public hidebysig static class [mscorlib]System.Collections.Generic.List`1> + AnonymousMethodStoreWithinLoop() cil managed + { + // Code size 45 (0x2d) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1, + class DelegateConstruction/'<>c__DisplayClass8_0' V_2) + IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0005: stloc.0 + IL_0006: ldc.i4.0 + IL_0007: stloc.1 + IL_0008: br.s IL_0026 + + IL_000a: newobj instance void DelegateConstruction/'<>c__DisplayClass8_0'::.ctor() + IL_000f: stloc.2 + IL_0010: ldloc.0 + IL_0011: ldloc.2 + IL_0012: ldftn instance void DelegateConstruction/'<>c__DisplayClass8_0'::'b__0'(int32) + IL_0018: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_001d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_0022: ldloc.1 + IL_0023: ldc.i4.1 + IL_0024: add + IL_0025: stloc.1 + IL_0026: ldloc.1 + IL_0027: ldc.i4.s 10 + IL_0029: blt.s IL_000a + + IL_002b: ldloc.0 + IL_002c: ret + } // end of method DelegateConstruction::AnonymousMethodStoreWithinLoop + + .method public hidebysig static class [mscorlib]System.Collections.Generic.List`1> + AnonymousMethodStoreOutsideLoop() cil managed + { + // Code size 64 (0x40) + .maxstack 4 + .locals init (class DelegateConstruction/'<>c__DisplayClass9_0' V_0, + class [mscorlib]System.Collections.Generic.List`1> V_1, + int32 V_2, + class [mscorlib]System.Action`1 V_3) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass9_0'::.ctor() + IL_0005: stloc.0 + IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_000b: stloc.1 + IL_000c: ldc.i4.0 + IL_000d: stloc.2 + IL_000e: br.s IL_0039 + + IL_0010: ldloc.1 + IL_0011: ldloc.0 + IL_0012: ldfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c__DisplayClass9_0'::'<>9__0' + IL_0017: dup + IL_0018: brtrue.s IL_0030 + + IL_001a: pop + IL_001b: ldloc.0 + IL_001c: ldloc.0 + IL_001d: ldftn instance void DelegateConstruction/'<>c__DisplayClass9_0'::'b__0'(int32) + IL_0023: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0028: dup + IL_0029: stloc.3 + IL_002a: stfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c__DisplayClass9_0'::'<>9__0' + IL_002f: ldloc.3 + IL_0030: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_0035: ldloc.2 + IL_0036: ldc.i4.1 + IL_0037: add + IL_0038: stloc.2 + IL_0039: ldloc.2 + IL_003a: ldc.i4.s 10 + IL_003c: blt.s IL_0010 + + IL_003e: ldloc.1 + IL_003f: ret + } // end of method DelegateConstruction::AnonymousMethodStoreOutsideLoop + + .method public hidebysig static class [mscorlib]System.Action + StaticAnonymousMethodNoClosure() cil managed + { + // Code size 32 (0x20) + .maxstack 8 + IL_0000: ldsfld class [mscorlib]System.Action DelegateConstruction/'<>c'::'<>9__10_0' + IL_0005: dup + IL_0006: brtrue.s IL_001f + + IL_0008: pop + IL_0009: ldsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' + IL_000e: ldftn instance void DelegateConstruction/'<>c'::'b__10_0'() + IL_0014: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0019: dup + IL_001a: stsfld class [mscorlib]System.Action DelegateConstruction/'<>c'::'<>9__10_0' + IL_001f: ret + } // end of method DelegateConstruction::StaticAnonymousMethodNoClosure + + .method public hidebysig static void NameConflict() cil managed + { + // Code size 79 (0x4f) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1, + class DelegateConstruction/'<>c__DisplayClass11_0' V_2, + int32 V_3) + IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0005: stloc.0 + IL_0006: ldc.i4.0 + IL_0007: stloc.1 + IL_0008: br.s IL_0049 + + IL_000a: newobj instance void DelegateConstruction/'<>c__DisplayClass11_0'::.ctor() + IL_000f: stloc.2 + IL_0010: ldloc.2 + IL_0011: ldc.i4.0 + IL_0012: stfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0017: br.s IL_003b + + IL_0019: ldloc.0 + IL_001a: ldloc.2 + IL_001b: ldftn instance void DelegateConstruction/'<>c__DisplayClass11_0'::'b__0'(int32) + IL_0021: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0026: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_002b: ldloc.2 + IL_002c: ldfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0031: stloc.3 + IL_0032: ldloc.2 + IL_0033: ldloc.3 + IL_0034: ldc.i4.1 + IL_0035: add + IL_0036: stfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_003b: ldloc.2 + IL_003c: ldfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0041: ldc.i4.s 10 + IL_0043: blt.s IL_0019 + + IL_0045: ldloc.1 + IL_0046: ldc.i4.1 + IL_0047: add + IL_0048: stloc.1 + IL_0049: ldloc.1 + IL_004a: ldc.i4.s 10 + IL_004c: blt.s IL_000a + + IL_004e: ret + } // end of method DelegateConstruction::NameConflict + + .method public hidebysig static void NameConflict2(int32 j) cil managed + { + // Code size 57 (0x39) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1) + IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0005: stloc.0 + IL_0006: ldc.i4.0 + IL_0007: stloc.1 + IL_0008: br.s IL_0033 + + IL_000a: ldloc.0 + IL_000b: ldsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__12_0' + IL_0010: dup + IL_0011: brtrue.s IL_002a + + IL_0013: pop + IL_0014: ldsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' + IL_0019: ldftn instance void DelegateConstruction/'<>c'::'b__12_0'(int32) + IL_001f: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0024: dup + IL_0025: stsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__12_0' + IL_002a: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_002f: ldloc.1 + IL_0030: ldc.i4.1 + IL_0031: add + IL_0032: stloc.1 + IL_0033: ldloc.1 + IL_0034: ldc.i4.s 10 + IL_0036: blt.s IL_000a + + IL_0038: ret + } // end of method DelegateConstruction::NameConflict2 + + .method public hidebysig static class [mscorlib]System.Action`1 + NameConflict3(int32 i) cil managed + { + // Code size 32 (0x20) + .maxstack 8 + IL_0000: ldsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__13_0' + IL_0005: dup + IL_0006: brtrue.s IL_001f + + IL_0008: pop + IL_0009: ldsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' + IL_000e: ldftn instance void DelegateConstruction/'<>c'::'b__13_0'(int32) + IL_0014: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0019: dup + IL_001a: stsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__13_0' + IL_001f: ret + } // end of method DelegateConstruction::NameConflict3 + + .method public hidebysig static class [mscorlib]System.Func`2> + CurriedAddition(int32 a) cil managed + { + // Code size 24 (0x18) + .maxstack 8 + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass14_0'::.ctor() + IL_0005: dup + IL_0006: ldarg.0 + IL_0007: stfld int32 DelegateConstruction/'<>c__DisplayClass14_0'::a + IL_000c: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass14_0'::'b__0'(int32) + IL_0012: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, + native int) + IL_0017: ret + } // end of method DelegateConstruction::CurriedAddition + + .method public hidebysig static class [mscorlib]System.Func`2>> + CurriedAddition2(int32 a) cil managed + { + // Code size 24 (0x18) + .maxstack 8 + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass15_0'::.ctor() + IL_0005: dup + IL_0006: ldarg.0 + IL_0007: stfld int32 DelegateConstruction/'<>c__DisplayClass15_0'::a + IL_000c: ldftn instance class [mscorlib]System.Func`2> DelegateConstruction/'<>c__DisplayClass15_0'::'b__0'(int32) + IL_0012: newobj instance void class [mscorlib]System.Func`2>>::.ctor(object, + native int) + IL_0017: ret + } // end of method DelegateConstruction::CurriedAddition2 + +} // end of class DelegateConstruction + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.roslyn.il new file mode 100644 index 000000000..e793c66c1 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.roslyn.il @@ -0,0 +1,1362 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly extern System.Core +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly DelegateConstruction +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module DelegateConstruction.dll +// MVID: {518B81C1-649D-4492-9DBC-30B3EB1721A3} +.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: 0x01670000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public abstract auto ansi sealed beforefieldinit DelegateConstruction + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .class auto ansi nested private beforefieldinit InstanceTests + extends [mscorlib]System.Object + { + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 a + .field public class DelegateConstruction/InstanceTests '<>4__this' + .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 '<>c__DisplayClass1_0'::.ctor + + .method assembly hidebysig instance void + 'b__0'() cil managed + { + // Code size 20 (0x14) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'<>4__this' + IL_0007: ldarg.0 + IL_0008: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::a + IL_000d: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0012: pop + IL_0013: ret + } // end of method '<>c__DisplayClass1_0'::'b__0' + + } // end of class '<>c__DisplayClass1_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass2_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 item + .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' 'CS$<>8__locals1' + .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 '<>c__DisplayClass2_0'::.ctor + + .method assembly hidebysig instance void + 'b__0'() cil managed + { + // Code size 37 (0x25) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' + IL_0007: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::'<>4__this' + IL_000c: ldarg.0 + IL_000d: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item + IL_0012: ldarg.0 + IL_0013: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' + IL_0018: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::a + IL_001d: add + IL_001e: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0023: pop + IL_0024: ret + } // end of method '<>c__DisplayClass2_0'::'b__0' + + } // end of class '<>c__DisplayClass2_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass2_1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 a + .field public class DelegateConstruction/InstanceTests '<>4__this' + .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 '<>c__DisplayClass2_1'::.ctor + + } // end of class '<>c__DisplayClass2_1' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass3_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 item + .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' 'CS$<>8__locals1' + .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 '<>c__DisplayClass3_0'::.ctor + + } // end of class '<>c__DisplayClass3_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass3_1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 a + .field public class DelegateConstruction/InstanceTests '<>4__this' + .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 '<>c__DisplayClass3_1'::.ctor + + } // end of class '<>c__DisplayClass3_1' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass3_2' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 copyOfItem + .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' 'CS$<>8__locals2' + .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 '<>c__DisplayClass3_2'::.ctor + + .method assembly hidebysig instance void + 'b__0'() cil managed + { + // Code size 59 (0x3b) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0007: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' + IL_000c: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::'<>4__this' + IL_0011: ldarg.0 + IL_0012: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0017: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_001c: ldarg.0 + IL_001d: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0022: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' + IL_0027: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::a + IL_002c: add + IL_002d: ldarg.0 + IL_002e: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::copyOfItem + IL_0033: add + IL_0034: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0039: pop + IL_003a: ret + } // end of method '<>c__DisplayClass3_2'::'b__0' + + } // end of class '<>c__DisplayClass3_2' + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThis() cil managed + { + // Code size 18 (0x12) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldftn instance void DelegateConstruction/InstanceTests::'b__0_0'() + IL_0008: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: br.s IL_0010 + + IL_0010: ldloc.0 + IL_0011: ret + } // end of method InstanceTests::CaptureOfThis + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThisAndParameter(int32 a) cil managed + { + // Code size 38 (0x26) + .maxstack 2 + .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0' V_0, + class [mscorlib]System.Action V_1) + IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'<>4__this' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::a + IL_0014: nop + IL_0015: ldloc.0 + IL_0016: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'b__0'() + IL_001c: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0021: stloc.1 + IL_0022: br.s IL_0024 + + IL_0024: ldloc.1 + IL_0025: ret + } // end of method InstanceTests::CaptureOfThisAndParameter + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThisAndParameterInForEach(int32 a) cil managed + { + // Code size 121 (0x79) + .maxstack 2 + .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' V_0, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0' V_2, + bool V_3, + class [mscorlib]System.Action V_4) + IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::'<>4__this' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::a + IL_0014: nop + IL_0015: nop + IL_0016: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() + IL_001b: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0020: stloc.1 + .try + { + IL_0021: br.s IL_005c + + IL_0023: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::.ctor() + IL_0028: stloc.2 + IL_0029: ldloc.2 + IL_002a: ldloc.0 + IL_002b: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' + IL_0030: ldloc.2 + IL_0031: ldloc.1 + IL_0032: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0037: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item + IL_003c: nop + IL_003d: ldloc.2 + IL_003e: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item + IL_0043: ldc.i4.0 + IL_0044: cgt + IL_0046: stloc.3 + IL_0047: ldloc.3 + IL_0048: brfalse.s IL_005b + + IL_004a: nop + IL_004b: ldloc.2 + IL_004c: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'b__0'() + IL_0052: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0057: stloc.s V_4 + IL_0059: leave.s IL_0076 + + IL_005b: nop + IL_005c: ldloc.1 + IL_005d: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() + IL_0062: brtrue.s IL_0023 + + IL_0064: leave.s IL_0071 + + } // end .try + finally + { + IL_0066: ldloc.1 + IL_0067: brfalse.s IL_0070 + + IL_0069: ldloc.1 + IL_006a: callvirt instance void [mscorlib]System.IDisposable::Dispose() + IL_006f: nop + IL_0070: endfinally + } // end handler + IL_0071: ldnull + IL_0072: stloc.s V_4 + IL_0074: br.s IL_0076 + + IL_0076: ldloc.s V_4 + IL_0078: ret + } // end of method InstanceTests::CaptureOfThisAndParameterInForEach + + .method public hidebysig instance class [mscorlib]System.Action + CaptureOfThisAndParameterInForEachWithItemCopy(int32 a) cil managed + { + // Code size 158 (0x9e) + .maxstack 2 + .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' V_0, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' V_2, + class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2' V_3, + bool V_4, + class [mscorlib]System.Action V_5) + IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::'<>4__this' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::a + IL_0014: nop + IL_0015: nop + IL_0016: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() + IL_001b: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0020: stloc.1 + .try + { + IL_0021: br.s IL_0081 + + IL_0023: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::.ctor() + IL_0028: stloc.2 + IL_0029: ldloc.2 + IL_002a: ldloc.0 + IL_002b: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' + IL_0030: ldloc.2 + IL_0031: ldloc.1 + IL_0032: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0037: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_003c: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::.ctor() + IL_0041: stloc.3 + IL_0042: ldloc.3 + IL_0043: ldloc.2 + IL_0044: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0049: nop + IL_004a: ldloc.3 + IL_004b: ldloc.3 + IL_004c: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0051: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_0056: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::copyOfItem + IL_005b: ldloc.3 + IL_005c: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0061: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_0066: ldc.i4.0 + IL_0067: cgt + IL_0069: stloc.s V_4 + IL_006b: ldloc.s V_4 + IL_006d: brfalse.s IL_0080 + + IL_006f: nop + IL_0070: ldloc.3 + IL_0071: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'b__0'() + IL_0077: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_007c: stloc.s V_5 + IL_007e: leave.s IL_009b + + IL_0080: nop + IL_0081: ldloc.1 + IL_0082: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() + IL_0087: brtrue.s IL_0023 + + IL_0089: leave.s IL_0096 + + } // end .try + finally + { + IL_008b: ldloc.1 + IL_008c: brfalse.s IL_0095 + + IL_008e: ldloc.1 + IL_008f: callvirt instance void [mscorlib]System.IDisposable::Dispose() + IL_0094: nop + IL_0095: endfinally + } // end handler + IL_0096: ldnull + IL_0097: stloc.s V_5 + IL_0099: br.s IL_009b + + IL_009b: ldloc.s V_5 + IL_009d: ret + } // end of method InstanceTests::CaptureOfThisAndParameterInForEachWithItemCopy + + .method public hidebysig instance void + LambdaInForLoop() cil managed + { + // Code size 43 (0x2b) + .maxstack 3 + .locals init (int32 V_0, + bool V_1) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: stloc.0 + IL_0003: br.s IL_001e + + IL_0005: nop + IL_0006: ldarg.0 + IL_0007: ldarg.0 + IL_0008: ldftn instance int32 DelegateConstruction/InstanceTests::'b__4_0'() + IL_000e: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0013: call instance void DelegateConstruction/InstanceTests::Bar(class [mscorlib]System.Func`1) + IL_0018: nop + IL_0019: nop + IL_001a: ldloc.0 + IL_001b: ldc.i4.1 + IL_001c: add + IL_001d: stloc.0 + IL_001e: ldloc.0 + IL_001f: ldc.i4 0x186a0 + IL_0024: clt + IL_0026: stloc.1 + IL_0027: ldloc.1 + IL_0028: brtrue.s IL_0005 + + IL_002a: ret + } // end of method InstanceTests::LambdaInForLoop + + .method public hidebysig instance int32 + Foo() cil managed + { + // Code size 7 (0x7) + .maxstack 1 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: stloc.0 + IL_0003: br.s IL_0005 + + IL_0005: ldloc.0 + IL_0006: ret + } // end of method InstanceTests::Foo + + .method public hidebysig instance void + Bar(class [mscorlib]System.Func`1 f) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method InstanceTests::Bar + + .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 InstanceTests::.ctor + + .method private hidebysig instance void + 'b__0_0'() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 9 (0x9) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThis() + IL_0007: pop + IL_0008: ret + } // end of method InstanceTests::'b__0_0' + + .method private hidebysig instance int32 + 'b__4_0'() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance int32 DelegateConstruction/InstanceTests::Foo() + IL_0006: ret + } // end of method InstanceTests::'b__4_0' + + } // end of class InstanceTests + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass8_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 counter + .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 '<>c__DisplayClass8_0'::.ctor + + .method assembly hidebysig instance void + 'b__0'(int32 x) cil managed + { + // Code size 9 (0x9) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: stfld int32 DelegateConstruction/'<>c__DisplayClass8_0'::counter + IL_0008: ret + } // end of method '<>c__DisplayClass8_0'::'b__0' + + } // end of class '<>c__DisplayClass8_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass9_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 counter + .field public class [mscorlib]System.Action`1 '<>9__0' + .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 '<>c__DisplayClass9_0'::.ctor + + .method assembly hidebysig instance void + 'b__0'(int32 x) cil managed + { + // Code size 9 (0x9) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: stfld int32 DelegateConstruction/'<>c__DisplayClass9_0'::counter + IL_0008: ret + } // end of method '<>c__DisplayClass9_0'::'b__0' + + } // end of class '<>c__DisplayClass9_0' + + .class auto ansi serializable sealed nested private beforefieldinit '<>c' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public static initonly class DelegateConstruction/'<>c' '<>9' + .field public static class [mscorlib]System.Action '<>9__10_0' + .field public static class [mscorlib]System.Action`1 '<>9__12_0' + .field public static class [mscorlib]System.Action`1 '<>9__13_0' + .method private hidebysig specialname rtspecialname static + void .cctor() cil managed + { + // Code size 11 (0xb) + .maxstack 8 + IL_0000: newobj instance void DelegateConstruction/'<>c'::.ctor() + IL_0005: stsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' + IL_000a: ret + } // end of method '<>c'::.cctor + + .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 '<>c'::.ctor + + .method assembly hidebysig instance void + 'b__10_0'() cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: nop + IL_0001: call void [mscorlib]System.Console::WriteLine() + IL_0006: nop + IL_0007: ret + } // end of method '<>c'::'b__10_0' + + .method assembly hidebysig instance void + 'b__12_0'(int32 i) cil managed + { + // Code size 9 (0x9) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: call void [mscorlib]System.Console::WriteLine(int32) + IL_0007: nop + IL_0008: ret + } // end of method '<>c'::'b__12_0' + + .method assembly hidebysig instance void + 'b__13_0'(int32 j) cil managed + { + // Code size 27 (0x1b) + .maxstack 2 + .locals init (int32 V_0, + bool V_1) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: stloc.0 + IL_0003: br.s IL_0012 + + IL_0005: nop + IL_0006: ldloc.0 + IL_0007: call void [mscorlib]System.Console::WriteLine(int32) + IL_000c: nop + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldc.i4.1 + IL_0010: add + IL_0011: stloc.0 + IL_0012: ldloc.0 + IL_0013: ldarg.1 + IL_0014: clt + IL_0016: stloc.1 + IL_0017: ldloc.1 + IL_0018: brtrue.s IL_0005 + + IL_001a: ret + } // end of method '<>c'::'b__13_0' + + } // end of class '<>c' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass11_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 i + .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 '<>c__DisplayClass11_0'::.ctor + + .method assembly hidebysig instance void + 'b__0'(int32 j) cil managed + { + // Code size 31 (0x1f) + .maxstack 2 + .locals init (int32 V_0, + bool V_1) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: stloc.0 + IL_0003: br.s IL_0011 + + IL_0005: nop + IL_0006: call void [mscorlib]System.Console::WriteLine() + IL_000b: nop + IL_000c: nop + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: add + IL_0010: stloc.0 + IL_0011: ldloc.0 + IL_0012: ldarg.0 + IL_0013: ldfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0018: clt + IL_001a: stloc.1 + IL_001b: ldloc.1 + IL_001c: brtrue.s IL_0005 + + IL_001e: ret + } // end of method '<>c__DisplayClass11_0'::'b__0' + + } // end of class '<>c__DisplayClass11_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass14_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 a + .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 '<>c__DisplayClass14_0'::.ctor + + .method assembly hidebysig instance class [mscorlib]System.Func`2 + 'b__0'(int32 b) cil managed + { + // Code size 33 (0x21) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass14_1' V_0) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass14_1'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass14_0' DelegateConstruction/'<>c__DisplayClass14_1'::'CS$<>8__locals1' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass14_1'::b + IL_0014: ldloc.0 + IL_0015: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass14_1'::'b__1'(int32) + IL_001b: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0020: ret + } // end of method '<>c__DisplayClass14_0'::'b__0' + + } // end of class '<>c__DisplayClass14_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass14_1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 b + .field public class DelegateConstruction/'<>c__DisplayClass14_0' 'CS$<>8__locals1' + .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 '<>c__DisplayClass14_1'::.ctor + + .method assembly hidebysig instance int32 + 'b__1'(int32 c) cil managed + { + // Code size 21 (0x15) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass14_0' DelegateConstruction/'<>c__DisplayClass14_1'::'CS$<>8__locals1' + IL_0006: ldfld int32 DelegateConstruction/'<>c__DisplayClass14_0'::a + IL_000b: ldarg.0 + IL_000c: ldfld int32 DelegateConstruction/'<>c__DisplayClass14_1'::b + IL_0011: add + IL_0012: ldarg.1 + IL_0013: add + IL_0014: ret + } // end of method '<>c__DisplayClass14_1'::'b__1' + + } // end of class '<>c__DisplayClass14_1' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass15_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 a + .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 '<>c__DisplayClass15_0'::.ctor + + .method assembly hidebysig instance class [mscorlib]System.Func`2> + 'b__0'(int32 b) cil managed + { + // Code size 33 (0x21) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass15_1' V_0) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass15_1'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass15_0' DelegateConstruction/'<>c__DisplayClass15_1'::'CS$<>8__locals1' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass15_1'::b + IL_0014: ldloc.0 + IL_0015: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass15_1'::'b__1'(int32) + IL_001b: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, + native int) + IL_0020: ret + } // end of method '<>c__DisplayClass15_0'::'b__0' + + } // end of class '<>c__DisplayClass15_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass15_1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 b + .field public class DelegateConstruction/'<>c__DisplayClass15_0' 'CS$<>8__locals1' + .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 '<>c__DisplayClass15_1'::.ctor + + .method assembly hidebysig instance class [mscorlib]System.Func`2 + 'b__1'(int32 c) cil managed + { + // Code size 33 (0x21) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass15_2' V_0) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass15_2'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass15_1' DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass15_2'::c + IL_0014: ldloc.0 + IL_0015: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass15_2'::'b__2'(int32) + IL_001b: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0020: ret + } // end of method '<>c__DisplayClass15_1'::'b__1' + + } // end of class '<>c__DisplayClass15_1' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass15_2' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 c + .field public class DelegateConstruction/'<>c__DisplayClass15_1' 'CS$<>8__locals2' + .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 '<>c__DisplayClass15_2'::.ctor + + .method assembly hidebysig instance int32 + 'b__2'(int32 d) cil managed + { + // Code size 38 (0x26) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass15_1' DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' + IL_0006: ldfld class DelegateConstruction/'<>c__DisplayClass15_0' DelegateConstruction/'<>c__DisplayClass15_1'::'CS$<>8__locals1' + IL_000b: ldfld int32 DelegateConstruction/'<>c__DisplayClass15_0'::a + IL_0010: ldarg.0 + IL_0011: ldfld class DelegateConstruction/'<>c__DisplayClass15_1' DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' + IL_0016: ldfld int32 DelegateConstruction/'<>c__DisplayClass15_1'::b + IL_001b: add + IL_001c: ldarg.0 + IL_001d: ldfld int32 DelegateConstruction/'<>c__DisplayClass15_2'::c + IL_0022: add + IL_0023: ldarg.1 + IL_0024: add + IL_0025: ret + } // end of method '<>c__DisplayClass15_2'::'b__2' + + } // end of class '<>c__DisplayClass15_2' + + .method public hidebysig static void Test(string a) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method DelegateConstruction::Test + + .method public hidebysig static class [mscorlib]System.Action`1 + ExtensionMethodUnbound() cil managed + { + // Code size 18 (0x12) + .maxstack 2 + .locals init (class [mscorlib]System.Action`1 V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: ldftn void DelegateConstruction::Test(string) + IL_0008: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: br.s IL_0010 + + IL_0010: ldloc.0 + IL_0011: ret + } // end of method DelegateConstruction::ExtensionMethodUnbound + + .method public hidebysig static class [mscorlib]System.Action + ExtensionMethodBound() cil managed + { + // Code size 22 (0x16) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0) + IL_0000: nop + IL_0001: ldstr "abc" + IL_0006: ldftn void DelegateConstruction::Test(string) + IL_000c: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_0011: stloc.0 + IL_0012: br.s IL_0014 + + IL_0014: ldloc.0 + IL_0015: ret + } // end of method DelegateConstruction::ExtensionMethodBound + + .method public hidebysig static class [mscorlib]System.Action + ExtensionMethodBoundOnNull() cil managed + { + // Code size 18 (0x12) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: ldftn void DelegateConstruction::Test(string) + IL_0008: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: br.s IL_0010 + + IL_0010: ldloc.0 + IL_0011: ret + } // end of method DelegateConstruction::ExtensionMethodBoundOnNull + + .method public hidebysig static object + StaticMethod() cil managed + { + // Code size 18 (0x12) + .maxstack 2 + .locals init (object V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: ldftn class [mscorlib]System.Action DelegateConstruction::ExtensionMethodBound() + IL_0008: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: br.s IL_0010 + + IL_0010: ldloc.0 + IL_0011: ret + } // end of method DelegateConstruction::StaticMethod + + .method public hidebysig static object + InstanceMethod() cil managed + { + // Code size 22 (0x16) + .maxstack 2 + .locals init (object V_0) + IL_0000: nop + IL_0001: ldstr "hello" + IL_0006: ldftn instance string [mscorlib]System.String::ToUpper() + IL_000c: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0011: stloc.0 + IL_0012: br.s IL_0014 + + IL_0014: ldloc.0 + IL_0015: ret + } // end of method DelegateConstruction::InstanceMethod + + .method public hidebysig static object + InstanceMethodOnNull() cil managed + { + // Code size 18 (0x12) + .maxstack 2 + .locals init (object V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: ldftn instance string [mscorlib]System.String::ToUpper() + IL_0008: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_000d: stloc.0 + IL_000e: br.s IL_0010 + + IL_0010: ldloc.0 + IL_0011: ret + } // end of method DelegateConstruction::InstanceMethodOnNull + + .method public hidebysig static class [mscorlib]System.Collections.Generic.List`1> + AnonymousMethodStoreWithinLoop() cil managed + { + // Code size 59 (0x3b) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1, + class DelegateConstruction/'<>c__DisplayClass8_0' V_2, + bool V_3, + class [mscorlib]System.Collections.Generic.List`1> V_4) + IL_0000: nop + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: stloc.1 + IL_0009: br.s IL_002a + + IL_000b: newobj instance void DelegateConstruction/'<>c__DisplayClass8_0'::.ctor() + IL_0010: stloc.2 + IL_0011: nop + IL_0012: ldloc.0 + IL_0013: ldloc.2 + IL_0014: ldftn instance void DelegateConstruction/'<>c__DisplayClass8_0'::'b__0'(int32) + IL_001a: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_001f: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_0024: nop + IL_0025: nop + IL_0026: ldloc.1 + IL_0027: ldc.i4.1 + IL_0028: add + IL_0029: stloc.1 + IL_002a: ldloc.1 + IL_002b: ldc.i4.s 10 + IL_002d: clt + IL_002f: stloc.3 + IL_0030: ldloc.3 + IL_0031: brtrue.s IL_000b + + IL_0033: ldloc.0 + IL_0034: stloc.s V_4 + IL_0036: br.s IL_0038 + + IL_0038: ldloc.s V_4 + IL_003a: ret + } // end of method DelegateConstruction::AnonymousMethodStoreWithinLoop + + .method public hidebysig static class [mscorlib]System.Collections.Generic.List`1> + AnonymousMethodStoreOutsideLoop() cil managed + { + // Code size 80 (0x50) + .maxstack 4 + .locals init (class DelegateConstruction/'<>c__DisplayClass9_0' V_0, + class [mscorlib]System.Collections.Generic.List`1> V_1, + int32 V_2, + class [mscorlib]System.Action`1 V_3, + bool V_4, + class [mscorlib]System.Collections.Generic.List`1> V_5) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass9_0'::.ctor() + IL_0005: stloc.0 + IL_0006: nop + IL_0007: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_000c: stloc.1 + IL_000d: ldc.i4.0 + IL_000e: stloc.2 + IL_000f: br.s IL_003d + + IL_0011: nop + IL_0012: ldloc.1 + IL_0013: ldloc.0 + IL_0014: ldfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c__DisplayClass9_0'::'<>9__0' + IL_0019: dup + IL_001a: brtrue.s IL_0032 + + IL_001c: pop + IL_001d: ldloc.0 + IL_001e: ldloc.0 + IL_001f: ldftn instance void DelegateConstruction/'<>c__DisplayClass9_0'::'b__0'(int32) + IL_0025: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_002a: dup + IL_002b: stloc.3 + IL_002c: stfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c__DisplayClass9_0'::'<>9__0' + IL_0031: ldloc.3 + IL_0032: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_0037: nop + IL_0038: nop + IL_0039: ldloc.2 + IL_003a: ldc.i4.1 + IL_003b: add + IL_003c: stloc.2 + IL_003d: ldloc.2 + IL_003e: ldc.i4.s 10 + IL_0040: clt + IL_0042: stloc.s V_4 + IL_0044: ldloc.s V_4 + IL_0046: brtrue.s IL_0011 + + IL_0048: ldloc.1 + IL_0049: stloc.s V_5 + IL_004b: br.s IL_004d + + IL_004d: ldloc.s V_5 + IL_004f: ret + } // end of method DelegateConstruction::AnonymousMethodStoreOutsideLoop + + .method public hidebysig static class [mscorlib]System.Action + StaticAnonymousMethodNoClosure() cil managed + { + // Code size 37 (0x25) + .maxstack 2 + .locals init (class [mscorlib]System.Action V_0) + IL_0000: nop + IL_0001: ldsfld class [mscorlib]System.Action DelegateConstruction/'<>c'::'<>9__10_0' + IL_0006: dup + IL_0007: brtrue.s IL_0020 + + IL_0009: pop + IL_000a: ldsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' + IL_000f: ldftn instance void DelegateConstruction/'<>c'::'b__10_0'() + IL_0015: newobj instance void [mscorlib]System.Action::.ctor(object, + native int) + IL_001a: dup + IL_001b: stsfld class [mscorlib]System.Action DelegateConstruction/'<>c'::'<>9__10_0' + IL_0020: stloc.0 + IL_0021: br.s IL_0023 + + IL_0023: ldloc.0 + IL_0024: ret + } // end of method DelegateConstruction::StaticAnonymousMethodNoClosure + + .method public hidebysig static void NameConflict() cil managed + { + // Code size 97 (0x61) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1, + class DelegateConstruction/'<>c__DisplayClass11_0' V_2, + int32 V_3, + bool V_4, + bool V_5) + IL_0000: nop + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: stloc.1 + IL_0009: br.s IL_0055 + + IL_000b: newobj instance void DelegateConstruction/'<>c__DisplayClass11_0'::.ctor() + IL_0010: stloc.2 + IL_0011: nop + IL_0012: ldloc.2 + IL_0013: ldc.i4.0 + IL_0014: stfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0019: br.s IL_0040 + + IL_001b: nop + IL_001c: ldloc.0 + IL_001d: ldloc.2 + IL_001e: ldftn instance void DelegateConstruction/'<>c__DisplayClass11_0'::'b__0'(int32) + IL_0024: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0029: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_002e: nop + IL_002f: nop + IL_0030: ldloc.2 + IL_0031: ldfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0036: stloc.3 + IL_0037: ldloc.2 + IL_0038: ldloc.3 + IL_0039: ldc.i4.1 + IL_003a: add + IL_003b: stfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0040: ldloc.2 + IL_0041: ldfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0046: ldc.i4.s 10 + IL_0048: clt + IL_004a: stloc.s V_4 + IL_004c: ldloc.s V_4 + IL_004e: brtrue.s IL_001b + + IL_0050: nop + IL_0051: ldloc.1 + IL_0052: ldc.i4.1 + IL_0053: add + IL_0054: stloc.1 + IL_0055: ldloc.1 + IL_0056: ldc.i4.s 10 + IL_0058: clt + IL_005a: stloc.s V_5 + IL_005c: ldloc.s V_5 + IL_005e: brtrue.s IL_000b + + IL_0060: ret + } // end of method DelegateConstruction::NameConflict + + .method public hidebysig static void NameConflict2(int32 j) cil managed + { + // Code size 65 (0x41) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, + int32 V_1, + bool V_2) + IL_0000: nop + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: stloc.1 + IL_0009: br.s IL_0037 + + IL_000b: nop + IL_000c: ldloc.0 + IL_000d: ldsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__12_0' + IL_0012: dup + IL_0013: brtrue.s IL_002c + + IL_0015: pop + IL_0016: ldsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' + IL_001b: ldftn instance void DelegateConstruction/'<>c'::'b__12_0'(int32) + IL_0021: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0026: dup + IL_0027: stsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__12_0' + IL_002c: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) + IL_0031: nop + IL_0032: nop + IL_0033: ldloc.1 + IL_0034: ldc.i4.1 + IL_0035: add + IL_0036: stloc.1 + IL_0037: ldloc.1 + IL_0038: ldc.i4.s 10 + IL_003a: clt + IL_003c: stloc.2 + IL_003d: ldloc.2 + IL_003e: brtrue.s IL_000b + + IL_0040: ret + } // end of method DelegateConstruction::NameConflict2 + + .method public hidebysig static class [mscorlib]System.Action`1 + NameConflict3(int32 i) cil managed + { + // Code size 37 (0x25) + .maxstack 2 + .locals init (class [mscorlib]System.Action`1 V_0) + IL_0000: nop + IL_0001: ldsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__13_0' + IL_0006: dup + IL_0007: brtrue.s IL_0020 + + IL_0009: pop + IL_000a: ldsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' + IL_000f: ldftn instance void DelegateConstruction/'<>c'::'b__13_0'(int32) + IL_0015: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_001a: dup + IL_001b: stsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__13_0' + IL_0020: stloc.0 + IL_0021: br.s IL_0023 + + IL_0023: ldloc.0 + IL_0024: ret + } // end of method DelegateConstruction::NameConflict3 + + .method public hidebysig static class [mscorlib]System.Func`2> + CurriedAddition(int32 a) cil managed + { + // Code size 31 (0x1f) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass14_0' V_0, + class [mscorlib]System.Func`2> V_1) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass14_0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld int32 DelegateConstruction/'<>c__DisplayClass14_0'::a + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass14_0'::'b__0'(int32) + IL_0015: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, + native int) + IL_001a: stloc.1 + IL_001b: br.s IL_001d + + IL_001d: ldloc.1 + IL_001e: ret + } // end of method DelegateConstruction::CurriedAddition + + .method public hidebysig static class [mscorlib]System.Func`2>> + CurriedAddition2(int32 a) cil managed + { + // Code size 31 (0x1f) + .maxstack 2 + .locals init (class DelegateConstruction/'<>c__DisplayClass15_0' V_0, + class [mscorlib]System.Func`2>> V_1) + IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass15_0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld int32 DelegateConstruction/'<>c__DisplayClass15_0'::a + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldftn instance class [mscorlib]System.Func`2> DelegateConstruction/'<>c__DisplayClass15_0'::'b__0'(int32) + IL_0015: newobj instance void class [mscorlib]System.Func`2>>::.ctor(object, + native int) + IL_001a: stloc.1 + IL_001b: br.s IL_001d + + IL_001d: ldloc.1 + IL_001e: ret + } // end of method DelegateConstruction::CurriedAddition2 + +} // end of class DelegateConstruction + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** From 164f9b82a8e3d0fd437ab93fb5adb91a199314e9 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 9 Oct 2017 21:05:37 +0200 Subject: [PATCH 059/190] Fix DeclareVariables.FindInsertionPoint not treating lambda bodies as capture scopes --- .../CSharp/StatementBuilder.cs | 4 ++- .../CSharp/Transforms/DeclareVariables.cs | 26 ++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 0987baa21..45849368c 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -609,7 +609,9 @@ namespace ICSharpCode.Decompiler.CSharp breakTarget = oldBreakTarget; return loop; } else { - return ConvertBlockContainer(container, false); + var blockStmt = ConvertBlockContainer(container, false); + blockStmt.AddAnnotation(container); + return blockStmt; } } diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs b/ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs index 91386de38..d4959d99e 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs @@ -188,7 +188,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms #endregion #region FindInsertionPoints - List<(InsertionPoint InsertionPoint, BlockContainer Loop)> loopTracking = new List<(InsertionPoint, BlockContainer)>(); + List<(InsertionPoint InsertionPoint, BlockContainer Scope)> scopeTracking = new List<(InsertionPoint, BlockContainer)>(); /// /// Finds insertion points for all variables used within `node` @@ -202,25 +202,27 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms /// void FindInsertionPoints(AstNode node, int nodeLevel) { - BlockContainer loop = node.Annotation(); - if (loop != null) { - loopTracking.Add((new InsertionPoint { level = nodeLevel, nextNode = node }, loop)); + BlockContainer scope = node.Annotation(); + if (scope != null && (scope.EntryPoint.IncomingEdgeCount > 1 || scope.Parent is ILFunction)) { + // track loops and function bodies as scopes, for comparison with CaptureScope. + scopeTracking.Add((new InsertionPoint { level = nodeLevel, nextNode = node }, scope)); + } else { + scope = null; // don't remove a scope if we didn't add one } try { for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) { FindInsertionPoints(child, nodeLevel + 1); } - var identExpr = node as IdentifierExpression; - if (identExpr != null) { + if (node is IdentifierExpression identExpr) { var rr = identExpr.GetResolveResult() as ILVariableResolveResult; if (rr != null && VariableNeedsDeclaration(rr.Variable.Kind)) { var variable = rr.Variable; InsertionPoint newPoint; - int startIndex = loopTracking.Count - 1; - if (variable.CaptureScope != null && startIndex > -1 && variable.CaptureScope != loopTracking[startIndex].Loop) { - while (startIndex > -1 && loopTracking[startIndex].Loop != variable.CaptureScope) + int startIndex = scopeTracking.Count - 1; + if (variable.CaptureScope != null && startIndex > 0 && variable.CaptureScope != scopeTracking[startIndex].Scope) { + while (startIndex > 0 && scopeTracking[startIndex].Scope != variable.CaptureScope) startIndex--; - newPoint = loopTracking[startIndex + 1].InsertionPoint; + newPoint = scopeTracking[startIndex + 1].InsertionPoint; } else { newPoint = new InsertionPoint { level = nodeLevel, nextNode = identExpr }; } @@ -236,8 +238,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms } } } finally { - if (loop != null) - loopTracking.RemoveAt(loopTracking.Count - 1); + if (scope != null) + scopeTracking.RemoveAt(scopeTracking.Count - 1); } } From 3a29a7e1b6ae45fb53cb4efda1675535647ddbb8 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 9 Oct 2017 21:17:14 +0200 Subject: [PATCH 060/190] Fix Unit tests --- ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs index ae0b87b2d..6aab7ade1 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs @@ -88,7 +88,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty { protected internal override void Test(int a) { - Action action = (Action)delegate() { + Action action = (Action)delegate { base.Test(a); }; if (a.Equals(1)) { From e01ee3bf96956d574ad63fc41e21aa1d5785bd3e Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 9 Oct 2017 22:29:43 +0200 Subject: [PATCH 061/190] CallBuilder: Add support for extension methods capturing the first argument --- ICSharpCode.Decompiler/CSharp/CallBuilder.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index b50676a44..57793310d 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -322,31 +322,38 @@ namespace ICSharpCode.Decompiler.CSharp method = ((LdVirtFtn)func).Method; break; default: - method = (IMethod)typeSystem.Resolve(((ILFunction)func).Method); + method = typeSystem.Resolve(((ILFunction)func).Method); break; } - var target = expressionBuilder.TranslateTarget(method, inst.Arguments[0], func.OpCode == OpCode.LdFtn); + var invokeMethod = inst.Method.DeclaringType.GetDelegateInvokeMethod(); + TranslatedExpression target; + IType targetType; + if (method.IsExtensionMethod && invokeMethod != null && method.Parameters.Count - 1 == invokeMethod.Parameters.Count) { + target = expressionBuilder.Translate(inst.Arguments[0]); + targetType = method.Parameters[0].Type; + } else { + target = expressionBuilder.TranslateTarget(method, inst.Arguments[0], func.OpCode == OpCode.LdFtn); + targetType = method.DeclaringType; + } var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly); var or = new OverloadResolution(resolver.Compilation, method.Parameters.SelectArray(p => new TypeResolveResult(p.Type))); var result = lookup.Lookup(target.ResolveResult, method.Name, method.TypeArguments, true) as MethodGroupResolveResult; if (result == null) { - target = target.ConvertTo(method.DeclaringType, expressionBuilder); + target = target.ConvertTo(targetType, expressionBuilder); } else { or.AddMethodLists(result.MethodsGroupedByDeclaringType.ToArray()); if (or.BestCandidateErrors != OverloadResolutionErrors.None || !IsAppropriateCallTarget(method, or.BestCandidate, func.OpCode == OpCode.LdVirtFtn)) - target = target.ConvertTo(method.DeclaringType, expressionBuilder); + target = target.ConvertTo(targetType, expressionBuilder); } var mre = new MemberReferenceExpression(target, method.Name); mre.TypeArguments.AddRange(method.TypeArguments.Select(expressionBuilder.ConvertType)); var oce = new ObjectCreateExpression(expressionBuilder.ConvertType(inst.Method.DeclaringType), mre) - // .WithAnnotation(new DelegateConstruction.Annotation(func.OpCode == OpCode.LdVirtFtn, target, method.Name)) .WithILInstruction(inst) .WithRR(new ConversionResolveResult( inst.Method.DeclaringType, new MemberResolveResult(target.ResolveResult, method), - // TODO handle extension methods capturing the first argument Conversion.MethodGroupConversion(method, func.OpCode == OpCode.LdVirtFtn, false))); if (func is ILFunction) { From 2f57b8c3c16afb6c25bf32ee3194a6fcbe2abde3 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 9 Oct 2017 22:50:47 +0200 Subject: [PATCH 062/190] Fix ILAst ldfld/stfld pretty-printing. --- .../IL/Instructions/MemoryInstructions.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Instructions/MemoryInstructions.cs b/ICSharpCode.Decompiler/IL/Instructions/MemoryInstructions.cs index de52425b3..bc8236d05 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/MemoryInstructions.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/MemoryInstructions.cs @@ -44,7 +44,7 @@ namespace ICSharpCode.Decompiler.IL output.Write("ldfld "); Disassembler.DisassemblerHelpers.WriteOperand(output, field); output.Write('('); - this.target.WriteTo(output, options); + target.WriteTo(output, options); output.Write(')'); return; } else if (this.MatchLdsFld(out field)) { @@ -66,16 +66,16 @@ namespace ICSharpCode.Decompiler.IL output.Write("stfld "); Disassembler.DisassemblerHelpers.WriteOperand(output, field); output.Write('('); - this.target.WriteTo(output, options); + target.WriteTo(output, options); output.Write(", "); - this.value.WriteTo(output, options); + value.WriteTo(output, options); output.Write(')'); return; } else if (this.MatchStsFld(out field, out value)) { output.Write("stsfld "); Disassembler.DisassemblerHelpers.WriteOperand(output, field); output.Write('('); - this.value.WriteTo(output, options); + value.WriteTo(output, options); output.Write(')'); return; } From 23bf8561320593f90042333aa7be75faafd86d7a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 9 Oct 2017 23:20:52 +0200 Subject: [PATCH 063/190] Fix bug in TransformPostIncDecOperatorOnAddress --- ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs index 5d41bb402..a69b91d8d 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs @@ -299,6 +299,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms bool TransformPostIncDecOperatorOnAddress(Block block, int i) { var inst = block.Instructions[i] as StLoc; + if (!inst.Variable.IsSingleDefinition || inst.Variable.LoadCount != 2) + return false; var nextInst = block.Instructions.ElementAtOrDefault(i + 1) as StLoc; var stobj = block.Instructions.ElementAtOrDefault(i + 2) as StObj; if (inst == null || nextInst == null || stobj == null) From f6ab796ba70d6efbf6f94fe4df0cce96ec887c20 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Tue, 10 Oct 2017 00:01:16 +0200 Subject: [PATCH 064/190] Add ldobj(ldloca) -> ldloc transform; and remove special case in ProxyCallReplacer. --- .../Transforms/EarlyExpressionTransforms.cs | 25 +++++++++++++++++-- .../IL/Transforms/ExpressionTransforms.cs | 8 +++++- .../IL/Transforms/ProxyCallReplacer.cs | 25 +------------------ 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs b/ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs index c48bc0655..e5b667734 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs @@ -54,9 +54,30 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (inst.Target.MatchLdLoca(out ILVariable v) && TypeUtils.IsCompatibleTypeForMemoryAccess(new ByReferenceType(v.Type), inst.Type) && inst.UnalignedPrefix == 0 - && !inst.IsVolatile) { + && !inst.IsVolatile) + { context.Step($"stobj(ldloca {v.Name}, ...) => stloc {v.Name}(...)", inst); - inst.ReplaceWith(new StLoc(v, inst.Value)); + inst.ReplaceWith(new StLoc(v, inst.Value) { ILRange = inst.ILRange }); + return true; + } + return false; + } + + protected internal override void VisitLdObj(LdObj inst) + { + base.VisitLdObj(inst); + LdObjToLdLoc(inst, context); + } + + internal static bool LdObjToLdLoc(LdObj inst, ILTransformContext context) + { + if (inst.Target.MatchLdLoca(out ILVariable v) + && TypeUtils.IsCompatibleTypeForMemoryAccess(new ByReferenceType(v.Type), inst.Type) + && inst.UnalignedPrefix == 0 + && !inst.IsVolatile) + { + context.Step($"ldobj(ldloca {v.Name}, ...) => ldloc {v.Name}(...)", inst); + inst.ReplaceWith(new LdLoc(v) { ILRange = inst.ILRange }); return true; } return false; diff --git a/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs b/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs index 4b97e7ac0..5256f7da7 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs @@ -275,7 +275,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms } return false; } - + + protected internal override void VisitLdObj(LdObj inst) + { + base.VisitLdObj(inst); + EarlyExpressionTransforms.LdObjToLdLoc(inst, context); + } + protected internal override void VisitStObj(StObj inst) { base.VisitStObj(inst); diff --git a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs index 1ea28340d..717d880cc 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs @@ -69,30 +69,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms Call newInst = (Call)call.Clone(); - newInst.Arguments.Clear(); - - if (inst.Arguments.Count > 0) { - ILInstruction thisArg = inst.Arguments[0]; - - // special handling for first argument (this) - the underlying issue may be somewhere else - // normally - // leave IL_0000(await(callvirt<> n__0(ldobj xxHandler(ldloca this), ldobj System.Net.Http.HttpRequestMessage(ldloca request), ldobj System.Threading.CancellationToken(ldloca cancellationToken)))) - // would be decompiled to - // return await((DelegatingHandler)this).SendAsync(request, cancellationToken); - // this changes it to - // return await base.SendAsync(request, cancellationToken); - if (thisArg.MatchLdObj(out ILInstruction loadedObject, out IType objectType) && - loadedObject.MatchLdLoca(out ILVariable loadedVar)) { - thisArg = new LdLoc(loadedVar); - } - - newInst.Arguments.Add(thisArg); - - // add everything except first argument - for (int i = 1; i < inst.Arguments.Count; i++) { - newInst.Arguments.Add(inst.Arguments[i]); - } - } + newInst.Arguments.ReplaceList(inst.Arguments); inst.ReplaceWith(newInst); } } From cf8d4936e650d3574c244a3a02e13f393e409af9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 Oct 2017 00:19:48 +0200 Subject: [PATCH 065/190] Fix regression in TransformPostIncDecOperatorOnAddress; Add pattern for Roslyn inc/dec operator on addresses --- .../IL/Transforms/TransformAssignment.cs | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs index a69b91d8d..7a2f2e7e9 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs @@ -47,6 +47,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms continue; if (TransformRoslynCompoundAssignmentCall(block, i)) continue; + if (TransformRoslynPostIncDecOperatorOnAddress(block, i)) + continue; } } @@ -299,12 +301,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms bool TransformPostIncDecOperatorOnAddress(Block block, int i) { var inst = block.Instructions[i] as StLoc; - if (!inst.Variable.IsSingleDefinition || inst.Variable.LoadCount != 2) - return false; var nextInst = block.Instructions.ElementAtOrDefault(i + 1) as StLoc; var stobj = block.Instructions.ElementAtOrDefault(i + 2) as StObj; if (inst == null || nextInst == null || stobj == null) return false; + if (!inst.Variable.IsSingleDefinition || inst.Variable.LoadCount != 2) + return false; if (!(inst.Value is LdElema || inst.Value is LdFlda || inst.Value is LdsFlda)) return false; ILInstruction target; @@ -323,7 +325,35 @@ namespace ICSharpCode.Decompiler.IL.Transforms block.Instructions.RemoveAt(i + 1); return true; } - + + /// + /// stloc l(ldobj(ldflda(target))) + /// stobj(ldflda(target), binary.op(ldloc l, ldc.i4 1)) + /// --> + /// compound.op.old(ldobj(ldflda(target)), ldc.i4 1) + /// + bool TransformRoslynPostIncDecOperatorOnAddress(Block block, int i) + { + var inst = block.Instructions[i] as StLoc; + var stobj = block.Instructions.ElementAtOrDefault(i + 1) as StObj; + if (inst == null || stobj == null) + return false; + if (!inst.Value.MatchLdObj(out var loadTarget, out var loadType) || !loadTarget.MatchLdFlda(out var fieldTarget, out var field)) + return false; + if (!stobj.Target.MatchLdFlda(out var fieldTarget2, out var field2)) + return false; + if (!fieldTarget.Match(fieldTarget2).Success || !field.Equals(field2)) + return false; + var binary = stobj.Value as BinaryNumericInstruction; + if (binary == null || !binary.Left.MatchLdLoc(inst.Variable) || !binary.Right.MatchLdcI4(1) + || (binary.Operator != BinaryNumericOperator.Add && binary.Operator != BinaryNumericOperator.Sub)) + return false; + context.Step($"TransformRoslynPostIncDecOperator", inst); + stobj.ReplaceWith(new CompoundAssignmentInstruction(binary, inst.Value, binary.Right, loadType, CompoundAssignmentType.EvaluatesToOldValue)); + block.Instructions.RemoveAt(i); + return true; + } + /// /// stloc s(ldflda) /// stloc s2(ldobj(ldflda(ldloc s))) From ab1598c5475dd945b3e165658988c78fedc16911 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 Oct 2017 00:50:23 +0200 Subject: [PATCH 066/190] Fix bug in TransformRoslynPostIncDecOperatorOnAddress; Add DelegateConstruction tests --- ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs | 2 +- .../IL/Transforms/DelegateConstruction.cs | 8 ++++++++ .../IL/Transforms/TransformAssignment.cs | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index b0afed891..483e1f3b0 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -97,7 +97,7 @@ namespace ICSharpCode.Decompiler.Tests Run(cscOptions: cscOptions); } - [Test, Ignore] + [Test] public void DelegateConstruction([ValueSource("defaultOptions")] CompilerOptions cscOptions) { Run(cscOptions: cscOptions); diff --git a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs index 6b0150216..da1a91382 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs @@ -319,6 +319,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms throw new NotImplementedException(); } } + + protected internal override void VisitCompoundAssignmentInstruction(CompoundAssignmentInstruction inst) + { + base.VisitCompoundAssignmentInstruction(inst); + if (inst.Target.MatchLdLoc(out var v)) { + inst.ReplaceWith(new StLoc(v, new BinaryNumericInstruction(inst.Operator, inst.Target, inst.Value, inst.CheckForOverflow, inst.Sign))); + } + } } #endregion } diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs index 7a2f2e7e9..a1de1bf3e 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs @@ -338,6 +338,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms var stobj = block.Instructions.ElementAtOrDefault(i + 1) as StObj; if (inst == null || stobj == null) return false; + if (!inst.Variable.IsSingleDefinition || inst.Variable.LoadCount != 1) + return false; if (!inst.Value.MatchLdObj(out var loadTarget, out var loadType) || !loadTarget.MatchLdFlda(out var fieldTarget, out var field)) return false; if (!stobj.Target.MatchLdFlda(out var fieldTarget2, out var field2)) @@ -348,7 +350,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (binary == null || !binary.Left.MatchLdLoc(inst.Variable) || !binary.Right.MatchLdcI4(1) || (binary.Operator != BinaryNumericOperator.Add && binary.Operator != BinaryNumericOperator.Sub)) return false; - context.Step($"TransformRoslynPostIncDecOperator", inst); + context.Step("TransformRoslynPostIncDecOperator", inst); stobj.ReplaceWith(new CompoundAssignmentInstruction(binary, inst.Value, binary.Right, loadType, CompoundAssignmentType.EvaluatesToOldValue)); block.Instructions.RemoveAt(i); return true; From 99f4d93d637cefcdbd57068be5bc072188cbb562 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 Oct 2017 01:44:31 +0200 Subject: [PATCH 067/190] Fix crash in InstructionCollection.IndexOf --- .../IL/Instructions/InstructionCollection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Instructions/InstructionCollection.cs b/ICSharpCode.Decompiler/IL/Instructions/InstructionCollection.cs index d0030a9bb..eb44716a8 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/InstructionCollection.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/InstructionCollection.cs @@ -135,14 +135,14 @@ namespace ICSharpCode.Decompiler.IL /// Returns -1 if the instruction does not exist in the collection. /// /// - /// Runs in O(1) is the item can be found using the Parent/ChildIndex properties. + /// Runs in O(1) if the item can be found using the Parent/ChildIndex properties. /// Otherwise, runs in O(N). /// public int IndexOf(T item) { // If this collection is the item's primary position, we can use ChildIndex: int index = item.ChildIndex - firstChildIndex; - if (index >= 0 && index <= list.Count && list[index] == item) + if (index >= 0 && index < list.Count && list[index] == item) return index; // But we still need to fall back on a full search, because the ILAst might be // in a state where item is in multiple locations. From 43f3b006a34cb57d14459db009da4e3d5b0b2bdc Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 Oct 2017 10:41:26 +0200 Subject: [PATCH 068/190] DelegateConstruction: Fix bug in that prevented all display class references from being removed. --- .../IL/Transforms/DelegateConstruction.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs index da1a91382..e94a5b216 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs @@ -46,9 +46,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (f != null) { call.Arguments[0].ReplaceWith(new Nop()); call.Arguments[1].ReplaceWith(f); + if (target is IInstructionWithVariableOperand && !target.MatchLdThis()) + targetsToReplace.Add((IInstructionWithVariableOperand)target); } - if (target is IInstructionWithVariableOperand && !target.MatchLdThis()) - targetsToReplace.Add((IInstructionWithVariableOperand)target); } ILVariable targetVariable; @@ -290,7 +290,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms base.VisitLdObj(inst); ILInstruction target; IField field; - if (!inst.Target.MatchLdFlda(out target, out field) || !MatchesTargetOrCopyLoad(target)) + if (!inst.Target.MatchLdFlda(out target, out field)) return; DisplayClassVariable info; if (!initValues.TryGetValue((IField)field.MemberDefinition, out info)) From ab7caaa2e2d86af8b8571eabd582aba222e4b5f9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 Oct 2017 10:43:27 +0200 Subject: [PATCH 069/190] DelegateConstruction: Clean up variable declarations --- .../IL/Transforms/DelegateConstruction.cs | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs index e94a5b216..1799528bb 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs @@ -41,8 +41,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms for (int i = block.Instructions.Count - 1; i >= 0; i--) { context.CancellationToken.ThrowIfCancellationRequested(); foreach (var call in block.Instructions[i].Descendants.OfType()) { - ILInstruction target; - ILFunction f = TransformDelegateConstruction(call, out target); + ILFunction f = TransformDelegateConstruction(call, out ILInstruction target); if (f != null) { call.Arguments[0].ReplaceWith(new Nop()); call.Arguments[1].ReplaceWith(f); @@ -50,10 +49,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms targetsToReplace.Add((IInstructionWithVariableOperand)target); } } - - ILVariable targetVariable; - ILInstruction value; - if (block.Instructions[i].MatchStLoc(out targetVariable, out value)) { + if (block.Instructions[i].MatchStLoc(out ILVariable targetVariable, out ILInstruction value)) { var newObj = value as NewObj; // TODO : it is probably not a good idea to remove *all* display-classes // is there a way to minimize the false-positives? @@ -261,14 +257,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms protected internal override void VisitStObj(StObj inst) { base.VisitStObj(inst); - ILInstruction target; - IField field; - if (!inst.Target.MatchLdFlda(out target, out field) || !MatchesTargetOrCopyLoad(target)) + if (!inst.Target.MatchLdFlda(out ILInstruction target, out IField field) || !MatchesTargetOrCopyLoad(target)) return; field = (IField)field.MemberDefinition; - DisplayClassVariable info; ILInstruction value; - if (initValues.TryGetValue(field, out info)) { + if (initValues.TryGetValue(field, out DisplayClassVariable info)) { inst.ReplaceWith(new StLoc(info.variable, inst.Value)); } else { if (inst.Value.MatchLdLoc(out var v) && v.Kind == VariableKind.Parameter && currentFunction == v.Function) { @@ -288,12 +281,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms protected internal override void VisitLdObj(LdObj inst) { base.VisitLdObj(inst); - ILInstruction target; - IField field; - if (!inst.Target.MatchLdFlda(out target, out field)) + if (!inst.Target.MatchLdFlda(out ILInstruction target, out IField field)) return; - DisplayClassVariable info; - if (!initValues.TryGetValue((IField)field.MemberDefinition, out info)) + if (!initValues.TryGetValue((IField)field.MemberDefinition, out DisplayClassVariable info)) return; inst.ReplaceWith(info.value.Clone()); } @@ -306,8 +296,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!MatchesTargetOrCopyLoad(inst.Target)) return; var field = (IField)inst.Field.MemberDefinition; - DisplayClassVariable info; - if (!initValues.TryGetValue(field, out info)) { + if (!initValues.TryGetValue(field, out DisplayClassVariable info)) { var v = currentFunction.RegisterVariable(VariableKind.Local, field.Type, field.Name); v.CaptureScope = captureScope; inst.ReplaceWith(new LdLoca(v)); From d61d026254cf9eeddcdf817e2c8e746b7be68c9d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 Oct 2017 11:04:19 +0200 Subject: [PATCH 070/190] Add LINQRaytracer test case --- .../CorrectnessTestRunner.cs | 6 + .../ICSharpCode.Decompiler.Tests.csproj | 1 + .../TestCases/Correctness/LINQRaytracer.cs | 390 ++++++++++++++++++ 3 files changed, 397 insertions(+) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Correctness/LINQRaytracer.cs diff --git a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs index d984705c6..e1e52288b 100644 --- a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs @@ -204,6 +204,12 @@ namespace ICSharpCode.Decompiler.Tests RunCS(options: options); } + [Test] + public void LINQRaytracer([ValueSource("defaultOptions")] CompilerOptions options) + { + RunCS(options: options); + } + void RunCS([CallerMemberName] string testName = null, CompilerOptions options = CompilerOptions.UseDebug) { string testFileName = testName + ".cs"; diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index f076a66e1..9227073bd 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -51,6 +51,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/LINQRaytracer.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/LINQRaytracer.cs new file mode 100644 index 000000000..3a2808a6c --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/LINQRaytracer.cs @@ -0,0 +1,390 @@ +// This test case is taken from https://blogs.msdn.microsoft.com/lukeh/2007/10/01/taking-linq-to-objects-to-extremes-a-fully-linqified-raytracer/ + +using System.Linq; +using System; +using System.Collections.Generic; + +namespace RayTracer +{ + public class RayTracer + { + static void Main() + { + const int width = 600; + const int height = 600; + + RayTracer rayTracer = new RayTracer(width, height, (int x, int y, Color color) => { + Console.Write("{0},{1}:{2};", x, y, color); + }); + rayTracer.Render(rayTracer.DefaultScene); + } + + private int screenWidth; + private int screenHeight; + private const int MaxDepth = 5; + + public Action setPixel; + + public RayTracer(int screenWidth, int screenHeight, Action setPixel) + { + this.screenWidth = screenWidth; + this.screenHeight = screenHeight; + this.setPixel = setPixel; + } + + private class Wrap + { + public readonly Func, T> It; + public Wrap(Func, T> it) { It = it; } + } + + public static Func Y(Func, Func> f) + { + Func>, Func> g = wx => f(wx.It(wx)); + return g(new Wrap>(wx => f(y => wx.It(wx)(y)))); + } + + class TraceRayArgs + { + public readonly Ray Ray; + public readonly Scene Scene; + public readonly int Depth; + + public TraceRayArgs(Ray ray, Scene scene, int depth) { Ray = ray; Scene = scene; Depth = depth; } + } + + internal void Render(Scene scene) + { + var pixelsQuery = + from y in Enumerable.Range(0, screenHeight) + let recenterY = -(y - (screenHeight / 2.0)) / (2.0 * screenHeight) + select from x in Enumerable.Range(0, screenWidth) + let recenterX = (x - (screenWidth / 2.0)) / (2.0 * screenWidth) + let point = + Vector.Norm(Vector.Plus(scene.Camera.Forward, + Vector.Plus(Vector.Times(recenterX, scene.Camera.Right), + Vector.Times(recenterY, scene.Camera.Up)))) + let ray = new Ray() { Start = scene.Camera.Pos, Dir = point } + let computeTraceRay = (Func, Func>) + (f => traceRayArgs => + (from isect in + from thing in traceRayArgs.Scene.Things + select thing.Intersect(traceRayArgs.Ray) + where isect != null + orderby isect.Dist + let d = isect.Ray.Dir + let pos = Vector.Plus(Vector.Times(isect.Dist, isect.Ray.Dir), isect.Ray.Start) + let normal = isect.Thing.Normal(pos) + let reflectDir = Vector.Minus(d, Vector.Times(2 * Vector.Dot(normal, d), normal)) + let naturalColors = + from light in traceRayArgs.Scene.Lights + let ldis = Vector.Minus(light.Pos, pos) + let livec = Vector.Norm(ldis) + let testRay = new Ray() { Start = pos, Dir = livec } + let testIsects = from inter in + from thing in traceRayArgs.Scene.Things + select thing.Intersect(testRay) + where inter != null + orderby inter.Dist + select inter + let testIsect = testIsects.FirstOrDefault() + let neatIsect = testIsect == null ? 0 : testIsect.Dist + let isInShadow = !((neatIsect > Vector.Mag(ldis)) || (neatIsect == 0)) + where !isInShadow + let illum = Vector.Dot(livec, normal) + let lcolor = illum > 0 ? Color.Times(illum, light.Color) : Color.Make(0, 0, 0) + let specular = Vector.Dot(livec, Vector.Norm(reflectDir)) + let scolor = specular > 0 + ? Color.Times(Math.Pow(specular, isect.Thing.Surface.Roughness), + light.Color) + : Color.Make(0, 0, 0) + select Color.Plus(Color.Times(isect.Thing.Surface.Diffuse(pos), lcolor), + Color.Times(isect.Thing.Surface.Specular(pos), scolor)) + let reflectPos = Vector.Plus(pos, Vector.Times(.001, reflectDir)) + let reflectColor = traceRayArgs.Depth >= MaxDepth + ? Color.Make(.5, .5, .5) + : Color.Times(isect.Thing.Surface.Reflect(reflectPos), + f(new TraceRayArgs(new Ray() { + Start = reflectPos, + Dir = reflectDir + }, + traceRayArgs.Scene, + traceRayArgs.Depth + 1))) + select naturalColors.Aggregate(reflectColor, + (color, natColor) => Color.Plus(color, natColor)) + ).DefaultIfEmpty(Color.Background).First()) + let traceRay = Y(computeTraceRay) + select new { X = x, Y = y, Color = traceRay(new TraceRayArgs(ray, scene, 0)) }; + + foreach (var row in pixelsQuery) + foreach (var pixel in row) + setPixel(pixel.X, pixel.Y, pixel.Color); + } + + internal readonly Scene DefaultScene = + new Scene() { + Things = new SceneObject[] { + new Plane() { + Norm = Vector.Make(0,1,0), + Offset = 0, + Surface = Surfaces.CheckerBoard + }, + new Sphere() { + Center = Vector.Make(0,1,0), + Radius = 1, + Surface = Surfaces.Shiny + }, + new Sphere() { + Center = Vector.Make(-1,.5,1.5), + Radius = .5, + Surface = Surfaces.Shiny + }}, + Lights = new Light[] { + new Light() { + Pos = Vector.Make(-2,2.5,0), + Color = Color.Make(.49,.07,.07) + }, + new Light() { + Pos = Vector.Make(1.5,2.5,1.5), + Color = Color.Make(.07,.07,.49) + }, + new Light() { + Pos = Vector.Make(1.5,2.5,-1.5), + Color = Color.Make(.07,.49,.071) + }, + new Light() { + Pos = Vector.Make(0,3.5,0), + Color = Color.Make(.21,.21,.35) + }}, + Camera = Camera.Create(Vector.Make(3, 2, 4), Vector.Make(-1, .5, 0)) + }; + } + + static class Surfaces + { + // Only works with X-Z plane. + public static readonly Surface CheckerBoard = + new Surface() { + Diffuse = pos => ((Math.Floor(pos.Z) + Math.Floor(pos.X)) % 2 != 0) + ? Color.Make(1, 1, 1) + : Color.Make(0, 0, 0), + Specular = pos => Color.Make(1, 1, 1), + Reflect = pos => ((Math.Floor(pos.Z) + Math.Floor(pos.X)) % 2 != 0) + ? .1 + : .7, + Roughness = 150 + }; + + + public static readonly Surface Shiny = + new Surface() { + Diffuse = pos => Color.Make(1, 1, 1), + Specular = pos => Color.Make(.5, .5, .5), + Reflect = pos => .6, + Roughness = 50 + }; + } + + class Vector + { + public readonly double X; + public readonly double Y; + public readonly double Z; + + public Vector(double x, double y, double z) { X = x; Y = y; Z = z; } + + public static Vector Make(double x, double y, double z) { return new Vector(x, y, z); } + public static Vector Times(double n, Vector v) + { + return new Vector(v.X * n, v.Y * n, v.Z * n); + } + public static Vector Minus(Vector v1, Vector v2) + { + return new Vector(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z); + } + public static Vector Plus(Vector v1, Vector v2) + { + return new Vector(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z); + } + public static double Dot(Vector v1, Vector v2) + { + return (v1.X * v2.X) + (v1.Y * v2.Y) + (v1.Z * v2.Z); + } + public static double Mag(Vector v) { return Math.Sqrt(Dot(v, v)); } + public static Vector Norm(Vector v) + { + double mag = Mag(v); + double div = mag == 0 ? double.PositiveInfinity : 1 / mag; + return Times(div, v); + } + public static Vector Cross(Vector v1, Vector v2) + { + return new Vector(((v1.Y * v2.Z) - (v1.Z * v2.Y)), + ((v1.Z * v2.X) - (v1.X * v2.Z)), + ((v1.X * v2.Y) - (v1.Y * v2.X))); + } + public static bool Equals(Vector v1, Vector v2) + { + return (v1.X == v2.X) && (v1.Y == v2.Y) && (v1.Z == v2.Z); + } + } + + public class Color + { + public double R; + public double G; + public double B; + + public Color(double r, double g, double b) { R = r; G = g; B = b; } + + public static Color Make(double r, double g, double b) { return new Color(r, g, b); } + + public static Color Times(double n, Color v) + { + return new Color(n * v.R, n * v.G, n * v.B); + } + public static Color Times(Color v1, Color v2) + { + return new Color(v1.R * v2.R, v1.G * v2.G, v1.B * v2.B); + } + + public static Color Plus(Color v1, Color v2) + { + return new Color(v1.R + v2.R, v1.G + v2.G, v1.B + v2.B); + } + public static Color Minus(Color v1, Color v2) + { + return new Color(v1.R - v2.R, v1.G - v2.G, v1.B - v2.B); + } + + public static readonly Color Background = Make(0, 0, 0); + public static readonly Color DefaultColor = Make(0, 0, 0); + + private double Legalize(double d) + { + return d > 1 ? 1 : d; + } + + public override string ToString() + { + return string.Format("[{0},{1},{2}]", R, G, B); + } + } + + class Ray + { + public Vector Start; + public Vector Dir; + } + + class ISect + { + public SceneObject Thing; + public Ray Ray; + public double Dist; + } + + class Surface + { + public Func Diffuse; + public Func Specular; + public Func Reflect; + public double Roughness; + } + + class Camera + { + public Vector Pos; + public Vector Forward; + public Vector Up; + public Vector Right; + + public static Camera Create(Vector pos, Vector lookAt) + { + Vector forward = Vector.Norm(Vector.Minus(lookAt, pos)); + Vector down = new Vector(0, -1, 0); + Vector right = Vector.Times(1.5, Vector.Norm(Vector.Cross(forward, down))); + Vector up = Vector.Times(1.5, Vector.Norm(Vector.Cross(forward, right))); + + return new Camera() { Pos = pos, Forward = forward, Up = up, Right = right }; + } + } + + class Light + { + public Vector Pos; + public Color Color; + } + + abstract class SceneObject + { + public Surface Surface; + public abstract ISect Intersect(Ray ray); + public abstract Vector Normal(Vector pos); + } + + class Sphere : SceneObject + { + public Vector Center; + public double Radius; + + public override ISect Intersect(Ray ray) + { + Vector eo = Vector.Minus(Center, ray.Start); + double v = Vector.Dot(eo, ray.Dir); + double dist; + if (v < 0) { + dist = 0; + } else { + double disc = Math.Pow(Radius, 2) - (Vector.Dot(eo, eo) - Math.Pow(v, 2)); + dist = disc < 0 ? 0 : v - Math.Sqrt(disc); + } + if (dist == 0) return null; + return new ISect() { + Thing = this, + Ray = ray, + Dist = dist + }; + } + + public override Vector Normal(Vector pos) + { + return Vector.Norm(Vector.Minus(pos, Center)); + } + } + + class Plane : SceneObject + { + public Vector Norm; + public double Offset; + + public override ISect Intersect(Ray ray) + { + double denom = Vector.Dot(Norm, ray.Dir); + if (denom > 0) return null; + return new ISect() { + Thing = this, + Ray = ray, + Dist = (Vector.Dot(Norm, ray.Start) + Offset) / (-denom) + }; + } + + public override Vector Normal(Vector pos) + { + return Norm; + } + } + + class Scene + { + public SceneObject[] Things; + public Light[] Lights; + public Camera Camera; + + public IEnumerable Intersect(Ray r) + { + return from thing in Things + select thing.Intersect(r); + } + } +} \ No newline at end of file From 7450a19a8e8ede3b37e73e6aad99f6b73694f244 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 Oct 2017 11:14:49 +0200 Subject: [PATCH 071/190] Add PR suffix in BuildTools/appveyor-install.ps1 --- BuildTools/appveyor-install.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/BuildTools/appveyor-install.ps1 b/BuildTools/appveyor-install.ps1 index ec98f7bcf..58b1801f9 100644 --- a/BuildTools/appveyor-install.ps1 +++ b/BuildTools/appveyor-install.ps1 @@ -23,9 +23,14 @@ if ($env:APPVEYOR_REPO_BRANCH -ne 'master') { } else { $branch = ""; } +if ($env:APPVEYOR_PULL_REQUEST_NUMBER) { + $suffix = "-pr$env:APPVEYOR_PULL_REQUEST_NUMBER"; +} else { + $suffix = ""; +} $revision = [Int32]::Parse((git rev-list --count "$baseCommit..HEAD")) + $baseCommitRev; $newVersion="$major.$minor.$build.$revision"; -$env:appveyor_build_version="$newVersion$branch$versionName"; -appveyor UpdateBuild -Version "$newVersion$branch$versionName"; \ No newline at end of file +$env:appveyor_build_version="$newVersion$branch$versionName$suffix"; +appveyor UpdateBuild -Version "$newVersion$branch$versionName$suffix"; \ No newline at end of file From 01c6f414f91d524d129b36f43aa6f4b18900a265 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 9 Oct 2017 14:43:29 +0200 Subject: [PATCH 072/190] Implement goto default in StatementBuilder --- .../CSharp/StatementBuilder.cs | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 12ba474aa..37705e265 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -83,7 +83,7 @@ namespace ICSharpCode.Decompiler.CSharp return new IfElseStatement(condition, trueStatement, falseStatement); } - CaseLabel CreateTypedCaseLabel(long i, IType type, string[] map = null) + ConstantResolveResult CreateTypedCaseLabel(long i, IType type, string[] map = null) { object value; if (type.IsKnownType(KnownTypeCode.Boolean)) { @@ -96,7 +96,7 @@ namespace ICSharpCode.Decompiler.CSharp } else { value = CSharpPrimitiveCast.Cast(ReflectionHelper.GetTypeCode(type), i, false); } - return new CaseLabel(exprBuilder.ConvertConstantValue(new ConstantResolveResult(type, value), allowImplicitConversion: true)); + return new ConstantResolveResult(type, value); } protected internal override Statement VisitSwitchInstruction(SwitchInstruction inst) @@ -109,6 +109,8 @@ namespace ICSharpCode.Decompiler.CSharp Debug.Assert(switchContainer.EntryPoint.IncomingEdgeCount == 1); var oldBreakTarget = breakTarget; breakTarget = switchContainer; // 'break' within a switch would only leave the switch + var oldCaseLabelMapping = caseLabelMapping; + caseLabelMapping = new Dictionary(); TranslatedExpression value; var strToInt = inst.Value as StringToInt; @@ -127,23 +129,53 @@ namespace ICSharpCode.Decompiler.CSharp } var stmt = new SwitchStatement() { Expression = value }; + Dictionary translationDictionary = new Dictionary(); + // initialize C# switch sections. foreach (var section in inst.Sections) { + // This is used in the block-label mapping. + ConstantResolveResult firstValueResolveResult; var astSection = new Syntax.SwitchSection(); + // Create case labels: if (section == defaultSection) { astSection.CaseLabels.Add(new CaseLabel()); + firstValueResolveResult = null; } else { + var values = section.Labels.Values.Select(i => CreateTypedCaseLabel(i, value.Type, strToInt?.Map)).ToArray(); if (section.HasNullLabel) { astSection.CaseLabels.Add(new CaseLabel(new NullReferenceExpression())); + firstValueResolveResult = new ConstantResolveResult(SpecialType.NullType, null); + } else { + Debug.Assert(values.Length > 0); + firstValueResolveResult = values[0]; } - astSection.CaseLabels.AddRange(section.Labels.Values.Select(i => CreateTypedCaseLabel(i, value.Type, strToInt?.Map))); + astSection.CaseLabels.AddRange(values.Select(label => new CaseLabel(exprBuilder.ConvertConstantValue(label, allowImplicitConversion: true)))); + } + switch (section.Body) { + case Branch br: + caseLabelMapping.Add(br.TargetBlock, firstValueResolveResult); + break; + default: + break; } - ConvertSwitchSectionBody(astSection, section.Body); + translationDictionary.Add(section, astSection); stmt.SwitchSections.Add(astSection); } + foreach (var section in inst.Sections) { + var astSection = translationDictionary[section]; + switch (section.Body) { + case Branch br: + ConvertSwitchSectionBody(astSection, br.TargetBlock); + break; + default: + ConvertSwitchSectionBody(astSection, section.Body); + break; + } + } if (switchContainer != null) { // Translate any remaining blocks: var lastSectionStatements = stmt.SwitchSections.Last().Statements; foreach (var block in switchContainer.Blocks.Skip(1)) { + if (caseLabelMapping.ContainsKey(block)) continue; lastSectionStatements.Add(new LabelStatement { Label = block.Label }); foreach (var nestedInst in block.Instructions) { var nestedStmt = Convert(nestedInst); @@ -163,6 +195,7 @@ namespace ICSharpCode.Decompiler.CSharp } breakTarget = oldBreakTarget; + caseLabelMapping = oldCaseLabelMapping; return stmt; } @@ -185,6 +218,8 @@ namespace ICSharpCode.Decompiler.CSharp Block continueTarget; /// Number of ContinueStatements that were created for the current continueTarget int continueCount; + /// Maps blocks to cases. + Dictionary caseLabelMapping; protected internal override Statement VisitBranch(Branch inst) { @@ -192,6 +227,11 @@ namespace ICSharpCode.Decompiler.CSharp continueCount++; return new ContinueStatement(); } + if (caseLabelMapping != null && caseLabelMapping.TryGetValue(inst.TargetBlock, out var label)) { + if (label == null) + return new GotoDefaultStatement(); + return new GotoCaseStatement() { LabelExpression = exprBuilder.ConvertConstantValue(label, allowImplicitConversion: true) }; + } return new GotoStatement(inst.TargetLabel); } From 4c44f05af169c1e1304c37b3bc53508d5da8b65a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 Oct 2017 13:06:13 +0200 Subject: [PATCH 073/190] Fix bug in StatementBuilder: do not inline blocks into switch case that are outside of the switchContainer. --- ICSharpCode.Decompiler/CSharp/StatementBuilder.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index cc5dd1d43..8cf20cfb8 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -152,7 +152,9 @@ namespace ICSharpCode.Decompiler.CSharp } switch (section.Body) { case Branch br: - caseLabelMapping.Add(br.TargetBlock, firstValueResolveResult); + // we can only inline the block, if all branches are in the switchContainer. + if (br.TargetBlock.IsDescendantOf(switchContainer)) + caseLabelMapping.Add(br.TargetBlock, firstValueResolveResult); break; default: break; @@ -164,7 +166,11 @@ namespace ICSharpCode.Decompiler.CSharp var astSection = translationDictionary[section]; switch (section.Body) { case Branch br: - ConvertSwitchSectionBody(astSection, br.TargetBlock); + // we can only inline the block, if all branches are in the switchContainer. + if (br.TargetBlock.IsDescendantOf(switchContainer)) + ConvertSwitchSectionBody(astSection, br.TargetBlock); + else + ConvertSwitchSectionBody(astSection, section.Body); break; default: ConvertSwitchSectionBody(astSection, section.Body); From 596fca2b373b60a59d4fb12b638037bb3eeb490b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 Oct 2017 16:35:06 +0200 Subject: [PATCH 074/190] Fix unit tests --- .../CSharp/StatementBuilder.cs | 4 ++-- .../ConnectMethodDecompiler.cs | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 8cf20cfb8..56fdfb6e9 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -153,7 +153,7 @@ namespace ICSharpCode.Decompiler.CSharp switch (section.Body) { case Branch br: // we can only inline the block, if all branches are in the switchContainer. - if (br.TargetBlock.IsDescendantOf(switchContainer)) + if (br.TargetBlock.Parent == switchContainer && switchContainer.Descendants.OfType().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestContainer(b) == switchContainer)) caseLabelMapping.Add(br.TargetBlock, firstValueResolveResult); break; default: @@ -167,7 +167,7 @@ namespace ICSharpCode.Decompiler.CSharp switch (section.Body) { case Branch br: // we can only inline the block, if all branches are in the switchContainer. - if (br.TargetBlock.IsDescendantOf(switchContainer)) + if (br.TargetBlock.Parent == switchContainer && switchContainer.Descendants.OfType().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestContainer(b) == switchContainer)) ConvertSwitchSectionBody(astSection, br.TargetBlock); else ConvertSwitchSectionBody(astSection, section.Body); diff --git a/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs b/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs index a28f63d7b..39ddba883 100644 --- a/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs +++ b/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs @@ -66,7 +66,7 @@ namespace ILSpy.BamlDecompiler function.RunTransforms(CSharpDecompiler.GetILTransforms(), context); var block = function.Body.Children.OfType().First(); - var ilSwitch = block.Children.OfType().FirstOrDefault(); + var ilSwitch = block.Descendants.OfType().FirstOrDefault(); if (ilSwitch != null) { foreach (var section in ilSwitch.Sections) { @@ -92,13 +92,18 @@ namespace ILSpy.BamlDecompiler { var events = new List(); - if (inst is Block) { - foreach (var node in ((Block)inst).Instructions) { - FindEvents(node, events); - } - FindEvents(((Block)inst).FinalInstruction, events); - } else { - FindEvents(inst, events); + switch (inst) { + case Block b: + foreach (var node in ((Block)inst).Instructions) { + FindEvents(node, events); + } + FindEvents(((Block)inst).FinalInstruction, events); + break; + case Branch br: + return FindEvents(br.TargetBlock); + default: + FindEvents(inst, events); + break; } return events.ToArray(); } From 403a79099a579c9092bcdfcf48c2db187b8d56c5 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 Oct 2017 22:39:57 +0200 Subject: [PATCH 075/190] Introduce BlockContainer.FindClosestSwitchContainer --- ICSharpCode.Decompiler/CSharp/StatementBuilder.cs | 4 ++-- .../IL/Instructions/BlockContainer.cs | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 56fdfb6e9..91ca8d309 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -153,7 +153,7 @@ namespace ICSharpCode.Decompiler.CSharp switch (section.Body) { case Branch br: // we can only inline the block, if all branches are in the switchContainer. - if (br.TargetBlock.Parent == switchContainer && switchContainer.Descendants.OfType().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestContainer(b) == switchContainer)) + if (br.TargetBlock.Parent == switchContainer && switchContainer.Descendants.OfType().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestSwitchContainer(b) == switchContainer)) caseLabelMapping.Add(br.TargetBlock, firstValueResolveResult); break; default: @@ -167,7 +167,7 @@ namespace ICSharpCode.Decompiler.CSharp switch (section.Body) { case Branch br: // we can only inline the block, if all branches are in the switchContainer. - if (br.TargetBlock.Parent == switchContainer && switchContainer.Descendants.OfType().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestContainer(b) == switchContainer)) + if (br.TargetBlock.Parent == switchContainer && switchContainer.Descendants.OfType().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestSwitchContainer(b) == switchContainer)) ConvertSwitchSectionBody(astSection, br.TargetBlock); else ConvertSwitchSectionBody(astSection, section.Body); diff --git a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs index c48021ac7..b70056841 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs @@ -226,5 +226,15 @@ namespace ICSharpCode.Decompiler.IL } return null; } + + public static BlockContainer FindClosestSwitchContainer(ILInstruction inst) + { + while (inst != null) { + if (inst is BlockContainer bc && bc.entryPoint.Instructions.FirstOrDefault() is SwitchInstruction) + return bc; + inst = inst.Parent; + } + return null; + } } } From fcbfada2e0eb9e57c1a78bfd06bbc8462ffa0e46 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 11 Oct 2017 11:31:06 +0200 Subject: [PATCH 076/190] Add legacy switch-on-nullable transform --- .../CSharp/CSharpDecompiler.cs | 1 + .../ICSharpCode.Decompiler.csproj | 1 + .../Transforms/SwitchOnNullableTransform.cs | 117 ++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 647dcdaf5..355464e64 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -83,6 +83,7 @@ namespace ICSharpCode.Decompiler.CSharp new SplitVariables(), // split variables once again, because the stobj(ldloca V, ...) may open up new replacements new SwitchDetection(), new SwitchOnStringTransform(), + new SwitchOnNullableTransform(), new BlockILTransform { // per-block transforms PostOrderTransforms = { // Even though it's a post-order block-transform as most other transforms, diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 534af2cbe..7fee5ff0d 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -277,6 +277,7 @@ + diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs new file mode 100644 index 000000000..30005e06b --- /dev/null +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs @@ -0,0 +1,117 @@ +// Copyright (c) 2017 Siegfried Pammer +// +// 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.Collections.Generic; +using System.Linq; +using ICSharpCode.Decompiler.IL.ControlFlow; +using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.Decompiler.Util; + +namespace ICSharpCode.Decompiler.IL.Transforms +{ + /// + /// Detects switch-on-nullable patterns employed by the C# compiler and transforms them to an ILAst-switch-instruction. + /// + class SwitchOnNullableTransform : IILTransform + { + public void Run(ILFunction function, ILTransformContext context) + { + if (!context.Settings.LiftNullables) + return; + + HashSet changedContainers = new HashSet(); + + foreach (var block in function.Descendants.OfType()) { + bool changed = false; + for (int i = block.Instructions.Count - 1; i >= 0; i--) { + SwitchInstruction newSwitch; + if (MatchSwitchOnNullable(block.Instructions, i, out newSwitch)) { + block.Instructions[i + 1].ReplaceWith(newSwitch); + block.Instructions.RemoveRange(i - 2, 3); + i -= 2; + changed = true; + continue; + } + } + if (!changed) continue; + SwitchDetection.SimplifySwitchInstruction(block); + if (block.Parent is BlockContainer container) + changedContainers.Add(container); + } + + foreach (var container in changedContainers) + container.SortBlocks(deleteUnreachableBlocks: true); + } + + bool MatchSwitchOnNullable(InstructionCollection instructions, int i, out SwitchInstruction newSwitch) + { + newSwitch = null; + // match first block: + // stloc tmp(ldloca switchValueVar) + // stloc switchVariable(call GetValueOrDefault(ldloc tmp)) + // if (logic.not(call get_HasValue(ldloc tmp))) br nullCaseBlock + // br switchBlock + if (i < 2) return false; + if (!instructions[i - 2].MatchStLoc(out var tmp, out var ldloca) || + !instructions[i - 1].MatchStLoc(out var switchVariable, out var getValueOrDefault) || + !instructions[i].MatchIfInstruction(out var condition, out var trueInst)) + return false; + if (!instructions[i + 1].MatchBranch(out var switchBlock) || !trueInst.MatchBranch(out var nullCaseBlock)) + return false; + if (!ldloca.MatchLdLoca(out var switchValueVar)) + return false; + if (!condition.MatchLogicNot(out var getHasValue)) + return false; + if (!(getValueOrDefault is Call getValueOrDefaultCall) || getValueOrDefaultCall.Method.FullName != "System.Nullable.GetValueOrDefault" || + getValueOrDefaultCall.Method.DeclaringType.TypeParameterCount != 1) + return false; + if (!(getHasValue is Call getHasValueCall) || !getHasValueCall.Method.IsAccessor || getHasValueCall.Method.FullName != "System.Nullable.get_HasValue" || + getHasValueCall.Method.DeclaringType.TypeParameterCount != 1) + return false; + if (getHasValueCall.Arguments.Count != 1 || getValueOrDefaultCall.Arguments.Count != 1) + return false; + if (!getHasValueCall.Arguments[0].MatchLdLoc(tmp) || !getValueOrDefaultCall.Arguments[0].MatchLdLoc(tmp)) + return false; + // match second block: switchBlock + // switch (ldloc swtichVariable) { + // case [0..1): br caseBlock1 + // ... more cases ... + // case [long.MinValue..0),[1..5),[6..10),[11..long.MaxValue]: br defaultBlock + // } + if (switchBlock.Instructions.Count != 1 || switchBlock.IncomingEdgeCount != 1) + return false; + if (!(switchBlock.Instructions[0] is SwitchInstruction switchInst)) + return false; + newSwitch = new SwitchInstruction(new LdLoc(switchValueVar)); + newSwitch.IsLifted = true; + SwitchSection defaultSection = null; + foreach (var section in switchInst.Sections) { + if (defaultSection == null || section.Labels.Count() >= defaultSection.Labels.Count()) + defaultSection = section; + newSwitch.Sections.Add(section); + } + if (defaultSection.Body.MatchBranch(out var defaultBlock) && defaultBlock == nullCaseBlock) + defaultSection.HasNullLabel = true; + else { + newSwitch.Sections.Add(new SwitchSection { Body = new Branch(nullCaseBlock), HasNullLabel = true }); + } + return true; + } + } +} From b3c7f53c8614a455cdc417690c85ccd0d7815830 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 11 Oct 2017 11:40:54 +0200 Subject: [PATCH 077/190] Add nullable handling to StatementBuilder.CreateTypedCaseLabel --- ICSharpCode.Decompiler/CSharp/StatementBuilder.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 91ca8d309..8be341e76 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -93,6 +93,9 @@ namespace ICSharpCode.Decompiler.CSharp } else if (type.Kind == TypeKind.Enum) { var enumType = type.GetDefinition().EnumUnderlyingType; value = CSharpPrimitiveCast.Cast(ReflectionHelper.GetTypeCode(enumType), i, false); + } else if (type.IsKnownType(KnownTypeCode.NullableOfT)) { + var nullableType = NullableType.GetUnderlyingType(type); + value = CSharpPrimitiveCast.Cast(ReflectionHelper.GetTypeCode(nullableType), i, false); } else { value = CSharpPrimitiveCast.Cast(ReflectionHelper.GetTypeCode(type), i, false); } From 51d13bfefedeeddf53cdcb00c97e0c6780ec045f Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 11 Oct 2017 12:28:35 +0200 Subject: [PATCH 078/190] Add transform for Roslyn Switch-On-Nullable --- .../TestCases/Pretty/Switch.cs | 200 +++++----- .../TestCases/Pretty/Switch.il | 360 +++++++++++++++++- .../TestCases/Pretty/Switch.opt.il | 288 +++++++++++++- .../TestCases/Pretty/Switch.opt.roslyn.il | 255 ++++++++++++- .../TestCases/Pretty/Switch.roslyn.il | 358 ++++++++++++++++- .../Transforms/SwitchOnNullableTransform.cs | 60 +++ 6 files changed, 1373 insertions(+), 148 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index e5f42c278..fcf01f6d9 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -82,83 +82,83 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } - //public static string SwitchOverNullableInt(int? i) - //{ - // switch (i) { - // case null: { - // return "null"; - // } - // case 0: { - // return "zero"; - // } - // case 5: { - // return "five"; - // } - // case 10: { - // return "ten"; - // } - // default: { - // return "large"; - // } - // } - //} + public static string SwitchOverNullableInt(int? i) + { + switch (i) { + case null: { + return "null"; + } + case 0: { + return "zero"; + } + case 5: { + return "five"; + } + case 10: { + return "ten"; + } + default: { + return "large"; + } + } + } - //public static string SwitchOverNullableIntShifted(int? i) - //{ - // switch (i + 5) { - // case null: { - // return "null"; - // } - // case 0: { - // return "zero"; - // } - // case 5: { - // return "five"; - // } - // case 10: { - // return "ten"; - // } - // default: { - // return "large"; - // } - // } - //} + public static string SwitchOverNullableIntShifted(int? i) + { + switch (i + 5) { + case null: { + return "null"; + } + case 0: { + return "zero"; + } + case 5: { + return "five"; + } + case 10: { + return "ten"; + } + default: { + return "large"; + } + } + } - //public static string SwitchOverNullableIntNoNullCase(int? i) - //{ - // switch (i) { - // case 0: { - // return "zero"; - // } - // case 5: { - // return "five"; - // } - // case 10: { - // return "ten"; - // } - // default: { - // return "other"; - // } - // } - //} + public static string SwitchOverNullableIntNoNullCase(int? i) + { + switch (i) { + case 0: { + return "zero"; + } + case 5: { + return "five"; + } + case 10: { + return "ten"; + } + default: { + return "other"; + } + } + } - //public static string SwitchOverNullableIntNoNullCaseShifted(int? i) - //{ - // switch (i + 5) { - // case 0: { - // return "zero"; - // } - // case 5: { - // return "five"; - // } - // case 10: { - // return "ten"; - // } - // default: { - // return "other"; - // } - // } - //} + public static string SwitchOverNullableIntNoNullCaseShifted(int? i) + { + switch (i + 5) { + case 0: { + return "zero"; + } + case 5: { + return "five"; + } + case 10: { + return "ten"; + } + default: { + return "other"; + } + } + } public static string ShortSwitchOverString(string text) { @@ -302,32 +302,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } - //public static void SwitchWithGoto(int i) - //{ - // Console.WriteLine("SwitchWithGoto: " + i); - // switch (i) { - // case 1: { - // Console.WriteLine("one"); - // goto default; - // } - // case 2: { - // Console.WriteLine("two"); - // goto case 3; - // } - // case 3: { - // Console.WriteLine("three"); - // break; - // } - // case 4: { - // Console.WriteLine("four"); - // return; - // } - // default: { - // Console.WriteLine("default"); - // break; - // } - // } - //} + public static void SwitchWithGoto(int i) + { + Console.WriteLine("SwitchWithGoto: " + i); + switch (i) { + case 1: { + Console.WriteLine("one"); + goto default; + } + case 2: { + Console.WriteLine("two"); + goto case 3; + } + case 3: { + Console.WriteLine("three"); + break; + } + case 4: { + Console.WriteLine("four"); + return; + } + default: { + Console.WriteLine("default"); + break; + } + } + } private static SetProperty[] GetProperties() { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il index eed5597a0..c6af28ac4 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il @@ -1,6 +1,6 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 -// Copyright (c) Microsoft Corporation. All rights reserved. +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly gn0oqkcb +.assembly nyniamwr { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module gn0oqkcb.dll -// MVID: {D3E1C722-15E3-49C8-B86B-96413DA7BEEE} +.module nyniamwr.dll +// MVID: {95C99B41-CBA3-42E4-A4DE-27E535671AB2} .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: 0x00C80000 +// Image base: 0x03080000 // =============== CLASS MEMBERS DECLARATION =================== @@ -214,6 +214,268 @@ IL_00df: ret } // end of method Switch::SparseIntegerSwitch + .method public hidebysig static string + SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 79 (0x4f) + .maxstack 2 + .locals init (string V_0, + int32 V_1) + IL_0000: nop + IL_0001: ldarga.s i + IL_0003: dup + IL_0004: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0009: stloc.1 + IL_000a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000f: brfalse.s IL_0020 + + IL_0011: ldloc.1 + IL_0012: ldc.i4.0 + IL_0013: beq.s IL_0029 + + IL_0015: ldloc.1 + IL_0016: ldc.i4.5 + IL_0017: beq.s IL_0032 + + IL_0019: ldloc.1 + IL_001a: ldc.i4.s 10 + IL_001c: beq.s IL_003b + + IL_001e: br.s IL_0044 + + IL_0020: nop + IL_0021: ldstr "null" + IL_0026: stloc.0 + IL_0027: br.s IL_004d + + IL_0029: nop + IL_002a: ldstr "zero" + IL_002f: stloc.0 + IL_0030: br.s IL_004d + + IL_0032: nop + IL_0033: ldstr "five" + IL_0038: stloc.0 + IL_0039: br.s IL_004d + + IL_003b: nop + IL_003c: ldstr "ten" + IL_0041: stloc.0 + IL_0042: br.s IL_004d + + IL_0044: nop + IL_0045: ldstr "large" + IL_004a: stloc.0 + IL_004b: br.s IL_004d + + IL_004d: ldloc.0 + IL_004e: ret + } // end of method Switch::SwitchOverNullableInt + + .method public hidebysig static string + SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 117 (0x75) + .maxstack 2 + .locals init (string V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloca.s V_1 + IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000a: brtrue.s IL_0017 + + IL_000c: ldloca.s V_2 + IL_000e: initobj valuetype [mscorlib]System.Nullable`1 + IL_0014: ldloc.2 + IL_0015: br.s IL_0025 + + IL_0017: ldloca.s V_1 + IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001e: ldc.i4.5 + IL_001f: add + IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0025: nop + IL_0026: stloc.2 + IL_0027: ldloca.s V_2 + IL_0029: dup + IL_002a: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_002f: stloc.3 + IL_0030: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0035: brfalse.s IL_0046 + + IL_0037: ldloc.3 + IL_0038: ldc.i4.0 + IL_0039: beq.s IL_004f + + IL_003b: ldloc.3 + IL_003c: ldc.i4.5 + IL_003d: beq.s IL_0058 + + IL_003f: ldloc.3 + IL_0040: ldc.i4.s 10 + IL_0042: beq.s IL_0061 + + IL_0044: br.s IL_006a + + IL_0046: nop + IL_0047: ldstr "null" + IL_004c: stloc.0 + IL_004d: br.s IL_0073 + + IL_004f: nop + IL_0050: ldstr "zero" + IL_0055: stloc.0 + IL_0056: br.s IL_0073 + + IL_0058: nop + IL_0059: ldstr "five" + IL_005e: stloc.0 + IL_005f: br.s IL_0073 + + IL_0061: nop + IL_0062: ldstr "ten" + IL_0067: stloc.0 + IL_0068: br.s IL_0073 + + IL_006a: nop + IL_006b: ldstr "large" + IL_0070: stloc.0 + IL_0071: br.s IL_0073 + + IL_0073: ldloc.0 + IL_0074: ret + } // end of method Switch::SwitchOverNullableIntShifted + + .method public hidebysig static string + SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 70 (0x46) + .maxstack 2 + .locals init (string V_0, + int32 V_1) + IL_0000: nop + IL_0001: ldarga.s i + IL_0003: dup + IL_0004: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0009: stloc.1 + IL_000a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000f: brfalse.s IL_003b + + IL_0011: ldloc.1 + IL_0012: ldc.i4.0 + IL_0013: beq.s IL_0020 + + IL_0015: ldloc.1 + IL_0016: ldc.i4.5 + IL_0017: beq.s IL_0029 + + IL_0019: ldloc.1 + IL_001a: ldc.i4.s 10 + IL_001c: beq.s IL_0032 + + IL_001e: br.s IL_003b + + IL_0020: nop + IL_0021: ldstr "zero" + IL_0026: stloc.0 + IL_0027: br.s IL_0044 + + IL_0029: nop + IL_002a: ldstr "five" + IL_002f: stloc.0 + IL_0030: br.s IL_0044 + + IL_0032: nop + IL_0033: ldstr "ten" + IL_0038: stloc.0 + IL_0039: br.s IL_0044 + + IL_003b: nop + IL_003c: ldstr "other" + IL_0041: stloc.0 + IL_0042: br.s IL_0044 + + IL_0044: ldloc.0 + IL_0045: ret + } // end of method Switch::SwitchOverNullableIntNoNullCase + + .method public hidebysig static string + SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 108 (0x6c) + .maxstack 2 + .locals init (string V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloca.s V_1 + IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000a: brtrue.s IL_0017 + + IL_000c: ldloca.s V_2 + IL_000e: initobj valuetype [mscorlib]System.Nullable`1 + IL_0014: ldloc.2 + IL_0015: br.s IL_0025 + + IL_0017: ldloca.s V_1 + IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001e: ldc.i4.5 + IL_001f: add + IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0025: nop + IL_0026: stloc.2 + IL_0027: ldloca.s V_2 + IL_0029: dup + IL_002a: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_002f: stloc.3 + IL_0030: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0035: brfalse.s IL_0061 + + IL_0037: ldloc.3 + IL_0038: ldc.i4.0 + IL_0039: beq.s IL_0046 + + IL_003b: ldloc.3 + IL_003c: ldc.i4.5 + IL_003d: beq.s IL_004f + + IL_003f: ldloc.3 + IL_0040: ldc.i4.s 10 + IL_0042: beq.s IL_0058 + + IL_0044: br.s IL_0061 + + IL_0046: nop + IL_0047: ldstr "zero" + IL_004c: stloc.0 + IL_004d: br.s IL_006a + + IL_004f: nop + IL_0050: ldstr "five" + IL_0055: stloc.0 + IL_0056: br.s IL_006a + + IL_0058: nop + IL_0059: ldstr "ten" + IL_005e: stloc.0 + IL_005f: br.s IL_006a + + IL_0061: nop + IL_0062: ldstr "other" + IL_0067: stloc.0 + IL_0068: br.s IL_006a + + IL_006a: ldloc.0 + IL_006b: ret + } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted + .method public hidebysig static string ShortSwitchOverString(string text) cil managed { @@ -298,7 +560,7 @@ IL_0015: brfalse IL_00ef IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000003-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x6000007-1' IL_0021: brtrue.s IL_0084 IL_0023: ldc.i4.7 @@ -339,9 +601,9 @@ IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007d: volatile. - IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000003-1' + IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x6000007-1' IL_0084: volatile. - IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000003-1' + IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x6000007-1' IL_008b: ldloc.1 IL_008c: ldloca.s V_2 IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -424,7 +686,7 @@ IL_0015: brfalse IL_0165 IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000004-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x6000008-1' IL_0021: brtrue IL_00ba IL_0026: ldc.i4.s 11 @@ -485,9 +747,9 @@ IL_00ae: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00b3: volatile. - IL_00b5: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000004-1' + IL_00b5: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x6000008-1' IL_00ba: volatile. - IL_00bc: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000004-1' + IL_00bc: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x6000008-1' IL_00c1: ldloc.2 IL_00c2: ldloca.s V_3 IL_00c4: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -689,6 +951,64 @@ IL_0091: ret } // end of method Switch::SwitchInLoop + .method public hidebysig static void SwitchWithGoto(int32 i) cil managed + { + // Code size 122 (0x7a) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldstr "SwitchWithGoto: " + IL_0006: ldarg.0 + IL_0007: box [mscorlib]System.Int32 + IL_000c: call string [mscorlib]System.String::Concat(object, + object) + IL_0011: call void [mscorlib]System.Console::WriteLine(string) + IL_0016: nop + IL_0017: ldarg.0 + IL_0018: stloc.0 + IL_0019: ldloc.0 + IL_001a: ldc.i4.1 + IL_001b: sub + IL_001c: switch ( + IL_0033, + IL_0041, + IL_004f, + IL_005d) + IL_0031: br.s IL_006b + + IL_0033: nop + IL_0034: ldstr "one" + IL_0039: call void [mscorlib]System.Console::WriteLine(string) + IL_003e: nop + IL_003f: br.s IL_006b + + IL_0041: nop + IL_0042: ldstr "two" + IL_0047: call void [mscorlib]System.Console::WriteLine(string) + IL_004c: nop + IL_004d: br.s IL_004f + + IL_004f: nop + IL_0050: ldstr "three" + IL_0055: call void [mscorlib]System.Console::WriteLine(string) + IL_005a: nop + IL_005b: br.s IL_0079 + + IL_005d: nop + IL_005e: ldstr "four" + IL_0063: call void [mscorlib]System.Console::WriteLine(string) + IL_0068: nop + IL_0069: br.s IL_0079 + + IL_006b: nop + IL_006c: ldstr "default" + IL_0071: call void [mscorlib]System.Console::WriteLine(string) + IL_0076: nop + IL_0077: br.s IL_0079 + + IL_0079: ret + } // end of method Switch::SwitchWithGoto + .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] GetProperties() cil managed { @@ -744,7 +1064,7 @@ IL_0034: brfalse IL_012d IL_0039: volatile. - IL_003b: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000008-1' + IL_003b: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x600000d-1' IL_0040: brtrue.s IL_0097 IL_0042: ldc.i4.6 @@ -780,9 +1100,9 @@ IL_008b: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_0090: volatile. - IL_0092: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000008-1' + IL_0092: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x600000d-1' IL_0097: volatile. - IL_0099: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000008-1' + IL_0099: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x600000d-1' IL_009e: ldloc.s V_6 IL_00a0: ldloca.s V_7 IL_00a2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -876,17 +1196,17 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}' +.class private auto ansi '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000003-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000004-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000007-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000008-1' -} // end of class '{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000d-1' +} // end of class '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}' // ============================================================= // *********** DISASSEMBLY COMPLETE *********************** -// WARNING: Created Win32 resource file ../../../TestCases/Pretty\Switch.res +// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\Switch.res" wurde erstellt. diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il index becdf49a9..e09dd767c 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il @@ -1,6 +1,6 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 -// Copyright (c) Microsoft Corporation. All rights reserved. +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly zlaei1fn +.assembly f3gworj3 { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module zlaei1fn.dll -// MVID: {64CCBA80-944A-4F77-9230-24B174DEE22A} +.module f3gworj3.dll +// MVID: {6837A40E-7A00-4F01-B2D7-DE0001F70EDF} .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: 0x00680000 +// Image base: 0x00780000 // =============== CLASS MEMBERS DECLARATION =================== @@ -176,6 +176,212 @@ IL_00b4: ret } // end of method Switch::SparseIntegerSwitch + .method public hidebysig static string + SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 61 (0x3d) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldarga.s i + IL_0002: dup + IL_0003: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0008: stloc.0 + IL_0009: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000e: brfalse.s IL_001f + + IL_0010: ldloc.0 + IL_0011: ldc.i4.0 + IL_0012: beq.s IL_0025 + + IL_0014: ldloc.0 + IL_0015: ldc.i4.5 + IL_0016: beq.s IL_002b + + IL_0018: ldloc.0 + IL_0019: ldc.i4.s 10 + IL_001b: beq.s IL_0031 + + IL_001d: br.s IL_0037 + + IL_001f: ldstr "null" + IL_0024: ret + + IL_0025: ldstr "zero" + IL_002a: ret + + IL_002b: ldstr "five" + IL_0030: ret + + IL_0031: ldstr "ten" + IL_0036: ret + + IL_0037: ldstr "large" + IL_003c: ret + } // end of method Switch::SwitchOverNullableInt + + .method public hidebysig static string + SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 98 (0x62) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brtrue.s IL_0016 + + IL_000b: ldloca.s V_1 + IL_000d: initobj valuetype [mscorlib]System.Nullable`1 + IL_0013: ldloc.1 + IL_0014: br.s IL_0024 + + IL_0016: ldloca.s V_0 + IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001d: ldc.i4.5 + IL_001e: add + IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0024: stloc.2 + IL_0025: ldloca.s V_2 + IL_0027: dup + IL_0028: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_002d: stloc.3 + IL_002e: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0033: brfalse.s IL_0044 + + IL_0035: ldloc.3 + IL_0036: ldc.i4.0 + IL_0037: beq.s IL_004a + + IL_0039: ldloc.3 + IL_003a: ldc.i4.5 + IL_003b: beq.s IL_0050 + + IL_003d: ldloc.3 + IL_003e: ldc.i4.s 10 + IL_0040: beq.s IL_0056 + + IL_0042: br.s IL_005c + + IL_0044: ldstr "null" + IL_0049: ret + + IL_004a: ldstr "zero" + IL_004f: ret + + IL_0050: ldstr "five" + IL_0055: ret + + IL_0056: ldstr "ten" + IL_005b: ret + + IL_005c: ldstr "large" + IL_0061: ret + } // end of method Switch::SwitchOverNullableIntShifted + + .method public hidebysig static string + SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 55 (0x37) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldarga.s i + IL_0002: dup + IL_0003: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0008: stloc.0 + IL_0009: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000e: brfalse.s IL_0031 + + IL_0010: ldloc.0 + IL_0011: ldc.i4.0 + IL_0012: beq.s IL_001f + + IL_0014: ldloc.0 + IL_0015: ldc.i4.5 + IL_0016: beq.s IL_0025 + + IL_0018: ldloc.0 + IL_0019: ldc.i4.s 10 + IL_001b: beq.s IL_002b + + IL_001d: br.s IL_0031 + + IL_001f: ldstr "zero" + IL_0024: ret + + IL_0025: ldstr "five" + IL_002a: ret + + IL_002b: ldstr "ten" + IL_0030: ret + + IL_0031: ldstr "other" + IL_0036: ret + } // end of method Switch::SwitchOverNullableIntNoNullCase + + .method public hidebysig static string + SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 92 (0x5c) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brtrue.s IL_0016 + + IL_000b: ldloca.s V_1 + IL_000d: initobj valuetype [mscorlib]System.Nullable`1 + IL_0013: ldloc.1 + IL_0014: br.s IL_0024 + + IL_0016: ldloca.s V_0 + IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001d: ldc.i4.5 + IL_001e: add + IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0024: stloc.2 + IL_0025: ldloca.s V_2 + IL_0027: dup + IL_0028: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_002d: stloc.3 + IL_002e: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0033: brfalse.s IL_0056 + + IL_0035: ldloc.3 + IL_0036: ldc.i4.0 + IL_0037: beq.s IL_0044 + + IL_0039: ldloc.3 + IL_003a: ldc.i4.5 + IL_003b: beq.s IL_004a + + IL_003d: ldloc.3 + IL_003e: ldc.i4.s 10 + IL_0040: beq.s IL_0050 + + IL_0042: br.s IL_0056 + + IL_0044: ldstr "zero" + IL_0049: ret + + IL_004a: ldstr "five" + IL_004f: ret + + IL_0050: ldstr "ten" + IL_0055: ret + + IL_0056: ldstr "other" + IL_005b: ret + } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted + .method public hidebysig static string ShortSwitchOverString(string text) cil managed { @@ -243,7 +449,7 @@ IL_0013: brfalse IL_00db IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000003-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x6000007-1' IL_001f: brtrue.s IL_0082 IL_0021: ldc.i4.7 @@ -284,9 +490,9 @@ IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007b: volatile. - IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000003-1' + IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x6000007-1' IL_0082: volatile. - IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000003-1' + IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x6000007-1' IL_0089: ldloc.0 IL_008a: ldloca.s V_1 IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -347,7 +553,7 @@ IL_0013: brfalse IL_013f IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000004-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x6000008-1' IL_001f: brtrue IL_00b8 IL_0024: ldc.i4.s 11 @@ -408,9 +614,9 @@ IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00b1: volatile. - IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000004-1' + IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x6000008-1' IL_00b8: volatile. - IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000004-1' + IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x6000008-1' IL_00bf: ldloc.1 IL_00c0: ldloca.s V_2 IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -551,6 +757,48 @@ IL_007a: br.s IL_0015 } // end of method Switch::SwitchInLoop + .method public hidebysig static void SwitchWithGoto(int32 i) cil managed + { + // Code size 104 (0x68) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldstr "SwitchWithGoto: " + IL_0005: ldarg.0 + IL_0006: box [mscorlib]System.Int32 + IL_000b: call string [mscorlib]System.String::Concat(object, + object) + IL_0010: call void [mscorlib]System.Console::WriteLine(string) + IL_0015: ldarg.0 + IL_0016: stloc.0 + IL_0017: ldloc.0 + IL_0018: ldc.i4.1 + IL_0019: sub + IL_001a: switch ( + IL_0031, + IL_003d, + IL_0047, + IL_0052) + IL_002f: br.s IL_005d + + IL_0031: ldstr "one" + IL_0036: call void [mscorlib]System.Console::WriteLine(string) + IL_003b: br.s IL_005d + + IL_003d: ldstr "two" + IL_0042: call void [mscorlib]System.Console::WriteLine(string) + IL_0047: ldstr "three" + IL_004c: call void [mscorlib]System.Console::WriteLine(string) + IL_0051: ret + + IL_0052: ldstr "four" + IL_0057: call void [mscorlib]System.Console::WriteLine(string) + IL_005c: ret + + IL_005d: ldstr "default" + IL_0062: call void [mscorlib]System.Console::WriteLine(string) + IL_0067: ret + } // end of method Switch::SwitchWithGoto + .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] GetProperties() cil managed { @@ -597,7 +845,7 @@ IL_0031: brfalse IL_0119 IL_0036: volatile. - IL_0038: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000008-1' + IL_0038: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x600000d-1' IL_003d: brtrue.s IL_0094 IL_003f: ldc.i4.6 @@ -633,9 +881,9 @@ IL_0088: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_008d: volatile. - IL_008f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000008-1' + IL_008f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x600000d-1' IL_0094: volatile. - IL_0096: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000008-1' + IL_0096: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x600000d-1' IL_009b: ldloc.s V_6 IL_009d: ldloca.s V_7 IL_009f: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -707,17 +955,17 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{64CCBA80-944A-4F77-9230-24B174DEE22A}' +.class private auto ansi '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000003-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000004-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000007-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000008-1' -} // end of class '{64CCBA80-944A-4F77-9230-24B174DEE22A}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000d-1' +} // end of class '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}' // ============================================================= // *********** DISASSEMBLY COMPLETE *********************** -// WARNING: Created Win32 resource file ../../../TestCases/Pretty\Switch.opt.res +// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\Switch.opt.res" wurde erstellt. diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il index 48993c1fe..bd0488bb3 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il @@ -1,6 +1,6 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 -// Copyright (c) Microsoft Corporation. All rights reserved. +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {25FC064E-F764-4556-A3C7-F6570E457CDD} +// MVID: {04DBCBA6-8175-41CD-8917-9428C9765986} .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: 0x00B30000 +// Image base: 0x00830000 // =============== CLASS MEMBERS DECLARATION =================== @@ -185,6 +185,214 @@ IL_00b8: ret } // end of method Switch::SparseIntegerSwitch + .method public hidebysig static string + SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 63 (0x3f) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brfalse.s IL_0021 + + IL_000b: ldloca.s V_0 + IL_000d: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0012: stloc.1 + IL_0013: ldloc.1 + IL_0014: brfalse.s IL_0027 + + IL_0016: ldloc.1 + IL_0017: ldc.i4.5 + IL_0018: beq.s IL_002d + + IL_001a: ldloc.1 + IL_001b: ldc.i4.s 10 + IL_001d: beq.s IL_0033 + + IL_001f: br.s IL_0039 + + IL_0021: ldstr "null" + IL_0026: ret + + IL_0027: ldstr "zero" + IL_002c: ret + + IL_002d: ldstr "five" + IL_0032: ret + + IL_0033: ldstr "ten" + IL_0038: ret + + IL_0039: ldstr "large" + IL_003e: ret + } // end of method Switch::SwitchOverNullableInt + + .method public hidebysig static string + SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 98 (0x62) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.1 + IL_0002: ldloca.s V_1 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brtrue.s IL_0016 + + IL_000b: ldloca.s V_2 + IL_000d: initobj valuetype [mscorlib]System.Nullable`1 + IL_0013: ldloc.2 + IL_0014: br.s IL_0024 + + IL_0016: ldloca.s V_1 + IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001d: ldc.i4.5 + IL_001e: add + IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0024: stloc.0 + IL_0025: ldloca.s V_0 + IL_0027: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_002c: brfalse.s IL_0044 + + IL_002e: ldloca.s V_0 + IL_0030: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0035: stloc.3 + IL_0036: ldloc.3 + IL_0037: brfalse.s IL_004a + + IL_0039: ldloc.3 + IL_003a: ldc.i4.5 + IL_003b: beq.s IL_0050 + + IL_003d: ldloc.3 + IL_003e: ldc.i4.s 10 + IL_0040: beq.s IL_0056 + + IL_0042: br.s IL_005c + + IL_0044: ldstr "null" + IL_0049: ret + + IL_004a: ldstr "zero" + IL_004f: ret + + IL_0050: ldstr "five" + IL_0055: ret + + IL_0056: ldstr "ten" + IL_005b: ret + + IL_005c: ldstr "large" + IL_0061: ret + } // end of method Switch::SwitchOverNullableIntShifted + + .method public hidebysig static string + SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 57 (0x39) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brfalse.s IL_0033 + + IL_000b: ldloca.s V_0 + IL_000d: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0012: stloc.1 + IL_0013: ldloc.1 + IL_0014: brfalse.s IL_0021 + + IL_0016: ldloc.1 + IL_0017: ldc.i4.5 + IL_0018: beq.s IL_0027 + + IL_001a: ldloc.1 + IL_001b: ldc.i4.s 10 + IL_001d: beq.s IL_002d + + IL_001f: br.s IL_0033 + + IL_0021: ldstr "zero" + IL_0026: ret + + IL_0027: ldstr "five" + IL_002c: ret + + IL_002d: ldstr "ten" + IL_0032: ret + + IL_0033: ldstr "other" + IL_0038: ret + } // end of method Switch::SwitchOverNullableIntNoNullCase + + .method public hidebysig static string + SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 92 (0x5c) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.1 + IL_0002: ldloca.s V_1 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brtrue.s IL_0016 + + IL_000b: ldloca.s V_2 + IL_000d: initobj valuetype [mscorlib]System.Nullable`1 + IL_0013: ldloc.2 + IL_0014: br.s IL_0024 + + IL_0016: ldloca.s V_1 + IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001d: ldc.i4.5 + IL_001e: add + IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0024: stloc.0 + IL_0025: ldloca.s V_0 + IL_0027: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_002c: brfalse.s IL_0056 + + IL_002e: ldloca.s V_0 + IL_0030: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0035: stloc.3 + IL_0036: ldloc.3 + IL_0037: brfalse.s IL_0044 + + IL_0039: ldloc.3 + IL_003a: ldc.i4.5 + IL_003b: beq.s IL_004a + + IL_003d: ldloc.3 + IL_003e: ldc.i4.s 10 + IL_0040: beq.s IL_0050 + + IL_0042: br.s IL_0056 + + IL_0044: ldstr "zero" + IL_0049: ret + + IL_004a: ldstr "five" + IL_004f: ret + + IL_0050: ldstr "ten" + IL_0055: ret + + IL_0056: ldstr "other" + IL_005b: ret + } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted + .method public hidebysig static string ShortSwitchOverString(string text) cil managed { @@ -659,6 +867,45 @@ IL_0078: br.s IL_0015 } // end of method Switch::SwitchInLoop + .method public hidebysig static void SwitchWithGoto(int32 i) cil managed + { + // Code size 102 (0x66) + .maxstack 2 + IL_0000: ldstr "SwitchWithGoto: " + IL_0005: ldarg.0 + IL_0006: box [mscorlib]System.Int32 + IL_000b: call string [mscorlib]System.String::Concat(object, + object) + IL_0010: call void [mscorlib]System.Console::WriteLine(string) + IL_0015: ldarg.0 + IL_0016: ldc.i4.1 + IL_0017: sub + IL_0018: switch ( + IL_002f, + IL_003b, + IL_0045, + IL_0050) + IL_002d: br.s IL_005b + + IL_002f: ldstr "one" + IL_0034: call void [mscorlib]System.Console::WriteLine(string) + IL_0039: br.s IL_005b + + IL_003b: ldstr "two" + IL_0040: call void [mscorlib]System.Console::WriteLine(string) + IL_0045: ldstr "three" + IL_004a: call void [mscorlib]System.Console::WriteLine(string) + IL_004f: ret + + IL_0050: ldstr "four" + IL_0055: call void [mscorlib]System.Console::WriteLine(string) + IL_005a: ret + + IL_005b: ldstr "default" + IL_0060: call void [mscorlib]System.Console::WriteLine(string) + IL_0065: ret + } // end of method Switch::SwitchWithGoto + .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] GetProperties() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il index 4da071b46..38331d470 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il @@ -1,6 +1,6 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 -// Copyright (c) Microsoft Corporation. All rights reserved. +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {134EA2E4-FA5A-4D44-A0FD-C4E5A18E39B1} +// MVID: {87DEBC09-DFAD-437D-9221-109E2117A07A} .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: 0x00C40000 +// Image base: 0x02960000 // =============== CLASS MEMBERS DECLARATION =================== @@ -229,6 +229,298 @@ IL_00ed: ret } // end of method Switch::SparseIntegerSwitch + .method public hidebysig static string + SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 87 (0x57) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + int32 V_2, + string V_3) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: stloc.0 + IL_0005: ldloca.s V_0 + IL_0007: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000c: brfalse.s IL_0028 + + IL_000e: ldloca.s V_0 + IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0015: stloc.2 + IL_0016: ldloc.2 + IL_0017: brfalse.s IL_0031 + + IL_0019: br.s IL_001b + + IL_001b: ldloc.2 + IL_001c: ldc.i4.5 + IL_001d: beq.s IL_003a + + IL_001f: br.s IL_0021 + + IL_0021: ldloc.2 + IL_0022: ldc.i4.s 10 + IL_0024: beq.s IL_0043 + + IL_0026: br.s IL_004c + + IL_0028: nop + IL_0029: ldstr "null" + IL_002e: stloc.3 + IL_002f: br.s IL_0055 + + IL_0031: nop + IL_0032: ldstr "zero" + IL_0037: stloc.3 + IL_0038: br.s IL_0055 + + IL_003a: nop + IL_003b: ldstr "five" + IL_0040: stloc.3 + IL_0041: br.s IL_0055 + + IL_0043: nop + IL_0044: ldstr "ten" + IL_0049: stloc.3 + IL_004a: br.s IL_0055 + + IL_004c: nop + IL_004d: ldstr "large" + IL_0052: stloc.3 + IL_0053: br.s IL_0055 + + IL_0055: ldloc.3 + IL_0056: ret + } // end of method Switch::SwitchOverNullableInt + + .method public hidebysig static string + SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 132 (0x84) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + valuetype [mscorlib]System.Nullable`1 V_3, + int32 V_4, + string V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.2 + IL_0003: ldloca.s V_2 + IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000a: brtrue.s IL_0017 + + IL_000c: ldloca.s V_3 + IL_000e: initobj valuetype [mscorlib]System.Nullable`1 + IL_0014: ldloc.3 + IL_0015: br.s IL_0025 + + IL_0017: ldloca.s V_2 + IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001e: ldc.i4.5 + IL_001f: add + IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0025: stloc.1 + IL_0026: ldloc.1 + IL_0027: stloc.0 + IL_0028: ldloca.s V_0 + IL_002a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_002f: brfalse.s IL_004f + + IL_0031: ldloca.s V_0 + IL_0033: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0038: stloc.s V_4 + IL_003a: ldloc.s V_4 + IL_003c: brfalse.s IL_0059 + + IL_003e: br.s IL_0040 + + IL_0040: ldloc.s V_4 + IL_0042: ldc.i4.5 + IL_0043: beq.s IL_0063 + + IL_0045: br.s IL_0047 + + IL_0047: ldloc.s V_4 + IL_0049: ldc.i4.s 10 + IL_004b: beq.s IL_006d + + IL_004d: br.s IL_0077 + + IL_004f: nop + IL_0050: ldstr "null" + IL_0055: stloc.s V_5 + IL_0057: br.s IL_0081 + + IL_0059: nop + IL_005a: ldstr "zero" + IL_005f: stloc.s V_5 + IL_0061: br.s IL_0081 + + IL_0063: nop + IL_0064: ldstr "five" + IL_0069: stloc.s V_5 + IL_006b: br.s IL_0081 + + IL_006d: nop + IL_006e: ldstr "ten" + IL_0073: stloc.s V_5 + IL_0075: br.s IL_0081 + + IL_0077: nop + IL_0078: ldstr "large" + IL_007d: stloc.s V_5 + IL_007f: br.s IL_0081 + + IL_0081: ldloc.s V_5 + IL_0083: ret + } // end of method Switch::SwitchOverNullableIntShifted + + .method public hidebysig static string + SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 78 (0x4e) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + int32 V_2, + string V_3) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: stloc.0 + IL_0005: ldloca.s V_0 + IL_0007: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000c: brfalse.s IL_0043 + + IL_000e: ldloca.s V_0 + IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0015: stloc.2 + IL_0016: ldloc.2 + IL_0017: brfalse.s IL_0028 + + IL_0019: br.s IL_001b + + IL_001b: ldloc.2 + IL_001c: ldc.i4.5 + IL_001d: beq.s IL_0031 + + IL_001f: br.s IL_0021 + + IL_0021: ldloc.2 + IL_0022: ldc.i4.s 10 + IL_0024: beq.s IL_003a + + IL_0026: br.s IL_0043 + + IL_0028: nop + IL_0029: ldstr "zero" + IL_002e: stloc.3 + IL_002f: br.s IL_004c + + IL_0031: nop + IL_0032: ldstr "five" + IL_0037: stloc.3 + IL_0038: br.s IL_004c + + IL_003a: nop + IL_003b: ldstr "ten" + IL_0040: stloc.3 + IL_0041: br.s IL_004c + + IL_0043: nop + IL_0044: ldstr "other" + IL_0049: stloc.3 + IL_004a: br.s IL_004c + + IL_004c: ldloc.3 + IL_004d: ret + } // end of method Switch::SwitchOverNullableIntNoNullCase + + .method public hidebysig static string + SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 122 (0x7a) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + valuetype [mscorlib]System.Nullable`1 V_3, + int32 V_4, + string V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.2 + IL_0003: ldloca.s V_2 + IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000a: brtrue.s IL_0017 + + IL_000c: ldloca.s V_3 + IL_000e: initobj valuetype [mscorlib]System.Nullable`1 + IL_0014: ldloc.3 + IL_0015: br.s IL_0025 + + IL_0017: ldloca.s V_2 + IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001e: ldc.i4.5 + IL_001f: add + IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0025: stloc.1 + IL_0026: ldloc.1 + IL_0027: stloc.0 + IL_0028: ldloca.s V_0 + IL_002a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_002f: brfalse.s IL_006d + + IL_0031: ldloca.s V_0 + IL_0033: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0038: stloc.s V_4 + IL_003a: ldloc.s V_4 + IL_003c: brfalse.s IL_004f + + IL_003e: br.s IL_0040 + + IL_0040: ldloc.s V_4 + IL_0042: ldc.i4.5 + IL_0043: beq.s IL_0059 + + IL_0045: br.s IL_0047 + + IL_0047: ldloc.s V_4 + IL_0049: ldc.i4.s 10 + IL_004b: beq.s IL_0063 + + IL_004d: br.s IL_006d + + IL_004f: nop + IL_0050: ldstr "zero" + IL_0055: stloc.s V_5 + IL_0057: br.s IL_0077 + + IL_0059: nop + IL_005a: ldstr "five" + IL_005f: stloc.s V_5 + IL_0061: br.s IL_0077 + + IL_0063: nop + IL_0064: ldstr "ten" + IL_0069: stloc.s V_5 + IL_006b: br.s IL_0077 + + IL_006d: nop + IL_006e: ldstr "other" + IL_0073: stloc.s V_5 + IL_0075: br.s IL_0077 + + IL_0077: ldloc.s V_5 + IL_0079: ret + } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted + .method public hidebysig static string ShortSwitchOverString(string text) cil managed { @@ -844,6 +1136,64 @@ IL_0091: ret } // end of method Switch::SwitchInLoop + .method public hidebysig static void SwitchWithGoto(int32 i) cil managed + { + // Code size 122 (0x7a) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldstr "SwitchWithGoto: " + IL_0006: ldarg.0 + IL_0007: box [mscorlib]System.Int32 + IL_000c: call string [mscorlib]System.String::Concat(object, + object) + IL_0011: call void [mscorlib]System.Console::WriteLine(string) + IL_0016: nop + IL_0017: ldarg.0 + IL_0018: stloc.0 + IL_0019: ldloc.0 + IL_001a: ldc.i4.1 + IL_001b: sub + IL_001c: switch ( + IL_0033, + IL_0041, + IL_004f, + IL_005d) + IL_0031: br.s IL_006b + + IL_0033: nop + IL_0034: ldstr "one" + IL_0039: call void [mscorlib]System.Console::WriteLine(string) + IL_003e: nop + IL_003f: br.s IL_006b + + IL_0041: nop + IL_0042: ldstr "two" + IL_0047: call void [mscorlib]System.Console::WriteLine(string) + IL_004c: nop + IL_004d: br.s IL_004f + + IL_004f: nop + IL_0050: ldstr "three" + IL_0055: call void [mscorlib]System.Console::WriteLine(string) + IL_005a: nop + IL_005b: br.s IL_0079 + + IL_005d: nop + IL_005e: ldstr "four" + IL_0063: call void [mscorlib]System.Console::WriteLine(string) + IL_0068: nop + IL_0069: br.s IL_0079 + + IL_006b: nop + IL_006c: ldstr "default" + IL_0071: call void [mscorlib]System.Console::WriteLine(string) + IL_0076: nop + IL_0077: br.s IL_0079 + + IL_0079: ret + } // end of method Switch::SwitchWithGoto + .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] GetProperties() cil managed { diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs index 30005e06b..f2e3107b2 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs @@ -48,6 +48,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms changed = true; continue; } + if (MatchRoslynSwitchOnNullable(block.Instructions, i, out newSwitch)) { + block.Instructions[i - 1].ReplaceWith(newSwitch); + block.Instructions.RemoveRange(i, 2); + i--; + changed = true; + continue; + } } if (!changed) continue; SwitchDetection.SimplifySwitchInstruction(block); @@ -59,6 +66,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms container.SortBlocks(deleteUnreachableBlocks: true); } + /// + /// Matches legacy C# switch on nullable. + /// bool MatchSwitchOnNullable(InstructionCollection instructions, int i, out SwitchInstruction newSwitch) { newSwitch = null; @@ -113,5 +123,55 @@ namespace ICSharpCode.Decompiler.IL.Transforms } return true; } + + /// + /// Matches Roslyn C# switch on nullable. + /// + bool MatchRoslynSwitchOnNullable(InstructionCollection instructions, int i, out SwitchInstruction newSwitch) + { + newSwitch = null; + // match first block: + // stloc tmp(ldloc switchValueVar) + // if (logic.not(call get_HasValue(ldloca tmp))) br nullCaseBlock + // br switchBlock + if (i < 1) return false; + if (!instructions[i - 1].MatchStLoc(out var tmp, out var switchValue) || + !instructions[i].MatchIfInstruction(out var condition, out var trueInst)) + return false; + if (!instructions[i + 1].MatchBranch(out var switchBlock) || !trueInst.MatchBranch(out var nullCaseBlock)) + return false; + if (!condition.MatchLogicNot(out var getHasValue) || !NullableLiftingTransform.MatchHasValueCall(getHasValue, out var target1) || target1 != tmp) + return false; + // match second block: switchBlock + // stloc switchVar(call GetValueOrDefault(ldloca tmp)) + // switch (ldloc switchVar) { + // case [0..1): br caseBlock1 + // ... more cases ... + // case [long.MinValue..0),[1..5),[6..10),[11..long.MaxValue]: br defaultBlock + // } + if (switchBlock.Instructions.Count != 2 || switchBlock.IncomingEdgeCount != 1) + return false; + if (!switchBlock.Instructions[0].MatchStLoc(out var switchVar, out var getValueOrDefault)) + return false; + if (!NullableLiftingTransform.MatchGetValueOrDefault(getValueOrDefault, out var target2) || target2 != tmp) + return false; + if (!(switchBlock.Instructions[1] is SwitchInstruction switchInst)) + return false; + newSwitch = new SwitchInstruction(switchValue); + newSwitch.IsLifted = true; + SwitchSection defaultSection = null; + foreach (var section in switchInst.Sections) { + if (defaultSection == null || section.Labels.Count() >= defaultSection.Labels.Count()) + defaultSection = section; + newSwitch.Sections.Add(section); + } + if (defaultSection.Body.MatchBranch(out var defaultBlock) && defaultBlock == nullCaseBlock) + defaultSection.HasNullLabel = true; + else { + newSwitch.Sections.Add(new SwitchSection { Body = new Branch(nullCaseBlock), HasNullLabel = true }); + } + return true; + } + } } From 71c0e8e0000e69fdfc40b76a5d21d407b2096524 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 11 Oct 2017 12:42:45 +0200 Subject: [PATCH 079/190] SwitchOnNullableTransform: add extra checks for temporary variables --- .../IL/Transforms/SwitchOnNullableTransform.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs index f2e3107b2..6e01731fc 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs @@ -82,6 +82,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms !instructions[i - 1].MatchStLoc(out var switchVariable, out var getValueOrDefault) || !instructions[i].MatchIfInstruction(out var condition, out var trueInst)) return false; + if (!tmp.IsSingleDefinition || tmp.LoadCount != 2) + return false; + if (!switchVariable.IsSingleDefinition || switchVariable.LoadCount != 1) + return false; if (!instructions[i + 1].MatchBranch(out var switchBlock) || !trueInst.MatchBranch(out var nullCaseBlock)) return false; if (!ldloca.MatchLdLoca(out var switchValueVar)) @@ -99,7 +103,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!getHasValueCall.Arguments[0].MatchLdLoc(tmp) || !getValueOrDefaultCall.Arguments[0].MatchLdLoc(tmp)) return false; // match second block: switchBlock - // switch (ldloc swtichVariable) { + // switch (ldloc switchVariable) { // case [0..1): br caseBlock1 // ... more cases ... // case [long.MinValue..0),[1..5),[6..10),[11..long.MaxValue]: br defaultBlock @@ -138,6 +142,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!instructions[i - 1].MatchStLoc(out var tmp, out var switchValue) || !instructions[i].MatchIfInstruction(out var condition, out var trueInst)) return false; + if (tmp.StoreCount != 1 || tmp.AddressCount != 2) + return false; if (!instructions[i + 1].MatchBranch(out var switchBlock) || !trueInst.MatchBranch(out var nullCaseBlock)) return false; if (!condition.MatchLogicNot(out var getHasValue) || !NullableLiftingTransform.MatchHasValueCall(getHasValue, out var target1) || target1 != tmp) @@ -153,6 +159,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!switchBlock.Instructions[0].MatchStLoc(out var switchVar, out var getValueOrDefault)) return false; + if (!switchVar.IsSingleDefinition || switchVar.LoadCount != 1) + return false; if (!NullableLiftingTransform.MatchGetValueOrDefault(getValueOrDefault, out var target2) || target2 != tmp) return false; if (!(switchBlock.Instructions[1] is SwitchInstruction switchInst)) @@ -172,6 +180,5 @@ namespace ICSharpCode.Decompiler.IL.Transforms } return true; } - } } From 9ef97703cd2e4a235c0e67a2a19607247e317f6f Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 11 Oct 2017 19:43:14 +0200 Subject: [PATCH 080/190] [switch] consider loop back-edges to be exit points when looking for the switch body --- .../FlowAnalysis/ControlFlowNode.cs | 63 ++--- .../ICSharpCode.Decompiler.csproj | 1 + .../IL/ControlFlow/LoopDetection.cs | 51 +++- ICSharpCode.Decompiler/Util/GraphVizGraph.cs | 221 ++++++++++++++++++ 4 files changed, 296 insertions(+), 40 deletions(-) create mode 100644 ICSharpCode.Decompiler/Util/GraphVizGraph.cs diff --git a/ICSharpCode.Decompiler/FlowAnalysis/ControlFlowNode.cs b/ICSharpCode.Decompiler/FlowAnalysis/ControlFlowNode.cs index f9aaabb30..f0a72bf20 100644 --- a/ICSharpCode.Decompiler/FlowAnalysis/ControlFlowNode.cs +++ b/ICSharpCode.Decompiler/FlowAnalysis/ControlFlowNode.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler.FlowAnalysis { @@ -118,35 +119,37 @@ namespace ICSharpCode.Decompiler.FlowAnalysis } return false; } - - //public static GraphVizGraph ExportGraph(IReadOnlyList nodes, Func labelFunc = null) - //{ - // if (labelFunc == null) { - // labelFunc = node => { - // var block = node.UserData as IL.Block; - // return block != null ? block.Label : node.UserData?.ToString(); - // }; - // } - // GraphVizGraph g = new GraphVizGraph(); - // GraphVizNode[] n = new GraphVizNode[nodes.Count]; - // for (int i = 0; i < n.Length; i++) { - // n[i] = new GraphVizNode(nodes[i].UserIndex); - // n[i].shape = "box"; - // n[i].label = labelFunc(nodes[i]); - // g.AddNode(n[i]); - // } - // foreach (var source in nodes) { - // foreach (var target in source.Successors) { - // g.AddEdge(new GraphVizEdge(source.UserIndex, target.UserIndex)); - // } - // if (source.ImmediateDominator != null) { - // g.AddEdge( - // new GraphVizEdge(source.ImmediateDominator.UserIndex, source.UserIndex) { - // color = "green" - // }); - // } - // } - // return g; - //} + +#if DEBUG + internal static GraphVizGraph ExportGraph(IReadOnlyList nodes, Func labelFunc = null) + { + if (labelFunc == null) { + labelFunc = node => { + var block = node.UserData as IL.Block; + return block != null ? block.Label : node.UserData?.ToString(); + }; + } + GraphVizGraph g = new GraphVizGraph(); + GraphVizNode[] n = new GraphVizNode[nodes.Count]; + for (int i = 0; i < n.Length; i++) { + n[i] = new GraphVizNode(nodes[i].UserIndex); + n[i].shape = "box"; + n[i].label = labelFunc(nodes[i]); + g.AddNode(n[i]); + } + foreach (var source in nodes) { + foreach (var target in source.Successors) { + g.AddEdge(new GraphVizEdge(source.UserIndex, target.UserIndex)); + } + if (source.ImmediateDominator != null) { + g.AddEdge( + new GraphVizEdge(source.ImmediateDominator.UserIndex, source.UserIndex) { + color = "green" + }); + } + } + return g; + } +#endif } } diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 7fee5ff0d..48313b70c 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -300,6 +300,7 @@ + diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs index 2e49db446..ad95af4c0 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs @@ -210,9 +210,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow /// exit-point (if non-null) is not in this set, /// nodes are no longer marked as visited in the CFG /// - void ExtendLoop(ControlFlowNode loopHead, List loop, out ControlFlowNode exitPoint) + void ExtendLoop(ControlFlowNode loopHead, List loop, out ControlFlowNode exitPoint, bool isSwitch=false) { - exitPoint = FindExitPoint(loopHead, loop); + exitPoint = FindExitPoint(loopHead, loop, isSwitch); Debug.Assert(!loop.Contains(exitPoint), "Cannot pick an exit point that is part of the natural loop"); if (exitPoint != null) { // Either we are in case 1 and just picked an exit that maximizes the amount of code @@ -258,9 +258,16 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow /// Finds a suitable single exit point for the specified loop. /// /// This method must not write to the Visited flags on the CFG. - ControlFlowNode FindExitPoint(ControlFlowNode loopHead, IReadOnlyList naturalLoop) + ControlFlowNode FindExitPoint(ControlFlowNode loopHead, IReadOnlyList naturalLoop, bool treatBackEdgesAsExits) { - if (!context.ControlFlowGraph.HasReachableExit(loopHead)) { + treatBackEdgesAsExits = false; + bool hasReachableExit = context.ControlFlowGraph.HasReachableExit(loopHead); + if (!hasReachableExit && treatBackEdgesAsExits) { + // If we're analyzing the switch, there's no reachable exit, but the loopHead (=switchHead) block + // is also a loop head, we consider the back-edge a reachable exit for the switch. + hasReachableExit = loopHead.Predecessors.Any(p => loopHead.Dominates(p)); + } + if (!hasReachableExit) { // Case 1: // There are no nodes n so that loopHead dominates a predecessor of n but not n itself // -> we could build a loop with zero exit points. @@ -275,7 +282,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow // We need to pick our exit point so that all paths from the loop head // to the reachable exits run through that exit point. var cfg = context.ControlFlowGraph.cfg; - var revCfg = PrepareReverseCFG(loopHead); + var revCfg = PrepareReverseCFG(loopHead, treatBackEdgesAsExits); //ControlFlowNode.ExportGraph(cfg).Show("cfg"); //ControlFlowNode.ExportGraph(revCfg).Show("rev"); ControlFlowNode commonAncestor = revCfg[loopHead.UserIndex]; @@ -297,7 +304,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow return exitPoint; } } - // least common dominator is the artificial exit node + // least common post-dominator is the artificial exit node return null; } } @@ -339,7 +346,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow } } - ControlFlowNode[] PrepareReverseCFG(ControlFlowNode loopHead) + ControlFlowNode[] PrepareReverseCFG(ControlFlowNode loopHead, bool treatBackEdgesAsExits) { ControlFlowNode[] cfg = context.ControlFlowGraph.cfg; ControlFlowNode[] rev = new ControlFlowNode[cfg.Length + 1]; @@ -353,7 +360,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow continue; // Add reverse edges for all edges in cfg foreach (var succ in cfg[i].Successors) { - if (loopHead.Dominates(succ)) { + if (loopHead.Dominates(succ) && (!treatBackEdgesAsExits || loopHead != succ)) { rev[succ.UserIndex].AddEdgeTo(rev[i]); } else { exitNode.AddEdgeTo(rev[i]); @@ -488,14 +495,22 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow private void DetectSwitchBody(Block block, SwitchInstruction switchInst) { Debug.Assert(block.Instructions.Last() == switchInst); - ControlFlowNode h = context.ControlFlowNode; // CFG node for our potential loop head + ControlFlowNode h = context.ControlFlowNode; // CFG node for our switch head Debug.Assert(h.UserData == block); Debug.Assert(!TreeTraversal.PreOrder(h, n => n.DominatorTreeChildren).Any(n => n.Visited)); var nodesInSwitch = new List(); nodesInSwitch.Add(h); h.Visited = true; - ExtendLoop(h, nodesInSwitch, out var exitPoint); + ExtendLoop(h, nodesInSwitch, out var exitPoint, isSwitch: true); + if (IsSimpleSwitchExit(exitPoint)) { + // Also move the exit point into the switch if it's simple enough. + exitPoint.TraversePreOrder(p => p.Successors, nodesInSwitch.Add); + foreach (var node in nodesInSwitch) { + node.Visited = false; + } + exitPoint = null; + } context.Step("Create BlockContainer for switch", switchInst); // Sort blocks in the loop in reverse post-order to make the output look a bit nicer. @@ -527,5 +542,21 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow } } } + + private bool IsSimpleSwitchExit(ControlFlowNode exitPoint) + { + int totalInstructionCount = 0; + while (exitPoint?.UserData is Block block && block.IncomingEdgeCount == 1) { + totalInstructionCount += block.Instructions.Count; + if (exitPoint.Successors.Count == 1 && block.Instructions.Last() is Branch) { + exitPoint = exitPoint.Successors[0]; + } else if (exitPoint.Successors.Count == 0 && block.Instructions.Last() is Leave leave && leave.IsLeavingFunction) { + return totalInstructionCount < 10; + } else { + return false; + } + } + return false; + } } } diff --git a/ICSharpCode.Decompiler/Util/GraphVizGraph.cs b/ICSharpCode.Decompiler/Util/GraphVizGraph.cs new file mode 100644 index 000000000..3488a52f1 --- /dev/null +++ b/ICSharpCode.Decompiler/Util/GraphVizGraph.cs @@ -0,0 +1,221 @@ +// Copyright (c) 2010-2013 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.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Text.RegularExpressions; + +namespace ICSharpCode.Decompiler.Util +{ +#if DEBUG + /// + /// GraphViz graph. + /// + sealed class GraphVizGraph + { + List nodes = new List(); + List edges = new List(); + + public string rankdir; + public string Title; + + public void AddEdge(GraphVizEdge edge) + { + edges.Add(edge); + } + + public void AddNode(GraphVizNode node) + { + nodes.Add(node); + } + + public void Save(string fileName) + { + using (StreamWriter writer = new StreamWriter(fileName)) + Save(writer); + } + + public void Show() + { + Show(null); + } + + public void Show(string name) + { + if (name == null) + name = Title; + if (name != null) + foreach (char c in Path.GetInvalidFileNameChars()) + name = name.Replace(c, '-'); + string fileName = name != null ? Path.Combine(Path.GetTempPath(), name) : Path.GetTempFileName(); + Save(fileName + ".gv"); + Process.Start("dot", "\"" + fileName + ".gv\" -Tpng -o \"" + fileName + ".png\"").WaitForExit(); + Process.Start(fileName + ".png"); + } + + static string Escape(string text) + { + if (Regex.IsMatch(text, @"^[\w\d]+$")) { + return text; + } else { + return "\"" + text.Replace("\\", "\\\\").Replace("\r", "").Replace("\n", "\\n").Replace("\"", "\\\"") + "\""; + } + } + + static void WriteGraphAttribute(TextWriter writer, string name, string value) + { + if (value != null) + writer.WriteLine("{0}={1};", name, Escape(value)); + } + + internal static void WriteAttribute(TextWriter writer, string name, double? value, ref bool isFirst) + { + if (value != null) { + WriteAttribute(writer, name, value.Value.ToString(CultureInfo.InvariantCulture), ref isFirst); + } + } + + internal static void WriteAttribute(TextWriter writer, string name, bool? value, ref bool isFirst) + { + if (value != null) { + WriteAttribute(writer, name, value.Value ? "true" : "false", ref isFirst); + } + } + + internal static void WriteAttribute(TextWriter writer, string name, string value, ref bool isFirst) + { + if (value != null) { + if (isFirst) + isFirst = false; + else + writer.Write(','); + writer.Write("{0}={1}", name, Escape(value)); + } + } + + public void Save(TextWriter writer) + { + if (writer == null) + throw new ArgumentNullException("writer"); + writer.WriteLine("digraph G {"); + writer.WriteLine("node [fontsize = 16];"); + WriteGraphAttribute(writer, "rankdir", rankdir); + foreach (GraphVizNode node in nodes) { + node.Save(writer); + } + foreach (GraphVizEdge edge in edges) { + edge.Save(writer); + } + writer.WriteLine("}"); + } + } + + sealed class GraphVizEdge + { + public readonly string Source, Target; + + /// edge stroke color + public string color; + /// use edge to affect node ranking + public bool? constraint; + + public string label; + + public string style; + + /// point size of label + public int? fontsize; + + public GraphVizEdge(string source, string target) + { + if (source == null) + throw new ArgumentNullException("source"); + if (target == null) + throw new ArgumentNullException("target"); + this.Source = source; + this.Target = target; + } + + public GraphVizEdge(int source, int target) + { + this.Source = source.ToString(CultureInfo.InvariantCulture); + this.Target = target.ToString(CultureInfo.InvariantCulture); + } + + public void Save(TextWriter writer) + { + writer.Write("{0} -> {1} [", Source, Target); + bool isFirst = true; + GraphVizGraph.WriteAttribute(writer, "label", label, ref isFirst); + GraphVizGraph.WriteAttribute(writer, "style", style, ref isFirst); + GraphVizGraph.WriteAttribute(writer, "fontsize", fontsize, ref isFirst); + GraphVizGraph.WriteAttribute(writer, "color", color, ref isFirst); + GraphVizGraph.WriteAttribute(writer, "constraint", constraint, ref isFirst); + writer.WriteLine("];"); + } + } + + sealed class GraphVizNode + { + public readonly string ID; + public string label; + + public string labelloc; + + /// point size of label + public int? fontsize; + + /// minimum height in inches + public double? height; + + /// space around label + public string margin; + + /// node shape + public string shape; + + public GraphVizNode(string id) + { + if (id == null) + throw new ArgumentNullException("id"); + this.ID = id; + } + + public GraphVizNode(int id) + { + this.ID = id.ToString(CultureInfo.InvariantCulture); + } + + public void Save(TextWriter writer) + { + writer.Write(ID); + writer.Write(" ["); + bool isFirst = true; + GraphVizGraph.WriteAttribute(writer, "label", label, ref isFirst); + GraphVizGraph.WriteAttribute(writer, "labelloc", labelloc, ref isFirst); + GraphVizGraph.WriteAttribute(writer, "fontsize", fontsize, ref isFirst); + GraphVizGraph.WriteAttribute(writer, "margin", margin, ref isFirst); + GraphVizGraph.WriteAttribute(writer, "shape", shape, ref isFirst); + writer.WriteLine("];"); + } + } +#endif +} From cd993ad0741d767fb6694b1976ad753318ff0fdb Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 11 Oct 2017 20:53:00 +0200 Subject: [PATCH 081/190] Property validate exit points determined using post-dominance. --- .../IL/ControlFlow/LoopDetection.cs | 49 +++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs index ad95af4c0..e01a84129 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs @@ -293,22 +293,63 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow commonAncestor = Dominance.FindCommonDominator(commonAncestor, revNode); } } + // All paths from within the loop to a reachable exit run through 'commonAncestor'. + // However, this doesn't mean that 'commonAncestor' is valid as an exit point. + // We walk up the post-dominator tree until we've got a valid exit point: ControlFlowNode exitPoint; while (commonAncestor.UserIndex >= 0) { exitPoint = cfg[commonAncestor.UserIndex]; Debug.Assert(exitPoint.Visited == naturalLoop.Contains(exitPoint)); - if (exitPoint.Visited) { - commonAncestor = commonAncestor.ImmediateDominator; - continue; - } else { + // It's possible that 'commonAncestor' is itself part of the natural loop. + // If so, it's not a valid exit point. + if (!exitPoint.Visited && ValidateExitPoint(loopHead, exitPoint)) { + // we found an exit point return exitPoint; } + commonAncestor = commonAncestor.ImmediateDominator; } // least common post-dominator is the artificial exit node return null; } } + /// + /// Validates an exit point. + /// + /// An exit point is invalid iff there is a node reachable from the exit point that + /// is dominated by the loop head, but not by the exit point. + /// (i.e. this method returns false iff the exit point's dominance frontier contains + /// a node dominated by the loop head. but we implement this the slow way because + /// we don't have dominance frontiers precomputed) + /// + /// + /// We need this because it's possible that there's a return block (thus reverse-unreachable node ignored by post-dominance) + /// that is reachable both directly from the loop, and from the exit point. + /// + bool ValidateExitPoint(ControlFlowNode loopHead, ControlFlowNode exitPoint) + { + var cfg = context.ControlFlowGraph; + return IsValid(exitPoint); + + bool IsValid(ControlFlowNode node) + { + if (!cfg.HasReachableExit(node)) { + // Optimization: if the dominance frontier is empty, we don't need + // to check every node. + return true; + } + foreach (var succ in node.Successors) { + if (loopHead.Dominates(succ) && !exitPoint.Dominates(succ)) + return false; + } + foreach (var child in node.DominatorTreeChildren) { + if (!IsValid(child)) + return false; + } + return true; + } + } + /// /// Pick exit point by picking any node that has no reachable exits. /// From de2c647114e5d1659179ee16b172154b342b4e13 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 11 Oct 2017 19:50:04 +0200 Subject: [PATCH 082/190] Revert "Fix bug that could cause nodes reachable from the exit point to be moved into the loop/switch." This reverts commit 105ff744b336111c6214552c4451619b2e6e6d35. A correctly chosen single exit point should dominate all other code that is dominated by the loop but not included in the body -- otherwise there would be multiple exit points. So this "bugfix" was only covering up for us not properly validating the exit points from post-dominance. --- .../IL/ControlFlow/LoopDetection.cs | 36 ++++--------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs index e01a84129..b73b7e2f5 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs @@ -101,6 +101,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow loop.Sort((a, b) => b.PostOrderNumber.CompareTo(a.PostOrderNumber)); Debug.Assert(loop[0] == h); foreach (var node in loop) { + node.Visited = false; // reset visited flag so that we can find outer loops Debug.Assert(h.Dominates(node) || !node.IsReachable, "The loop body must be dominated by the loop head"); } ConstructLoop(loop, exitPoint); @@ -206,9 +207,6 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow /// used by the post-dominance analysis. In this case, we fall back to the old heuristic algorithm. /// /// Precondition: Requires that a node is marked as visited iff it is contained in the loop. - /// Postcondition: loop is subset of nodes that are only reachable from each other, - /// exit-point (if non-null) is not in this set, - /// nodes are no longer marked as visited in the CFG /// void ExtendLoop(ControlFlowNode loopHead, List loop, out ControlFlowNode exitPoint, bool isSwitch=false) { @@ -217,16 +215,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow if (exitPoint != null) { // Either we are in case 1 and just picked an exit that maximizes the amount of code // outside the loop, or we are in case 2 and found an exit point via post-dominance. - - // We'll move all blocks dominated by the loop head into the loop, except for those that - // are reachable from the exit point. - MarkReachableWithinBlocksDominatedByLoop(exitPoint, loopHead); - foreach (var node in TreeTraversal.PreOrder(loopHead, n => n.DominatorTreeChildren)) { - if (node.Visited) { - // node.Visited means that the node is already part of the loop, - // or that it is reachable from the exit point. - node.Visited = false; - } else { + var ep = exitPoint; + foreach (var node in TreeTraversal.PreOrder(loopHead, n => (n != ep) ? n.DominatorTreeChildren : null)) { + if (node != exitPoint && !node.Visited) { loop.Add(node); } } @@ -235,25 +226,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow // Heuristically try to minimize the number of exit points // (but we'll always end up with more than 1 exit and will require goto statements). ExtendLoopHeuristic(loopHead, loop, loopHead); - // Reset Visited flag: - foreach (var node in loop) { - node.Visited = false; - } - } - } - - void MarkReachableWithinBlocksDominatedByLoop(ControlFlowNode node, ControlFlowNode loopHead) - { - if (node.Visited) - return; // already visited - if (!loopHead.Dominates(node)) - return; - node.Visited = true; - foreach (var successor in node.Successors) { - MarkReachableWithinBlocksDominatedByLoop(successor, loopHead); } } - + /// /// Finds a suitable single exit point for the specified loop. /// @@ -559,6 +534,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow nodesInSwitch.Sort((a, b) => b.PostOrderNumber.CompareTo(a.PostOrderNumber)); Debug.Assert(nodesInSwitch[0] == h); foreach (var node in nodesInSwitch) { + node.Visited = false; // reset visited flag so that we can find outer loops Debug.Assert(h.Dominates(node) || !node.IsReachable, "The switch body must be dominated by the switch head"); } From 51c895d5a5fb5158451f3c14dc9d0dfcf29fdc3d Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 11 Oct 2017 21:15:41 +0200 Subject: [PATCH 083/190] Fix inlining into switch instructions. --- ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs b/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs index d5dd01d6e..c78072dac 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs @@ -292,6 +292,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms parent = parent.Parent; } return parent == next; + case OpCode.BlockContainer: + if (((BlockContainer)next).EntryPoint.Instructions[0] is SwitchInstruction switchInst) { + next = switchInst; + goto case OpCode.SwitchInstruction; + } else { + return false; + } case OpCode.SwitchInstruction: return parent == next || (parent.MatchBinaryNumericInstruction(BinaryNumericOperator.Sub) && parent.Parent == next); default: @@ -333,6 +340,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms default: return false; } + } else if (expr is BlockContainer container && container.EntryPoint.IncomingEdgeCount == 1) { + // Possibly a switch-container, allow inlining into the switch instruction: + return FindLoadInNext(container.EntryPoint.Instructions[0], v, expressionBeingMoved, out loadInst) ?? false; + // If FindLoadInNext() returns null, we still can't continue searching + // because we can't inline over the remainder of the blockcontainer. } foreach (var child in expr.Children) { if (!child.SlotInfo.CanInlineInto) From c7490ff2fe1a7a0934261d341eb445b4ed8088da Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 11 Oct 2017 21:30:15 +0200 Subject: [PATCH 084/190] [switch] Sort switch sections --- ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs index 6e2fa3e67..7f72c6806 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs @@ -115,6 +115,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow return false; }); AdjustLabels(sw); + sw.Sections.ReplaceList(sw.Sections.OrderBy(s => (s.Body as Branch)?.TargetILOffset).ThenBy(s => s.Labels.Values.FirstOrDefault())); } static void AdjustLabels(SwitchInstruction sw) From 953c6a092977254863762a1e585e7de9fa8a0abb Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 11 Oct 2017 21:41:11 +0200 Subject: [PATCH 085/190] Keep code dominated by a single switch section within the switch. --- .../IL/ControlFlow/LoopDetection.cs | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs index b73b7e2f5..06dabbfcc 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs @@ -519,12 +519,12 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow nodesInSwitch.Add(h); h.Visited = true; ExtendLoop(h, nodesInSwitch, out var exitPoint, isSwitch: true); - if (IsSimpleSwitchExit(exitPoint)) { - // Also move the exit point into the switch if it's simple enough. - exitPoint.TraversePreOrder(p => p.Successors, nodesInSwitch.Add); - foreach (var node in nodesInSwitch) { - node.Visited = false; - } + if (exitPoint != null && exitPoint.Predecessors.Count == 1 && !context.ControlFlowGraph.HasReachableExit(exitPoint)) { + // If the exit point is reachable from just one single "break;", + // it's better to move the code into the switch. + // (unlike loops which should not be nested unless necessary, + // nesting switches makes it clearer in which cases a piece of code is reachable) + nodesInSwitch.AddRange(TreeTraversal.PreOrder(exitPoint, p => p.DominatorTreeChildren)); exitPoint = null; } @@ -559,21 +559,5 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow } } } - - private bool IsSimpleSwitchExit(ControlFlowNode exitPoint) - { - int totalInstructionCount = 0; - while (exitPoint?.UserData is Block block && block.IncomingEdgeCount == 1) { - totalInstructionCount += block.Instructions.Count; - if (exitPoint.Successors.Count == 1 && block.Instructions.Last() is Branch) { - exitPoint = exitPoint.Successors[0]; - } else if (exitPoint.Successors.Count == 0 && block.Instructions.Last() is Leave leave && leave.IsLeavingFunction) { - return totalInstructionCount < 10; - } else { - return false; - } - } - return false; - } } } From f2ee1c55f95d30938800e71959db1399aeaabfa6 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 11 Oct 2017 22:11:59 +0200 Subject: [PATCH 086/190] Add test case for switch without default + remove empty default sections in StatementBuilder. --- .../TestCases/Pretty/Switch.cs | 34 +++++ .../TestCases/Pretty/Switch.il | 129 +++++++++++++++--- .../TestCases/Pretty/Switch.opt.il | 112 ++++++++++++--- .../TestCases/Pretty/Switch.opt.roslyn.il | 78 ++++++++++- .../TestCases/Pretty/Switch.roslyn.il | 106 +++++++++++++- .../CSharp/StatementBuilder.cs | 6 + 6 files changed, 427 insertions(+), 38 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index fcf01f6d9..47cae5066 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -160,6 +160,40 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } + public static void SwitchOverInt(int i) + { + switch (i) { + case 0: { + Console.WriteLine("zero"); + break; + } + case 5: { + Console.WriteLine("five"); + break; + } + case 10: { + Console.WriteLine("ten"); + break; + } + case 15: { + Console.WriteLine("fifteen"); + break; + } + case 20: { + Console.WriteLine("twenty"); + break; + } + case 25: { + Console.WriteLine("twenty-five"); + break; + } + case 30: { + Console.WriteLine("thirty"); + break; + } + } + } + public static string ShortSwitchOverString(string text) { Console.WriteLine("ShortSwitchOverString: " + text); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il index c6af28ac4..f5e28683c 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly nyniamwr +.assembly cgwywrw0 { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module nyniamwr.dll -// MVID: {95C99B41-CBA3-42E4-A4DE-27E535671AB2} +.module cgwywrw0.dll +// MVID: {12C66A56-696F-4026-B79B-EFB40F4CD81E} .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: 0x03080000 +// Image base: 0x00B50000 // =============== CLASS MEMBERS DECLARATION =================== @@ -476,6 +476,101 @@ IL_006b: ret } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted + .method public hidebysig static void SwitchOverInt(int32 i) cil managed + { + // Code size 151 (0x97) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.0 + IL_0003: ldloc.0 + IL_0004: ldc.i4.s 10 + IL_0006: bgt.s IL_0017 + + IL_0008: ldloc.0 + IL_0009: ldc.i4.0 + IL_000a: beq.s IL_0034 + + IL_000c: ldloc.0 + IL_000d: ldc.i4.5 + IL_000e: beq.s IL_0042 + + IL_0010: ldloc.0 + IL_0011: ldc.i4.s 10 + IL_0013: beq.s IL_0050 + + IL_0015: br.s IL_0096 + + IL_0017: ldloc.0 + IL_0018: ldc.i4.s 20 + IL_001a: bgt.s IL_0028 + + IL_001c: ldloc.0 + IL_001d: ldc.i4.s 15 + IL_001f: beq.s IL_005e + + IL_0021: ldloc.0 + IL_0022: ldc.i4.s 20 + IL_0024: beq.s IL_006c + + IL_0026: br.s IL_0096 + + IL_0028: ldloc.0 + IL_0029: ldc.i4.s 25 + IL_002b: beq.s IL_007a + + IL_002d: ldloc.0 + IL_002e: ldc.i4.s 30 + IL_0030: beq.s IL_0088 + + IL_0032: br.s IL_0096 + + IL_0034: nop + IL_0035: ldstr "zero" + IL_003a: call void [mscorlib]System.Console::WriteLine(string) + IL_003f: nop + IL_0040: br.s IL_0096 + + IL_0042: nop + IL_0043: ldstr "five" + IL_0048: call void [mscorlib]System.Console::WriteLine(string) + IL_004d: nop + IL_004e: br.s IL_0096 + + IL_0050: nop + IL_0051: ldstr "ten" + IL_0056: call void [mscorlib]System.Console::WriteLine(string) + IL_005b: nop + IL_005c: br.s IL_0096 + + IL_005e: nop + IL_005f: ldstr "fifteen" + IL_0064: call void [mscorlib]System.Console::WriteLine(string) + IL_0069: nop + IL_006a: br.s IL_0096 + + IL_006c: nop + IL_006d: ldstr "twenty" + IL_0072: call void [mscorlib]System.Console::WriteLine(string) + IL_0077: nop + IL_0078: br.s IL_0096 + + IL_007a: nop + IL_007b: ldstr "twenty-five" + IL_0080: call void [mscorlib]System.Console::WriteLine(string) + IL_0085: nop + IL_0086: br.s IL_0096 + + IL_0088: nop + IL_0089: ldstr "thirty" + IL_008e: call void [mscorlib]System.Console::WriteLine(string) + IL_0093: nop + IL_0094: br.s IL_0096 + + IL_0096: ret + } // end of method Switch::SwitchOverInt + .method public hidebysig static string ShortSwitchOverString(string text) cil managed { @@ -560,7 +655,7 @@ IL_0015: brfalse IL_00ef IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x6000007-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x6000008-1' IL_0021: brtrue.s IL_0084 IL_0023: ldc.i4.7 @@ -601,9 +696,9 @@ IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007d: volatile. - IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x6000007-1' + IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x6000008-1' IL_0084: volatile. - IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x6000007-1' + IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x6000008-1' IL_008b: ldloc.1 IL_008c: ldloca.s V_2 IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -686,7 +781,7 @@ IL_0015: brfalse IL_0165 IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x6000008-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x6000009-1' IL_0021: brtrue IL_00ba IL_0026: ldc.i4.s 11 @@ -747,9 +842,9 @@ IL_00ae: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00b3: volatile. - IL_00b5: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x6000008-1' + IL_00b5: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x6000009-1' IL_00ba: volatile. - IL_00bc: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x6000008-1' + IL_00bc: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x6000009-1' IL_00c1: ldloc.2 IL_00c2: ldloca.s V_3 IL_00c4: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1064,7 +1159,7 @@ IL_0034: brfalse IL_012d IL_0039: volatile. - IL_003b: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x600000d-1' + IL_003b: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x600000e-1' IL_0040: brtrue.s IL_0097 IL_0042: ldc.i4.6 @@ -1100,9 +1195,9 @@ IL_008b: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_0090: volatile. - IL_0092: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x600000d-1' + IL_0092: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x600000e-1' IL_0097: volatile. - IL_0099: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}'::'$$method0x600000d-1' + IL_0099: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x600000e-1' IL_009e: ldloc.s V_6 IL_00a0: ldloca.s V_7 IL_00a2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1196,14 +1291,14 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}' +.class private auto ansi '{12C66A56-696F-4026-B79B-EFB40F4CD81E}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000007-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000008-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000d-1' -} // end of class '{95C99B41-CBA3-42E4-A4DE-27E535671AB2}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000009-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000e-1' +} // end of class '{12C66A56-696F-4026-B79B-EFB40F4CD81E}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il index e09dd767c..bff2ea6b4 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly f3gworj3 +.assembly '2bmtzwrf' { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module f3gworj3.dll -// MVID: {6837A40E-7A00-4F01-B2D7-DE0001F70EDF} +.module '2bmtzwrf.dll' +// MVID: {F90E3F03-F070-45F0-AC05-0914EF70B327} .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: 0x00780000 +// Image base: 0x02E10000 // =============== CLASS MEMBERS DECLARATION =================== @@ -382,6 +382,84 @@ IL_005b: ret } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted + .method public hidebysig static void SwitchOverInt(int32 i) cil managed + { + // Code size 125 (0x7d) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldc.i4.s 10 + IL_0005: bgt.s IL_0015 + + IL_0007: ldloc.0 + IL_0008: ldc.i4.0 + IL_0009: beq.s IL_0030 + + IL_000b: ldloc.0 + IL_000c: ldc.i4.5 + IL_000d: beq.s IL_003b + + IL_000f: ldloc.0 + IL_0010: ldc.i4.s 10 + IL_0012: beq.s IL_0046 + + IL_0014: ret + + IL_0015: ldloc.0 + IL_0016: ldc.i4.s 20 + IL_0018: bgt.s IL_0025 + + IL_001a: ldloc.0 + IL_001b: ldc.i4.s 15 + IL_001d: beq.s IL_0051 + + IL_001f: ldloc.0 + IL_0020: ldc.i4.s 20 + IL_0022: beq.s IL_005c + + IL_0024: ret + + IL_0025: ldloc.0 + IL_0026: ldc.i4.s 25 + IL_0028: beq.s IL_0067 + + IL_002a: ldloc.0 + IL_002b: ldc.i4.s 30 + IL_002d: beq.s IL_0072 + + IL_002f: ret + + IL_0030: ldstr "zero" + IL_0035: call void [mscorlib]System.Console::WriteLine(string) + IL_003a: ret + + IL_003b: ldstr "five" + IL_0040: call void [mscorlib]System.Console::WriteLine(string) + IL_0045: ret + + IL_0046: ldstr "ten" + IL_004b: call void [mscorlib]System.Console::WriteLine(string) + IL_0050: ret + + IL_0051: ldstr "fifteen" + IL_0056: call void [mscorlib]System.Console::WriteLine(string) + IL_005b: ret + + IL_005c: ldstr "twenty" + IL_0061: call void [mscorlib]System.Console::WriteLine(string) + IL_0066: ret + + IL_0067: ldstr "twenty-five" + IL_006c: call void [mscorlib]System.Console::WriteLine(string) + IL_0071: ret + + IL_0072: ldstr "thirty" + IL_0077: call void [mscorlib]System.Console::WriteLine(string) + IL_007c: ret + } // end of method Switch::SwitchOverInt + .method public hidebysig static string ShortSwitchOverString(string text) cil managed { @@ -449,7 +527,7 @@ IL_0013: brfalse IL_00db IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x6000007-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x6000008-1' IL_001f: brtrue.s IL_0082 IL_0021: ldc.i4.7 @@ -490,9 +568,9 @@ IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007b: volatile. - IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x6000007-1' + IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x6000008-1' IL_0082: volatile. - IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x6000007-1' + IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x6000008-1' IL_0089: ldloc.0 IL_008a: ldloca.s V_1 IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -553,7 +631,7 @@ IL_0013: brfalse IL_013f IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x6000008-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x6000009-1' IL_001f: brtrue IL_00b8 IL_0024: ldc.i4.s 11 @@ -614,9 +692,9 @@ IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00b1: volatile. - IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x6000008-1' + IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x6000009-1' IL_00b8: volatile. - IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x6000008-1' + IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x6000009-1' IL_00bf: ldloc.1 IL_00c0: ldloca.s V_2 IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -845,7 +923,7 @@ IL_0031: brfalse IL_0119 IL_0036: volatile. - IL_0038: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x600000d-1' + IL_0038: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x600000e-1' IL_003d: brtrue.s IL_0094 IL_003f: ldc.i4.6 @@ -881,9 +959,9 @@ IL_0088: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_008d: volatile. - IL_008f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x600000d-1' + IL_008f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x600000e-1' IL_0094: volatile. - IL_0096: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}'::'$$method0x600000d-1' + IL_0096: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x600000e-1' IL_009b: ldloc.s V_6 IL_009d: ldloca.s V_7 IL_009f: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -955,14 +1033,14 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}' +.class private auto ansi '{F90E3F03-F070-45F0-AC05-0914EF70B327}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000007-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000008-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000d-1' -} // end of class '{6837A40E-7A00-4F01-B2D7-DE0001F70EDF}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000009-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000e-1' +} // end of class '{F90E3F03-F070-45F0-AC05-0914EF70B327}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il index bd0488bb3..50e230ad0 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {04DBCBA6-8175-41CD-8917-9428C9765986} +// MVID: {C83C2FCD-FA35-4E74-9418-9B91F2C0748A} .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: 0x00830000 +// Image base: 0x01020000 // =============== CLASS MEMBERS DECLARATION =================== @@ -393,6 +393,80 @@ IL_005b: ret } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted + .method public hidebysig static void SwitchOverInt(int32 i) cil managed + { + // Code size 122 (0x7a) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldc.i4.s 10 + IL_0003: bgt.s IL_0012 + + IL_0005: ldarg.0 + IL_0006: brfalse.s IL_002d + + IL_0008: ldarg.0 + IL_0009: ldc.i4.5 + IL_000a: beq.s IL_0038 + + IL_000c: ldarg.0 + IL_000d: ldc.i4.s 10 + IL_000f: beq.s IL_0043 + + IL_0011: ret + + IL_0012: ldarg.0 + IL_0013: ldc.i4.s 20 + IL_0015: bgt.s IL_0022 + + IL_0017: ldarg.0 + IL_0018: ldc.i4.s 15 + IL_001a: beq.s IL_004e + + IL_001c: ldarg.0 + IL_001d: ldc.i4.s 20 + IL_001f: beq.s IL_0059 + + IL_0021: ret + + IL_0022: ldarg.0 + IL_0023: ldc.i4.s 25 + IL_0025: beq.s IL_0064 + + IL_0027: ldarg.0 + IL_0028: ldc.i4.s 30 + IL_002a: beq.s IL_006f + + IL_002c: ret + + IL_002d: ldstr "zero" + IL_0032: call void [mscorlib]System.Console::WriteLine(string) + IL_0037: ret + + IL_0038: ldstr "five" + IL_003d: call void [mscorlib]System.Console::WriteLine(string) + IL_0042: ret + + IL_0043: ldstr "ten" + IL_0048: call void [mscorlib]System.Console::WriteLine(string) + IL_004d: ret + + IL_004e: ldstr "fifteen" + IL_0053: call void [mscorlib]System.Console::WriteLine(string) + IL_0058: ret + + IL_0059: ldstr "twenty" + IL_005e: call void [mscorlib]System.Console::WriteLine(string) + IL_0063: ret + + IL_0064: ldstr "twenty-five" + IL_0069: call void [mscorlib]System.Console::WriteLine(string) + IL_006e: ret + + IL_006f: ldstr "thirty" + IL_0074: call void [mscorlib]System.Console::WriteLine(string) + IL_0079: ret + } // end of method Switch::SwitchOverInt + .method public hidebysig static string ShortSwitchOverString(string text) cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il index 38331d470..eb57faa5d 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {87DEBC09-DFAD-437D-9221-109E2117A07A} +// MVID: {B5801C4A-C979-4EC9-B5B2-295587FEEF30} .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: 0x02960000 +// Image base: 0x005D0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -521,6 +521,108 @@ IL_0079: ret } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted + .method public hidebysig static void SwitchOverInt(int32 i) cil managed + { + // Code size 161 (0xa1) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.0 + IL_0003: ldloc.0 + IL_0004: ldc.i4.s 10 + IL_0006: bgt.s IL_001d + + IL_0008: ldloc.0 + IL_0009: brfalse.s IL_003e + + IL_000b: br.s IL_000d + + IL_000d: ldloc.0 + IL_000e: ldc.i4.5 + IL_000f: beq.s IL_004c + + IL_0011: br.s IL_0013 + + IL_0013: ldloc.0 + IL_0014: ldc.i4.s 10 + IL_0016: beq.s IL_005a + + IL_0018: br IL_00a0 + + IL_001d: ldloc.0 + IL_001e: ldc.i4.s 20 + IL_0020: bgt.s IL_0030 + + IL_0022: ldloc.0 + IL_0023: ldc.i4.s 15 + IL_0025: beq.s IL_0068 + + IL_0027: br.s IL_0029 + + IL_0029: ldloc.0 + IL_002a: ldc.i4.s 20 + IL_002c: beq.s IL_0076 + + IL_002e: br.s IL_00a0 + + IL_0030: ldloc.0 + IL_0031: ldc.i4.s 25 + IL_0033: beq.s IL_0084 + + IL_0035: br.s IL_0037 + + IL_0037: ldloc.0 + IL_0038: ldc.i4.s 30 + IL_003a: beq.s IL_0092 + + IL_003c: br.s IL_00a0 + + IL_003e: nop + IL_003f: ldstr "zero" + IL_0044: call void [mscorlib]System.Console::WriteLine(string) + IL_0049: nop + IL_004a: br.s IL_00a0 + + IL_004c: nop + IL_004d: ldstr "five" + IL_0052: call void [mscorlib]System.Console::WriteLine(string) + IL_0057: nop + IL_0058: br.s IL_00a0 + + IL_005a: nop + IL_005b: ldstr "ten" + IL_0060: call void [mscorlib]System.Console::WriteLine(string) + IL_0065: nop + IL_0066: br.s IL_00a0 + + IL_0068: nop + IL_0069: ldstr "fifteen" + IL_006e: call void [mscorlib]System.Console::WriteLine(string) + IL_0073: nop + IL_0074: br.s IL_00a0 + + IL_0076: nop + IL_0077: ldstr "twenty" + IL_007c: call void [mscorlib]System.Console::WriteLine(string) + IL_0081: nop + IL_0082: br.s IL_00a0 + + IL_0084: nop + IL_0085: ldstr "twenty-five" + IL_008a: call void [mscorlib]System.Console::WriteLine(string) + IL_008f: nop + IL_0090: br.s IL_00a0 + + IL_0092: nop + IL_0093: ldstr "thirty" + IL_0098: call void [mscorlib]System.Console::WriteLine(string) + IL_009d: nop + IL_009e: br.s IL_00a0 + + IL_00a0: ret + } // end of method Switch::SwitchOverInt + .method public hidebysig static string ShortSwitchOverString(string text) cil managed { diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 8be341e76..909339d6d 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -175,6 +175,12 @@ namespace ICSharpCode.Decompiler.CSharp else ConvertSwitchSectionBody(astSection, section.Body); break; + case Leave leave: + if (astSection.CaseLabels.Count == 1 && astSection.CaseLabels.First().Expression.IsNull && leave.TargetContainer == switchContainer) { + stmt.SwitchSections.Remove(astSection); + break; + } + goto default; default: ConvertSwitchSectionBody(astSection, section.Body); break; From 3bf8d0da91ea0d4525884c7bb050f1b9d235eca9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 11 Oct 2017 23:20:39 +0200 Subject: [PATCH 087/190] Reduce size of LINQRaytracer test case --- .../TestCases/Correctness/LINQRaytracer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/LINQRaytracer.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/LINQRaytracer.cs index 3a2808a6c..c18201788 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/LINQRaytracer.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/LINQRaytracer.cs @@ -10,8 +10,8 @@ namespace RayTracer { static void Main() { - const int width = 600; - const int height = 600; + const int width = 50; + const int height = 50; RayTracer rayTracer = new RayTracer(width, height, (int x, int y, Color color) => { Console.Write("{0},{1}:{2};", x, y, color); From 4927de647ba34deb4713f76498894a32c3d625c9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 11 Oct 2017 23:21:17 +0200 Subject: [PATCH 088/190] Add more switch pretty test cases --- .../TestCases/Pretty/Switch.cs | 337 ++++++++++-------- .../TestCases/Pretty/Switch.il | 178 ++++++++- .../TestCases/Pretty/Switch.opt.il | 176 +++++++-- .../TestCases/Pretty/Switch.opt.roslyn.il | 143 +++++++- .../TestCases/Pretty/Switch.roslyn.il | 144 +++++++- 5 files changed, 771 insertions(+), 207 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index 47cae5066..056229bff 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -44,41 +44,41 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("SparseIntegerSwitch: " + i); switch (i) { case -10000000: { - return "-10 mln"; - } + return "-10 mln"; + } case -100: { - return "-hundred"; - } + return "-hundred"; + } case -1: { - return "-1"; - } + return "-1"; + } case 0: { - return "0"; - } + return "0"; + } case 1: { - return "1"; - } + return "1"; + } case 2: { - return "2"; - } + return "2"; + } case 4: { - return "4"; - } + return "4"; + } case 100: { - return "hundred"; - } + return "hundred"; + } case 10000: { - return "ten thousand"; - } + return "ten thousand"; + } case 10001: { - return "ten thousand and one"; - } + return "ten thousand and one"; + } case 2147483647: { - return "int.MaxValue"; - } + return "int.MaxValue"; + } default: { - return "something else"; - } + return "something else"; + } } } @@ -86,20 +86,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { switch (i) { case null: { - return "null"; - } + return "null"; + } case 0: { - return "zero"; - } + return "zero"; + } case 5: { - return "five"; - } + return "five"; + } case 10: { - return "ten"; - } + return "ten"; + } default: { - return "large"; - } + return "large"; + } } } @@ -107,20 +107,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { switch (i + 5) { case null: { - return "null"; - } + return "null"; + } case 0: { - return "zero"; - } + return "zero"; + } case 5: { - return "five"; - } + return "five"; + } case 10: { - return "ten"; - } + return "ten"; + } default: { - return "large"; - } + return "large"; + } } } @@ -128,17 +128,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { switch (i) { case 0: { - return "zero"; - } + return "zero"; + } case 5: { - return "five"; - } + return "five"; + } case 10: { - return "ten"; - } + return "ten"; + } default: { - return "other"; - } + return "other"; + } } } @@ -146,17 +146,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { switch (i + 5) { case 0: { - return "zero"; - } + return "zero"; + } case 5: { - return "five"; - } + return "five"; + } case 10: { - return "ten"; - } + return "ten"; + } default: { - return "other"; - } + return "other"; + } } } @@ -199,17 +199,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("ShortSwitchOverString: " + text); switch (text) { case "First case": { - return "Text1"; - } + return "Text1"; + } case "Second case": { - return "Text2"; - } + return "Text2"; + } case "Third case": { - return "Text3"; - } + return "Text3"; + } default: { - return "Default"; - } + return "Default"; + } } } @@ -218,30 +218,30 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("SwitchOverString1: " + text); switch (text) { case "First case": { - return "Text1"; - } + return "Text1"; + } case "Second case": case "2nd case": { - return "Text2"; - } + return "Text2"; + } case "Third case": { - return "Text3"; - } + return "Text3"; + } case "Fourth case": { - return "Text4"; - } + return "Text4"; + } case "Fifth case": { - return "Text5"; - } + return "Text5"; + } case "Sixth case": { - return "Text6"; - } + return "Text6"; + } case null: { - return null; - } + return null; + } default: { - return "Default"; - } + return "Default"; + } } } @@ -251,41 +251,41 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty string userName = Environment.UserName; switch (userName) { case "First case": { - return "Text1"; - } + return "Text1"; + } case "Second case": { - return "Text2"; - } + return "Text2"; + } case "Third case": { - return "Text3"; - } + return "Text3"; + } case "Fourth case": { - return "Text4"; - } + return "Text4"; + } case "Fifth case": { - return "Text5"; - } + return "Text5"; + } case "Sixth case": { - return "Text6"; - } + return "Text6"; + } case "Seventh case": { - return "Text7"; - } + return "Text7"; + } case "Eighth case": { - return "Text8"; - } + return "Text8"; + } case "Ninth case": { - return "Text9"; - } + return "Text9"; + } case "Tenth case": { - return "Text10"; - } + return "Text10"; + } case "Eleventh case": { - return "Text11"; - } + return "Text11"; + } default: { - return "Default"; - } + return "Default"; + } } } @@ -294,14 +294,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("SwitchOverBool: " + b.ToString()); switch (b) { case true: { - return bool.TrueString; - } + return bool.TrueString; + } case false: { - return bool.FalseString; - } + return bool.FalseString; + } default: { - return null; - } + return null; + } } } @@ -311,26 +311,26 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty while (true) { switch (i) { case 1: { - Console.WriteLine("one"); - break; - } + Console.WriteLine("one"); + break; + } case 2: { - Console.WriteLine("two"); - break; - } + Console.WriteLine("two"); + break; + } case 3: { - Console.WriteLine("three"); - continue; - } + Console.WriteLine("three"); + continue; + } case 4: { - Console.WriteLine("four"); - return; - } + Console.WriteLine("four"); + return; + } default: { - Console.WriteLine("default"); - Console.WriteLine("more code"); - return; - } + Console.WriteLine("default"); + Console.WriteLine("more code"); + return; + } } i++; } @@ -341,26 +341,27 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("SwitchWithGoto: " + i); switch (i) { case 1: { - Console.WriteLine("one"); - goto default; - } + Console.WriteLine("one"); + goto default; + } case 2: { - Console.WriteLine("two"); - goto case 3; - } + Console.WriteLine("two"); + goto case 3; + } case 3: { - Console.WriteLine("three"); - break; - } + Console.WriteLine("three"); + break; + } case 4: { - Console.WriteLine("four"); - return; - } + Console.WriteLine("four"); + return; + } default: { - Console.WriteLine("default"); - break; - } + Console.WriteLine("default"); + break; + } } + Console.WriteLine("End of method"); } private static SetProperty[] GetProperties() @@ -409,5 +410,51 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } } + + public static void SwitchWithComplexCondition(string[] args) + { + switch (args.Length == 0 ? "dummy" : args[0]) { + case "a": { + Console.WriteLine("a"); + break; + } + case "b": { + Console.WriteLine("b"); + break; + } + case "c": { + Console.WriteLine("c"); + break; + } + case "d": { + Console.WriteLine("d"); + break; + } + } + Console.WriteLine("end"); + } + + public static void SwitchWithArray(string[] args) + { + switch (args[0]) { + case "a": { + Console.WriteLine("a"); + break; + } + case "b": { + Console.WriteLine("b"); + break; + } + case "c": { + Console.WriteLine("c"); + break; + } + case "d": { + Console.WriteLine("d"); + break; + } + } + Console.WriteLine("end"); + } } } \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il index f5e28683c..91f9e4ff5 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly cgwywrw0 +.assembly y0cd2lcb { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module cgwywrw0.dll -// MVID: {12C66A56-696F-4026-B79B-EFB40F4CD81E} +.module y0cd2lcb.dll +// MVID: {85E7C039-2097-47F9-A636-4F4E3015541A} .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: 0x00B50000 +// Image base: 0x02630000 // =============== CLASS MEMBERS DECLARATION =================== @@ -655,7 +655,7 @@ IL_0015: brfalse IL_00ef IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x6000008-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x6000008-1' IL_0021: brtrue.s IL_0084 IL_0023: ldc.i4.7 @@ -696,9 +696,9 @@ IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007d: volatile. - IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x6000008-1' + IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x6000008-1' IL_0084: volatile. - IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x6000008-1' + IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x6000008-1' IL_008b: ldloc.1 IL_008c: ldloca.s V_2 IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -781,7 +781,7 @@ IL_0015: brfalse IL_0165 IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x6000009-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x6000009-1' IL_0021: brtrue IL_00ba IL_0026: ldc.i4.s 11 @@ -842,9 +842,9 @@ IL_00ae: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00b3: volatile. - IL_00b5: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x6000009-1' + IL_00b5: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x6000009-1' IL_00ba: volatile. - IL_00bc: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x6000009-1' + IL_00bc: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x6000009-1' IL_00c1: ldloc.2 IL_00c2: ldloca.s V_3 IL_00c4: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1048,7 +1048,7 @@ .method public hidebysig static void SwitchWithGoto(int32 i) cil managed { - // Code size 122 (0x7a) + // Code size 133 (0x85) .maxstack 2 .locals init (int32 V_0) IL_0000: nop @@ -1093,7 +1093,7 @@ IL_005e: ldstr "four" IL_0063: call void [mscorlib]System.Console::WriteLine(string) IL_0068: nop - IL_0069: br.s IL_0079 + IL_0069: br.s IL_0084 IL_006b: nop IL_006c: ldstr "default" @@ -1101,7 +1101,10 @@ IL_0076: nop IL_0077: br.s IL_0079 - IL_0079: ret + IL_0079: ldstr "End of method" + IL_007e: call void [mscorlib]System.Console::WriteLine(string) + IL_0083: nop + IL_0084: ret } // end of method Switch::SwitchWithGoto .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] @@ -1159,7 +1162,7 @@ IL_0034: brfalse IL_012d IL_0039: volatile. - IL_003b: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x600000e-1' + IL_003b: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x600000e-1' IL_0040: brtrue.s IL_0097 IL_0042: ldc.i4.6 @@ -1195,9 +1198,9 @@ IL_008b: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_0090: volatile. - IL_0092: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x600000e-1' + IL_0092: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x600000e-1' IL_0097: volatile. - IL_0099: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{12C66A56-696F-4026-B79B-EFB40F4CD81E}'::'$$method0x600000e-1' + IL_0099: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x600000e-1' IL_009e: ldloc.s V_6 IL_00a0: ldloca.s V_7 IL_00a2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1289,16 +1292,155 @@ IL_014d: ret } // end of method Switch::SwitchOnStringInForLoop + .method public hidebysig static void SwitchWithComplexCondition(string[] args) cil managed + { + // Code size 139 (0x8b) + .maxstack 2 + .locals init (string V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldlen + IL_0003: conv.i4 + IL_0004: brfalse.s IL_000b + + IL_0006: ldarg.0 + IL_0007: ldc.i4.0 + IL_0008: ldelem.ref + IL_0009: br.s IL_0010 + + IL_000b: ldstr "dummy" + IL_0010: nop + IL_0011: stloc.0 + IL_0012: ldloc.0 + IL_0013: brfalse.s IL_007f + + IL_0015: ldloc.0 + IL_0016: ldstr "a" + IL_001b: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0020: brtrue.s IL_004b + + IL_0022: ldloc.0 + IL_0023: ldstr "b" + IL_0028: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_002d: brtrue.s IL_0058 + + IL_002f: ldloc.0 + IL_0030: ldstr "c" + IL_0035: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_003a: brtrue.s IL_0065 + + IL_003c: ldloc.0 + IL_003d: ldstr "d" + IL_0042: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0047: brtrue.s IL_0072 + + IL_0049: br.s IL_007f + + IL_004b: ldstr "a" + IL_0050: call void [mscorlib]System.Console::WriteLine(string) + IL_0055: nop + IL_0056: br.s IL_007f + + IL_0058: ldstr "b" + IL_005d: call void [mscorlib]System.Console::WriteLine(string) + IL_0062: nop + IL_0063: br.s IL_007f + + IL_0065: ldstr "c" + IL_006a: call void [mscorlib]System.Console::WriteLine(string) + IL_006f: nop + IL_0070: br.s IL_007f + + IL_0072: ldstr "d" + IL_0077: call void [mscorlib]System.Console::WriteLine(string) + IL_007c: nop + IL_007d: br.s IL_007f + + IL_007f: ldstr "end" + IL_0084: call void [mscorlib]System.Console::WriteLine(string) + IL_0089: nop + IL_008a: ret + } // end of method Switch::SwitchWithComplexCondition + + .method public hidebysig static void SwitchWithArray(string[] args) cil managed + { + // Code size 126 (0x7e) + .maxstack 2 + .locals init (string V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldc.i4.0 + IL_0003: ldelem.ref + IL_0004: stloc.0 + IL_0005: ldloc.0 + IL_0006: brfalse.s IL_0072 + + IL_0008: ldloc.0 + IL_0009: ldstr "a" + IL_000e: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0013: brtrue.s IL_003e + + IL_0015: ldloc.0 + IL_0016: ldstr "b" + IL_001b: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0020: brtrue.s IL_004b + + IL_0022: ldloc.0 + IL_0023: ldstr "c" + IL_0028: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_002d: brtrue.s IL_0058 + + IL_002f: ldloc.0 + IL_0030: ldstr "d" + IL_0035: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_003a: brtrue.s IL_0065 + + IL_003c: br.s IL_0072 + + IL_003e: ldstr "a" + IL_0043: call void [mscorlib]System.Console::WriteLine(string) + IL_0048: nop + IL_0049: br.s IL_0072 + + IL_004b: ldstr "b" + IL_0050: call void [mscorlib]System.Console::WriteLine(string) + IL_0055: nop + IL_0056: br.s IL_0072 + + IL_0058: ldstr "c" + IL_005d: call void [mscorlib]System.Console::WriteLine(string) + IL_0062: nop + IL_0063: br.s IL_0072 + + IL_0065: ldstr "d" + IL_006a: call void [mscorlib]System.Console::WriteLine(string) + IL_006f: nop + IL_0070: br.s IL_0072 + + IL_0072: ldstr "end" + IL_0077: call void [mscorlib]System.Console::WriteLine(string) + IL_007c: nop + IL_007d: ret + } // end of method Switch::SwitchWithArray + } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{12C66A56-696F-4026-B79B-EFB40F4CD81E}' +.class private auto ansi '{85E7C039-2097-47F9-A636-4F4E3015541A}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000008-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000009-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000e-1' -} // end of class '{12C66A56-696F-4026-B79B-EFB40F4CD81E}' +} // end of class '{85E7C039-2097-47F9-A636-4F4E3015541A}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il index bff2ea6b4..85eea31f3 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly '2bmtzwrf' +.assembly nwkzngd2 { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module '2bmtzwrf.dll' -// MVID: {F90E3F03-F070-45F0-AC05-0914EF70B327} +.module nwkzngd2.dll +// MVID: {2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5} .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: 0x02E10000 +// Image base: 0x008E0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -527,7 +527,7 @@ IL_0013: brfalse IL_00db IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x6000008-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x6000008-1' IL_001f: brtrue.s IL_0082 IL_0021: ldc.i4.7 @@ -568,9 +568,9 @@ IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007b: volatile. - IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x6000008-1' + IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x6000008-1' IL_0082: volatile. - IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x6000008-1' + IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x6000008-1' IL_0089: ldloc.0 IL_008a: ldloca.s V_1 IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -631,7 +631,7 @@ IL_0013: brfalse IL_013f IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x6000009-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x6000009-1' IL_001f: brtrue IL_00b8 IL_0024: ldc.i4.s 11 @@ -692,9 +692,9 @@ IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00b1: volatile. - IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x6000009-1' + IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x6000009-1' IL_00b8: volatile. - IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x6000009-1' + IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x6000009-1' IL_00bf: ldloc.1 IL_00c0: ldloca.s V_2 IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -837,7 +837,7 @@ .method public hidebysig static void SwitchWithGoto(int32 i) cil managed { - // Code size 104 (0x68) + // Code size 115 (0x73) .maxstack 2 .locals init (int32 V_0) IL_0000: ldstr "SwitchWithGoto: " @@ -855,26 +855,28 @@ IL_0031, IL_003d, IL_0047, - IL_0052) - IL_002f: br.s IL_005d + IL_0053) + IL_002f: br.s IL_005e IL_0031: ldstr "one" IL_0036: call void [mscorlib]System.Console::WriteLine(string) - IL_003b: br.s IL_005d + IL_003b: br.s IL_005e IL_003d: ldstr "two" IL_0042: call void [mscorlib]System.Console::WriteLine(string) IL_0047: ldstr "three" IL_004c: call void [mscorlib]System.Console::WriteLine(string) - IL_0051: ret + IL_0051: br.s IL_0068 - IL_0052: ldstr "four" - IL_0057: call void [mscorlib]System.Console::WriteLine(string) - IL_005c: ret + IL_0053: ldstr "four" + IL_0058: call void [mscorlib]System.Console::WriteLine(string) + IL_005d: ret - IL_005d: ldstr "default" - IL_0062: call void [mscorlib]System.Console::WriteLine(string) - IL_0067: ret + IL_005e: ldstr "default" + IL_0063: call void [mscorlib]System.Console::WriteLine(string) + IL_0068: ldstr "End of method" + IL_006d: call void [mscorlib]System.Console::WriteLine(string) + IL_0072: ret } // end of method Switch::SwitchWithGoto .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] @@ -923,7 +925,7 @@ IL_0031: brfalse IL_0119 IL_0036: volatile. - IL_0038: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x600000e-1' + IL_0038: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x600000e-1' IL_003d: brtrue.s IL_0094 IL_003f: ldc.i4.6 @@ -959,9 +961,9 @@ IL_0088: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_008d: volatile. - IL_008f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x600000e-1' + IL_008f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x600000e-1' IL_0094: volatile. - IL_0096: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F90E3F03-F070-45F0-AC05-0914EF70B327}'::'$$method0x600000e-1' + IL_0096: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x600000e-1' IL_009b: ldloc.s V_6 IL_009d: ldloca.s V_7 IL_009f: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1031,16 +1033,138 @@ IL_012e: ret } // end of method Switch::SwitchOnStringInForLoop + .method public hidebysig static void SwitchWithComplexCondition(string[] args) cil managed + { + // Code size 130 (0x82) + .maxstack 2 + .locals init (string V_0) + IL_0000: ldarg.0 + IL_0001: ldlen + IL_0002: conv.i4 + IL_0003: brfalse.s IL_000a + + IL_0005: ldarg.0 + IL_0006: ldc.i4.0 + IL_0007: ldelem.ref + IL_0008: br.s IL_000f + + IL_000a: ldstr "dummy" + IL_000f: dup + IL_0010: stloc.0 + IL_0011: brfalse.s IL_0077 + + IL_0013: ldloc.0 + IL_0014: ldstr "a" + IL_0019: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_001e: brtrue.s IL_0049 + + IL_0020: ldloc.0 + IL_0021: ldstr "b" + IL_0026: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_002b: brtrue.s IL_0055 + + IL_002d: ldloc.0 + IL_002e: ldstr "c" + IL_0033: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0038: brtrue.s IL_0061 + + IL_003a: ldloc.0 + IL_003b: ldstr "d" + IL_0040: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0045: brtrue.s IL_006d + + IL_0047: br.s IL_0077 + + IL_0049: ldstr "a" + IL_004e: call void [mscorlib]System.Console::WriteLine(string) + IL_0053: br.s IL_0077 + + IL_0055: ldstr "b" + IL_005a: call void [mscorlib]System.Console::WriteLine(string) + IL_005f: br.s IL_0077 + + IL_0061: ldstr "c" + IL_0066: call void [mscorlib]System.Console::WriteLine(string) + IL_006b: br.s IL_0077 + + IL_006d: ldstr "d" + IL_0072: call void [mscorlib]System.Console::WriteLine(string) + IL_0077: ldstr "end" + IL_007c: call void [mscorlib]System.Console::WriteLine(string) + IL_0081: ret + } // end of method Switch::SwitchWithComplexCondition + + .method public hidebysig static void SwitchWithArray(string[] args) cil managed + { + // Code size 118 (0x76) + .maxstack 2 + .locals init (string V_0) + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: ldelem.ref + IL_0003: dup + IL_0004: stloc.0 + IL_0005: brfalse.s IL_006b + + IL_0007: ldloc.0 + IL_0008: ldstr "a" + IL_000d: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0012: brtrue.s IL_003d + + IL_0014: ldloc.0 + IL_0015: ldstr "b" + IL_001a: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_001f: brtrue.s IL_0049 + + IL_0021: ldloc.0 + IL_0022: ldstr "c" + IL_0027: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_002c: brtrue.s IL_0055 + + IL_002e: ldloc.0 + IL_002f: ldstr "d" + IL_0034: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0039: brtrue.s IL_0061 + + IL_003b: br.s IL_006b + + IL_003d: ldstr "a" + IL_0042: call void [mscorlib]System.Console::WriteLine(string) + IL_0047: br.s IL_006b + + IL_0049: ldstr "b" + IL_004e: call void [mscorlib]System.Console::WriteLine(string) + IL_0053: br.s IL_006b + + IL_0055: ldstr "c" + IL_005a: call void [mscorlib]System.Console::WriteLine(string) + IL_005f: br.s IL_006b + + IL_0061: ldstr "d" + IL_0066: call void [mscorlib]System.Console::WriteLine(string) + IL_006b: ldstr "end" + IL_0070: call void [mscorlib]System.Console::WriteLine(string) + IL_0075: ret + } // end of method Switch::SwitchWithArray + } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{F90E3F03-F070-45F0-AC05-0914EF70B327}' +.class private auto ansi '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000008-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000009-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000e-1' -} // end of class '{F90E3F03-F070-45F0-AC05-0914EF70B327}' +} // end of class '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il index 50e230ad0..c28f0e721 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {C83C2FCD-FA35-4E74-9418-9B91F2C0748A} +// MVID: {94058166-F81D-4A82-ABCC-FB400C785214} .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: 0x01020000 +// Image base: 0x00EF0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -943,7 +943,7 @@ .method public hidebysig static void SwitchWithGoto(int32 i) cil managed { - // Code size 102 (0x66) + // Code size 113 (0x71) .maxstack 2 IL_0000: ldstr "SwitchWithGoto: " IL_0005: ldarg.0 @@ -958,26 +958,28 @@ IL_002f, IL_003b, IL_0045, - IL_0050) - IL_002d: br.s IL_005b + IL_0051) + IL_002d: br.s IL_005c IL_002f: ldstr "one" IL_0034: call void [mscorlib]System.Console::WriteLine(string) - IL_0039: br.s IL_005b + IL_0039: br.s IL_005c IL_003b: ldstr "two" IL_0040: call void [mscorlib]System.Console::WriteLine(string) IL_0045: ldstr "three" IL_004a: call void [mscorlib]System.Console::WriteLine(string) - IL_004f: ret + IL_004f: br.s IL_0066 - IL_0050: ldstr "four" - IL_0055: call void [mscorlib]System.Console::WriteLine(string) - IL_005a: ret + IL_0051: ldstr "four" + IL_0056: call void [mscorlib]System.Console::WriteLine(string) + IL_005b: ret - IL_005b: ldstr "default" - IL_0060: call void [mscorlib]System.Console::WriteLine(string) - IL_0065: ret + IL_005c: ldstr "default" + IL_0061: call void [mscorlib]System.Console::WriteLine(string) + IL_0066: ldstr "End of method" + IL_006b: call void [mscorlib]System.Console::WriteLine(string) + IL_0070: ret } // end of method Switch::SwitchWithGoto .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] @@ -1109,6 +1111,121 @@ IL_00e9: ret } // end of method Switch::SwitchOnStringInForLoop + .method public hidebysig static void SwitchWithComplexCondition(string[] args) cil managed + { + // Code size 126 (0x7e) + .maxstack 2 + .locals init (string V_0) + IL_0000: ldarg.0 + IL_0001: ldlen + IL_0002: brfalse.s IL_0009 + + IL_0004: ldarg.0 + IL_0005: ldc.i4.0 + IL_0006: ldelem.ref + IL_0007: br.s IL_000e + + IL_0009: ldstr "dummy" + IL_000e: stloc.0 + IL_000f: ldloc.0 + IL_0010: ldstr "a" + IL_0015: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_001a: brtrue.s IL_0045 + + IL_001c: ldloc.0 + IL_001d: ldstr "b" + IL_0022: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0027: brtrue.s IL_0051 + + IL_0029: ldloc.0 + IL_002a: ldstr "c" + IL_002f: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0034: brtrue.s IL_005d + + IL_0036: ldloc.0 + IL_0037: ldstr "d" + IL_003c: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0041: brtrue.s IL_0069 + + IL_0043: br.s IL_0073 + + IL_0045: ldstr "a" + IL_004a: call void [mscorlib]System.Console::WriteLine(string) + IL_004f: br.s IL_0073 + + IL_0051: ldstr "b" + IL_0056: call void [mscorlib]System.Console::WriteLine(string) + IL_005b: br.s IL_0073 + + IL_005d: ldstr "c" + IL_0062: call void [mscorlib]System.Console::WriteLine(string) + IL_0067: br.s IL_0073 + + IL_0069: ldstr "d" + IL_006e: call void [mscorlib]System.Console::WriteLine(string) + IL_0073: ldstr "end" + IL_0078: call void [mscorlib]System.Console::WriteLine(string) + IL_007d: ret + } // end of method Switch::SwitchWithComplexCondition + + .method public hidebysig static void SwitchWithArray(string[] args) cil managed + { + // Code size 115 (0x73) + .maxstack 2 + .locals init (string V_0) + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: ldelem.ref + IL_0003: stloc.0 + IL_0004: ldloc.0 + IL_0005: ldstr "a" + IL_000a: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_000f: brtrue.s IL_003a + + IL_0011: ldloc.0 + IL_0012: ldstr "b" + IL_0017: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_001c: brtrue.s IL_0046 + + IL_001e: ldloc.0 + IL_001f: ldstr "c" + IL_0024: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0029: brtrue.s IL_0052 + + IL_002b: ldloc.0 + IL_002c: ldstr "d" + IL_0031: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0036: brtrue.s IL_005e + + IL_0038: br.s IL_0068 + + IL_003a: ldstr "a" + IL_003f: call void [mscorlib]System.Console::WriteLine(string) + IL_0044: br.s IL_0068 + + IL_0046: ldstr "b" + IL_004b: call void [mscorlib]System.Console::WriteLine(string) + IL_0050: br.s IL_0068 + + IL_0052: ldstr "c" + IL_0057: call void [mscorlib]System.Console::WriteLine(string) + IL_005c: br.s IL_0068 + + IL_005e: ldstr "d" + IL_0063: call void [mscorlib]System.Console::WriteLine(string) + IL_0068: ldstr "end" + IL_006d: call void [mscorlib]System.Console::WriteLine(string) + IL_0072: ret + } // end of method Switch::SwitchWithArray + } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch .class private auto ansi sealed '' diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il index eb57faa5d..b74cb403c 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {B5801C4A-C979-4EC9-B5B2-295587FEEF30} +// MVID: {1E0E6114-7796-44C6-B88B-AA126D09F561} .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: 0x005D0000 +// Image base: 0x02FE0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -1240,7 +1240,7 @@ .method public hidebysig static void SwitchWithGoto(int32 i) cil managed { - // Code size 122 (0x7a) + // Code size 133 (0x85) .maxstack 2 .locals init (int32 V_0) IL_0000: nop @@ -1285,7 +1285,7 @@ IL_005e: ldstr "four" IL_0063: call void [mscorlib]System.Console::WriteLine(string) IL_0068: nop - IL_0069: br.s IL_0079 + IL_0069: br.s IL_0084 IL_006b: nop IL_006c: ldstr "default" @@ -1293,7 +1293,10 @@ IL_0076: nop IL_0077: br.s IL_0079 - IL_0079: ret + IL_0079: ldstr "End of method" + IL_007e: call void [mscorlib]System.Console::WriteLine(string) + IL_0083: nop + IL_0084: ret } // end of method Switch::SwitchWithGoto .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] @@ -1459,6 +1462,137 @@ IL_0108: ret } // end of method Switch::SwitchOnStringInForLoop + .method public hidebysig static void SwitchWithComplexCondition(string[] args) cil managed + { + // Code size 134 (0x86) + .maxstack 2 + .locals init (string V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldlen + IL_0003: brfalse.s IL_000a + + IL_0005: ldarg.0 + IL_0006: ldc.i4.0 + IL_0007: ldelem.ref + IL_0008: br.s IL_000f + + IL_000a: ldstr "dummy" + IL_000f: stloc.0 + IL_0010: ldloc.0 + IL_0011: ldstr "a" + IL_0016: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_001b: brtrue.s IL_0046 + + IL_001d: ldloc.0 + IL_001e: ldstr "b" + IL_0023: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0028: brtrue.s IL_0053 + + IL_002a: ldloc.0 + IL_002b: ldstr "c" + IL_0030: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0035: brtrue.s IL_0060 + + IL_0037: ldloc.0 + IL_0038: ldstr "d" + IL_003d: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0042: brtrue.s IL_006d + + IL_0044: br.s IL_007a + + IL_0046: ldstr "a" + IL_004b: call void [mscorlib]System.Console::WriteLine(string) + IL_0050: nop + IL_0051: br.s IL_007a + + IL_0053: ldstr "b" + IL_0058: call void [mscorlib]System.Console::WriteLine(string) + IL_005d: nop + IL_005e: br.s IL_007a + + IL_0060: ldstr "c" + IL_0065: call void [mscorlib]System.Console::WriteLine(string) + IL_006a: nop + IL_006b: br.s IL_007a + + IL_006d: ldstr "d" + IL_0072: call void [mscorlib]System.Console::WriteLine(string) + IL_0077: nop + IL_0078: br.s IL_007a + + IL_007a: ldstr "end" + IL_007f: call void [mscorlib]System.Console::WriteLine(string) + IL_0084: nop + IL_0085: ret + } // end of method Switch::SwitchWithComplexCondition + + .method public hidebysig static void SwitchWithArray(string[] args) cil managed + { + // Code size 123 (0x7b) + .maxstack 2 + .locals init (string V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldc.i4.0 + IL_0003: ldelem.ref + IL_0004: stloc.0 + IL_0005: ldloc.0 + IL_0006: ldstr "a" + IL_000b: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0010: brtrue.s IL_003b + + IL_0012: ldloc.0 + IL_0013: ldstr "b" + IL_0018: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_001d: brtrue.s IL_0048 + + IL_001f: ldloc.0 + IL_0020: ldstr "c" + IL_0025: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_002a: brtrue.s IL_0055 + + IL_002c: ldloc.0 + IL_002d: ldstr "d" + IL_0032: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0037: brtrue.s IL_0062 + + IL_0039: br.s IL_006f + + IL_003b: ldstr "a" + IL_0040: call void [mscorlib]System.Console::WriteLine(string) + IL_0045: nop + IL_0046: br.s IL_006f + + IL_0048: ldstr "b" + IL_004d: call void [mscorlib]System.Console::WriteLine(string) + IL_0052: nop + IL_0053: br.s IL_006f + + IL_0055: ldstr "c" + IL_005a: call void [mscorlib]System.Console::WriteLine(string) + IL_005f: nop + IL_0060: br.s IL_006f + + IL_0062: ldstr "d" + IL_0067: call void [mscorlib]System.Console::WriteLine(string) + IL_006c: nop + IL_006d: br.s IL_006f + + IL_006f: ldstr "end" + IL_0074: call void [mscorlib]System.Console::WriteLine(string) + IL_0079: nop + IL_007a: ret + } // end of method Switch::SwitchWithArray + } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch .class private auto ansi sealed '' From 800a635663224d183d4238f3f337c8cf2d310d61 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 11 Oct 2017 23:21:36 +0200 Subject: [PATCH 089/190] Fix bug in SimplifyCascadingIfStatements --- .../IL/Transforms/SwitchOnStringTransform.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 0c8e6ef45..cd360d722 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -88,15 +88,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!firstBlockJump.MatchBranch(out var firstBlock)) return false; - bool isLegacy; List<(string, Block)> values = new List<(string, Block)>(); // match null check: this is used by the old C# compiler. if (condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && left.MatchLdLoc(out var switchValueVar)) { - isLegacy = true; values.Add((null, firstBlock)); // Roslyn: match call to operator ==(string, string) } else if (MatchStringEqualityComparison(condition, out switchValueVar, out string value)) { - isLegacy = false; values.Add((value, firstBlock)); } else return false; // switchValueVar must be assigned only once and must be of type string. @@ -115,9 +112,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms // We didn't find enough cases, exit if (values.Count < 3) return false; - // The block after all cases should only be reachable from the previous block and the null-check (in legacy code). - if (currentCaseBlock.IncomingEdgeCount != (isLegacy ? 2 : 1)) - return false; var sections = new List(values.SelectWithIndex((index, b) => new SwitchSection { Labels = new LongSet(index), Body = new Branch(b.Item2) })); sections.Add(new SwitchSection { Labels = new LongSet(new LongInterval(0, sections.Count)).Invert(), Body = new Branch(currentCaseBlock) }); var stringToInt = new StringToInt(new LdLoc(switchValueVar), values.SelectArray(item => item.Item1)); From 87b350e4eb1b976b74fe032362ff9d1c722804eb Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 11 Oct 2017 23:36:41 +0200 Subject: [PATCH 090/190] Fix SwitchAnalysis not recursing into the default-block of IL switches. --- .../IL/ControlFlow/SwitchAnalysis.cs | 13 ++++++++----- ILSpy/Languages/ILAstLanguage.cs | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs index 962c76f3f..20767b136 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs @@ -126,8 +126,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow } else if (block.Instructions.Last() is SwitchInstruction switchInst) { if (!(tailOnly || block.Instructions.Count == 1)) return false; - if (AnalyzeSwitch(switchInst, inputValues, out trueValues)) { + if (AnalyzeSwitch(switchInst, inputValues)) { ContainsILSwitch = true; // OK + return true; } else { // switch analysis failed (e.g. switchVar mismatch) return false; } @@ -148,10 +149,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow return true; } - private bool AnalyzeSwitch(SwitchInstruction inst, LongSet inputValues, out LongSet anyMatchValues) + private bool AnalyzeSwitch(SwitchInstruction inst, LongSet inputValues) { Debug.Assert(!inst.IsLifted); - anyMatchValues = LongSet.Empty; long offset; if (MatchSwitchVar(inst.Value)) { offset = 0; @@ -177,8 +177,11 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow } foreach (var section in inst.Sections) { var matchValues = section.Labels.AddOffset(offset).IntersectWith(inputValues); - AddSection(matchValues, section.Body); - anyMatchValues = anyMatchValues.UnionWith(matchValues); + if (matchValues.Count() > 1 && section.Body.MatchBranch(out var targetBlock) && AnalyzeBlock(targetBlock, matchValues)) { + InnerBlocks.Add(targetBlock); + } else { + AddSection(matchValues, section.Body); + } } return true; } diff --git a/ILSpy/Languages/ILAstLanguage.cs b/ILSpy/Languages/ILAstLanguage.cs index 488926a76..a812da2b5 100644 --- a/ILSpy/Languages/ILAstLanguage.cs +++ b/ILSpy/Languages/ILAstLanguage.cs @@ -169,6 +169,10 @@ namespace ICSharpCode.ILSpy try { il.RunTransforms(transforms, context); } catch (StepLimitReachedException) { + } catch (Exception ex) { + output.WriteLine(ex.ToString()); + output.WriteLine(); + output.WriteLine("ILAst after the crash:"); } finally { // update stepper even if a transform crashed unexpectedly if (options.StepLimit == int.MaxValue) { From f7f583056a79424c76fde9102d7d78e631745f9a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 12 Oct 2017 00:12:20 +0200 Subject: [PATCH 091/190] Fix order of switch blocks. --- ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs index 7f72c6806..8473c17bf 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs @@ -81,6 +81,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow innerBlock.Instructions.Clear(); } blockContainerNeedsCleanup = true; + SortSwitchSections(sw); } else { // 2nd pass of SimplifySwitchInstruction (after duplicating return blocks), // (1st pass was in ControlFlowSimplification) @@ -115,6 +116,11 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow return false; }); AdjustLabels(sw); + SortSwitchSections(sw); + } + + static void SortSwitchSections(SwitchInstruction sw) + { sw.Sections.ReplaceList(sw.Sections.OrderBy(s => (s.Body as Branch)?.TargetILOffset).ThenBy(s => s.Labels.Values.FirstOrDefault())); } From 98b99eddb83f690d23d975820670b3ae7ea7a7ec Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Tue, 10 Oct 2017 13:33:33 +0200 Subject: [PATCH 092/190] Fix catch with object --- .../DetectCatchWhenConditionBlocks.cs | 62 +++++++++++++------ 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs b/ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs index 14bc7ac4e..49c579708 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs @@ -41,10 +41,18 @@ namespace ICSharpCode.Decompiler.IL.Transforms // br whenConditionBlock // } var instructions = container.EntryPoint.Instructions; - ((StLoc)instructions[0]).Value = exceptionSlot; - instructions[1].ReplaceWith(new Branch(whenConditionBlock)); - instructions.RemoveAt(2); - container.SortBlocks(deleteUnreachableBlocks: true); + if (instructions.Count == 3) { + ((StLoc)instructions[0]).Value = exceptionSlot; + instructions[1].ReplaceWith(new Branch(whenConditionBlock)); + instructions.RemoveAt(2); + container.SortBlocks(deleteUnreachableBlocks: true); + } else if (instructions.Count == 2) { + // if (comp(isinst exceptionType(ldloc exceptionVar) != ldnull)) br whenConditionBlock + // br falseBlock + instructions[0].ReplaceWith(new Branch(whenConditionBlock)); + instructions.RemoveAt(1); + container.SortBlocks(deleteUnreachableBlocks: true); + } } } } @@ -61,21 +69,39 @@ namespace ICSharpCode.Decompiler.IL.Transforms exceptionType = null; exceptionSlot = null; whenConditionBlock = null; - if (entryPoint == null || entryPoint.IncomingEdgeCount != 1 || entryPoint.Instructions.Count != 3) + if (entryPoint == null || entryPoint.IncomingEdgeCount != 1) return false; - if (!entryPoint.Instructions[0].MatchStLoc(out var temp, out var isinst) || - temp.Kind != VariableKind.StackSlot || !isinst.MatchIsInst(out exceptionSlot, out exceptionType)) - return false; - if (!exceptionSlot.MatchLdLoc(out var exceptionVar) || exceptionVar.Kind != VariableKind.Exception) - return false; - if (!entryPoint.Instructions[1].MatchIfInstruction(out var condition, out var branch)) - return false; - if (!condition.MatchCompNotEquals(out var left, out var right)) - return false; - if (!entryPoint.Instructions[2].MatchBranch(out var falseBlock) || !MatchFalseBlock(container, falseBlock, out var returnVar, out var exitBlock)) - return false; - if ((left.MatchLdNull() && right.MatchLdLoc(temp)) || (right.MatchLdNull() && left.MatchLdLoc(temp))) { - return branch.MatchBranch(out whenConditionBlock); + if (entryPoint.Instructions.Count == 3) { + if (!entryPoint.Instructions[0].MatchStLoc(out var temp, out var isinst) || + temp.Kind != VariableKind.StackSlot || !isinst.MatchIsInst(out exceptionSlot, out exceptionType)) + return false; + if (!exceptionSlot.MatchLdLoc(out var exceptionVar) || exceptionVar.Kind != VariableKind.Exception) + return false; + if (!entryPoint.Instructions[1].MatchIfInstruction(out var condition, out var branch)) + return false; + if (!condition.MatchCompNotEquals(out var left, out var right)) + return false; + if (!entryPoint.Instructions[2].MatchBranch(out var falseBlock) || !MatchFalseBlock(container, falseBlock, out var returnVar, out var exitBlock)) + return false; + if ((left.MatchLdNull() && right.MatchLdLoc(temp)) || (right.MatchLdNull() && left.MatchLdLoc(temp))) { + return branch.MatchBranch(out whenConditionBlock); + } + } else if (entryPoint.Instructions.Count == 2) { + // if (comp(isinst exceptionType(ldloc exceptionVar) != ldnull)) br whenConditionBlock + // br falseBlock + if (!entryPoint.Instructions[0].MatchIfInstruction(out var condition, out var branch)) + return false; + if (!condition.MatchCompNotEquals(out var left, out var right)) + return false; + if (!entryPoint.Instructions[1].MatchBranch(out var falseBlock) || !MatchFalseBlock(container, falseBlock, out var returnVar, out var exitBlock)) + return false; + if (!left.MatchIsInst(out exceptionSlot, out exceptionType)) + return false; + if (!exceptionSlot.MatchLdLoc(out var exceptionVar) || exceptionVar.Kind != VariableKind.Exception) + return false; + if (right.MatchLdNull()) { + return branch.MatchBranch(out whenConditionBlock); + } } return false; } From d39a21afd78027a5e1b6647cc8b146755d266cb3 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 12 Oct 2017 15:06:23 +0200 Subject: [PATCH 093/190] SimplifyCascadingIfStatements: Remove extra variable declarations before switch, if possible. --- .../IL/Transforms/SwitchOnStringTransform.cs | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index cd360d722..458445f32 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -41,9 +41,21 @@ namespace ICSharpCode.Decompiler.IL.Transforms bool changed = false; for (int i = block.Instructions.Count - 1; i >= 0; i--) { SwitchInstruction newSwitch; - if (SimplifyCascadingIfStatements(block.Instructions, i, out newSwitch)) { - block.Instructions[i + 1].ReplaceWith(newSwitch); - block.Instructions.RemoveAt(i); + if (SimplifyCascadingIfStatements(block.Instructions, i, out newSwitch, out var extraLoad, out var keepAssignmentBefore)) { + if (extraLoad) { + block.Instructions[i - 2].ReplaceWith(newSwitch); + block.Instructions.RemoveRange(i - 1, 3); + i -= 2; + } else { + if (keepAssignmentBefore) { + block.Instructions[i].ReplaceWith(newSwitch); + block.Instructions.RemoveAt(i + 1); + } else { + block.Instructions[i - 1].ReplaceWith(newSwitch); + block.Instructions.RemoveRange(i, 2); + i--; + } + } changed = true; continue; } @@ -77,9 +89,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms container.SortBlocks(deleteUnreachableBlocks: true); } - bool SimplifyCascadingIfStatements(InstructionCollection instructions, int i, out SwitchInstruction inst) + bool SimplifyCascadingIfStatements(InstructionCollection instructions, int i, out SwitchInstruction inst, out bool extraLoad, out bool keepAssignmentBefore) { inst = null; + extraLoad = false; + keepAssignmentBefore = false; + if (i < 1) return false; // match first block: checking switch-value for null or first value (Roslyn) // if (call op_Equality(ldloc switchValueVar, ldstr value)) br firstBlock // -or- @@ -99,6 +114,19 @@ namespace ICSharpCode.Decompiler.IL.Transforms // switchValueVar must be assigned only once and must be of type string. if (!switchValueVar.IsSingleDefinition || !switchValueVar.Type.IsKnownType(KnownTypeCode.String)) return false; + // if instruction must be preceeded by a stloc to the switchValueVar + if (instructions[i - 1].MatchStLoc(switchValueVar, out var switchValue)) { } + // in case of legacy code there are two stlocs: + // stloc switchValueVar(ldloc switchValue) + // stloc otherSwitchValueVar(ldloc switchValueVar) + // if (comp(ldloc switchValueVar == ldnull)) br nullCase + else if (i > 1 && instructions[i - 2].MatchStLoc(switchValueVar, out switchValue) && + instructions[i - 1].MatchStLoc(out var otherSwitchValueVar, out var switchValueCopyInst) && + switchValueCopyInst.MatchLdLoc(switchValueVar) && otherSwitchValueVar.IsSingleDefinition && switchValueVar.LoadCount == 2) + { + extraLoad = true; + } + else return false; // if instruction must be followed by a branch to the next case if (!(instructions.ElementAtOrDefault(i + 1) is Branch nextCaseJump)) return false; @@ -112,9 +140,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms // We didn't find enough cases, exit if (values.Count < 3) return false; + // if the switchValueVar is used in other places as well, do not eliminate the store. + if (switchValueVar.LoadCount > values.Count) { + keepAssignmentBefore = true; + switchValue = new LdLoc(switchValueVar); + } var sections = new List(values.SelectWithIndex((index, b) => new SwitchSection { Labels = new LongSet(index), Body = new Branch(b.Item2) })); sections.Add(new SwitchSection { Labels = new LongSet(new LongInterval(0, sections.Count)).Invert(), Body = new Branch(currentCaseBlock) }); - var stringToInt = new StringToInt(new LdLoc(switchValueVar), values.SelectArray(item => item.Item1)); + var stringToInt = new StringToInt(switchValue, values.SelectArray(item => item.Item1)); inst = new SwitchInstruction(stringToInt); inst.Sections.AddRange(sections); return true; From 67272e58efc5b548054f1d5dab90410b31ed7d9d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 12 Oct 2017 16:42:25 +0200 Subject: [PATCH 094/190] SwitchOnStringTransform: Remove extra variables introduced by switch pattern. --- .../TestCases/Pretty/Switch.cs | 2 +- .../IL/Transforms/SwitchOnStringTransform.cs | 46 +++++++++++++++---- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index 056229bff..53ebea954 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -413,7 +413,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SwitchWithComplexCondition(string[] args) { - switch (args.Length == 0 ? "dummy" : args[0]) { + switch ((args.Length == 0) ? "dummy" : args[0]) { case "a": { Console.WriteLine("a"); break; diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 458445f32..d8eac46fe 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -65,17 +65,28 @@ namespace ICSharpCode.Decompiler.IL.Transforms changed = true; continue; } - if (MatchLegacySwitchOnStringWithDict(block.Instructions, i, out newSwitch)) { + if (MatchLegacySwitchOnStringWithDict(block.Instructions, i, out newSwitch, out keepAssignmentBefore)) { block.Instructions[i + 1].ReplaceWith(newSwitch); - block.Instructions.RemoveAt(i); + if (keepAssignmentBefore) { + block.Instructions.RemoveAt(i); + i--; + } else { + block.Instructions.RemoveRange(i - 1, 2); + i -= 2; + } changed = true; continue; } - if (MatchRoslynSwitchOnString(block.Instructions, i, out newSwitch)) { - block.Instructions[i - 1].ReplaceWith(newSwitch); - block.Instructions.RemoveAt(i); + if (MatchRoslynSwitchOnString(block.Instructions, i, out newSwitch, out keepAssignmentBefore)) { + block.Instructions[i].ReplaceWith(newSwitch); + if (keepAssignmentBefore) { + block.Instructions.RemoveAt(i - 1); + i--; + } else { + block.Instructions.RemoveRange(i - 2, 2); + i -= 2; + } changed = true; - i--; continue; } } @@ -217,14 +228,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms /// /// Matches the C# 2.0 switch-on-string pattern, which uses Dictionary<string, int>. /// - bool MatchLegacySwitchOnStringWithDict(InstructionCollection instructions, int i, out SwitchInstruction inst) + bool MatchLegacySwitchOnStringWithDict(InstructionCollection instructions, int i, out SwitchInstruction inst, out bool keepAssignmentBefore) { inst = null; + keepAssignmentBefore = false; if (i < 1) return false; // match first block: checking switch-value for null if (!(instructions[i].MatchIfInstruction(out var condition, out var exitBlockJump) && instructions[i - 1].MatchStLoc(out var switchValueVar, out var switchValue) && switchValueVar.Type.IsKnownType(KnownTypeCode.String))) return false; + if (!switchValueVar.IsSingleDefinition) + return false; if (!exitBlockJump.MatchBranch(out var nullValueCaseBlock)) return false; if (!(condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && (left.Match(switchValue).Success || left.MatchLdLoc(switchValueVar)))) @@ -279,7 +293,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms stringValues.Add(null); sections.Add(new SwitchSection() { Labels = label, Body = new Branch(nullValueCaseBlock) }); } - var stringToInt = new StringToInt(new LdLoc(switchValueVar), stringValues.ToArray()); + if (switchValueVar.LoadCount > 2) { + switchValue = new LdLoc(switchValueVar); + keepAssignmentBefore = true; + } + var stringToInt = new StringToInt(switchValue, stringValues.ToArray()); inst = new SwitchInstruction(stringToInt); inst.Sections.AddRange(sections); return true; @@ -434,9 +452,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; } - bool MatchRoslynSwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst) + bool MatchRoslynSwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst, out bool keepAssignmentBefore) { inst = null; + keepAssignmentBefore = false; if (i < 1) return false; if (!(instructions[i] is SwitchInstruction switchInst && switchInst.Value.MatchLdLoc(out var targetVar) && MatchComputeStringHashCall(instructions[i - 1], targetVar, out var switchValue))) @@ -473,8 +492,15 @@ namespace ICSharpCode.Decompiler.IL.Transforms } stringValues.Add((index++, stringValue, body)); } + ILInstruction switchValueInst = switchValue; + if (i > 1 && instructions[i - 2].MatchStLoc(switchValue.Variable, out var switchValueTmp) && + switchValue.Variable.IsSingleDefinition && switchValue.Variable.LoadCount == switchInst.Sections.Count) { + switchValueInst = switchValueTmp; + } else { + keepAssignmentBefore = true; + } var defaultLabel = new LongSet(new LongInterval(0, index)).Invert(); - var value = new StringToInt(switchValue.Clone(), stringValues.Select(item => item.Item2).ToArray()); + var value = new StringToInt(switchValueInst, stringValues.Select(item => item.Item2).ToArray()); inst = new SwitchInstruction(value); inst.Sections.AddRange(stringValues.Select(section => new SwitchSection { Labels = new Util.LongSet(section.Item1), Body = new Branch(section.Item3) })); inst.Sections.Add(new SwitchSection { Labels = defaultLabel, Body = defaultBranch }); From 236c7c28b4a7032840603aab7c850800bc12d418 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 12 Oct 2017 20:59:53 +0200 Subject: [PATCH 095/190] Remove redundant lambda casts. --- ICSharpCode.Decompiler.Tests/DataFlowTest.cs | 2 +- .../TestCases/Correctness/Async.cs | 6 +- .../TestCases/Pretty/CheckedUnchecked.cs | 5 +- .../TestCases/Pretty/DelegateConstruction.cs | 26 ++--- .../TestCases/Pretty/FixProxyCalls.cs | 8 +- .../TestCases/Pretty/Loops.cs | 2 +- .../TestCases/Pretty/PropertiesAndEvents.cs | 2 +- .../TestCases/Pretty/QueryExpressions.cs | 2 +- ICSharpCode.Decompiler/CSharp/CallBuilder.cs | 15 ++- .../CSharp/ExpressionBuilder.cs | 95 +++++++++++++------ .../CSharp/Resolver/LambdaResolveResult.cs | 77 +++++++++++++++ .../CSharp/TranslatedExpression.cs | 8 +- .../IL/ControlFlow/AsyncAwaitDecompiler.cs | 2 +- .../IL/ControlFlow/YieldReturnDecompiler.cs | 2 +- ICSharpCode.Decompiler/IL/ILReader.cs | 3 +- .../IL/Instructions/ILFunction.cs | 8 +- .../IL/Transforms/AssignVariableNames.cs | 6 +- .../IL/Transforms/DelegateConstruction.cs | 4 +- 18 files changed, 195 insertions(+), 78 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/DataFlowTest.cs b/ICSharpCode.Decompiler.Tests/DataFlowTest.cs index e42850616..a6b8ebfeb 100644 --- a/ICSharpCode.Decompiler.Tests/DataFlowTest.cs +++ b/ICSharpCode.Decompiler.Tests/DataFlowTest.cs @@ -55,7 +55,7 @@ namespace ICSharpCode.Decompiler.Tests public void TryFinallyWithAssignmentInFinally() { ILVariable v = new ILVariable(VariableKind.Local, SpecialType.UnknownType, 0); - ILFunction f = new ILFunction(null, new TryFinally( + ILFunction f = new ILFunction(null, null, new TryFinally( new Nop(), new StLoc(v, new LdcI4(0)) )); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Async.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Async.cs index 2d35dab5f..751f14d41 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Async.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Async.cs @@ -30,15 +30,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { public static void Main() { - new Async().Run(); + new Async().Run().Wait(); } - public async void Run() + public async Task Run() { await SimpleBoolTaskMethod(); StreamCopyTo(new MemoryStream(new byte[1024]), 16); StreamCopyToWithConfigureAwait(new MemoryStream(new byte[1024]), 16); - await AwaitInForEach(Enumerable.Range(0, 100).Select(i => Task.FromResult(i))); + await AwaitInForEach(Enumerable.Range(0, 100).Select(i => Task.FromResult(i))); await TaskMethodWithoutAwaitButWithExceptionHandling(); #if !LEGACY_CSC await AwaitCatch(Task.FromResult(1)); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CheckedUnchecked.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CheckedUnchecked.cs index 62e28d983..f58fa70b4 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CheckedUnchecked.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CheckedUnchecked.cs @@ -83,16 +83,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty }); } - public void ArrayInitializerChecked() { this.TestHelp(new int[2] { 1, 2 - }, (Func)((int[] n) => checked(new int[2] { + }, (int[] n) => checked(new int[2] { n[0] + 1, n[1] + 1 - }))); + })); } public T TestHelp(T t, Func f) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs index 283a89acc..f253f21b6 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs @@ -26,14 +26,14 @@ public static class DelegateConstruction { public Action CaptureOfThis() { - return (Action)delegate { + return delegate { this.CaptureOfThis(); }; } public Action CaptureOfThisAndParameter(int a) { - return (Action)delegate { + return delegate { this.CaptureOfThisAndParameter(a); }; } @@ -42,7 +42,7 @@ public static class DelegateConstruction { foreach (int item in Enumerable.Empty()) { if (item > 0) { - return (Action)delegate { + return delegate { this.CaptureOfThisAndParameter(item + a); }; } @@ -55,7 +55,7 @@ public static class DelegateConstruction foreach (int item in Enumerable.Empty()) { int copyOfItem = item; if (item > 0) { - return (Action)delegate { + return delegate { this.CaptureOfThisAndParameter(item + a + copyOfItem); }; } @@ -66,7 +66,7 @@ public static class DelegateConstruction public void LambdaInForLoop() { for (int i = 0; i < 100000; i++) { - this.Bar((Func)(() => this.Foo())); + this.Bar(() => this.Foo()); } } @@ -119,7 +119,7 @@ public static class DelegateConstruction List> list = new List>(); for (int i = 0; i < 10; i++) { int counter; - list.Add((Action)delegate(int x) { + list.Add(delegate(int x) { counter = x; }); } @@ -131,7 +131,7 @@ public static class DelegateConstruction List> list = new List>(); int counter; for (int i = 0; i < 10; i++) { - list.Add((Action)delegate(int x) { + list.Add(delegate(int x) { counter = x; }); } @@ -140,7 +140,7 @@ public static class DelegateConstruction public static Action StaticAnonymousMethodNoClosure() { - return (Action)delegate { + return delegate { Console.WriteLine(); }; } @@ -156,7 +156,7 @@ public static class DelegateConstruction for (int k = 0; k < 10; k++) { int i; for (i = 0; i < 10; i++) { - list.Add((Action)delegate(int j) { + list.Add(delegate(int j) { for (int l = 0; l < i; l += j) { Console.WriteLine(); } @@ -169,7 +169,7 @@ public static class DelegateConstruction { List> list = new List>(); for (int k = 0; k < 10; k++) { - list.Add((Action)delegate(int i) { + list.Add(delegate(int i) { Console.WriteLine(i); }); } @@ -177,7 +177,7 @@ public static class DelegateConstruction public static Action NameConflict3(int i) { - return (Action)delegate(int j) { + return delegate(int j) { for (int k = 0; k < j; k++) { Console.WriteLine(k); } @@ -186,11 +186,11 @@ public static class DelegateConstruction public static Func> CurriedAddition(int a) { - return (Func>)((int b) => (Func)((int c) => a + b + c)); + return (int b) => (int c) => a + b + c; } public static Func>> CurriedAddition2(int a) { - return (Func>>)((int b) => (Func>)((int c) => (Func)((int d) => a + b + c + d))); + return (int b) => (int c) => (int d) => a + b + c + d; } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs index 6aab7ade1..35a6e5740 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs @@ -8,7 +8,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty { protected internal virtual Task Test(string test) { - return Task.Run((Func)(() => test.ToUpper())); + return Task.Run(() => test.ToUpper()); } } @@ -48,7 +48,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty { protected internal override string Test(string test) { - Func func = (Func)((string a) => base.Test(a)); + Func func = (string a) => base.Test(a); test = string.Join(test, "aa"); return func(test); } @@ -66,7 +66,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty { protected internal override void Test(string test) { - Action action = (Action)delegate(string a) { + Action action = delegate(string a) { base.Test(a); }; if (test.Equals(1)) { @@ -88,7 +88,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty { protected internal override void Test(int a) { - Action action = (Action)delegate { + Action action = delegate { base.Test(a); }; if (a.Equals(1)) { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs index c6326520d..8bacd3048 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs @@ -388,7 +388,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { foreach (int item in items) { int c = item; - Loops.Operation((Func)(() => c == 5)); + Loops.Operation(() => c == 5); } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs index e08a8b8fd..3da7eada2 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs @@ -40,7 +40,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public event EventHandler AutomaticEvent; [field: NonSerialized] - public event EventHandler AutomaticEventWithInitializer = (EventHandler)delegate(object sender, EventArgs e) { + public event EventHandler AutomaticEventWithInitializer = delegate(object sender, EventArgs e) { }; public event EventHandler CustomEvent { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs index ba9ca3afe..32a91494f 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs @@ -111,7 +111,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public object FromLetWhereSelect() { return from o in this.orders - let t = o.Details.Sum((Func)((OrderDetail d) => d.UnitPrice * d.Quantity)) + let t = o.Details.Sum((OrderDetail d) => d.UnitPrice * d.Quantity) where t >= 1000m select new { OrderID = o.OrderID, diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index 57793310d..2a57d77e7 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -140,7 +140,7 @@ namespace ICSharpCode.Decompiler.CSharp atce.Initializers.Add( new NamedExpression { Name = expectedParameters[i].Name, - Expression = argumentExpressions[i] + Expression = arguments[i].ConvertTo(expectedParameters[i].Type, expressionBuilder) }); } } @@ -321,9 +321,11 @@ namespace ICSharpCode.Decompiler.CSharp case OpCode.LdVirtFtn: method = ((LdVirtFtn)func).Method; break; + case OpCode.ILFunction: + method = ((ILFunction)func).Method; + return expressionBuilder.TranslateFunction(inst.Method.DeclaringType, (ILFunction)func); default: - method = typeSystem.Resolve(((ILFunction)func).Method); - break; + throw new ArgumentException($"Unknown instruction type: {func.OpCode}"); } var invokeMethod = inst.Method.DeclaringType.GetDelegateInvokeMethod(); TranslatedExpression target; @@ -355,12 +357,7 @@ namespace ICSharpCode.Decompiler.CSharp inst.Method.DeclaringType, new MemberResolveResult(target.ResolveResult, method), Conversion.MethodGroupConversion(method, func.OpCode == OpCode.LdVirtFtn, false))); - - if (func is ILFunction) { - return expressionBuilder.TranslateFunction(oce, target, (ILFunction)func); - } else { - return oce; - } + return oce; } } } \ No newline at end of file diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index f05f0b85b..0fdd45467 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -310,12 +310,12 @@ namespace ICSharpCode.Decompiler.CSharp .WithILInstruction(inst) .WithRR(new ConstantResolveResult(compilation.FindType(KnownTypeCode.String), inst.Value)); } - + protected internal override TranslatedExpression VisitLdNull(LdNull inst, TranslationContext context) { return GetDefaultValueExpression(SpecialType.NullType).WithILInstruction(inst); } - + protected internal override TranslatedExpression VisitDefaultValue(DefaultValue inst, TranslationContext context) { return GetDefaultValueExpression(inst.Type).WithILInstruction(inst); @@ -1024,9 +1024,9 @@ namespace ICSharpCode.Decompiler.CSharp return new CallBuilder(this, typeSystem, settings).Build(inst); } - internal TranslatedExpression TranslateFunction(TranslatedExpression objectCreateExpression, TranslatedExpression target, ILFunction function) + internal TranslatedExpression TranslateFunction(IType delegateType, ILFunction function) { - var method = typeSystem.Resolve(function.Method)?.MemberDefinition as IMethod; + var method = function.Method.MemberDefinition as IMethod; Debug.Assert(method != null); // Create AnonymousMethodExpression and prepare parameters @@ -1036,19 +1036,18 @@ namespace ICSharpCode.Decompiler.CSharp ame.HasParameterList = ame.Parameters.Count > 0; StatementBuilder builder = new StatementBuilder(typeSystem.GetSpecializingTypeSystem(new SimpleTypeResolveContext(method)), this.decompilationContext, method, function, settings, cancellationToken); var body = builder.ConvertAsBlock(function.Body); - bool isLambda = false; - bool isMultiLineLambda = false; Comment prev = null; foreach (string warning in function.Warnings) { body.InsertChildAfter(prev, prev = new Comment(warning), Roles.Comment); } - // if there is an anonymous type involved, we are forced to use a lambda expression. + bool isLambda = false; if (ame.Parameters.Any(p => p.Type.IsNull)) { + // if there is an anonymous type involved, we are forced to use a lambda expression. isLambda = true; - isMultiLineLambda = body.Statements.Count > 1; } else if (ame.Parameters.All(p => p.ParameterModifier == ParameterModifier.None)) { + // otherwise use lambda only if an expression lambda is possible isLambda = (body.Statements.Count == 1 && body.Statements.Single() is ReturnStatement); } // Remove the parameter list from an AnonymousMethodExpression if the original method had no names, @@ -1064,39 +1063,81 @@ namespace ICSharpCode.Decompiler.CSharp ame.HasParameterList = false; } } - + Expression replacement; + IType inferredReturnType; if (isLambda) { LambdaExpression lambda = new LambdaExpression(); + lambda.IsAsync = ame.IsAsync; lambda.CopyAnnotationsFrom(ame); ame.Parameters.MoveTo(lambda.Parameters); - if (isMultiLineLambda) { - lambda.Body = body; + if (body.Statements.Count == 1 && body.Statements.Single() is ReturnStatement returnStmt) { + lambda.Body = returnStmt.Expression.Detach(); + inferredReturnType = lambda.Body.GetResolveResult().Type; } else { - Expression returnExpr = ((ReturnStatement)body.Statements.Single()).Expression; - returnExpr.Remove(); - lambda.Body = returnExpr; + lambda.Body = body; + inferredReturnType = InferReturnType(body); } replacement = lambda; } else { ame.Body = body; + inferredReturnType = InferReturnType(body); replacement = ame; } - var expectedType = objectCreateExpression.ResolveResult.Type; - var expectedTypeDefinition = expectedType.GetDefinition(); - if (expectedTypeDefinition != null && expectedTypeDefinition.Kind != TypeKind.Delegate) { - var simplifiedDelegateCreation = (ObjectCreateExpression)objectCreateExpression.Expression.Clone(); - simplifiedDelegateCreation.Arguments.Clear(); - simplifiedDelegateCreation.Arguments.Add(replacement); - replacement = simplifiedDelegateCreation; - } else if (!settings.AnonymousTypes || !expectedType.ContainsAnonymousType()) { - replacement = new CastExpression(ConvertType(expectedType), replacement); + if (ame.IsAsync) { + inferredReturnType = GetTaskType(inferredReturnType); } - return replacement - .WithILInstruction(function) - .WithRR(objectCreateExpression.ResolveResult); + + var rr = new DecompiledLambdaResolveResult( + function, delegateType, inferredReturnType, + hasParameterList: ame.HasParameterList, + isAnonymousMethod: !isLambda, + isImplicitlyTyped: ame.Parameters.Any(p => p.Type.IsNull)); + + TranslatedExpression translatedLambda = replacement.WithILInstruction(function).WithRR(rr); + return new CastExpression(ConvertType(delegateType), translatedLambda) + .WithoutILInstruction().WithRR(new ConversionResolveResult(delegateType, rr, LambdaConversion.Instance)); } - + + IType InferReturnType(BlockStatement body) + { + var returnExpressions = new List(); + CollectReturnExpressions(body); + var ti = new TypeInference(compilation, resolver.conversions); + return ti.GetBestCommonType(returnExpressions, out _); + // Failure to infer a return type does not make the lambda invalid, + // so we can ignore the 'success' value + + void CollectReturnExpressions(AstNode node) + { + if (node is ReturnStatement ret) { + if (!ret.Expression.IsNull) { + returnExpressions.Add(ret.Expression.GetResolveResult()); + } + } else if (node is LambdaExpression || node is AnonymousMethodExpression) { + // do not recurse into nested lambdas + return; + } + foreach (var child in node.Children) { + CollectReturnExpressions(child); + } + } + } + + IType GetTaskType(IType resultType) + { + if (resultType.Kind == TypeKind.Unknown) + return SpecialType.UnknownType; + if (resultType.Kind == TypeKind.Void) + return compilation.FindType(KnownTypeCode.Task); + + ITypeDefinition def = compilation.FindType(KnownTypeCode.TaskOfT).GetDefinition(); + if (def != null) + return new ParameterizedType(def, new[] { resultType }); + else + return SpecialType.UnknownType; + } + IEnumerable MakeParameters(IMethod method, ILFunction function) { var variables = function.Variables.Where(v => v.Kind == VariableKind.Parameter).ToDictionary(v => v.Index); diff --git a/ICSharpCode.Decompiler/CSharp/Resolver/LambdaResolveResult.cs b/ICSharpCode.Decompiler/CSharp/Resolver/LambdaResolveResult.cs index 73f431953..e699e15d6 100644 --- a/ICSharpCode.Decompiler/CSharp/Resolver/LambdaResolveResult.cs +++ b/ICSharpCode.Decompiler/CSharp/Resolver/LambdaResolveResult.cs @@ -16,6 +16,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +using System; using System.Collections.Generic; using ICSharpCode.Decompiler.Semantics; using ICSharpCode.Decompiler.TypeSystem; @@ -97,4 +98,80 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver return new [] { this.Body }; } } + + sealed class DecompiledLambdaResolveResult : LambdaResolveResult + { + readonly IL.ILFunction function; + public readonly IType DelegateType; + + /// + /// The inferred return type. + /// Can differ from ReturnType if a return statement + /// performs an implicit conversion. + /// + public readonly IType InferredReturnType; + + public DecompiledLambdaResolveResult(IL.ILFunction function, + IType delegateType, + IType inferredReturnType, + bool hasParameterList, + bool isAnonymousMethod, + bool isImplicitlyTyped) + { + this.function = function ?? throw new ArgumentNullException(nameof(function)); + this.DelegateType = delegateType ?? throw new ArgumentNullException(nameof(delegateType)); + this.InferredReturnType = inferredReturnType ?? throw new ArgumentNullException(nameof(inferredReturnType)); + this.HasParameterList = hasParameterList; + this.IsAnonymousMethod = isAnonymousMethod; + this.IsImplicitlyTyped = isImplicitlyTyped; + this.Body = new ResolveResult(SpecialType.UnknownType); + } + + public override bool HasParameterList { get; } + public override bool IsAnonymousMethod { get; } + public override bool IsImplicitlyTyped { get; } + public override bool IsAsync => function.IsAsync; + + public override IList Parameters => function.Method.Parameters; + public override IType ReturnType => function.Method.ReturnType; + + public override ResolveResult Body { get; } + + public override IType GetInferredReturnType(IType[] parameterTypes) + { + // We don't know how to compute which type would be inferred if + // given other parameter types. + // Let's hope this is good enough: + return InferredReturnType; + } + + public override Conversion IsValid(IType[] parameterTypes, IType returnType, CSharpConversions conversions) + { + if (this.Parameters.Count != parameterTypes.Length) + return Conversion.None; + for (int i = 0; i < parameterTypes.Length; ++i) { + if (!parameterTypes[i].Equals(this.Parameters[i].Type)) { + if (IsImplicitlyTyped) { + // it's possible that different parameter types also lead to a valid conversion + return LambdaConversion.Instance; + } else { + return Conversion.None; + } + } + } + if (returnType.Equals(this.ReturnType)) { + return LambdaConversion.Instance; + } else { + return Conversion.None; + } + } + } + + class LambdaConversion : Conversion + { + public static readonly LambdaConversion Instance = new LambdaConversion(); + + public override bool IsAnonymousFunctionConversion => true; + public override bool IsImplicit => true; + } } diff --git a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs index 8d49ce4cd..a4f9f2bdd 100644 --- a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs @@ -172,9 +172,11 @@ namespace ICSharpCode.Decompiler.CSharp { var type = this.Type; if (type.Equals(targetType)) { - // Remove boxing conversion if possible - if (allowImplicitConversion && type.IsKnownType(KnownTypeCode.Object)) { - if (Expression is CastExpression cast && ResolveResult is ConversionResolveResult conversion && conversion.Conversion.IsBoxingConversion) { + // Make explicit conversion implicit, if possible + if (allowImplicitConversion && Expression is CastExpression cast && ResolveResult is ConversionResolveResult conversion) { + if (type.IsKnownType(KnownTypeCode.Object) && conversion.Conversion.IsBoxingConversion + || type.Kind == TypeKind.Delegate && conversion.Conversion.IsAnonymousFunctionConversion) + { return this.UnwrapChild(cast.Expression); } } diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs index bc3a92038..44cd59c8e 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs @@ -169,7 +169,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow return false; if (startCall.Method.Name != "Start") return false; - taskType = context.TypeSystem.Resolve(function.Method.ReturnType); + taskType = function.Method.ReturnType; builderType = startCall.Method.DeclaringTypeDefinition; const string ns = "System.Runtime.CompilerServices"; if (taskType.IsKnownType(KnownTypeCode.Void)) { diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs b/ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs index b9273a821..16e545250 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs @@ -105,7 +105,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow if (!context.Settings.YieldReturn) return; // abort if enumerator decompilation is disabled this.context = context; - this.currentType = function.Method.DeclaringType; + this.currentType = function.CecilMethod.DeclaringType; this.enumeratorType = null; this.enumeratorCtor = null; this.stateField = null; diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index dbf152ee7..3700399b3 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -317,7 +317,8 @@ namespace ICSharpCode.Decompiler.IL ReadInstructions(cancellationToken); var blockBuilder = new BlockBuilder(body, typeSystem, variableByExceptionHandler); blockBuilder.CreateBlocks(mainContainer, instructionBuilder, isBranchTarget, cancellationToken); - var function = new ILFunction(body.Method, mainContainer); + var method = typeSystem.Resolve(body.Method); + var function = new ILFunction(method, body.Method, mainContainer); CollectionExtensions.AddRange(function.Variables, parameterVariables); CollectionExtensions.AddRange(function.Variables, localVariables); CollectionExtensions.AddRange(function.Variables, stackVariables); diff --git a/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs b/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs index 4c385d202..7fd03b666 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs @@ -18,10 +18,8 @@ using System; using System.Collections.Generic; -using System.Threading; using ICSharpCode.Decompiler.IL.Transforms; using Mono.Cecil; -using ICSharpCode.Decompiler.Disassembler; using System.Linq; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.Util; @@ -31,7 +29,8 @@ namespace ICSharpCode.Decompiler.IL { partial class ILFunction { - public readonly MethodDefinition Method; + public readonly IMethod Method; + public readonly MethodDefinition CecilMethod; public readonly ILVariableCollection Variables; /// @@ -62,10 +61,11 @@ namespace ICSharpCode.Decompiler.IL /// public IType AsyncReturnType; - public ILFunction(MethodDefinition method, ILInstruction body) : base(OpCode.ILFunction) + public ILFunction(IMethod method, MethodDefinition cecilMethod, ILInstruction body) : base(OpCode.ILFunction) { this.Body = body; this.Method = method; + this.CecilMethod = cecilMethod; this.Variables = new ILVariableCollection(this); } diff --git a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs index 6d512e570..520a2d18e 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs @@ -58,7 +58,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms public void Run(ILFunction function, ILTransformContext context) { this.context = context; - currentFieldNames = function.Method.DeclaringType.Fields.Select(f => f.Name).ToArray(); + currentFieldNames = function.CecilMethod.DeclaringType.Fields.Select(f => f.Name).ToArray(); reservedVariableNames = new Dictionary(); loopCounters = CollectLoopCounters(function); foreach (var p in function.Descendants.OfType().Select(f => f.Method).SelectMany(m => m.Parameters)) @@ -358,7 +358,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (v != existingVariable) AddExistingName(reservedVariableNames, v.Name); } - foreach (var f in function.Method.DeclaringType.Fields.Select(f => f.Name)) + foreach (var f in function.CecilMethod.DeclaringType.Fields.Select(f => f.Name)) AddExistingName(reservedVariableNames, f); string baseName = GetNameFromInstruction(valueContext); @@ -399,7 +399,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (v != existingVariable) AddExistingName(reservedVariableNames, v.Name); } - foreach (var f in function.Method.DeclaringType.Fields.Select(f => f.Name)) + foreach (var f in function.CecilMethod.DeclaringType.Fields.Select(f => f.Name)) AddExistingName(reservedVariableNames, f); string baseName = GetNameByType(type); diff --git a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs index 1799528bb..c248a457d 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs @@ -34,7 +34,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!context.Settings.AnonymousMethods) return; this.context = context; - this.decompilationContext = new SimpleTypeResolveContext(context.TypeSystem.Resolve(function.Method)); + this.decompilationContext = new SimpleTypeResolveContext(function.Method); var orphanedVariableInits = new List(); var targetsToReplace = new List(); foreach (var block in function.Descendants.OfType()) { @@ -102,7 +102,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms internal static bool IsPotentialClosure(ILTransformContext context, NewObj inst) { - var decompilationContext = new SimpleTypeResolveContext(context.TypeSystem.Resolve(context.Function.Method)); + var decompilationContext = new SimpleTypeResolveContext(context.Function.Method); return IsPotentialClosure(decompilationContext.CurrentTypeDefinition, inst.Method.DeclaringTypeDefinition); } From fc9ee0ff90d44e96e5b9b18e8512b3d8765bd05d Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Thu, 12 Oct 2017 21:46:12 +0200 Subject: [PATCH 096/190] Add comments for clarification. --- .../IL/Transforms/DetectCatchWhenConditionBlocks.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs b/ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs index 49c579708..872d0acd7 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs @@ -42,6 +42,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms // } var instructions = container.EntryPoint.Instructions; if (instructions.Count == 3) { + // stloc temp(isinst exceptionType(ldloc exceptionVar)) + // if (comp(ldloc temp != ldnull)) br whenConditionBlock + // br falseBlock ((StLoc)instructions[0]).Value = exceptionSlot; instructions[1].ReplaceWith(new Branch(whenConditionBlock)); instructions.RemoveAt(2); @@ -72,6 +75,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (entryPoint == null || entryPoint.IncomingEdgeCount != 1) return false; if (entryPoint.Instructions.Count == 3) { + // stloc temp(isinst exceptionType(ldloc exceptionVar)) + // if (comp(ldloc temp != ldnull)) br whenConditionBlock + // br falseBlock if (!entryPoint.Instructions[0].MatchStLoc(out var temp, out var isinst) || temp.Kind != VariableKind.StackSlot || !isinst.MatchIsInst(out exceptionSlot, out exceptionType)) return false; From c199c61c62946e74f0f13d153292e73429ddbc87 Mon Sep 17 00:00:00 2001 From: mohe2015 Date: Thu, 12 Oct 2017 22:11:12 +0200 Subject: [PATCH 097/190] Add testcase. --- .../TestCases/Pretty/ExceptionHandling.cs | 17 +- .../TestCases/Pretty/ExceptionHandling.il | 14 +- .../TestCases/Pretty/ExceptionHandling.opt.il | 14 +- .../Pretty/ExceptionHandling.opt.roslyn.il | 259 ++++++++++-------- .../Pretty/ExceptionHandling.roslyn.il | 255 ++++++++++------- 5 files changed, 330 insertions(+), 229 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs index 0ca459f92..ff1d34741 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs @@ -97,6 +97,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } return false; } + + public void CatchWhenWithConditionWithoutExceptionVar() + { + int num = 0; + try { + throw new Exception(); + } catch (Exception) when (num == 0) { + Console.WriteLine("jo"); + } + } + #endif public bool SimpleTryFinally() @@ -144,7 +155,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("Try"); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); - } catch (Exception ex2) { + } catch (SystemException ex2) { Console.WriteLine(ex2.Message); } catch { Console.WriteLine("other"); @@ -176,5 +187,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } } + + } -} +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.il index 3b306dbfc..a2159701a 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.il @@ -1,5 +1,5 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly lxxrs5dq +.assembly vicbdq3v { .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 lxxrs5dq.dll -// MVID: {82D6FFAF-FF9D-4E8C-AC93-080CC89EB80E} +.module vicbdq3v.dll +// MVID: {5E2AA050-D333-4323-8C5A-29B86C8D98BB} .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: 0x02E30000 +// Image base: 0x01160000 // =============== CLASS MEMBERS DECLARATION =================== @@ -323,7 +323,7 @@ // Code size 68 (0x44) .maxstack 1 .locals init (class [mscorlib]System.InvalidOperationException V_0, - class [mscorlib]System.Exception V_1) + class [mscorlib]System.SystemException V_1) IL_0000: nop .try { @@ -347,7 +347,7 @@ IL_001f: leave.s IL_0042 } // end handler - catch [mscorlib]System.Exception + catch [mscorlib]System.SystemException { IL_0021: stloc.1 IL_0022: nop diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.il index 6845c7f24..19e1de7c6 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.il @@ -1,5 +1,5 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly mydv32cl +.assembly uidw4n1e { .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 mydv32cl.dll -// MVID: {6B95C83E-B82F-493E-BD92-AF0A5E82F1B4} +.module uidw4n1e.dll +// MVID: {A6A100AA-2C72-4B40-9C9F-50DA438D4727} .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: 0x014A0000 +// Image base: 0x00380000 // =============== CLASS MEMBERS DECLARATION =================== @@ -258,7 +258,7 @@ // Code size 54 (0x36) .maxstack 1 .locals init (class [mscorlib]System.InvalidOperationException V_0, - class [mscorlib]System.Exception V_1) + class [mscorlib]System.SystemException V_1) .try { IL_0000: ldstr "Try" @@ -275,7 +275,7 @@ IL_0018: leave.s IL_0035 } // end handler - catch [mscorlib]System.Exception + catch [mscorlib]System.SystemException { IL_001a: stloc.1 IL_001b: ldloc.1 diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.roslyn.il index 3d18c07ed..ab43a0e40 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.roslyn.il @@ -1,5 +1,5 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module ExceptionHandling.dll -// MVID: {07FDA375-CD7B-478B-922A-E82E4CA881CF} +// MVID: {A4875794-8C32-4802-A38C-B190A38BD06B} .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: 0x02CE0000 +// Image base: 0x029B0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -53,135 +53,136 @@ instance void MoveNext() cil managed { .override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext - // Code size 242 (0xf2) + // Code size 240 (0xf0) .maxstack 3 .locals init (int32 V_0, - bool V_1, - valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 V_2, - class [mscorlib]System.Exception V_3, - class [mscorlib]System.Exception V_4) + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling V_1, + bool V_2, + valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 V_3, + class [mscorlib]System.Exception V_4, + class [mscorlib]System.Exception V_5) IL_0000: ldarg.0 IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' IL_0006: stloc.0 + IL_0007: ldarg.0 + IL_0008: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>4__this' + IL_000d: stloc.1 .try { - IL_0007: ldloc.0 - IL_0008: pop - IL_0009: nop + IL_000e: ldloc.0 + IL_000f: pop + IL_0010: nop .try { - IL_000a: ldloc.0 - IL_000b: brfalse.s IL_0054 - - IL_000d: ldstr "Try" - IL_0012: call void [mscorlib]System.Console::WriteLine(string) - IL_0017: ldarg.0 - IL_0018: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>4__this' - IL_001d: callvirt instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling::T() - IL_0022: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::GetAwaiter() - IL_0027: stloc.2 - IL_0028: ldloca.s V_2 - IL_002a: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::get_IsCompleted() - IL_002f: brtrue.s IL_0070 - - IL_0031: ldarg.0 - IL_0032: ldc.i4.0 - IL_0033: dup - IL_0034: stloc.0 - IL_0035: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' - IL_003a: ldarg.0 - IL_003b: ldloc.2 - IL_003c: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>u__1' - IL_0041: ldarg.0 - IL_0042: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>t__builder' - IL_0047: ldloca.s V_2 - IL_0049: ldarg.0 - IL_004a: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted,valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'>(!!0&, + IL_0011: ldloc.0 + IL_0012: brfalse.s IL_0056 + + IL_0014: ldstr "Try" + IL_0019: call void [mscorlib]System.Console::WriteLine(string) + IL_001e: ldloc.1 + IL_001f: callvirt instance class [mscorlib]System.Threading.Tasks.Task`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling::T() + IL_0024: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 class [mscorlib]System.Threading.Tasks.Task`1::GetAwaiter() + IL_0029: stloc.3 + IL_002a: ldloca.s V_3 + IL_002c: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::get_IsCompleted() + IL_0031: brtrue.s IL_0072 + + IL_0033: ldarg.0 + IL_0034: ldc.i4.0 + IL_0035: dup + IL_0036: stloc.0 + IL_0037: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' + IL_003c: ldarg.0 + IL_003d: ldloc.3 + IL_003e: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>u__1' + IL_0043: ldarg.0 + IL_0044: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>t__builder' + IL_0049: ldloca.s V_3 + IL_004b: ldarg.0 + IL_004c: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted,valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'>(!!0&, !!1&) - IL_004f: leave IL_00f1 - - IL_0054: ldarg.0 - IL_0055: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>u__1' - IL_005a: stloc.2 - IL_005b: ldarg.0 - IL_005c: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>u__1' - IL_0061: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 - IL_0067: ldarg.0 - IL_0068: ldc.i4.m1 - IL_0069: dup - IL_006a: stloc.0 - IL_006b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' - IL_0070: ldloca.s V_2 - IL_0072: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() - IL_0077: ldloca.s V_2 - IL_0079: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 - IL_007f: stloc.1 - IL_0080: leave.s IL_00dd + IL_0051: leave IL_00ef + + IL_0056: ldarg.0 + IL_0057: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>u__1' + IL_005c: stloc.3 + IL_005d: ldarg.0 + IL_005e: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>u__1' + IL_0063: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 + IL_0069: ldarg.0 + IL_006a: ldc.i4.m1 + IL_006b: dup + IL_006c: stloc.0 + IL_006d: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' + IL_0072: ldloca.s V_3 + IL_0074: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() + IL_0079: stloc.2 + IL_007a: leave.s IL_00db } // end .try filter { - IL_0082: isinst [mscorlib]System.Exception - IL_0087: dup - IL_0088: brtrue.s IL_008e - - IL_008a: pop - IL_008b: ldc.i4.0 - IL_008c: br.s IL_00a6 - - IL_008e: stloc.3 - IL_008f: ldloc.3 - IL_0090: isinst [mscorlib]System.ArgumentException - IL_0095: brtrue.s IL_00a2 - - IL_0097: ldloc.3 - IL_0098: isinst [mscorlib]System.IO.IOException - IL_009d: ldnull - IL_009e: cgt.un - IL_00a0: br.s IL_00a3 - - IL_00a2: ldc.i4.1 - IL_00a3: ldc.i4.0 - IL_00a4: cgt.un - IL_00a6: endfilter + IL_007c: isinst [mscorlib]System.Exception + IL_0081: dup + IL_0082: brtrue.s IL_0088 + + IL_0084: pop + IL_0085: ldc.i4.0 + IL_0086: br.s IL_00a3 + + IL_0088: stloc.s V_4 + IL_008a: ldloc.s V_4 + IL_008c: isinst [mscorlib]System.ArgumentException + IL_0091: brtrue.s IL_009f + + IL_0093: ldloc.s V_4 + IL_0095: isinst [mscorlib]System.IO.IOException + IL_009a: ldnull + IL_009b: cgt.un + IL_009d: br.s IL_00a0 + + IL_009f: ldc.i4.1 + IL_00a0: ldc.i4.0 + IL_00a1: cgt.un + IL_00a3: endfilter } // end filter { // handler - IL_00a8: pop - IL_00a9: ldstr "CatchException ex: " - IL_00ae: ldloc.3 - IL_00af: callvirt instance string [mscorlib]System.Object::ToString() - IL_00b4: call string [mscorlib]System.String::Concat(string, + IL_00a5: pop + IL_00a6: ldstr "CatchException ex: " + IL_00ab: ldloc.s V_4 + IL_00ad: callvirt instance string [mscorlib]System.Object::ToString() + IL_00b2: call string [mscorlib]System.String::Concat(string, string) - IL_00b9: call void [mscorlib]System.Console::WriteLine(string) - IL_00be: leave.s IL_00c0 + IL_00b7: call void [mscorlib]System.Console::WriteLine(string) + IL_00bc: leave.s IL_00be } // end handler - IL_00c0: ldc.i4.0 - IL_00c1: stloc.1 - IL_00c2: leave.s IL_00dd + IL_00be: ldc.i4.0 + IL_00bf: stloc.2 + IL_00c0: leave.s IL_00db } // end .try catch [mscorlib]System.Exception { - IL_00c4: stloc.s V_4 - IL_00c6: ldarg.0 - IL_00c7: ldc.i4.s -2 - IL_00c9: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' - IL_00ce: ldarg.0 - IL_00cf: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>t__builder' - IL_00d4: ldloc.s V_4 - IL_00d6: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetException(class [mscorlib]System.Exception) - IL_00db: leave.s IL_00f1 + IL_00c2: stloc.s V_5 + IL_00c4: ldarg.0 + IL_00c5: ldc.i4.s -2 + IL_00c7: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' + IL_00cc: ldarg.0 + IL_00cd: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>t__builder' + IL_00d2: ldloc.s V_5 + IL_00d4: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetException(class [mscorlib]System.Exception) + IL_00d9: leave.s IL_00ef } // end handler - IL_00dd: ldarg.0 - IL_00de: ldc.i4.s -2 - IL_00e0: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' - IL_00e5: ldarg.0 - IL_00e6: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>t__builder' - IL_00eb: ldloc.1 - IL_00ec: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) - IL_00f1: ret + IL_00db: ldarg.0 + IL_00dc: ldc.i4.s -2 + IL_00de: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' + IL_00e3: ldarg.0 + IL_00e4: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>t__builder' + IL_00e9: ldloc.2 + IL_00ea: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) + IL_00ef: ret } // end of method 'd__8'::MoveNext .method private hidebysig newslot virtual final @@ -478,6 +479,48 @@ IL_0038: ret } // end of method ExceptionHandling::SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr + .method public hidebysig instance void + CatchWhenWithConditionWithoutExceptionVar() cil managed + { + // Code size 44 (0x2c) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + .try + { + IL_0002: newobj instance void [mscorlib]System.Exception::.ctor() + IL_0007: throw + + } // end .try + filter + { + IL_0008: isinst [mscorlib]System.Exception + IL_000d: dup + IL_000e: brtrue.s IL_0014 + + IL_0010: pop + IL_0011: ldc.i4.0 + IL_0012: br.s IL_001c + + IL_0014: pop + IL_0015: ldloc.0 + IL_0016: ldc.i4.0 + IL_0017: ceq + IL_0019: ldc.i4.0 + IL_001a: cgt.un + IL_001c: endfilter + } // end filter + { // handler + IL_001e: pop + IL_001f: ldstr "jo" + IL_0024: call void [mscorlib]System.Console::WriteLine(string) + IL_0029: leave.s IL_002b + + } // end handler + IL_002b: ret + } // end of method ExceptionHandling::CatchWhenWithConditionWithoutExceptionVar + .method public hidebysig instance bool SimpleTryFinally() cil managed { @@ -586,7 +629,7 @@ IL_0016: leave.s IL_0031 } // end handler - catch [mscorlib]System.Exception + catch [mscorlib]System.SystemException { IL_0018: callvirt instance string [mscorlib]System.Exception::get_Message() IL_001d: call void [mscorlib]System.Console::WriteLine(string) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.roslyn.il index a2b3cfc11..6270c48d0 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.roslyn.il @@ -1,5 +1,5 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module ExceptionHandling.dll -// MVID: {07B52948-317B-4C30-A2A5-A7482568AD67} +// MVID: {9413A96F-08C3-4F13-A800-C6BE70786A44} .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: 0x00ED0000 +// Image base: 0x00370000 // =============== CLASS MEMBERS DECLARATION =================== @@ -66,15 +66,14 @@ instance void MoveNext() cil managed { .override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext - // Code size 306 (0x132) + // Code size 295 (0x127) .maxstack 3 .locals init (int32 V_0, bool V_1, valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 V_2, - bool V_3, - class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8' V_4, - class [mscorlib]System.Exception V_5, - bool V_6) + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8' V_3, + class [mscorlib]System.Exception V_4, + bool V_5) IL_0000: ldarg.0 IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' IL_0006: stloc.0 @@ -96,7 +95,7 @@ IL_0013: br.s IL_0017 - IL_0015: br.s IL_0065 + IL_0015: br.s IL_0064 IL_0017: nop IL_0018: ldstr "Try" @@ -109,7 +108,7 @@ IL_0033: stloc.2 IL_0034: ldloca.s V_2 IL_0036: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::get_IsCompleted() - IL_003b: brtrue.s IL_0081 + IL_003b: brtrue.s IL_0080 IL_003d: ldarg.0 IL_003e: ldc.i4.0 @@ -120,117 +119,113 @@ IL_0047: ldloc.2 IL_0048: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>u__1' IL_004d: ldarg.0 - IL_004e: stloc.s V_4 - IL_0050: ldarg.0 - IL_0051: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>t__builder' - IL_0056: ldloca.s V_2 - IL_0058: ldloca.s V_4 - IL_005a: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted,class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'>(!!0&, + IL_004e: stloc.3 + IL_004f: ldarg.0 + IL_0050: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>t__builder' + IL_0055: ldloca.s V_2 + IL_0057: ldloca.s V_3 + IL_0059: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::AwaitUnsafeOnCompleted,class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'>(!!0&, !!1&) - IL_005f: nop - IL_0060: leave IL_0131 - - IL_0065: ldarg.0 - IL_0066: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>u__1' - IL_006b: stloc.2 - IL_006c: ldarg.0 - IL_006d: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>u__1' - IL_0072: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 - IL_0078: ldarg.0 - IL_0079: ldc.i4.m1 - IL_007a: dup - IL_007b: stloc.0 - IL_007c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' + IL_005e: nop + IL_005f: leave IL_0126 + + IL_0064: ldarg.0 + IL_0065: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>u__1' + IL_006a: stloc.2 + IL_006b: ldarg.0 + IL_006c: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>u__1' + IL_0071: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 + IL_0077: ldarg.0 + IL_0078: ldc.i4.m1 + IL_0079: dup + IL_007a: stloc.0 + IL_007b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' + IL_0080: ldarg.0 IL_0081: ldloca.s V_2 IL_0083: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1::GetResult() - IL_0088: stloc.3 - IL_0089: ldloca.s V_2 - IL_008b: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1 - IL_0091: ldarg.0 - IL_0092: ldloc.3 - IL_0093: stfld bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>s__1' - IL_0098: ldarg.0 - IL_0099: ldfld bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>s__1' - IL_009e: stloc.1 - IL_009f: leave.s IL_011c + IL_0088: stfld bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>s__1' + IL_008d: ldarg.0 + IL_008e: ldfld bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>s__1' + IL_0093: stloc.1 + IL_0094: leave.s IL_0111 } // end .try filter { - IL_00a1: isinst [mscorlib]System.Exception - IL_00a6: dup - IL_00a7: brtrue.s IL_00ad - - IL_00a9: pop - IL_00aa: ldc.i4.0 - IL_00ab: br.s IL_00dc - - IL_00ad: stloc.s V_5 - IL_00af: ldarg.0 - IL_00b0: ldloc.s V_5 - IL_00b2: stfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'5__2' - IL_00b7: ldarg.0 - IL_00b8: ldfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'5__2' - IL_00bd: isinst [mscorlib]System.ArgumentException - IL_00c2: brtrue.s IL_00d4 - - IL_00c4: ldarg.0 - IL_00c5: ldfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'5__2' - IL_00ca: isinst [mscorlib]System.IO.IOException - IL_00cf: ldnull - IL_00d0: cgt.un - IL_00d2: br.s IL_00d5 - - IL_00d4: ldc.i4.1 - IL_00d5: stloc.s V_6 - IL_00d7: ldloc.s V_6 - IL_00d9: ldc.i4.0 - IL_00da: cgt.un - IL_00dc: endfilter + IL_0096: isinst [mscorlib]System.Exception + IL_009b: dup + IL_009c: brtrue.s IL_00a2 + + IL_009e: pop + IL_009f: ldc.i4.0 + IL_00a0: br.s IL_00d1 + + IL_00a2: stloc.s V_4 + IL_00a4: ldarg.0 + IL_00a5: ldloc.s V_4 + IL_00a7: stfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'5__2' + IL_00ac: ldarg.0 + IL_00ad: ldfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'5__2' + IL_00b2: isinst [mscorlib]System.ArgumentException + IL_00b7: brtrue.s IL_00c9 + + IL_00b9: ldarg.0 + IL_00ba: ldfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'5__2' + IL_00bf: isinst [mscorlib]System.IO.IOException + IL_00c4: ldnull + IL_00c5: cgt.un + IL_00c7: br.s IL_00ca + + IL_00c9: ldc.i4.1 + IL_00ca: stloc.s V_5 + IL_00cc: ldloc.s V_5 + IL_00ce: ldc.i4.0 + IL_00cf: cgt.un + IL_00d1: endfilter } // end filter { // handler - IL_00de: pop - IL_00df: nop - IL_00e0: ldstr "CatchException ex: " - IL_00e5: ldarg.0 - IL_00e6: ldfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'5__2' - IL_00eb: callvirt instance string [mscorlib]System.Object::ToString() - IL_00f0: call string [mscorlib]System.String::Concat(string, + IL_00d3: pop + IL_00d4: nop + IL_00d5: ldstr "CatchException ex: " + IL_00da: ldarg.0 + IL_00db: ldfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'5__2' + IL_00e0: callvirt instance string [mscorlib]System.Object::ToString() + IL_00e5: call string [mscorlib]System.String::Concat(string, string) - IL_00f5: call void [mscorlib]System.Console::WriteLine(string) - IL_00fa: nop - IL_00fb: nop - IL_00fc: leave.s IL_00fe + IL_00ea: call void [mscorlib]System.Console::WriteLine(string) + IL_00ef: nop + IL_00f0: nop + IL_00f1: leave.s IL_00f3 } // end handler - IL_00fe: ldc.i4.0 - IL_00ff: stloc.1 - IL_0100: leave.s IL_011c + IL_00f3: ldc.i4.0 + IL_00f4: stloc.1 + IL_00f5: leave.s IL_0111 } // end .try catch [mscorlib]System.Exception { - IL_0102: stloc.s V_5 - IL_0104: ldarg.0 - IL_0105: ldc.i4.s -2 - IL_0107: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' - IL_010c: ldarg.0 - IL_010d: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>t__builder' - IL_0112: ldloc.s V_5 - IL_0114: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetException(class [mscorlib]System.Exception) - IL_0119: nop - IL_011a: leave.s IL_0131 + IL_00f7: stloc.s V_4 + IL_00f9: ldarg.0 + IL_00fa: ldc.i4.s -2 + IL_00fc: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' + IL_0101: ldarg.0 + IL_0102: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>t__builder' + IL_0107: ldloc.s V_4 + IL_0109: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetException(class [mscorlib]System.Exception) + IL_010e: nop + IL_010f: leave.s IL_0126 } // end handler - IL_011c: ldarg.0 - IL_011d: ldc.i4.s -2 - IL_011f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' - IL_0124: ldarg.0 - IL_0125: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>t__builder' - IL_012a: ldloc.1 - IL_012b: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) - IL_0130: nop - IL_0131: ret + IL_0111: ldarg.0 + IL_0112: ldc.i4.s -2 + IL_0114: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>1__state' + IL_0119: ldarg.0 + IL_011a: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'d__8'::'<>t__builder' + IL_011f: ldloc.1 + IL_0120: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1::SetResult(!0) + IL_0125: nop + IL_0126: ret } // end of method 'd__8'::MoveNext .method private hidebysig newslot virtual final @@ -570,6 +565,56 @@ IL_003a: ret } // end of method ExceptionHandling::SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr + .method public hidebysig instance void + CatchWhenWithConditionWithoutExceptionVar() cil managed + { + // Code size 51 (0x33) + .maxstack 2 + .locals init (int32 V_0, + bool V_1) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: stloc.0 + .try + { + IL_0003: nop + IL_0004: newobj instance void [mscorlib]System.Exception::.ctor() + IL_0009: throw + + } // end .try + filter + { + IL_000a: isinst [mscorlib]System.Exception + IL_000f: dup + IL_0010: brtrue.s IL_0016 + + IL_0012: pop + IL_0013: ldc.i4.0 + IL_0014: br.s IL_0020 + + IL_0016: pop + IL_0017: ldloc.0 + IL_0018: ldc.i4.0 + IL_0019: ceq + IL_001b: stloc.1 + IL_001c: ldloc.1 + IL_001d: ldc.i4.0 + IL_001e: cgt.un + IL_0020: endfilter + } // end filter + { // handler + IL_0022: pop + IL_0023: nop + IL_0024: ldstr "jo" + IL_0029: call void [mscorlib]System.Console::WriteLine(string) + IL_002e: nop + IL_002f: nop + IL_0030: leave.s IL_0032 + + } // end handler + IL_0032: ret + } // end of method ExceptionHandling::CatchWhenWithConditionWithoutExceptionVar + .method public hidebysig instance bool SimpleTryFinally() cil managed { @@ -700,7 +745,7 @@ // Code size 67 (0x43) .maxstack 1 .locals init (class [mscorlib]System.InvalidOperationException V_0, - class [mscorlib]System.Exception V_1) + class [mscorlib]System.SystemException V_1) IL_0000: nop .try { @@ -724,7 +769,7 @@ IL_001f: leave.s IL_0042 } // end handler - catch [mscorlib]System.Exception + catch [mscorlib]System.SystemException { IL_0021: stloc.1 IL_0022: nop From 9e5d4c10f76ca587cdbbc7532590fb03422e585d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 12 Oct 2017 23:13:03 +0200 Subject: [PATCH 098/190] Fix array.Length == 0 in Roslyn. --- .../IL/Transforms/ExpressionTransforms.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs b/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs index 5256f7da7..f0011a9cf 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs @@ -111,16 +111,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms && inst.Sign == Sign.Unsigned && (inst.Kind == ComparisonKind.GreaterThan || inst.Kind == ComparisonKind.LessThanOrEqual)) { - ILInstruction array; - if (inst.Left.MatchLdLen(StackType.I, out array)) { - // comp.unsigned(ldlen array > conv i4->i(ldc.i4 0)) - // => comp(ldlen.i4 array > ldc.i4 0) - // This is a special case where the C# compiler doesn't generate conv.i4 after ldlen. - context.Step("comp(ldlen.i4 array > ldc.i4 0)", inst); - inst.InputType = StackType.I4; - inst.Left.ReplaceWith(new LdLen(StackType.I4, array) { ILRange = inst.Left.ILRange }); - inst.Right = rightWithoutConv; - } if (inst.Kind == ComparisonKind.GreaterThan) { context.Step("comp.unsigned(left > ldc.i4 0) => comp(left != ldc.i4 0)", inst); inst.Kind = ComparisonKind.Inequality; @@ -132,6 +122,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms VisitComp(inst); return; } + } else if (rightWithoutConv.MatchLdcI4(0) && inst.Kind.IsEqualityOrInequality()) { + if (inst.Left.MatchLdLen(StackType.I, out ILInstruction array)) { + // comp.unsigned(ldlen array == conv i4->i(ldc.i4 0)) + // => comp(ldlen.i4 array == ldc.i4 0) + // This is a special case where the C# compiler doesn't generate conv.i4 after ldlen. + context.Step("comp(ldlen.i4 array == ldc.i4 0)", inst); + inst.InputType = StackType.I4; + inst.Left.ReplaceWith(new LdLen(StackType.I4, array) { ILRange = inst.Left.ILRange }); + inst.Right = rightWithoutConv; + } } if (inst.Right.MatchLdNull() && inst.Left.MatchBox(out arg, out var type) && type.Kind == TypeKind.TypeParameter) { From 12e39cf63c5754b16d982c2cd29d6de003d239b2 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 12 Oct 2017 23:14:01 +0200 Subject: [PATCH 099/190] Fix switch exit points. --- ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs index 06dabbfcc..ce3d0f43d 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs @@ -235,7 +235,6 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow /// This method must not write to the Visited flags on the CFG. ControlFlowNode FindExitPoint(ControlFlowNode loopHead, IReadOnlyList naturalLoop, bool treatBackEdgesAsExits) { - treatBackEdgesAsExits = false; bool hasReachableExit = context.ControlFlowGraph.HasReachableExit(loopHead); if (!hasReachableExit && treatBackEdgesAsExits) { // If we're analyzing the switch, there's no reachable exit, but the loopHead (=switchHead) block @@ -314,7 +313,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow return true; } foreach (var succ in node.Successors) { - if (loopHead.Dominates(succ) && !exitPoint.Dominates(succ)) + if (loopHead != succ && loopHead.Dominates(succ) && !exitPoint.Dominates(succ)) return false; } foreach (var child in node.DominatorTreeChildren) { From 6ffec75c247fcace3e6d06d31152dd3a6d9b5861 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 12 Oct 2017 23:16:59 +0200 Subject: [PATCH 100/190] Run another round of SplitVariables so that the NullableLiftingTransform can work in the switch expression. --- ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 355464e64..dff75e4c8 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -84,6 +84,7 @@ namespace ICSharpCode.Decompiler.CSharp new SwitchDetection(), new SwitchOnStringTransform(), new SwitchOnNullableTransform(), + new SplitVariables(), // split variables once again, because SwitchOnNullableTransform eliminates ldloca new BlockILTransform { // per-block transforms PostOrderTransforms = { // Even though it's a post-order block-transform as most other transforms, From e33a010cc75494c296147dca8c4ea9f4fc9df8b6 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 12 Oct 2017 23:17:37 +0200 Subject: [PATCH 101/190] Remove compiler-generated variable in while (true) loops. --- .../ControlFlow/ControlFlowSimplification.cs | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs b/ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs index 695af22a4..a896ca11a 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using ICSharpCode.Decompiler.IL.Transforms; +using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.IL.ControlFlow { @@ -52,7 +53,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow SwitchDetection.SimplifySwitchInstruction(block); } SimplifyBranchChains(function, context); - CleanUpEmptyBlocks(function); + CleanUpEmptyBlocks(function, context); } void InlineVariableInReturnBlock(Block block, ILTransformContext context) @@ -129,13 +130,13 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow } } - void CleanUpEmptyBlocks(ILFunction function) + void CleanUpEmptyBlocks(ILFunction function, ILTransformContext context) { foreach (var container in function.Descendants.OfType()) { foreach (var block in container.Blocks) { if (block.Instructions.Count == 0) continue; // block is already marked for deletion - while (CombineBlockWithNextBlock(container, block)) { + while (CombineBlockWithNextBlock(container, block, context)) { // repeat combining blocks until it is no longer possible // (this loop terminates because a block is deleted in every iteration) } @@ -153,7 +154,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow return targetBlock.Instructions[0].MatchReturn(out var value) && value is LdLoc; } - static bool CombineBlockWithNextBlock(BlockContainer container, Block block) + static bool CombineBlockWithNextBlock(BlockContainer container, Block block, ILTransformContext context) { Debug.Assert(container == block.Parent); // Ensure the block will stay a basic block -- we don't want extended basic blocks prior to LoopDetection. @@ -165,12 +166,31 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow return false; if (br.TargetBlock == block) return false; // don't inline block into itself + context.Step("CombineBlockWithNextBlock", br); var targetBlock = br.TargetBlock; + if (targetBlock.ILRange.Start < block.ILRange.Start && IsDeadTrueStore(block)) { + // The C# compiler generates a dead store for the condition of while (true) loops. + block.Instructions.RemoveRange(block.Instructions.Count - 3, 2); + } block.Instructions.Remove(br); block.Instructions.AddRange(targetBlock.Instructions); targetBlock.Instructions.Clear(); // mark targetBlock for deletion return true; } - + + /// + /// Returns true if the last two instructions before the branch are storing the value 'true' into an unused variable. + /// + private static bool IsDeadTrueStore(Block block) + { + if (block.Instructions.Count < 3) return false; + if (!(block.Instructions.SecondToLastOrDefault() is StLoc deadStore && block.Instructions[block.Instructions.Count - 3] is StLoc tempStore)) + return false; + if (!(deadStore.Variable.LoadCount == 0 && deadStore.Variable.AddressCount == 0)) + return false; + if (!(deadStore.Value.MatchLdLoc(tempStore.Variable) && tempStore.Variable.IsSingleDefinition && tempStore.Variable.LoadCount == 1)) + return false; + return tempStore.Value.MatchLdcI4(1) && deadStore.Variable.Type.IsKnownType(KnownTypeCode.Boolean); + } } } From f4209947a06ebf13f0daa0ae40bf2f1bbc17964a Mon Sep 17 00:00:00 2001 From: Moritz Date: Fri, 13 Oct 2017 11:06:02 +0200 Subject: [PATCH 102/190] Fix await calls not getting decompiled correctly (#904) --- .../CorrectnessTestRunner.cs | 4 ++-- .../IL/ControlFlow/AsyncAwaitDecompiler.cs | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs index e1e52288b..510ee1067 100644 --- a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs @@ -198,8 +198,8 @@ namespace ICSharpCode.Decompiler.Tests RunCS(options: options); } - [Test, Ignore("Run() method cannot be fully decompiled.")] - public void Async([ValueSource("defaultOptions")] CompilerOptions options) + [Test] + public void Async([Values(CompilerOptions.None, CompilerOptions.Optimize)] CompilerOptions options) { RunCS(options: options); } diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs index 44cd59c8e..bf83b4334 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs @@ -774,17 +774,26 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow return false; if (!target.MatchLdThis()) return false; - if (field.MemberDefinition != awaiterField) + if (!field.Equals(awaiterField)) return false; pos++; // stfld awaiterField(ldloc this, default.value) if (block.Instructions[pos].MatchStFld(out target, out field, out value) && target.MatchLdThis() - && field.MemberDefinition == awaiterField + && field.Equals(awaiterField) && value.OpCode == OpCode.DefaultValue) { pos++; + } else { + // {stloc V_6(default.value System.Runtime.CompilerServices.TaskAwaiter)} + // {stobj System.Runtime.CompilerServices.TaskAwaiter`1[[System.Int32]](ldflda <>u__$awaiter4(ldloc this), ldloc V_6) at IL_0163} + if (block.Instructions[pos].MatchStLoc(out var variable, out value) && value.OpCode == OpCode.DefaultValue + && block.Instructions[pos + 1].MatchStFld(out target, out field, out value) + && field.Equals(awaiterField) + && value.MatchLdLoc(variable)) { + pos += 2; + } } // stloc S_28(ldc.i4 -1) @@ -804,7 +813,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow if (block.Instructions[pos].MatchStFld(out target, out field, out value)) { if (!target.MatchLdThis()) return false; - if (field.MemberDefinition != stateField) + if (!field.MemberDefinition.Equals(stateField.MemberDefinition)) return false; if (!(value.MatchLdcI4(initialState) || value.MatchLdLoc(m1Var))) return false; From faa0c8a80503e5aa853db6dc0476a0e54840980e Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 13 Oct 2017 12:00:44 +0200 Subject: [PATCH 103/190] Aggressively inline in the whole catch-when block, not just on top-level. --- ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs b/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs index d5dd01d6e..571434836 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs @@ -64,8 +64,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms static bool IsCatchWhenBlock(Block block) { - return block.Parent is BlockContainer container && container.Parent is TryCatchHandler handler - && handler.Filter == container && block == container.EntryPoint; + var container = BlockContainer.FindClosestContainer(block); + return container?.Parent is TryCatchHandler handler + && handler.Filter == container; } /// From 71f85d8e1de49f5dab298dd0b22fbef5ea97bbbe Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 13 Oct 2017 13:04:11 +0200 Subject: [PATCH 104/190] Move DelegateConstruction test into namespace. --- .../TestCases/Pretty/DelegateConstruction.cs | 277 ++++++++--------- .../TestCases/Pretty/DelegateConstruction.il | 268 ++++++++--------- .../Pretty/DelegateConstruction.opt.il | 268 ++++++++--------- .../Pretty/DelegateConstruction.opt.roslyn.il | 266 ++++++++--------- .../Pretty/DelegateConstruction.roslyn.il | 278 +++++++++--------- 5 files changed, 680 insertions(+), 677 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs index f253f21b6..cd9681ddc 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs @@ -20,177 +20,180 @@ using System; using System.Collections.Generic; using System.Linq; -public static class DelegateConstruction +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { - private class InstanceTests + public static class DelegateConstruction { - public Action CaptureOfThis() + private class InstanceTests { - return delegate { - this.CaptureOfThis(); - }; - } - - public Action CaptureOfThisAndParameter(int a) - { - return delegate { - this.CaptureOfThisAndParameter(a); - }; - } - - public Action CaptureOfThisAndParameterInForEach(int a) - { - foreach (int item in Enumerable.Empty()) { - if (item > 0) { - return delegate { - this.CaptureOfThisAndParameter(item + a); - }; + public Action CaptureOfThis() + { + return delegate { + this.CaptureOfThis(); + }; + } + + public Action CaptureOfThisAndParameter(int a) + { + return delegate { + this.CaptureOfThisAndParameter(a); + }; + } + + public Action CaptureOfThisAndParameterInForEach(int a) + { + foreach (int item in Enumerable.Empty()) { + if (item > 0) { + return delegate { + this.CaptureOfThisAndParameter(item + a); + }; + } } + return null; } - return null; - } - - public Action CaptureOfThisAndParameterInForEachWithItemCopy(int a) - { - foreach (int item in Enumerable.Empty()) { - int copyOfItem = item; - if (item > 0) { - return delegate { - this.CaptureOfThisAndParameter(item + a + copyOfItem); - }; + + public Action CaptureOfThisAndParameterInForEachWithItemCopy(int a) + { + foreach (int item in Enumerable.Empty()) { + int copyOfItem = item; + if (item > 0) { + return delegate { + this.CaptureOfThisAndParameter(item + a + copyOfItem); + }; + } } + return null; } - return null; - } - - public void LambdaInForLoop() - { - for (int i = 0; i < 100000; i++) { - this.Bar(() => this.Foo()); + + public void LambdaInForLoop() + { + for (int i = 0; i < 100000; i++) { + this.Bar(() => this.Foo()); + } + } + + public int Foo() + { + return 0; + } + + public void Bar(Func f) + { } } - - public int Foo() + + public static void Test(this string a) { - return 0; } - - public void Bar(Func f) + + public static Action ExtensionMethodUnbound() { + return new Action(DelegateConstruction.Test); } - } - - public static void Test(this string a) - { - } - public static Action ExtensionMethodUnbound() - { - return new Action(DelegateConstruction.Test); - } + public static Action ExtensionMethodBound() + { + return new Action("abc".Test); + } - public static Action ExtensionMethodBound() - { - return new Action("abc".Test); - } + public static Action ExtensionMethodBoundOnNull() + { + return new Action(((string)null).Test); + } - public static Action ExtensionMethodBoundOnNull() - { - return new Action(((string)null).Test); - } + public static object StaticMethod() + { + return new Func(DelegateConstruction.ExtensionMethodBound); + } - public static object StaticMethod() - { - return new Func(DelegateConstruction.ExtensionMethodBound); - } + public static object InstanceMethod() + { + return new Func("hello".ToUpper); + } - public static object InstanceMethod() - { - return new Func("hello".ToUpper); - } + public static object InstanceMethodOnNull() + { + return new Func(((string)null).ToUpper); + } - public static object InstanceMethodOnNull() - { - return new Func(((string)null).ToUpper); - } + public static List> AnonymousMethodStoreWithinLoop() + { + List> list = new List>(); + for (int i = 0; i < 10; i++) { + int counter; + list.Add(delegate(int x) { + counter = x; + }); + } + return list; + } - public static List> AnonymousMethodStoreWithinLoop() - { - List> list = new List>(); - for (int i = 0; i < 10; i++) { + public static List> AnonymousMethodStoreOutsideLoop() + { + List> list = new List>(); int counter; - list.Add(delegate(int x) { - counter = x; - }); + for (int i = 0; i < 10; i++) { + list.Add(delegate(int x) { + counter = x; + }); + } + return list; } - return list; - } - - public static List> AnonymousMethodStoreOutsideLoop() - { - List> list = new List>(); - int counter; - for (int i = 0; i < 10; i++) { - list.Add(delegate(int x) { - counter = x; - }); - } - return list; - } - public static Action StaticAnonymousMethodNoClosure() - { - return delegate { - Console.WriteLine(); - }; - } + public static Action StaticAnonymousMethodNoClosure() + { + return delegate { + Console.WriteLine(); + }; + } - public static void NameConflict() - { - // i is captured variable, - // j 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> list = new List>(); - for (int k = 0; k < 10; k++) { - int i; - for (i = 0; i < 10; i++) { - list.Add(delegate(int j) { + public static void NameConflict() + { + // i is captured variable, + // j 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> list = new List>(); + for (int k = 0; k < 10; k++) { + int i; + for (i = 0; i < 10; i++) { + list.Add(delegate(int j) { for (int l = 0; l < i; l += j) { Console.WriteLine(); } }); + } } } - } - public static void NameConflict2(int j) - { - List> list = new List>(); - for (int k = 0; k < 10; k++) { - list.Add(delegate(int i) { + public static void NameConflict2(int j) + { + List> list = new List>(); + for (int k = 0; k < 10; k++) { + list.Add(delegate(int i) { Console.WriteLine(i); }); + } } - } - public static Action NameConflict3(int i) - { - return delegate(int j) { - for (int k = 0; k < j; k++) { - Console.WriteLine(k); - } - }; - } - - public static Func> CurriedAddition(int a) - { - return (int b) => (int c) => a + b + c; - } - - public static Func>> CurriedAddition2(int a) - { - return (int b) => (int c) => (int d) => a + b + c + d; + public static Action NameConflict3(int i) + { + return delegate(int j) { + for (int k = 0; k < j; k++) { + Console.WriteLine(k); + } + }; + } + + public static Func> CurriedAddition(int a) + { + return (int b) => (int c) => a + b + c; + } + + public static Func>> CurriedAddition2(int a) + { + return (int b) => (int c) => (int d) => a + b + c + d; + } } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.il index b783a086b..b3a565c14 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.il @@ -1,5 +1,5 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -15,7 +15,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly bmq55mnq +.assembly kdaefnvq { .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.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) @@ -26,20 +26,20 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module bmq55mnq.dll -// MVID: {F2F10218-F242-427C-ADE5-E367B0EA41E3} +.module kdaefnvq.dll +// MVID: {568C8EB4-6E17-4688-8B36-6BFD1BF31DEB} .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: 0x02B40000 +// Image base: 0x00C30000 // =============== CLASS MEMBERS DECLARATION =================== -.class public abstract auto ansi sealed beforefieldinit DelegateConstruction +.class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) @@ -50,7 +50,7 @@ extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this' .field public int32 a .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -69,10 +69,10 @@ .maxstack 8 IL_0000: nop IL_0001: ldarg.0 - IL_0002: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'<>4__this' + IL_0002: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'<>4__this' IL_0007: ldarg.0 - IL_0008: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::a - IL_000d: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0008: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::a + IL_000d: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) IL_0012: pop IL_0013: ret } // end of method '<>c__DisplayClass22'::'b__21' @@ -83,7 +83,7 @@ extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this' .field public int32 a .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -101,7 +101,7 @@ extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' 'CS$<>8__locals26' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25' 'CS$<>8__locals26' .field public int32 item .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -120,15 +120,15 @@ .maxstack 8 IL_0000: nop IL_0001: ldarg.0 - IL_0002: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' - IL_0007: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::'<>4__this' + IL_0002: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' + IL_0007: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::'<>4__this' IL_000c: ldarg.0 - IL_000d: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item + IL_000d: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item IL_0012: ldarg.0 - IL_0013: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' - IL_0018: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::a + IL_0013: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' + IL_0018: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::a IL_001d: add - IL_001e: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_001e: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) IL_0023: pop IL_0024: ret } // end of method '<>c__DisplayClass28'::'b__24' @@ -139,7 +139,7 @@ extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this' .field public int32 a .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -174,8 +174,8 @@ extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' 'CS$<>8__locals2e' - .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' 'CS$<>8__locals2c' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' 'CS$<>8__locals2e' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' 'CS$<>8__locals2c' .field public int32 copyOfItem .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -194,19 +194,19 @@ .maxstack 8 IL_0000: nop IL_0001: ldarg.0 - IL_0002: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' - IL_0007: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::'<>4__this' + IL_0002: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' + IL_0007: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::'<>4__this' IL_000c: ldarg.0 - IL_000d: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2e' - IL_0012: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_000d: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2e' + IL_0012: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item IL_0017: ldarg.0 - IL_0018: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' - IL_001d: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::a + IL_0018: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' + IL_001d: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::a IL_0022: add IL_0023: ldarg.0 - IL_0024: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::copyOfItem + IL_0024: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::copyOfItem IL_0029: add - IL_002a: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_002a: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) IL_002f: pop IL_0030: ret } // end of method '<>c__DisplayClass30'::'b__2a' @@ -221,7 +221,7 @@ .locals init (class [mscorlib]System.Action V_0) IL_0000: nop IL_0001: ldarg.0 - IL_0002: ldftn instance void DelegateConstruction/InstanceTests::'b__20'() + IL_0002: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::'b__20'() IL_0008: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_000d: stloc.0 @@ -236,19 +236,19 @@ { // Code size 38 (0x26) .maxstack 2 - .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass22' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22' V_0, class [mscorlib]System.Action V_1) - IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.1 - IL_0008: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::a + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::a IL_000d: ldloc.0 IL_000e: ldarg.0 - IL_000f: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'<>4__this' + IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'<>4__this' IL_0014: nop IL_0015: ldloc.0 - IL_0016: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'b__21'() + IL_0016: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'b__21'() IL_001c: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_0021: stloc.1 @@ -264,19 +264,19 @@ // Code size 150 (0x96) .maxstack 2 .locals init (class [mscorlib]System.Action V_0, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass28' V_1, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' V_2, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28' V_1, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25' V_2, class [mscorlib]System.Action V_3, class [mscorlib]System.Collections.Generic.IEnumerator`1 V_4, bool V_5) - IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::.ctor() IL_0005: stloc.2 IL_0006: ldloc.2 IL_0007: ldarg.1 - IL_0008: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::a + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::a IL_000d: ldloc.2 IL_000e: ldarg.0 - IL_000f: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::'<>4__this' + IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::'<>4__this' IL_0014: nop IL_0015: nop IL_0016: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() @@ -288,18 +288,18 @@ IL_0024: ldnull IL_0025: stloc.0 - IL_0026: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::.ctor() + IL_0026: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::.ctor() IL_002b: stloc.1 IL_002c: ldloc.1 IL_002d: ldloc.2 - IL_002e: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' + IL_002e: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' IL_0033: ldloc.1 IL_0034: ldloc.s V_4 IL_0036: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() - IL_003b: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item + IL_003b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item IL_0040: nop IL_0041: ldloc.1 - IL_0042: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item + IL_0042: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item IL_0047: ldc.i4.0 IL_0048: cgt IL_004a: ldc.i4.0 @@ -313,7 +313,7 @@ IL_0055: brtrue.s IL_0066 IL_0057: ldloc.1 - IL_0058: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'b__24'() + IL_0058: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'b__24'() IL_005e: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_0063: stloc.0 @@ -363,20 +363,20 @@ // Code size 178 (0xb2) .maxstack 2 .locals init (class [mscorlib]System.Action V_0, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass30' V_1, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' V_2, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' V_3, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30' V_1, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' V_2, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' V_3, class [mscorlib]System.Action V_4, class [mscorlib]System.Collections.Generic.IEnumerator`1 V_5, bool V_6) - IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::.ctor() IL_0005: stloc.3 IL_0006: ldloc.3 IL_0007: ldarg.1 - IL_0008: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::a + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::a IL_000d: ldloc.3 IL_000e: ldarg.0 - IL_000f: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::'<>4__this' + IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::'<>4__this' IL_0014: nop IL_0015: nop IL_0016: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() @@ -386,29 +386,29 @@ { IL_0022: br.s IL_0085 - IL_0024: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::.ctor() + IL_0024: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::.ctor() IL_0029: stloc.2 IL_002a: ldloc.2 IL_002b: ldloc.s V_5 IL_002d: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() - IL_0032: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_0032: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item IL_0037: ldnull IL_0038: stloc.0 - IL_0039: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::.ctor() + IL_0039: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::.ctor() IL_003e: stloc.1 IL_003f: ldloc.1 IL_0040: ldloc.2 - IL_0041: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2e' + IL_0041: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2e' IL_0046: ldloc.1 IL_0047: ldloc.3 - IL_0048: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' + IL_0048: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' IL_004d: nop IL_004e: ldloc.1 IL_004f: ldloc.2 - IL_0050: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item - IL_0055: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::copyOfItem + IL_0050: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_0055: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::copyOfItem IL_005a: ldloc.2 - IL_005b: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_005b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item IL_0060: ldc.i4.0 IL_0061: cgt IL_0063: ldc.i4.0 @@ -422,7 +422,7 @@ IL_006e: brtrue.s IL_007f IL_0070: ldloc.1 - IL_0071: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'b__2a'() + IL_0071: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'b__2a'() IL_0077: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_007c: stloc.0 @@ -487,14 +487,14 @@ IL_000a: brtrue.s IL_001b IL_000c: ldarg.0 - IL_000d: ldftn instance int32 DelegateConstruction/InstanceTests::'b__32'() + IL_000d: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::'b__32'() IL_0013: newobj instance void class [mscorlib]System.Func`1::.ctor(object, native int) IL_0018: stloc.1 IL_0019: br.s IL_001b IL_001b: ldloc.1 - IL_001c: call instance void DelegateConstruction/InstanceTests::Bar(class [mscorlib]System.Func`1) + IL_001c: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::Bar(class [mscorlib]System.Func`1) IL_0021: nop IL_0022: nop IL_0023: ldloc.0 @@ -554,7 +554,7 @@ .maxstack 8 IL_0000: nop IL_0001: ldarg.0 - IL_0002: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThis() + IL_0002: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThis() IL_0007: pop IL_0008: ret } // end of method InstanceTests::'b__20' @@ -567,7 +567,7 @@ .maxstack 1 .locals init (int32 V_0) IL_0000: ldarg.0 - IL_0001: call instance int32 DelegateConstruction/InstanceTests::Foo() + IL_0001: call instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::Foo() IL_0006: stloc.0 IL_0007: br.s IL_0009 @@ -600,7 +600,7 @@ IL_0000: nop IL_0001: ldarg.0 IL_0002: ldarg.1 - IL_0003: stfld int32 DelegateConstruction/'<>c__DisplayClass1'::counter + IL_0003: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1'::counter IL_0008: ret } // end of method '<>c__DisplayClass1'::'b__0' @@ -629,7 +629,7 @@ IL_0000: nop IL_0001: ldarg.0 IL_0002: ldarg.1 - IL_0003: stfld int32 DelegateConstruction/'<>c__DisplayClass5'::counter + IL_0003: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass5'::counter IL_0008: ret } // end of method '<>c__DisplayClass5'::'b__3' @@ -672,7 +672,7 @@ IL_0010: stloc.0 IL_0011: ldloc.0 IL_0012: ldarg.0 - IL_0013: ldfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0013: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::i IL_0018: clt IL_001a: stloc.1 IL_001b: ldloc.1 @@ -690,7 +690,7 @@ .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass15' extends [mscorlib]System.Object { - .field public class DelegateConstruction/'<>c__DisplayClass13' 'CS$<>8__locals14' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13' 'CS$<>8__locals14' .field public int32 b .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -709,10 +709,10 @@ .maxstack 2 .locals init (int32 V_0) IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass13' DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'CS$<>8__locals14' - IL_0006: ldfld int32 DelegateConstruction/'<>c__DisplayClass13'::a + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'CS$<>8__locals14' + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'::a IL_000b: ldarg.0 - IL_000c: ldfld int32 DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::b + IL_000c: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::b IL_0011: add IL_0012: ldarg.1 IL_0013: add @@ -741,18 +741,18 @@ { // Code size 37 (0x25) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15' V_0, class [mscorlib]System.Func`2 V_1) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass13' DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'CS$<>8__locals14' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'CS$<>8__locals14' IL_000d: ldloc.0 IL_000e: ldarg.1 - IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::b + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::b IL_0014: ldloc.0 - IL_0015: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'b__12'(int32) + IL_0015: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'b__12'(int32) IL_001b: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_0020: stloc.1 @@ -774,8 +774,8 @@ .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1e' extends [mscorlib]System.Object { - .field public class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' 'CS$<>8__locals1d' - .field public class DelegateConstruction/'<>c__DisplayClass1a' 'CS$<>8__locals1b' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' 'CS$<>8__locals1d' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' 'CS$<>8__locals1b' .field public int32 c .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -794,14 +794,14 @@ .maxstack 2 .locals init (int32 V_0) IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1b' - IL_0006: ldfld int32 DelegateConstruction/'<>c__DisplayClass1a'::a + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1b' + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'::a IL_000b: ldarg.0 - IL_000c: ldfld class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1d' - IL_0011: ldfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::b + IL_000c: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1d' + IL_0011: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::b IL_0016: add IL_0017: ldarg.0 - IL_0018: ldfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::c + IL_0018: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::c IL_001d: add IL_001e: ldarg.1 IL_001f: add @@ -814,7 +814,7 @@ } // end of class '<>c__DisplayClass1e' - .field public class DelegateConstruction/'<>c__DisplayClass1a' 'CS$<>8__locals1b' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' 'CS$<>8__locals1b' .field public int32 b .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -831,22 +831,22 @@ { // Code size 49 (0x31) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e' V_0, class [mscorlib]System.Func`2 V_1) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1d' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1d' IL_000d: ldloc.0 IL_000e: ldarg.0 - IL_000f: ldfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'CS$<>8__locals1b' - IL_0014: stfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1b' + IL_000f: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'CS$<>8__locals1b' + IL_0014: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1b' IL_0019: ldloc.0 IL_001a: ldarg.1 - IL_001b: stfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::c + IL_001b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::c IL_0020: ldloc.0 - IL_0021: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'b__19'(int32) + IL_0021: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'b__19'(int32) IL_0027: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_002c: stloc.1 @@ -874,18 +874,18 @@ { // Code size 37 (0x25) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' V_0, class [mscorlib]System.Func`2> V_1) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'CS$<>8__locals1b' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'CS$<>8__locals1b' IL_000d: ldloc.0 IL_000e: ldarg.1 - IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::b + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::b IL_0014: ldloc.0 - IL_0015: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'b__18'(int32) + IL_0015: ldftn instance class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'b__18'(int32) IL_001b: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, native int) IL_0020: stloc.1 @@ -920,7 +920,7 @@ .locals init (class [mscorlib]System.Action`1 V_0) IL_0000: nop IL_0001: ldnull - IL_0002: ldftn void DelegateConstruction::Test(string) + IL_0002: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::Test(string) IL_0008: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_000d: stloc.0 @@ -938,7 +938,7 @@ .locals init (class [mscorlib]System.Action V_0) IL_0000: nop IL_0001: ldstr "abc" - IL_0006: ldftn void DelegateConstruction::Test(string) + IL_0006: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::Test(string) IL_000c: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_0011: stloc.0 @@ -956,7 +956,7 @@ .locals init (class [mscorlib]System.Action V_0) IL_0000: nop IL_0001: ldnull - IL_0002: ldftn void DelegateConstruction::Test(string) + IL_0002: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::Test(string) IL_0008: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_000d: stloc.0 @@ -974,7 +974,7 @@ .locals init (object V_0) IL_0000: nop IL_0001: ldnull - IL_0002: ldftn class [mscorlib]System.Action DelegateConstruction::ExtensionMethodBound() + IL_0002: ldftn class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::ExtensionMethodBound() IL_0008: newobj instance void class [mscorlib]System.Func`1::.ctor(object, native int) IL_000d: stloc.0 @@ -1027,7 +1027,7 @@ .maxstack 3 .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, int32 V_1, - class DelegateConstruction/'<>c__DisplayClass1' V_2, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1' V_2, class [mscorlib]System.Collections.Generic.List`1> V_3, bool V_4) IL_0000: nop @@ -1037,12 +1037,12 @@ IL_0008: stloc.1 IL_0009: br.s IL_002a - IL_000b: newobj instance void DelegateConstruction/'<>c__DisplayClass1'::.ctor() + IL_000b: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1'::.ctor() IL_0010: stloc.2 IL_0011: nop IL_0012: ldloc.0 IL_0013: ldloc.2 - IL_0014: ldftn instance void DelegateConstruction/'<>c__DisplayClass1'::'b__0'(int32) + IL_0014: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1'::'b__0'(int32) IL_001a: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_001f: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) @@ -1075,12 +1075,12 @@ .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, int32 V_1, class [mscorlib]System.Action`1 V_2, - class DelegateConstruction/'<>c__DisplayClass5' V_3, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass5' V_3, class [mscorlib]System.Collections.Generic.List`1> V_4, bool V_5) IL_0000: ldnull IL_0001: stloc.2 - IL_0002: newobj instance void DelegateConstruction/'<>c__DisplayClass5'::.ctor() + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass5'::.ctor() IL_0007: stloc.3 IL_0008: nop IL_0009: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() @@ -1095,7 +1095,7 @@ IL_0016: brtrue.s IL_0027 IL_0018: ldloc.3 - IL_0019: ldftn instance void DelegateConstruction/'<>c__DisplayClass5'::'b__3'(int32) + IL_0019: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass5'::'b__3'(int32) IL_001f: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_0024: stloc.2 @@ -1131,17 +1131,17 @@ .maxstack 2 .locals init (class [mscorlib]System.Action V_0) IL_0000: nop - IL_0001: ldsfld class [mscorlib]System.Action DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_0001: ldsfld class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' IL_0006: brtrue.s IL_001b IL_0008: ldnull - IL_0009: ldftn void DelegateConstruction::'b__7'() + IL_0009: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'b__7'() IL_000f: newobj instance void [mscorlib]System.Action::.ctor(object, native int) - IL_0014: stsfld class [mscorlib]System.Action DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_0014: stsfld class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' IL_0019: br.s IL_001b - IL_001b: ldsfld class [mscorlib]System.Action DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_001b: ldsfld class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' IL_0020: stloc.0 IL_0021: br.s IL_0023 @@ -1156,7 +1156,7 @@ .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, int32 V_1, class [mscorlib]System.Action`1 V_2, - class DelegateConstruction/'<>c__DisplayClassb' V_3, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb' V_3, bool V_4) IL_0000: nop IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() @@ -1167,12 +1167,12 @@ IL_000b: ldnull IL_000c: stloc.2 - IL_000d: newobj instance void DelegateConstruction/'<>c__DisplayClassb'::.ctor() + IL_000d: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::.ctor() IL_0012: stloc.3 IL_0013: nop IL_0014: ldloc.3 IL_0015: ldc.i4.0 - IL_0016: stfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0016: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::i IL_001b: br.s IL_0047 IL_001d: nop @@ -1181,7 +1181,7 @@ IL_0020: brtrue.s IL_0031 IL_0022: ldloc.3 - IL_0023: ldftn instance void DelegateConstruction/'<>c__DisplayClassb'::'b__9'(int32) + IL_0023: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::'b__9'(int32) IL_0029: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_002e: stloc.2 @@ -1193,12 +1193,12 @@ IL_0038: nop IL_0039: ldloc.3 IL_003a: dup - IL_003b: ldfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_003b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::i IL_0040: ldc.i4.1 IL_0041: add - IL_0042: stfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0042: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::i IL_0047: ldloc.3 - IL_0048: ldfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0048: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::i IL_004d: ldc.i4.s 10 IL_004f: clt IL_0051: stloc.s V_4 @@ -1236,17 +1236,17 @@ IL_000b: nop IL_000c: ldloc.0 - IL_000d: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' + IL_000d: ldsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' IL_0012: brtrue.s IL_0027 IL_0014: ldnull - IL_0015: ldftn void DelegateConstruction::'b__d'(int32) + IL_0015: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'b__d'(int32) IL_001b: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) - IL_0020: stsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' + IL_0020: stsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' IL_0025: br.s IL_0027 - IL_0027: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' + IL_0027: ldsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' IL_002c: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) IL_0031: nop IL_0032: nop @@ -1271,17 +1271,17 @@ .maxstack 2 .locals init (class [mscorlib]System.Action`1 V_0) IL_0000: nop - IL_0001: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' + IL_0001: ldsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' IL_0006: brtrue.s IL_001b IL_0008: ldnull - IL_0009: ldftn void DelegateConstruction::'b__f'(int32) + IL_0009: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'b__f'(int32) IL_000f: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) - IL_0014: stsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' + IL_0014: stsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' IL_0019: br.s IL_001b - IL_001b: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' + IL_001b: ldsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' IL_0020: stloc.0 IL_0021: br.s IL_0023 @@ -1294,16 +1294,16 @@ { // Code size 31 (0x1f) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass13' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13' V_0, class [mscorlib]System.Func`2> V_1) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass13'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld int32 DelegateConstruction/'<>c__DisplayClass13'::a + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'::a IL_000d: nop IL_000e: ldloc.0 - IL_000f: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass13'::'b__11'(int32) + IL_000f: ldftn instance class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'::'b__11'(int32) IL_0015: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, native int) IL_001a: stloc.1 @@ -1318,16 +1318,16 @@ { // Code size 31 (0x1f) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass1a' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' V_0, class [mscorlib]System.Func`2>> V_1) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass1a'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld int32 DelegateConstruction/'<>c__DisplayClass1a'::a + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'::a IL_000d: nop IL_000e: ldloc.0 - IL_000f: ldftn instance class [mscorlib]System.Func`2> DelegateConstruction/'<>c__DisplayClass1a'::'b__17'(int32) + IL_000f: ldftn instance class [mscorlib]System.Func`2> ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'::'b__17'(int32) IL_0015: newobj instance void class [mscorlib]System.Func`2>>::.ctor(object, native int) IL_001a: stloc.1 @@ -1391,7 +1391,7 @@ IL_001a: ret } // end of method DelegateConstruction::'b__f' -} // end of class DelegateConstruction +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.il index 5ae47aa6a..f12117f03 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.il @@ -1,5 +1,5 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -15,7 +15,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly xrchixjz +.assembly c0bnf0jn { .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.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) @@ -26,20 +26,20 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module xrchixjz.dll -// MVID: {4764226C-6D0F-4413-9843-94B16795E6C2} +.module c0bnf0jn.dll +// MVID: {ABE4DCE9-5E34-4357-84BA-7850DA8457DD} .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: 0x00C80000 +// Image base: 0x00E80000 // =============== CLASS MEMBERS DECLARATION =================== -.class public abstract auto ansi sealed beforefieldinit DelegateConstruction +.class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) @@ -50,7 +50,7 @@ extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this' .field public int32 a .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -68,10 +68,10 @@ // Code size 19 (0x13) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'<>4__this' + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'<>4__this' IL_0006: ldarg.0 - IL_0007: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::a - IL_000c: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0007: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::a + IL_000c: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) IL_0011: pop IL_0012: ret } // end of method '<>c__DisplayClass22'::'b__21' @@ -82,7 +82,7 @@ extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this' .field public int32 a .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -100,7 +100,7 @@ extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' 'CS$<>8__locals26' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25' 'CS$<>8__locals26' .field public int32 item .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -118,15 +118,15 @@ // Code size 36 (0x24) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' - IL_0006: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::'<>4__this' + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' + IL_0006: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::'<>4__this' IL_000b: ldarg.0 - IL_000c: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item + IL_000c: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item IL_0011: ldarg.0 - IL_0012: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' - IL_0017: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::a + IL_0012: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' + IL_0017: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::a IL_001c: add - IL_001d: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_001d: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) IL_0022: pop IL_0023: ret } // end of method '<>c__DisplayClass28'::'b__24' @@ -137,7 +137,7 @@ extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this' .field public int32 a .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -172,8 +172,8 @@ extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' 'CS$<>8__locals2e' - .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' 'CS$<>8__locals2c' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' 'CS$<>8__locals2e' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' 'CS$<>8__locals2c' .field public int32 copyOfItem .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -191,19 +191,19 @@ // Code size 48 (0x30) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' - IL_0006: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::'<>4__this' + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' + IL_0006: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::'<>4__this' IL_000b: ldarg.0 - IL_000c: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2e' - IL_0011: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_000c: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2e' + IL_0011: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item IL_0016: ldarg.0 - IL_0017: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' - IL_001c: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::a + IL_0017: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' + IL_001c: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::a IL_0021: add IL_0022: ldarg.0 - IL_0023: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::copyOfItem + IL_0023: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::copyOfItem IL_0028: add - IL_0029: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0029: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) IL_002e: pop IL_002f: ret } // end of method '<>c__DisplayClass30'::'b__2a' @@ -216,7 +216,7 @@ // Code size 13 (0xd) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldftn instance void DelegateConstruction/InstanceTests::'b__20'() + IL_0001: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::'b__20'() IL_0007: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_000c: ret @@ -227,17 +227,17 @@ { // Code size 33 (0x21) .maxstack 2 - .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass22' V_0) - IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::.ctor() + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.1 - IL_0008: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::a + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::a IL_000d: ldloc.0 IL_000e: ldarg.0 - IL_000f: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'<>4__this' + IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'<>4__this' IL_0014: ldloc.0 - IL_0015: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'b__21'() + IL_0015: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass22'::'b__21'() IL_001b: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_0020: ret @@ -249,18 +249,18 @@ // Code size 118 (0x76) .maxstack 2 .locals init (class [mscorlib]System.Action V_0, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass28' V_1, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' V_2, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28' V_1, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25' V_2, class [mscorlib]System.Action V_3, class [mscorlib]System.Collections.Generic.IEnumerator`1 V_4) - IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::.ctor() IL_0005: stloc.2 IL_0006: ldloc.2 IL_0007: ldarg.1 - IL_0008: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::a + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::a IL_000d: ldloc.2 IL_000e: ldarg.0 - IL_000f: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::'<>4__this' + IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25'::'<>4__this' IL_0014: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() IL_0019: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() IL_001e: stloc.s V_4 @@ -270,17 +270,17 @@ IL_0022: ldnull IL_0023: stloc.0 - IL_0024: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::.ctor() + IL_0024: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::.ctor() IL_0029: stloc.1 IL_002a: ldloc.1 IL_002b: ldloc.2 - IL_002c: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass25' DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' + IL_002c: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass25' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'CS$<>8__locals26' IL_0031: ldloc.1 IL_0032: ldloc.s V_4 IL_0034: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() - IL_0039: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item + IL_0039: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item IL_003e: ldloc.1 - IL_003f: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item + IL_003f: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::item IL_0044: ldc.i4.0 IL_0045: ble.s IL_005b @@ -288,7 +288,7 @@ IL_0048: brtrue.s IL_0057 IL_004a: ldloc.1 - IL_004b: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'b__24'() + IL_004b: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass28'::'b__24'() IL_0051: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_0056: stloc.0 @@ -325,19 +325,19 @@ // Code size 145 (0x91) .maxstack 2 .locals init (class [mscorlib]System.Action V_0, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass30' V_1, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' V_2, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' V_3, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30' V_1, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' V_2, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' V_3, class [mscorlib]System.Action V_4, class [mscorlib]System.Collections.Generic.IEnumerator`1 V_5) - IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::.ctor() IL_0005: stloc.3 IL_0006: ldloc.3 IL_0007: ldarg.1 - IL_0008: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::a + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::a IL_000d: ldloc.3 IL_000e: ldarg.0 - IL_000f: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::'<>4__this' + IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b'::'<>4__this' IL_0014: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() IL_0019: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() IL_001e: stloc.s V_5 @@ -345,28 +345,28 @@ { IL_0020: br.s IL_0075 - IL_0022: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::.ctor() + IL_0022: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::.ctor() IL_0027: stloc.2 IL_0028: ldloc.2 IL_0029: ldloc.s V_5 IL_002b: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() - IL_0030: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_0030: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item IL_0035: ldnull IL_0036: stloc.0 - IL_0037: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::.ctor() + IL_0037: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::.ctor() IL_003c: stloc.1 IL_003d: ldloc.1 IL_003e: ldloc.2 - IL_003f: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2e' + IL_003f: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2e' IL_0044: ldloc.1 IL_0045: ldloc.3 - IL_0046: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' + IL_0046: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2b' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'CS$<>8__locals2c' IL_004b: ldloc.1 IL_004c: ldloc.2 - IL_004d: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item - IL_0052: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::copyOfItem + IL_004d: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_0052: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::copyOfItem IL_0057: ldloc.2 - IL_0058: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item + IL_0058: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2d'::item IL_005d: ldc.i4.0 IL_005e: ble.s IL_0075 @@ -374,7 +374,7 @@ IL_0061: brtrue.s IL_0070 IL_0063: ldloc.1 - IL_0064: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'b__2a'() + IL_0064: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass30'::'b__2a'() IL_006a: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_006f: stloc.0 @@ -423,12 +423,12 @@ IL_0008: brtrue.s IL_0017 IL_000a: ldarg.0 - IL_000b: ldftn instance int32 DelegateConstruction/InstanceTests::'b__32'() + IL_000b: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::'b__32'() IL_0011: newobj instance void class [mscorlib]System.Func`1::.ctor(object, native int) IL_0016: stloc.1 IL_0017: ldloc.1 - IL_0018: call instance void DelegateConstruction/InstanceTests::Bar(class [mscorlib]System.Func`1) + IL_0018: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::Bar(class [mscorlib]System.Func`1) IL_001d: ldloc.0 IL_001e: ldc.i4.1 IL_001f: add @@ -474,7 +474,7 @@ // Code size 8 (0x8) .maxstack 8 IL_0000: ldarg.0 - IL_0001: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThis() + IL_0001: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThis() IL_0006: pop IL_0007: ret } // end of method InstanceTests::'b__20' @@ -486,7 +486,7 @@ // Code size 7 (0x7) .maxstack 8 IL_0000: ldarg.0 - IL_0001: call instance int32 DelegateConstruction/InstanceTests::Foo() + IL_0001: call instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::Foo() IL_0006: ret } // end of method InstanceTests::'b__32' @@ -514,7 +514,7 @@ .maxstack 8 IL_0000: ldarg.0 IL_0001: ldarg.1 - IL_0002: stfld int32 DelegateConstruction/'<>c__DisplayClass1'::counter + IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1'::counter IL_0007: ret } // end of method '<>c__DisplayClass1'::'b__0' @@ -542,7 +542,7 @@ .maxstack 8 IL_0000: ldarg.0 IL_0001: ldarg.1 - IL_0002: stfld int32 DelegateConstruction/'<>c__DisplayClass5'::counter + IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass5'::counter IL_0007: ret } // end of method '<>c__DisplayClass5'::'b__3' @@ -580,7 +580,7 @@ IL_000c: stloc.0 IL_000d: ldloc.0 IL_000e: ldarg.0 - IL_000f: ldfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_000f: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::i IL_0014: blt.s IL_0004 IL_0016: ret @@ -595,7 +595,7 @@ .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass15' extends [mscorlib]System.Object { - .field public class DelegateConstruction/'<>c__DisplayClass13' 'CS$<>8__locals14' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13' 'CS$<>8__locals14' .field public int32 b .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -613,10 +613,10 @@ // Code size 21 (0x15) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass13' DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'CS$<>8__locals14' - IL_0006: ldfld int32 DelegateConstruction/'<>c__DisplayClass13'::a + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'CS$<>8__locals14' + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'::a IL_000b: ldarg.0 - IL_000c: ldfld int32 DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::b + IL_000c: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::b IL_0011: add IL_0012: ldarg.1 IL_0013: add @@ -641,17 +641,17 @@ { // Code size 33 (0x21) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15' V_0) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::.ctor() + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass13' DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'CS$<>8__locals14' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'CS$<>8__locals14' IL_000d: ldloc.0 IL_000e: ldarg.1 - IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::b + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::b IL_0014: ldloc.0 - IL_0015: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'b__12'(int32) + IL_0015: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'/'<>c__DisplayClass15'::'b__12'(int32) IL_001b: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_0020: ret @@ -669,8 +669,8 @@ .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass1e' extends [mscorlib]System.Object { - .field public class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' 'CS$<>8__locals1d' - .field public class DelegateConstruction/'<>c__DisplayClass1a' 'CS$<>8__locals1b' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' 'CS$<>8__locals1d' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' 'CS$<>8__locals1b' .field public int32 c .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -688,14 +688,14 @@ // Code size 33 (0x21) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1b' - IL_0006: ldfld int32 DelegateConstruction/'<>c__DisplayClass1a'::a + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1b' + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'::a IL_000b: ldarg.0 - IL_000c: ldfld class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1d' - IL_0011: ldfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::b + IL_000c: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1d' + IL_0011: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::b IL_0016: add IL_0017: ldarg.0 - IL_0018: ldfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::c + IL_0018: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::c IL_001d: add IL_001e: ldarg.1 IL_001f: add @@ -704,7 +704,7 @@ } // end of class '<>c__DisplayClass1e' - .field public class DelegateConstruction/'<>c__DisplayClass1a' 'CS$<>8__locals1b' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' 'CS$<>8__locals1b' .field public int32 b .method public hidebysig specialname rtspecialname instance void .ctor() cil managed @@ -721,21 +721,21 @@ { // Code size 45 (0x2d) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e' V_0) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::.ctor() + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1d' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1d' IL_000d: ldloc.0 IL_000e: ldarg.0 - IL_000f: ldfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'CS$<>8__locals1b' - IL_0014: stfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1b' + IL_000f: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'CS$<>8__locals1b' + IL_0014: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'CS$<>8__locals1b' IL_0019: ldloc.0 IL_001a: ldarg.1 - IL_001b: stfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::c + IL_001b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::c IL_0020: ldloc.0 - IL_0021: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'b__19'(int32) + IL_0021: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'/'<>c__DisplayClass1e'::'b__19'(int32) IL_0027: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_002c: ret @@ -759,17 +759,17 @@ { // Code size 33 (0x21) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' V_0) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::.ctor() + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass1a' DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'CS$<>8__locals1b' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'CS$<>8__locals1b' IL_000d: ldloc.0 IL_000e: ldarg.1 - IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::b + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::b IL_0014: ldloc.0 - IL_0015: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'b__18'(int32) + IL_0015: ldftn instance class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'/'<>c__DisplayClass1c'::'b__18'(int32) IL_001b: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, native int) IL_0020: ret @@ -797,7 +797,7 @@ // Code size 13 (0xd) .maxstack 8 IL_0000: ldnull - IL_0001: ldftn void DelegateConstruction::Test(string) + IL_0001: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::Test(string) IL_0007: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_000c: ret @@ -809,7 +809,7 @@ // Code size 17 (0x11) .maxstack 8 IL_0000: ldstr "abc" - IL_0005: ldftn void DelegateConstruction::Test(string) + IL_0005: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::Test(string) IL_000b: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_0010: ret @@ -821,7 +821,7 @@ // Code size 13 (0xd) .maxstack 8 IL_0000: ldnull - IL_0001: ldftn void DelegateConstruction::Test(string) + IL_0001: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::Test(string) IL_0007: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_000c: ret @@ -833,7 +833,7 @@ // Code size 13 (0xd) .maxstack 8 IL_0000: ldnull - IL_0001: ldftn class [mscorlib]System.Action DelegateConstruction::ExtensionMethodBound() + IL_0001: ldftn class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::ExtensionMethodBound() IL_0007: newobj instance void class [mscorlib]System.Func`1::.ctor(object, native int) IL_000c: ret @@ -870,18 +870,18 @@ .maxstack 3 .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, int32 V_1, - class DelegateConstruction/'<>c__DisplayClass1' V_2) + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1' V_2) IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() IL_0005: stloc.0 IL_0006: ldc.i4.0 IL_0007: stloc.1 IL_0008: br.s IL_0026 - IL_000a: newobj instance void DelegateConstruction/'<>c__DisplayClass1'::.ctor() + IL_000a: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1'::.ctor() IL_000f: stloc.2 IL_0010: ldloc.0 IL_0011: ldloc.2 - IL_0012: ldftn instance void DelegateConstruction/'<>c__DisplayClass1'::'b__0'(int32) + IL_0012: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1'::'b__0'(int32) IL_0018: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_001d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) @@ -905,10 +905,10 @@ .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, int32 V_1, class [mscorlib]System.Action`1 V_2, - class DelegateConstruction/'<>c__DisplayClass5' V_3) + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass5' V_3) IL_0000: ldnull IL_0001: stloc.2 - IL_0002: newobj instance void DelegateConstruction/'<>c__DisplayClass5'::.ctor() + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass5'::.ctor() IL_0007: stloc.3 IL_0008: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() IL_000d: stloc.0 @@ -921,7 +921,7 @@ IL_0014: brtrue.s IL_0023 IL_0016: ldloc.3 - IL_0017: ldftn instance void DelegateConstruction/'<>c__DisplayClass5'::'b__3'(int32) + IL_0017: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass5'::'b__3'(int32) IL_001d: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_0022: stloc.2 @@ -944,15 +944,15 @@ { // Code size 30 (0x1e) .maxstack 8 - IL_0000: ldsfld class [mscorlib]System.Action DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_0000: ldsfld class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' IL_0005: brtrue.s IL_0018 IL_0007: ldnull - IL_0008: ldftn void DelegateConstruction::'b__7'() + IL_0008: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'b__7'() IL_000e: newobj instance void [mscorlib]System.Action::.ctor(object, native int) - IL_0013: stsfld class [mscorlib]System.Action DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' - IL_0018: ldsfld class [mscorlib]System.Action DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_0013: stsfld class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_0018: ldsfld class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate8' IL_001d: ret } // end of method DelegateConstruction::StaticAnonymousMethodNoClosure @@ -963,7 +963,7 @@ .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, int32 V_1, class [mscorlib]System.Action`1 V_2, - class DelegateConstruction/'<>c__DisplayClassb' V_3) + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb' V_3) IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() IL_0005: stloc.0 IL_0006: ldc.i4.0 @@ -972,11 +972,11 @@ IL_000a: ldnull IL_000b: stloc.2 - IL_000c: newobj instance void DelegateConstruction/'<>c__DisplayClassb'::.ctor() + IL_000c: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::.ctor() IL_0011: stloc.3 IL_0012: ldloc.3 IL_0013: ldc.i4.0 - IL_0014: stfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::i IL_0019: br.s IL_0040 IL_001b: ldloc.0 @@ -984,7 +984,7 @@ IL_001d: brtrue.s IL_002c IL_001f: ldloc.3 - IL_0020: ldftn instance void DelegateConstruction/'<>c__DisplayClassb'::'b__9'(int32) + IL_0020: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::'b__9'(int32) IL_0026: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_002b: stloc.2 @@ -992,12 +992,12 @@ IL_002d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) IL_0032: ldloc.3 IL_0033: dup - IL_0034: ldfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0034: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::i IL_0039: ldc.i4.1 IL_003a: add - IL_003b: stfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_003b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::i IL_0040: ldloc.3 - IL_0041: ldfld int32 DelegateConstruction/'<>c__DisplayClassb'::i + IL_0041: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClassb'::i IL_0046: ldc.i4.s 10 IL_0048: blt.s IL_001b @@ -1025,15 +1025,15 @@ IL_0008: br.s IL_0031 IL_000a: ldloc.0 - IL_000b: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' + IL_000b: ldsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' IL_0010: brtrue.s IL_0023 IL_0012: ldnull - IL_0013: ldftn void DelegateConstruction::'b__d'(int32) + IL_0013: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'b__d'(int32) IL_0019: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) - IL_001e: stsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' - IL_0023: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' + IL_001e: stsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' + IL_0023: ldsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegatee' IL_0028: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) IL_002d: ldloc.1 IL_002e: ldc.i4.1 @@ -1051,15 +1051,15 @@ { // Code size 30 (0x1e) .maxstack 8 - IL_0000: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' + IL_0000: ldsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' IL_0005: brtrue.s IL_0018 IL_0007: ldnull - IL_0008: ldftn void DelegateConstruction::'b__f'(int32) + IL_0008: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'b__f'(int32) IL_000e: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) - IL_0013: stsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' - IL_0018: ldsfld class [mscorlib]System.Action`1 DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' + IL_0013: stsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' + IL_0018: ldsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::'CS$<>9__CachedAnonymousMethodDelegate10' IL_001d: ret } // end of method DelegateConstruction::NameConflict3 @@ -1068,14 +1068,14 @@ { // Code size 26 (0x1a) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass13' V_0) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass13'::.ctor() + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld int32 DelegateConstruction/'<>c__DisplayClass13'::a + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'::a IL_000d: ldloc.0 - IL_000e: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass13'::'b__11'(int32) + IL_000e: ldftn instance class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass13'::'b__11'(int32) IL_0014: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, native int) IL_0019: ret @@ -1086,14 +1086,14 @@ { // Code size 26 (0x1a) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass1a' V_0) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass1a'::.ctor() + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld int32 DelegateConstruction/'<>c__DisplayClass1a'::a + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'::a IL_000d: ldloc.0 - IL_000e: ldftn instance class [mscorlib]System.Func`2> DelegateConstruction/'<>c__DisplayClass1a'::'b__17'(int32) + IL_000e: ldftn instance class [mscorlib]System.Func`2> ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass1a'::'b__17'(int32) IL_0014: newobj instance void class [mscorlib]System.Func`2>>::.ctor(object, native int) IL_0019: ret @@ -1141,7 +1141,7 @@ IL_0012: ret } // end of method DelegateConstruction::'b__f' -} // end of class DelegateConstruction +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.roslyn.il index afa8fe5da..e4f4a6bff 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.roslyn.il @@ -1,5 +1,5 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -31,19 +31,19 @@ .ver 0:0:0:0 } .module DelegateConstruction.dll -// MVID: {D01DFE9F-2A31-46AA-8CBD-03D412485F40} +// MVID: {534F3E90-3206-4E6A-821F-26BFD75A6959} .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: 0x009F0000 +// Image base: 0x01460000 // =============== CLASS MEMBERS DECLARATION =================== -.class public abstract auto ansi sealed beforefieldinit DelegateConstruction +.class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) @@ -55,7 +55,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 a - .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -72,10 +72,10 @@ // Code size 19 (0x13) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'<>4__this' + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'<>4__this' IL_0006: ldarg.0 - IL_0007: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::a - IL_000c: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0007: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::a + IL_000c: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) IL_0011: pop IL_0012: ret } // end of method '<>c__DisplayClass1_0'::'b__0' @@ -87,7 +87,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 item - .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' 'CS$<>8__locals1' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' 'CS$<>8__locals1' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -104,15 +104,15 @@ // Code size 36 (0x24) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' - IL_0006: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::'<>4__this' + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' + IL_0006: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::'<>4__this' IL_000b: ldarg.0 - IL_000c: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item + IL_000c: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item IL_0011: ldarg.0 - IL_0012: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' - IL_0017: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::a + IL_0012: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' + IL_0017: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::a IL_001c: add - IL_001d: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_001d: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) IL_0022: pop IL_0023: ret } // end of method '<>c__DisplayClass2_0'::'b__0' @@ -124,7 +124,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 a - .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -142,7 +142,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 item - .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' 'CS$<>8__locals1' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' 'CS$<>8__locals1' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -160,7 +160,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 a - .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -178,7 +178,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 copyOfItem - .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' 'CS$<>8__locals2' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' 'CS$<>8__locals2' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -195,21 +195,21 @@ // Code size 58 (0x3a) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' - IL_0006: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' - IL_000b: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::'<>4__this' + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0006: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' + IL_000b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::'<>4__this' IL_0010: ldarg.0 - IL_0011: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' - IL_0016: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_0011: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0016: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item IL_001b: ldarg.0 - IL_001c: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' - IL_0021: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' - IL_0026: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::a + IL_001c: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0021: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' + IL_0026: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::a IL_002b: add IL_002c: ldarg.0 - IL_002d: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::copyOfItem + IL_002d: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::copyOfItem IL_0032: add - IL_0033: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0033: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) IL_0038: pop IL_0039: ret } // end of method '<>c__DisplayClass3_2'::'b__0' @@ -222,7 +222,7 @@ // Code size 13 (0xd) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldftn instance void DelegateConstruction/InstanceTests::'b__0_0'() + IL_0001: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::'b__0_0'() IL_0007: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_000c: ret @@ -233,14 +233,14 @@ { // Code size 31 (0x1f) .maxstack 8 - IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::.ctor() IL_0005: dup IL_0006: ldarg.0 - IL_0007: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'<>4__this' + IL_0007: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'<>4__this' IL_000c: dup IL_000d: ldarg.1 - IL_000e: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::a - IL_0013: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'b__0'() + IL_000e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::a + IL_0013: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'b__0'() IL_0019: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_001e: ret @@ -251,18 +251,18 @@ { // Code size 106 (0x6a) .maxstack 2 - .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' V_0, class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0' V_2, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0' V_2, class [mscorlib]System.Action V_3) - IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::'<>4__this' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::'<>4__this' IL_000d: ldloc.0 IL_000e: ldarg.1 - IL_000f: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::a + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::a IL_0014: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() IL_0019: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() IL_001e: stloc.1 @@ -270,22 +270,22 @@ { IL_001f: br.s IL_0052 - IL_0021: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::.ctor() + IL_0021: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::.ctor() IL_0026: stloc.2 IL_0027: ldloc.2 IL_0028: ldloc.0 - IL_0029: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' + IL_0029: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' IL_002e: ldloc.2 IL_002f: ldloc.1 IL_0030: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() - IL_0035: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item + IL_0035: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item IL_003a: ldloc.2 - IL_003b: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item + IL_003b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item IL_0040: ldc.i4.0 IL_0041: ble.s IL_0052 IL_0043: ldloc.2 - IL_0044: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'b__0'() + IL_0044: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'b__0'() IL_004a: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_004f: stloc.3 @@ -319,19 +319,19 @@ { // Code size 143 (0x8f) .maxstack 2 - .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' V_0, class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' V_2, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2' V_3, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' V_2, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2' V_3, class [mscorlib]System.Action V_4) - IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::'<>4__this' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::'<>4__this' IL_000d: ldloc.0 IL_000e: ldarg.1 - IL_000f: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::a + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::a IL_0014: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() IL_0019: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() IL_001e: stloc.1 @@ -339,33 +339,33 @@ { IL_001f: br.s IL_0076 - IL_0021: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::.ctor() + IL_0021: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::.ctor() IL_0026: stloc.2 IL_0027: ldloc.2 IL_0028: ldloc.0 - IL_0029: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' + IL_0029: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' IL_002e: ldloc.2 IL_002f: ldloc.1 IL_0030: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() - IL_0035: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item - IL_003a: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::.ctor() + IL_0035: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_003a: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::.ctor() IL_003f: stloc.3 IL_0040: ldloc.3 IL_0041: ldloc.2 - IL_0042: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0042: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' IL_0047: ldloc.3 IL_0048: ldloc.3 - IL_0049: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' - IL_004e: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item - IL_0053: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::copyOfItem + IL_0049: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_004e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_0053: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::copyOfItem IL_0058: ldloc.3 - IL_0059: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' - IL_005e: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_0059: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_005e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item IL_0063: ldc.i4.0 IL_0064: ble.s IL_0076 IL_0066: ldloc.3 - IL_0067: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'b__0'() + IL_0067: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'b__0'() IL_006d: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_0072: stloc.s V_4 @@ -406,10 +406,10 @@ IL_0004: ldarg.0 IL_0005: ldarg.0 - IL_0006: ldftn instance int32 DelegateConstruction/InstanceTests::'b__4_0'() + IL_0006: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::'b__4_0'() IL_000c: newobj instance void class [mscorlib]System.Func`1::.ctor(object, native int) - IL_0011: call instance void DelegateConstruction/InstanceTests::Bar(class [mscorlib]System.Func`1) + IL_0011: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::Bar(class [mscorlib]System.Func`1) IL_0016: ldloc.0 IL_0017: ldc.i4.1 IL_0018: add @@ -455,7 +455,7 @@ // Code size 8 (0x8) .maxstack 8 IL_0000: ldarg.0 - IL_0001: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThis() + IL_0001: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThis() IL_0006: pop IL_0007: ret } // end of method InstanceTests::'b__0_0' @@ -467,7 +467,7 @@ // Code size 7 (0x7) .maxstack 8 IL_0000: ldarg.0 - IL_0001: call instance int32 DelegateConstruction/InstanceTests::Foo() + IL_0001: call instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::Foo() IL_0006: ret } // end of method InstanceTests::'b__4_0' @@ -495,7 +495,7 @@ .maxstack 8 IL_0000: ldarg.0 IL_0001: ldarg.1 - IL_0002: stfld int32 DelegateConstruction/'<>c__DisplayClass8_0'::counter + IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass8_0'::counter IL_0007: ret } // end of method '<>c__DisplayClass8_0'::'b__0' @@ -524,7 +524,7 @@ .maxstack 8 IL_0000: ldarg.0 IL_0001: ldarg.1 - IL_0002: stfld int32 DelegateConstruction/'<>c__DisplayClass9_0'::counter + IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass9_0'::counter IL_0007: ret } // end of method '<>c__DisplayClass9_0'::'b__0' @@ -534,7 +534,7 @@ extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public static initonly class DelegateConstruction/'<>c' '<>9' + .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c' '<>9' .field public static class [mscorlib]System.Action '<>9__10_0' .field public static class [mscorlib]System.Action`1 '<>9__12_0' .field public static class [mscorlib]System.Action`1 '<>9__13_0' @@ -543,8 +543,8 @@ { // Code size 11 (0xb) .maxstack 8 - IL_0000: newobj instance void DelegateConstruction/'<>c'::.ctor() - IL_0005: stsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::.ctor() + IL_0005: stsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9' IL_000a: ret } // end of method '<>c'::.cctor @@ -634,7 +634,7 @@ IL_000c: stloc.0 IL_000d: ldloc.0 IL_000e: ldarg.0 - IL_000f: ldfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_000f: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::i IL_0014: blt.s IL_0004 IL_0016: ret @@ -662,14 +662,14 @@ { // Code size 31 (0x1f) .maxstack 8 - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass14_1'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_1'::.ctor() IL_0005: dup IL_0006: ldarg.0 - IL_0007: stfld class DelegateConstruction/'<>c__DisplayClass14_0' DelegateConstruction/'<>c__DisplayClass14_1'::'CS$<>8__locals1' + IL_0007: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_1'::'CS$<>8__locals1' IL_000c: dup IL_000d: ldarg.1 - IL_000e: stfld int32 DelegateConstruction/'<>c__DisplayClass14_1'::b - IL_0013: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass14_1'::'b__1'(int32) + IL_000e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_1'::b + IL_0013: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_1'::'b__1'(int32) IL_0019: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_001e: ret @@ -682,7 +682,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 b - .field public class DelegateConstruction/'<>c__DisplayClass14_0' 'CS$<>8__locals1' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0' 'CS$<>8__locals1' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -699,10 +699,10 @@ // Code size 21 (0x15) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass14_0' DelegateConstruction/'<>c__DisplayClass14_1'::'CS$<>8__locals1' - IL_0006: ldfld int32 DelegateConstruction/'<>c__DisplayClass14_0'::a + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_1'::'CS$<>8__locals1' + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0'::a IL_000b: ldarg.0 - IL_000c: ldfld int32 DelegateConstruction/'<>c__DisplayClass14_1'::b + IL_000c: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_1'::b IL_0011: add IL_0012: ldarg.1 IL_0013: add @@ -731,14 +731,14 @@ { // Code size 31 (0x1f) .maxstack 8 - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass15_1'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1'::.ctor() IL_0005: dup IL_0006: ldarg.0 - IL_0007: stfld class DelegateConstruction/'<>c__DisplayClass15_0' DelegateConstruction/'<>c__DisplayClass15_1'::'CS$<>8__locals1' + IL_0007: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1'::'CS$<>8__locals1' IL_000c: dup IL_000d: ldarg.1 - IL_000e: stfld int32 DelegateConstruction/'<>c__DisplayClass15_1'::b - IL_0013: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass15_1'::'b__1'(int32) + IL_000e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1'::b + IL_0013: ldftn instance class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1'::'b__1'(int32) IL_0019: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, native int) IL_001e: ret @@ -751,7 +751,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 b - .field public class DelegateConstruction/'<>c__DisplayClass15_0' 'CS$<>8__locals1' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0' 'CS$<>8__locals1' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -767,14 +767,14 @@ { // Code size 31 (0x1f) .maxstack 8 - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass15_2'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::.ctor() IL_0005: dup IL_0006: ldarg.0 - IL_0007: stfld class DelegateConstruction/'<>c__DisplayClass15_1' DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' + IL_0007: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' IL_000c: dup IL_000d: ldarg.1 - IL_000e: stfld int32 DelegateConstruction/'<>c__DisplayClass15_2'::c - IL_0013: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass15_2'::'b__2'(int32) + IL_000e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::c + IL_0013: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::'b__2'(int32) IL_0019: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_001e: ret @@ -787,7 +787,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 c - .field public class DelegateConstruction/'<>c__DisplayClass15_1' 'CS$<>8__locals2' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1' 'CS$<>8__locals2' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -804,15 +804,15 @@ // Code size 38 (0x26) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass15_1' DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' - IL_0006: ldfld class DelegateConstruction/'<>c__DisplayClass15_0' DelegateConstruction/'<>c__DisplayClass15_1'::'CS$<>8__locals1' - IL_000b: ldfld int32 DelegateConstruction/'<>c__DisplayClass15_0'::a + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' + IL_0006: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1'::'CS$<>8__locals1' + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0'::a IL_0010: ldarg.0 - IL_0011: ldfld class DelegateConstruction/'<>c__DisplayClass15_1' DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' - IL_0016: ldfld int32 DelegateConstruction/'<>c__DisplayClass15_1'::b + IL_0011: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' + IL_0016: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1'::b IL_001b: add IL_001c: ldarg.0 - IL_001d: ldfld int32 DelegateConstruction/'<>c__DisplayClass15_2'::c + IL_001d: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::c IL_0022: add IL_0023: ldarg.1 IL_0024: add @@ -835,7 +835,7 @@ // Code size 13 (0xd) .maxstack 8 IL_0000: ldnull - IL_0001: ldftn void DelegateConstruction::Test(string) + IL_0001: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::Test(string) IL_0007: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_000c: ret @@ -847,7 +847,7 @@ // Code size 17 (0x11) .maxstack 8 IL_0000: ldstr "abc" - IL_0005: ldftn void DelegateConstruction::Test(string) + IL_0005: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::Test(string) IL_000b: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_0010: ret @@ -859,7 +859,7 @@ // Code size 13 (0xd) .maxstack 8 IL_0000: ldnull - IL_0001: ldftn void DelegateConstruction::Test(string) + IL_0001: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::Test(string) IL_0007: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_000c: ret @@ -871,7 +871,7 @@ // Code size 13 (0xd) .maxstack 8 IL_0000: ldnull - IL_0001: ldftn class [mscorlib]System.Action DelegateConstruction::ExtensionMethodBound() + IL_0001: ldftn class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::ExtensionMethodBound() IL_0007: newobj instance void class [mscorlib]System.Func`1::.ctor(object, native int) IL_000c: ret @@ -908,18 +908,18 @@ .maxstack 3 .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, int32 V_1, - class DelegateConstruction/'<>c__DisplayClass8_0' V_2) + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass8_0' V_2) IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() IL_0005: stloc.0 IL_0006: ldc.i4.0 IL_0007: stloc.1 IL_0008: br.s IL_0026 - IL_000a: newobj instance void DelegateConstruction/'<>c__DisplayClass8_0'::.ctor() + IL_000a: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass8_0'::.ctor() IL_000f: stloc.2 IL_0010: ldloc.0 IL_0011: ldloc.2 - IL_0012: ldftn instance void DelegateConstruction/'<>c__DisplayClass8_0'::'b__0'(int32) + IL_0012: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass8_0'::'b__0'(int32) IL_0018: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_001d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) @@ -940,11 +940,11 @@ { // Code size 64 (0x40) .maxstack 4 - .locals init (class DelegateConstruction/'<>c__DisplayClass9_0' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass9_0' V_0, class [mscorlib]System.Collections.Generic.List`1> V_1, int32 V_2, class [mscorlib]System.Action`1 V_3) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass9_0'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass9_0'::.ctor() IL_0005: stloc.0 IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() IL_000b: stloc.1 @@ -954,19 +954,19 @@ IL_0010: ldloc.1 IL_0011: ldloc.0 - IL_0012: ldfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c__DisplayClass9_0'::'<>9__0' + IL_0012: ldfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass9_0'::'<>9__0' IL_0017: dup IL_0018: brtrue.s IL_0030 IL_001a: pop IL_001b: ldloc.0 IL_001c: ldloc.0 - IL_001d: ldftn instance void DelegateConstruction/'<>c__DisplayClass9_0'::'b__0'(int32) + IL_001d: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass9_0'::'b__0'(int32) IL_0023: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_0028: dup IL_0029: stloc.3 - IL_002a: stfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c__DisplayClass9_0'::'<>9__0' + IL_002a: stfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass9_0'::'<>9__0' IL_002f: ldloc.3 IL_0030: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) IL_0035: ldloc.2 @@ -986,17 +986,17 @@ { // Code size 32 (0x20) .maxstack 8 - IL_0000: ldsfld class [mscorlib]System.Action DelegateConstruction/'<>c'::'<>9__10_0' + IL_0000: ldsfld class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9__10_0' IL_0005: dup IL_0006: brtrue.s IL_001f IL_0008: pop - IL_0009: ldsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' - IL_000e: ldftn instance void DelegateConstruction/'<>c'::'b__10_0'() + IL_0009: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9' + IL_000e: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'b__10_0'() IL_0014: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_0019: dup - IL_001a: stsfld class [mscorlib]System.Action DelegateConstruction/'<>c'::'<>9__10_0' + IL_001a: stsfld class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9__10_0' IL_001f: ret } // end of method DelegateConstruction::StaticAnonymousMethodNoClosure @@ -1006,7 +1006,7 @@ .maxstack 3 .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, int32 V_1, - class DelegateConstruction/'<>c__DisplayClass11_0' V_2, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0' V_2, int32 V_3) IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() IL_0005: stloc.0 @@ -1014,29 +1014,29 @@ IL_0007: stloc.1 IL_0008: br.s IL_0049 - IL_000a: newobj instance void DelegateConstruction/'<>c__DisplayClass11_0'::.ctor() + IL_000a: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::.ctor() IL_000f: stloc.2 IL_0010: ldloc.2 IL_0011: ldc.i4.0 - IL_0012: stfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0012: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::i IL_0017: br.s IL_003b IL_0019: ldloc.0 IL_001a: ldloc.2 - IL_001b: ldftn instance void DelegateConstruction/'<>c__DisplayClass11_0'::'b__0'(int32) + IL_001b: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::'b__0'(int32) IL_0021: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_0026: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) IL_002b: ldloc.2 - IL_002c: ldfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_002c: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::i IL_0031: stloc.3 IL_0032: ldloc.2 IL_0033: ldloc.3 IL_0034: ldc.i4.1 IL_0035: add - IL_0036: stfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0036: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::i IL_003b: ldloc.2 - IL_003c: ldfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_003c: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::i IL_0041: ldc.i4.s 10 IL_0043: blt.s IL_0019 @@ -1064,17 +1064,17 @@ IL_0008: br.s IL_0033 IL_000a: ldloc.0 - IL_000b: ldsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__12_0' + IL_000b: ldsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9__12_0' IL_0010: dup IL_0011: brtrue.s IL_002a IL_0013: pop - IL_0014: ldsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' - IL_0019: ldftn instance void DelegateConstruction/'<>c'::'b__12_0'(int32) + IL_0014: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9' + IL_0019: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'b__12_0'(int32) IL_001f: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_0024: dup - IL_0025: stsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__12_0' + IL_0025: stsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9__12_0' IL_002a: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) IL_002f: ldloc.1 IL_0030: ldc.i4.1 @@ -1092,17 +1092,17 @@ { // Code size 32 (0x20) .maxstack 8 - IL_0000: ldsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__13_0' + IL_0000: ldsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9__13_0' IL_0005: dup IL_0006: brtrue.s IL_001f IL_0008: pop - IL_0009: ldsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' - IL_000e: ldftn instance void DelegateConstruction/'<>c'::'b__13_0'(int32) + IL_0009: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9' + IL_000e: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'b__13_0'(int32) IL_0014: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_0019: dup - IL_001a: stsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__13_0' + IL_001a: stsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9__13_0' IL_001f: ret } // end of method DelegateConstruction::NameConflict3 @@ -1111,11 +1111,11 @@ { // Code size 24 (0x18) .maxstack 8 - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass14_0'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0'::.ctor() IL_0005: dup IL_0006: ldarg.0 - IL_0007: stfld int32 DelegateConstruction/'<>c__DisplayClass14_0'::a - IL_000c: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass14_0'::'b__0'(int32) + IL_0007: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0'::a + IL_000c: ldftn instance class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0'::'b__0'(int32) IL_0012: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, native int) IL_0017: ret @@ -1126,17 +1126,17 @@ { // Code size 24 (0x18) .maxstack 8 - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass15_0'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0'::.ctor() IL_0005: dup IL_0006: ldarg.0 - IL_0007: stfld int32 DelegateConstruction/'<>c__DisplayClass15_0'::a - IL_000c: ldftn instance class [mscorlib]System.Func`2> DelegateConstruction/'<>c__DisplayClass15_0'::'b__0'(int32) + IL_0007: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0'::a + IL_000c: ldftn instance class [mscorlib]System.Func`2> ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0'::'b__0'(int32) IL_0012: newobj instance void class [mscorlib]System.Func`2>>::.ctor(object, native int) IL_0017: ret } // end of method DelegateConstruction::CurriedAddition2 -} // end of class DelegateConstruction +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.roslyn.il index e793c66c1..f5ea3ce98 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.roslyn.il @@ -1,5 +1,5 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -31,19 +31,19 @@ .ver 0:0:0:0 } .module DelegateConstruction.dll -// MVID: {518B81C1-649D-4492-9DBC-30B3EB1721A3} +// MVID: {8AC9B4E6-77A7-45DC-BBF4-76DB9EA29AFF} .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: 0x01670000 +// Image base: 0x01820000 // =============== CLASS MEMBERS DECLARATION =================== -.class public abstract auto ansi sealed beforefieldinit DelegateConstruction +.class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) @@ -55,7 +55,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 a - .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -74,10 +74,10 @@ .maxstack 8 IL_0000: nop IL_0001: ldarg.0 - IL_0002: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'<>4__this' + IL_0002: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'<>4__this' IL_0007: ldarg.0 - IL_0008: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::a - IL_000d: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0008: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::a + IL_000d: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) IL_0012: pop IL_0013: ret } // end of method '<>c__DisplayClass1_0'::'b__0' @@ -89,7 +89,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 item - .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' 'CS$<>8__locals1' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' 'CS$<>8__locals1' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -108,15 +108,15 @@ .maxstack 8 IL_0000: nop IL_0001: ldarg.0 - IL_0002: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' - IL_0007: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::'<>4__this' + IL_0002: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' + IL_0007: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::'<>4__this' IL_000c: ldarg.0 - IL_000d: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item + IL_000d: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item IL_0012: ldarg.0 - IL_0013: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' - IL_0018: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::a + IL_0013: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' + IL_0018: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::a IL_001d: add - IL_001e: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_001e: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) IL_0023: pop IL_0024: ret } // end of method '<>c__DisplayClass2_0'::'b__0' @@ -128,7 +128,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 a - .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -147,7 +147,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 item - .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' 'CS$<>8__locals1' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' 'CS$<>8__locals1' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -166,7 +166,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 a - .field public class DelegateConstruction/InstanceTests '<>4__this' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -185,7 +185,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 copyOfItem - .field public class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' 'CS$<>8__locals2' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' 'CS$<>8__locals2' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -204,21 +204,21 @@ .maxstack 8 IL_0000: nop IL_0001: ldarg.0 - IL_0002: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' - IL_0007: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' - IL_000c: ldfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::'<>4__this' + IL_0002: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0007: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' + IL_000c: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::'<>4__this' IL_0011: ldarg.0 - IL_0012: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' - IL_0017: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_0012: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0017: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item IL_001c: ldarg.0 - IL_001d: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' - IL_0022: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' - IL_0027: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::a + IL_001d: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0022: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' + IL_0027: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::a IL_002c: add IL_002d: ldarg.0 - IL_002e: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::copyOfItem + IL_002e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::copyOfItem IL_0033: add - IL_0034: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) + IL_0034: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThisAndParameter(int32) IL_0039: pop IL_003a: ret } // end of method '<>c__DisplayClass3_2'::'b__0' @@ -233,7 +233,7 @@ .locals init (class [mscorlib]System.Action V_0) IL_0000: nop IL_0001: ldarg.0 - IL_0002: ldftn instance void DelegateConstruction/InstanceTests::'b__0_0'() + IL_0002: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::'b__0_0'() IL_0008: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_000d: stloc.0 @@ -248,19 +248,19 @@ { // Code size 38 (0x26) .maxstack 2 - .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0' V_0, class [mscorlib]System.Action V_1) - IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'<>4__this' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'<>4__this' IL_000d: ldloc.0 IL_000e: ldarg.1 - IL_000f: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::a + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::a IL_0014: nop IL_0015: ldloc.0 - IL_0016: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'b__0'() + IL_0016: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass1_0'::'b__0'() IL_001c: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_0021: stloc.1 @@ -275,19 +275,19 @@ { // Code size 121 (0x79) .maxstack 2 - .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' V_0, class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0' V_2, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0' V_2, bool V_3, class [mscorlib]System.Action V_4) - IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::'<>4__this' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::'<>4__this' IL_000d: ldloc.0 IL_000e: ldarg.1 - IL_000f: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::a + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1'::a IL_0014: nop IL_0015: nop IL_0016: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() @@ -297,18 +297,18 @@ { IL_0021: br.s IL_005c - IL_0023: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::.ctor() + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::.ctor() IL_0028: stloc.2 IL_0029: ldloc.2 IL_002a: ldloc.0 - IL_002b: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' + IL_002b: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'CS$<>8__locals1' IL_0030: ldloc.2 IL_0031: ldloc.1 IL_0032: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() - IL_0037: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item + IL_0037: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item IL_003c: nop IL_003d: ldloc.2 - IL_003e: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item + IL_003e: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::item IL_0043: ldc.i4.0 IL_0044: cgt IL_0046: stloc.3 @@ -317,7 +317,7 @@ IL_004a: nop IL_004b: ldloc.2 - IL_004c: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'b__0'() + IL_004c: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass2_0'::'b__0'() IL_0052: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_0057: stloc.s V_4 @@ -354,20 +354,20 @@ { // Code size 158 (0x9e) .maxstack 2 - .locals init (class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' V_0, class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' V_2, - class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2' V_3, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' V_2, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2' V_3, bool V_4, class [mscorlib]System.Action V_5) - IL_0000: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/InstanceTests DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::'<>4__this' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::'<>4__this' IL_000d: ldloc.0 IL_000e: ldarg.1 - IL_000f: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::a + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1'::a IL_0014: nop IL_0015: nop IL_0016: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Empty() @@ -377,29 +377,29 @@ { IL_0021: br.s IL_0081 - IL_0023: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::.ctor() + IL_0023: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::.ctor() IL_0028: stloc.2 IL_0029: ldloc.2 IL_002a: ldloc.0 - IL_002b: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' + IL_002b: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::'CS$<>8__locals1' IL_0030: ldloc.2 IL_0031: ldloc.1 IL_0032: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() - IL_0037: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item - IL_003c: newobj instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::.ctor() + IL_0037: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_003c: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::.ctor() IL_0041: stloc.3 IL_0042: ldloc.3 IL_0043: ldloc.2 - IL_0044: stfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0044: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' IL_0049: nop IL_004a: ldloc.3 IL_004b: ldloc.3 - IL_004c: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' - IL_0051: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item - IL_0056: stfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::copyOfItem + IL_004c: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0051: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_0056: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::copyOfItem IL_005b: ldloc.3 - IL_005c: ldfld class DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' - IL_0061: ldfld int32 DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item + IL_005c: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'CS$<>8__locals2' + IL_0061: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_0'::item IL_0066: ldc.i4.0 IL_0067: cgt IL_0069: stloc.s V_4 @@ -408,7 +408,7 @@ IL_006f: nop IL_0070: ldloc.3 - IL_0071: ldftn instance void DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'b__0'() + IL_0071: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3_2'::'b__0'() IL_0077: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_007c: stloc.s V_5 @@ -455,10 +455,10 @@ IL_0005: nop IL_0006: ldarg.0 IL_0007: ldarg.0 - IL_0008: ldftn instance int32 DelegateConstruction/InstanceTests::'b__4_0'() + IL_0008: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::'b__4_0'() IL_000e: newobj instance void class [mscorlib]System.Func`1::.ctor(object, native int) - IL_0013: call instance void DelegateConstruction/InstanceTests::Bar(class [mscorlib]System.Func`1) + IL_0013: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::Bar(class [mscorlib]System.Func`1) IL_0018: nop IL_0019: nop IL_001a: ldloc.0 @@ -518,7 +518,7 @@ .maxstack 8 IL_0000: nop IL_0001: ldarg.0 - IL_0002: call instance class [mscorlib]System.Action DelegateConstruction/InstanceTests::CaptureOfThis() + IL_0002: call instance class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::CaptureOfThis() IL_0007: pop IL_0008: ret } // end of method InstanceTests::'b__0_0' @@ -530,7 +530,7 @@ // Code size 7 (0x7) .maxstack 8 IL_0000: ldarg.0 - IL_0001: call instance int32 DelegateConstruction/InstanceTests::Foo() + IL_0001: call instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::Foo() IL_0006: ret } // end of method InstanceTests::'b__4_0' @@ -560,7 +560,7 @@ IL_0000: nop IL_0001: ldarg.0 IL_0002: ldarg.1 - IL_0003: stfld int32 DelegateConstruction/'<>c__DisplayClass8_0'::counter + IL_0003: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass8_0'::counter IL_0008: ret } // end of method '<>c__DisplayClass8_0'::'b__0' @@ -591,7 +591,7 @@ IL_0000: nop IL_0001: ldarg.0 IL_0002: ldarg.1 - IL_0003: stfld int32 DelegateConstruction/'<>c__DisplayClass9_0'::counter + IL_0003: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass9_0'::counter IL_0008: ret } // end of method '<>c__DisplayClass9_0'::'b__0' @@ -601,7 +601,7 @@ extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field public static initonly class DelegateConstruction/'<>c' '<>9' + .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c' '<>9' .field public static class [mscorlib]System.Action '<>9__10_0' .field public static class [mscorlib]System.Action`1 '<>9__12_0' .field public static class [mscorlib]System.Action`1 '<>9__13_0' @@ -610,8 +610,8 @@ { // Code size 11 (0xb) .maxstack 8 - IL_0000: newobj instance void DelegateConstruction/'<>c'::.ctor() - IL_0005: stsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::.ctor() + IL_0005: stsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9' IL_000a: ret } // end of method '<>c'::.cctor @@ -720,7 +720,7 @@ IL_0010: stloc.0 IL_0011: ldloc.0 IL_0012: ldarg.0 - IL_0013: ldfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0013: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::i IL_0018: clt IL_001a: stloc.1 IL_001b: ldloc.1 @@ -752,17 +752,17 @@ { // Code size 33 (0x21) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass14_1' V_0) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass14_1'::.ctor() + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_1' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_1'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass14_0' DelegateConstruction/'<>c__DisplayClass14_1'::'CS$<>8__locals1' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_1'::'CS$<>8__locals1' IL_000d: ldloc.0 IL_000e: ldarg.1 - IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass14_1'::b + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_1'::b IL_0014: ldloc.0 - IL_0015: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass14_1'::'b__1'(int32) + IL_0015: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_1'::'b__1'(int32) IL_001b: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_0020: ret @@ -775,7 +775,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 b - .field public class DelegateConstruction/'<>c__DisplayClass14_0' 'CS$<>8__locals1' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0' 'CS$<>8__locals1' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -793,10 +793,10 @@ // Code size 21 (0x15) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass14_0' DelegateConstruction/'<>c__DisplayClass14_1'::'CS$<>8__locals1' - IL_0006: ldfld int32 DelegateConstruction/'<>c__DisplayClass14_0'::a + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_1'::'CS$<>8__locals1' + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0'::a IL_000b: ldarg.0 - IL_000c: ldfld int32 DelegateConstruction/'<>c__DisplayClass14_1'::b + IL_000c: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_1'::b IL_0011: add IL_0012: ldarg.1 IL_0013: add @@ -826,17 +826,17 @@ { // Code size 33 (0x21) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass15_1' V_0) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass15_1'::.ctor() + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass15_0' DelegateConstruction/'<>c__DisplayClass15_1'::'CS$<>8__locals1' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1'::'CS$<>8__locals1' IL_000d: ldloc.0 IL_000e: ldarg.1 - IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass15_1'::b + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1'::b IL_0014: ldloc.0 - IL_0015: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass15_1'::'b__1'(int32) + IL_0015: ldftn instance class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1'::'b__1'(int32) IL_001b: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, native int) IL_0020: ret @@ -849,7 +849,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 b - .field public class DelegateConstruction/'<>c__DisplayClass15_0' 'CS$<>8__locals1' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0' 'CS$<>8__locals1' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -866,17 +866,17 @@ { // Code size 33 (0x21) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass15_2' V_0) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass15_2'::.ctor() + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld class DelegateConstruction/'<>c__DisplayClass15_1' DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' + IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' IL_000d: ldloc.0 IL_000e: ldarg.1 - IL_000f: stfld int32 DelegateConstruction/'<>c__DisplayClass15_2'::c + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::c IL_0014: ldloc.0 - IL_0015: ldftn instance int32 DelegateConstruction/'<>c__DisplayClass15_2'::'b__2'(int32) + IL_0015: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::'b__2'(int32) IL_001b: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_0020: ret @@ -889,7 +889,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public int32 c - .field public class DelegateConstruction/'<>c__DisplayClass15_1' 'CS$<>8__locals2' + .field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1' 'CS$<>8__locals2' .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -907,15 +907,15 @@ // Code size 38 (0x26) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld class DelegateConstruction/'<>c__DisplayClass15_1' DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' - IL_0006: ldfld class DelegateConstruction/'<>c__DisplayClass15_0' DelegateConstruction/'<>c__DisplayClass15_1'::'CS$<>8__locals1' - IL_000b: ldfld int32 DelegateConstruction/'<>c__DisplayClass15_0'::a + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' + IL_0006: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1'::'CS$<>8__locals1' + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0'::a IL_0010: ldarg.0 - IL_0011: ldfld class DelegateConstruction/'<>c__DisplayClass15_1' DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' - IL_0016: ldfld int32 DelegateConstruction/'<>c__DisplayClass15_1'::b + IL_0011: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::'CS$<>8__locals2' + IL_0016: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_1'::b IL_001b: add IL_001c: ldarg.0 - IL_001d: ldfld int32 DelegateConstruction/'<>c__DisplayClass15_2'::c + IL_001d: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_2'::c IL_0022: add IL_0023: ldarg.1 IL_0024: add @@ -941,7 +941,7 @@ .locals init (class [mscorlib]System.Action`1 V_0) IL_0000: nop IL_0001: ldnull - IL_0002: ldftn void DelegateConstruction::Test(string) + IL_0002: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::Test(string) IL_0008: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_000d: stloc.0 @@ -959,7 +959,7 @@ .locals init (class [mscorlib]System.Action V_0) IL_0000: nop IL_0001: ldstr "abc" - IL_0006: ldftn void DelegateConstruction::Test(string) + IL_0006: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::Test(string) IL_000c: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_0011: stloc.0 @@ -977,7 +977,7 @@ .locals init (class [mscorlib]System.Action V_0) IL_0000: nop IL_0001: ldnull - IL_0002: ldftn void DelegateConstruction::Test(string) + IL_0002: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::Test(string) IL_0008: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_000d: stloc.0 @@ -995,7 +995,7 @@ .locals init (object V_0) IL_0000: nop IL_0001: ldnull - IL_0002: ldftn class [mscorlib]System.Action DelegateConstruction::ExtensionMethodBound() + IL_0002: ldftn class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction::ExtensionMethodBound() IL_0008: newobj instance void class [mscorlib]System.Func`1::.ctor(object, native int) IL_000d: stloc.0 @@ -1048,7 +1048,7 @@ .maxstack 3 .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, int32 V_1, - class DelegateConstruction/'<>c__DisplayClass8_0' V_2, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass8_0' V_2, bool V_3, class [mscorlib]System.Collections.Generic.List`1> V_4) IL_0000: nop @@ -1058,12 +1058,12 @@ IL_0008: stloc.1 IL_0009: br.s IL_002a - IL_000b: newobj instance void DelegateConstruction/'<>c__DisplayClass8_0'::.ctor() + IL_000b: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass8_0'::.ctor() IL_0010: stloc.2 IL_0011: nop IL_0012: ldloc.0 IL_0013: ldloc.2 - IL_0014: ldftn instance void DelegateConstruction/'<>c__DisplayClass8_0'::'b__0'(int32) + IL_0014: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass8_0'::'b__0'(int32) IL_001a: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_001f: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) @@ -1093,13 +1093,13 @@ { // Code size 80 (0x50) .maxstack 4 - .locals init (class DelegateConstruction/'<>c__DisplayClass9_0' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass9_0' V_0, class [mscorlib]System.Collections.Generic.List`1> V_1, int32 V_2, class [mscorlib]System.Action`1 V_3, bool V_4, class [mscorlib]System.Collections.Generic.List`1> V_5) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass9_0'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass9_0'::.ctor() IL_0005: stloc.0 IL_0006: nop IL_0007: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() @@ -1111,19 +1111,19 @@ IL_0011: nop IL_0012: ldloc.1 IL_0013: ldloc.0 - IL_0014: ldfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c__DisplayClass9_0'::'<>9__0' + IL_0014: ldfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass9_0'::'<>9__0' IL_0019: dup IL_001a: brtrue.s IL_0032 IL_001c: pop IL_001d: ldloc.0 IL_001e: ldloc.0 - IL_001f: ldftn instance void DelegateConstruction/'<>c__DisplayClass9_0'::'b__0'(int32) + IL_001f: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass9_0'::'b__0'(int32) IL_0025: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_002a: dup IL_002b: stloc.3 - IL_002c: stfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c__DisplayClass9_0'::'<>9__0' + IL_002c: stfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass9_0'::'<>9__0' IL_0031: ldloc.3 IL_0032: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) IL_0037: nop @@ -1154,17 +1154,17 @@ .maxstack 2 .locals init (class [mscorlib]System.Action V_0) IL_0000: nop - IL_0001: ldsfld class [mscorlib]System.Action DelegateConstruction/'<>c'::'<>9__10_0' + IL_0001: ldsfld class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9__10_0' IL_0006: dup IL_0007: brtrue.s IL_0020 IL_0009: pop - IL_000a: ldsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' - IL_000f: ldftn instance void DelegateConstruction/'<>c'::'b__10_0'() + IL_000a: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9' + IL_000f: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'b__10_0'() IL_0015: newobj instance void [mscorlib]System.Action::.ctor(object, native int) IL_001a: dup - IL_001b: stsfld class [mscorlib]System.Action DelegateConstruction/'<>c'::'<>9__10_0' + IL_001b: stsfld class [mscorlib]System.Action ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9__10_0' IL_0020: stloc.0 IL_0021: br.s IL_0023 @@ -1178,7 +1178,7 @@ .maxstack 3 .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0, int32 V_1, - class DelegateConstruction/'<>c__DisplayClass11_0' V_2, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0' V_2, int32 V_3, bool V_4, bool V_5) @@ -1189,33 +1189,33 @@ IL_0008: stloc.1 IL_0009: br.s IL_0055 - IL_000b: newobj instance void DelegateConstruction/'<>c__DisplayClass11_0'::.ctor() + IL_000b: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::.ctor() IL_0010: stloc.2 IL_0011: nop IL_0012: ldloc.2 IL_0013: ldc.i4.0 - IL_0014: stfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::i IL_0019: br.s IL_0040 IL_001b: nop IL_001c: ldloc.0 IL_001d: ldloc.2 - IL_001e: ldftn instance void DelegateConstruction/'<>c__DisplayClass11_0'::'b__0'(int32) + IL_001e: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::'b__0'(int32) IL_0024: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_0029: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) IL_002e: nop IL_002f: nop IL_0030: ldloc.2 - IL_0031: ldfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0031: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::i IL_0036: stloc.3 IL_0037: ldloc.2 IL_0038: ldloc.3 IL_0039: ldc.i4.1 IL_003a: add - IL_003b: stfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_003b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::i IL_0040: ldloc.2 - IL_0041: ldfld int32 DelegateConstruction/'<>c__DisplayClass11_0'::i + IL_0041: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass11_0'::i IL_0046: ldc.i4.s 10 IL_0048: clt IL_004a: stloc.s V_4 @@ -1253,17 +1253,17 @@ IL_000b: nop IL_000c: ldloc.0 - IL_000d: ldsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__12_0' + IL_000d: ldsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9__12_0' IL_0012: dup IL_0013: brtrue.s IL_002c IL_0015: pop - IL_0016: ldsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' - IL_001b: ldftn instance void DelegateConstruction/'<>c'::'b__12_0'(int32) + IL_0016: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9' + IL_001b: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'b__12_0'(int32) IL_0021: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_0026: dup - IL_0027: stsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__12_0' + IL_0027: stsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9__12_0' IL_002c: callvirt instance void class [mscorlib]System.Collections.Generic.List`1>::Add(!0) IL_0031: nop IL_0032: nop @@ -1288,17 +1288,17 @@ .maxstack 2 .locals init (class [mscorlib]System.Action`1 V_0) IL_0000: nop - IL_0001: ldsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__13_0' + IL_0001: ldsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9__13_0' IL_0006: dup IL_0007: brtrue.s IL_0020 IL_0009: pop - IL_000a: ldsfld class DelegateConstruction/'<>c' DelegateConstruction/'<>c'::'<>9' - IL_000f: ldftn instance void DelegateConstruction/'<>c'::'b__13_0'(int32) + IL_000a: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9' + IL_000f: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'b__13_0'(int32) IL_0015: newobj instance void class [mscorlib]System.Action`1::.ctor(object, native int) IL_001a: dup - IL_001b: stsfld class [mscorlib]System.Action`1 DelegateConstruction/'<>c'::'<>9__13_0' + IL_001b: stsfld class [mscorlib]System.Action`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c'::'<>9__13_0' IL_0020: stloc.0 IL_0021: br.s IL_0023 @@ -1311,16 +1311,16 @@ { // Code size 31 (0x1f) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass14_0' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0' V_0, class [mscorlib]System.Func`2> V_1) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass14_0'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld int32 DelegateConstruction/'<>c__DisplayClass14_0'::a + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0'::a IL_000d: nop IL_000e: ldloc.0 - IL_000f: ldftn instance class [mscorlib]System.Func`2 DelegateConstruction/'<>c__DisplayClass14_0'::'b__0'(int32) + IL_000f: ldftn instance class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass14_0'::'b__0'(int32) IL_0015: newobj instance void class [mscorlib]System.Func`2>::.ctor(object, native int) IL_001a: stloc.1 @@ -1335,16 +1335,16 @@ { // Code size 31 (0x1f) .maxstack 2 - .locals init (class DelegateConstruction/'<>c__DisplayClass15_0' V_0, + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0' V_0, class [mscorlib]System.Func`2>> V_1) - IL_0000: newobj instance void DelegateConstruction/'<>c__DisplayClass15_0'::.ctor() + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0'::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: ldarg.0 - IL_0008: stfld int32 DelegateConstruction/'<>c__DisplayClass15_0'::a + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0'::a IL_000d: nop IL_000e: ldloc.0 - IL_000f: ldftn instance class [mscorlib]System.Func`2> DelegateConstruction/'<>c__DisplayClass15_0'::'b__0'(int32) + IL_000f: ldftn instance class [mscorlib]System.Func`2> ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/'<>c__DisplayClass15_0'::'b__0'(int32) IL_0015: newobj instance void class [mscorlib]System.Func`2>>::.ctor(object, native int) IL_001a: stloc.1 @@ -1354,7 +1354,7 @@ IL_001e: ret } // end of method DelegateConstruction::CurriedAddition2 -} // end of class DelegateConstruction +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction // ============================================================= From 63b626716f8b7ee221ca556be3dd1aee554bd484 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 13 Oct 2017 13:26:57 +0200 Subject: [PATCH 105/190] Refactoring and cleanup of SimplifyCascadingIfStatements and other switch transforms. --- .../IL/Transforms/SwitchOnStringTransform.cs | 103 +++++++++++------- 1 file changed, 62 insertions(+), 41 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index d8eac46fe..2ff02e41f 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -115,36 +115,42 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!firstBlockJump.MatchBranch(out var firstBlock)) return false; List<(string, Block)> values = new List<(string, Block)>(); - // match null check: this is used by the old C# compiler. - if (condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && left.MatchLdLoc(out var switchValueVar)) { - values.Add((null, firstBlock)); - // Roslyn: match call to operator ==(string, string) - } else if (MatchStringEqualityComparison(condition, out switchValueVar, out string value)) { + ILInstruction switchValue = null; + // Roslyn: match call to operator ==(string, string) + if (MatchStringEqualityComparison(condition, out var switchValueVar, out string value)) { values.Add((value, firstBlock)); - } else return false; - // switchValueVar must be assigned only once and must be of type string. - if (!switchValueVar.IsSingleDefinition || !switchValueVar.Type.IsKnownType(KnownTypeCode.String)) - return false; - // if instruction must be preceeded by a stloc to the switchValueVar - if (instructions[i - 1].MatchStLoc(switchValueVar, out var switchValue)) { } - // in case of legacy code there are two stlocs: - // stloc switchValueVar(ldloc switchValue) - // stloc otherSwitchValueVar(ldloc switchValueVar) - // if (comp(ldloc switchValueVar == ldnull)) br nullCase - else if (i > 1 && instructions[i - 2].MatchStLoc(switchValueVar, out switchValue) && - instructions[i - 1].MatchStLoc(out var otherSwitchValueVar, out var switchValueCopyInst) && - switchValueCopyInst.MatchLdLoc(switchValueVar) && otherSwitchValueVar.IsSingleDefinition && switchValueVar.LoadCount == 2) - { - extraLoad = true; + if(!instructions[i - 1].MatchStLoc(switchValueVar, out switchValue)) { + switchValue = new LdLoc(switchValueVar); + } + } else { + // match null check with different variable: + // this is used by the old C# compiler. + if (MatchCompEqualsNull(condition, out var otherSwitchValueVar)) { + values.Add((null, firstBlock)); + } else { + return false; + } + + // in case of optimized legacy code there are two stlocs: + // stloc otherSwitchValueVar(ldloc switchValue) + // stloc switchValueVar(ldloc otherSwitchValueVar) + // if (comp(ldloc otherSwitchValueVar == ldnull)) br nullCase + if (i > 1 && otherSwitchValueVar != null && instructions[i - 2].MatchStLoc(otherSwitchValueVar, out switchValue) + && instructions[i - 1].MatchStLoc(out switchValueVar, out var switchValueCopyInst) + && switchValueCopyInst.MatchLdLoc(otherSwitchValueVar) && otherSwitchValueVar.IsSingleDefinition && otherSwitchValueVar.LoadCount == 2) { + extraLoad = true; + } else if (instructions[i - 1].MatchStLoc(out switchValueVar, out switchValue)) { + // unoptimized legacy switch + } } - else return false; + // if instruction must be followed by a branch to the next case if (!(instructions.ElementAtOrDefault(i + 1) is Branch nextCaseJump)) return false; // extract all cases and add them to the values list. Block currentCaseBlock = nextCaseJump.TargetBlock; Block nextCaseBlock; - while ((nextCaseBlock = MatchCaseBlock(currentCaseBlock, ref switchValueVar, out string value, out Block block)) != null) { + while ((nextCaseBlock = MatchCaseBlock(currentCaseBlock, switchValueVar, out value, out Block block)) != null) { values.Add((value, block)); currentCaseBlock = nextCaseBlock; } @@ -169,13 +175,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms /// 1. block: /// if (call op_Equality(ldloc switchVariable, ldstr value)) br caseBlock /// br nextBlock + /// -or- + /// if (comp(ldloc switchValueVar == ldnull)) br nextBlock + /// br caseBlock + /// 2. block is caseBlock /// This method matches the above pattern or its inverted form: /// the call to ==(string, string) is wrapped in logic.not and the branch targets are reversed. /// Returns the next block that follows in the block-chain. /// The is updated if the value gets copied to a different variable. /// See comments below for more info. /// - Block MatchCaseBlock(Block currentBlock, ref ILVariable switchVariable, out string value, out Block caseBlock) + Block MatchCaseBlock(Block currentBlock, ILVariable switchVariable, out string value, out Block caseBlock) { value = null; caseBlock = null; @@ -196,19 +206,15 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!currentBlock.Instructions[1].MatchBranch(out nextBlock)) return null; } - // Sometimes the switch pattern uses one variable at the beginning for null checks - // and another variable for the if-else-if-else-pattern. - // both variables must be only assigned once and be of the type: System.String. - if (!MatchStringEqualityComparison(condition, out var newSwitchVariable, out value)) - return null; - if (!newSwitchVariable.IsSingleDefinition) - return null; - // if the used variable differs and both variables are not related, return null: - if (switchVariable != newSwitchVariable && !(IsInitializedBy(switchVariable, newSwitchVariable) || IsInitializedBy(newSwitchVariable, switchVariable))) - return null; - if (!newSwitchVariable.Type.IsKnownType(KnownTypeCode.String)) + if (!MatchStringEqualityComparison(condition, out var v, out value)) { + if (MatchCompEqualsNull(condition, out v)) { + value = null; + } else { + return null; + } + } + if (v != switchVariable) return null; - switchVariable = newSwitchVariable; return nextBlock; } @@ -482,8 +488,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!bodyBranch.MatchBranch(out Block body)) return false; - if (!MatchStringEqualityComparison(condition, switchValue.Variable, out string stringValue)) { - if (condition.MatchLogicNot(out condition) && MatchStringEqualityComparison(condition, switchValue.Variable, out stringValue)) { + if (!MatchStringEqualityOrNullComparison(condition, switchValue.Variable, out string stringValue)) { + if (condition.MatchLogicNot(out condition) && MatchStringEqualityOrNullComparison(condition, switchValue.Variable, out stringValue)) { if (!target.Instructions[1].MatchBranch(out Block exit)) return false; body = exit; @@ -520,9 +526,15 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; } - bool MatchStringEqualityComparison(ILInstruction condition, ILVariable variable, out string stringValue) + bool MatchStringEqualityOrNullComparison(ILInstruction condition, ILVariable variable, out string stringValue) { - return MatchStringEqualityComparison(condition, out var v, out stringValue) && v == variable; + if (!MatchStringEqualityComparison(condition, out var v, out stringValue)) { + if (!MatchCompEqualsNull(condition, out v)) + return false; + stringValue = null; + } + + return v == variable; } bool MatchStringEqualityComparison(ILInstruction condition, out ILVariable variable, out string stringValue) @@ -535,9 +547,18 @@ namespace ICSharpCode.Decompiler.IL.Transforms right = c.Arguments[1]; if (!right.MatchLdStr(out stringValue)) return false; - } else if (condition.MatchCompEquals(out left, out right) && right.MatchLdNull()) { - } else return false; + } else { + return false; + } return left.MatchLdLoc(out variable); } + + bool MatchCompEqualsNull(ILInstruction condition, out ILVariable variable) + { + variable = null; + if (!condition.MatchCompEquals(out var left, out var right)) + return false; + return right.MatchLdNull() && left.MatchLdLoc(out variable); + } } } From c2761b0e0246aeeb4074d93174a218a59c80faa8 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 13 Oct 2017 13:28:11 +0200 Subject: [PATCH 106/190] Update test cases for switch. --- .../PrettyTestRunner.cs | 2 +- .../TestCases/Pretty/Switch.cs | 33 +- .../TestCases/Pretty/Switch.il | 807 ++++++++++-------- .../TestCases/Pretty/Switch.opt.il | 529 ++++++------ .../TestCases/Pretty/Switch.opt.roslyn.il | 84 +- .../TestCases/Pretty/Switch.roslyn.il | 785 +++++++++-------- 6 files changed, 1216 insertions(+), 1024 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index 1acbd0023..6e340a2d3 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -97,7 +97,7 @@ namespace ICSharpCode.Decompiler.Tests Run(cscOptions: cscOptions); } - [Test, Ignore("unnecessary casts on null literals, control-flow issues with switch in loops, goto, goto case, etc.")] + [Test] public void Switch([ValueSource("defaultOptions")] CompilerOptions cscOptions) { Run(cscOptions: cscOptions); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index 53ebea954..45c1c8274 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -213,6 +213,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } + public static string ShortSwitchOverStringWithNullCase(string text) + { + Console.WriteLine("ShortSwitchOverStringWithNullCase: " + text); + switch (text) { + case "First case": { + return "Text1"; + } + case "Second case": { + return "Text2"; + } + case null: { + return "null"; + } + default: { + return "Default"; + } + } + } + public static string SwitchOverString1(string text) { Console.WriteLine("SwitchOverString1: " + text); @@ -248,8 +267,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static string SwitchOverString2() { Console.WriteLine("SwitchOverString2:"); - string userName = Environment.UserName; - switch (userName) { + switch (Environment.UserName) { case "First case": { return "Text1"; } @@ -318,10 +336,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("two"); break; } - case 3: { - Console.WriteLine("three"); - continue; - } + //case 3: { + // Console.WriteLine("three"); + // continue; + // } case 4: { Console.WriteLine("four"); return; @@ -376,8 +394,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty SetProperty[] properties = Switch.GetProperties(); for (int i = 0; i < properties.Length; i++) { SetProperty setProperty = properties[i]; - string name = setProperty.Property.Name; - switch (name) { + switch (setProperty.Property.Name) { case "Name1": { setProperty.Set = 1; list.Add(setProperty); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il index 91f9e4ff5..e4f06b1f6 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly y0cd2lcb +.assembly yojdxjhu { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module y0cd2lcb.dll -// MVID: {85E7C039-2097-47F9-A636-4F4E3015541A} +.module yojdxjhu.dll +// MVID: {7A918135-BE28-4F14-9240-86E34BA33540} .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: 0x02630000 +// Image base: 0x032F0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -634,6 +634,63 @@ IL_0065: ret } // end of method Switch::ShortSwitchOverString + .method public hidebysig static string + ShortSwitchOverStringWithNullCase(string text) cil managed + { + // Code size 89 (0x59) + .maxstack 2 + .locals init (string V_0, + string V_1) + IL_0000: nop + IL_0001: ldstr "ShortSwitchOverStringWithNullCase: " + IL_0006: ldarg.0 + IL_0007: call string [mscorlib]System.String::Concat(string, + string) + IL_000c: call void [mscorlib]System.Console::WriteLine(string) + IL_0011: nop + IL_0012: ldarg.0 + IL_0013: stloc.1 + IL_0014: ldloc.1 + IL_0015: brfalse.s IL_0045 + + IL_0017: ldloc.1 + IL_0018: ldstr "First case" + IL_001d: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0022: brtrue.s IL_0033 + + IL_0024: ldloc.1 + IL_0025: ldstr "Second case" + IL_002a: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_002f: brtrue.s IL_003c + + IL_0031: br.s IL_004e + + IL_0033: nop + IL_0034: ldstr "Text1" + IL_0039: stloc.0 + IL_003a: br.s IL_0057 + + IL_003c: nop + IL_003d: ldstr "Text2" + IL_0042: stloc.0 + IL_0043: br.s IL_0057 + + IL_0045: nop + IL_0046: ldstr "null" + IL_004b: stloc.0 + IL_004c: br.s IL_0057 + + IL_004e: nop + IL_004f: ldstr "Default" + IL_0054: stloc.0 + IL_0055: br.s IL_0057 + + IL_0057: ldloc.0 + IL_0058: ret + } // end of method Switch::ShortSwitchOverStringWithNullCase + .method public hidebysig static string SwitchOverString1(string text) cil managed { @@ -655,7 +712,7 @@ IL_0015: brfalse IL_00ef IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x6000008-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x6000009-1' IL_0021: brtrue.s IL_0084 IL_0023: ldc.i4.7 @@ -696,9 +753,9 @@ IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007d: volatile. - IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x6000008-1' + IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x6000009-1' IL_0084: volatile. - IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x6000008-1' + IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x6000009-1' IL_008b: ldloc.1 IL_008c: ldloca.s V_2 IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -763,171 +820,168 @@ .method public hidebysig static string SwitchOverString2() cil managed { - // Code size 368 (0x170) + // Code size 366 (0x16e) .maxstack 4 .locals init (string V_0, string V_1, - string V_2, - int32 V_3) + int32 V_2) IL_0000: nop IL_0001: ldstr "SwitchOverString2:" IL_0006: call void [mscorlib]System.Console::WriteLine(string) IL_000b: nop IL_000c: call string [mscorlib]System.Environment::get_UserName() - IL_0011: stloc.0 - IL_0012: ldloc.0 - IL_0013: stloc.2 - IL_0014: ldloc.2 - IL_0015: brfalse IL_0165 - - IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x6000009-1' - IL_0021: brtrue IL_00ba - - IL_0026: ldc.i4.s 11 - IL_0028: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) - IL_002d: dup - IL_002e: ldstr "First case" - IL_0033: ldc.i4.0 - IL_0034: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0011: stloc.1 + IL_0012: ldloc.1 + IL_0013: brfalse IL_0163 + + IL_0018: volatile. + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x600000a-1' + IL_001f: brtrue IL_00b8 + + IL_0024: ldc.i4.s 11 + IL_0026: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_002b: dup + IL_002c: ldstr "First case" + IL_0031: ldc.i4.0 + IL_0032: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0039: dup - IL_003a: ldstr "Second case" - IL_003f: ldc.i4.1 - IL_0040: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0037: dup + IL_0038: ldstr "Second case" + IL_003d: ldc.i4.1 + IL_003e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0045: dup - IL_0046: ldstr "Third case" - IL_004b: ldc.i4.2 - IL_004c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0043: dup + IL_0044: ldstr "Third case" + IL_0049: ldc.i4.2 + IL_004a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0051: dup - IL_0052: ldstr "Fourth case" - IL_0057: ldc.i4.3 - IL_0058: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_004f: dup + IL_0050: ldstr "Fourth case" + IL_0055: ldc.i4.3 + IL_0056: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_005d: dup - IL_005e: ldstr "Fifth case" - IL_0063: ldc.i4.4 - IL_0064: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_005b: dup + IL_005c: ldstr "Fifth case" + IL_0061: ldc.i4.4 + IL_0062: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0069: dup - IL_006a: ldstr "Sixth case" - IL_006f: ldc.i4.5 - IL_0070: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0067: dup + IL_0068: ldstr "Sixth case" + IL_006d: ldc.i4.5 + IL_006e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0075: dup - IL_0076: ldstr "Seventh case" - IL_007b: ldc.i4.6 - IL_007c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0073: dup + IL_0074: ldstr "Seventh case" + IL_0079: ldc.i4.6 + IL_007a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0081: dup - IL_0082: ldstr "Eighth case" - IL_0087: ldc.i4.7 - IL_0088: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_007f: dup + IL_0080: ldstr "Eighth case" + IL_0085: ldc.i4.7 + IL_0086: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_008d: dup - IL_008e: ldstr "Ninth case" - IL_0093: ldc.i4.8 - IL_0094: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_008b: dup + IL_008c: ldstr "Ninth case" + IL_0091: ldc.i4.8 + IL_0092: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0099: dup - IL_009a: ldstr "Tenth case" - IL_009f: ldc.i4.s 9 - IL_00a1: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0097: dup + IL_0098: ldstr "Tenth case" + IL_009d: ldc.i4.s 9 + IL_009f: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_00a6: dup - IL_00a7: ldstr "Eleventh case" - IL_00ac: ldc.i4.s 10 - IL_00ae: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_00a4: dup + IL_00a5: ldstr "Eleventh case" + IL_00aa: ldc.i4.s 10 + IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_00b3: volatile. - IL_00b5: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x6000009-1' - IL_00ba: volatile. - IL_00bc: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x6000009-1' - IL_00c1: ldloc.2 - IL_00c2: ldloca.s V_3 - IL_00c4: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + IL_00b1: volatile. + IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x600000a-1' + IL_00b8: volatile. + IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x600000a-1' + IL_00bf: ldloc.1 + IL_00c0: ldloca.s V_2 + IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, !1&) - IL_00c9: brfalse IL_0165 + IL_00c7: brfalse IL_0163 + + IL_00cc: ldloc.2 + IL_00cd: switch ( + IL_0100, + IL_0109, + IL_0112, + IL_011b, + IL_0124, + IL_012d, + IL_0136, + IL_013f, + IL_0148, + IL_0151, + IL_015a) + IL_00fe: br.s IL_0163 - IL_00ce: ldloc.3 - IL_00cf: switch ( - IL_0102, - IL_010b, - IL_0114, - IL_011d, - IL_0126, - IL_012f, - IL_0138, - IL_0141, - IL_014a, - IL_0153, - IL_015c) - IL_0100: br.s IL_0165 - - IL_0102: nop - IL_0103: ldstr "Text1" - IL_0108: stloc.1 - IL_0109: br.s IL_016e - - IL_010b: nop - IL_010c: ldstr "Text2" - IL_0111: stloc.1 - IL_0112: br.s IL_016e - - IL_0114: nop - IL_0115: ldstr "Text3" - IL_011a: stloc.1 - IL_011b: br.s IL_016e + IL_0100: nop + IL_0101: ldstr "Text1" + IL_0106: stloc.0 + IL_0107: br.s IL_016c - IL_011d: nop - IL_011e: ldstr "Text4" - IL_0123: stloc.1 - IL_0124: br.s IL_016e + IL_0109: nop + IL_010a: ldstr "Text2" + IL_010f: stloc.0 + IL_0110: br.s IL_016c - IL_0126: nop - IL_0127: ldstr "Text5" - IL_012c: stloc.1 - IL_012d: br.s IL_016e - - IL_012f: nop - IL_0130: ldstr "Text6" - IL_0135: stloc.1 - IL_0136: br.s IL_016e - - IL_0138: nop - IL_0139: ldstr "Text7" - IL_013e: stloc.1 - IL_013f: br.s IL_016e - - IL_0141: nop - IL_0142: ldstr "Text8" - IL_0147: stloc.1 - IL_0148: br.s IL_016e - - IL_014a: nop - IL_014b: ldstr "Text9" - IL_0150: stloc.1 - IL_0151: br.s IL_016e - - IL_0153: nop - IL_0154: ldstr "Text10" - IL_0159: stloc.1 - IL_015a: br.s IL_016e - - IL_015c: nop - IL_015d: ldstr "Text11" - IL_0162: stloc.1 - IL_0163: br.s IL_016e - - IL_0165: nop - IL_0166: ldstr "Default" - IL_016b: stloc.1 - IL_016c: br.s IL_016e - - IL_016e: ldloc.1 - IL_016f: ret + IL_0112: nop + IL_0113: ldstr "Text3" + IL_0118: stloc.0 + IL_0119: br.s IL_016c + + IL_011b: nop + IL_011c: ldstr "Text4" + IL_0121: stloc.0 + IL_0122: br.s IL_016c + + IL_0124: nop + IL_0125: ldstr "Text5" + IL_012a: stloc.0 + IL_012b: br.s IL_016c + + IL_012d: nop + IL_012e: ldstr "Text6" + IL_0133: stloc.0 + IL_0134: br.s IL_016c + + IL_0136: nop + IL_0137: ldstr "Text7" + IL_013c: stloc.0 + IL_013d: br.s IL_016c + + IL_013f: nop + IL_0140: ldstr "Text8" + IL_0145: stloc.0 + IL_0146: br.s IL_016c + + IL_0148: nop + IL_0149: ldstr "Text9" + IL_014e: stloc.0 + IL_014f: br.s IL_016c + + IL_0151: nop + IL_0152: ldstr "Text10" + IL_0157: stloc.0 + IL_0158: br.s IL_016c + + IL_015a: nop + IL_015b: ldstr "Text11" + IL_0160: stloc.0 + IL_0161: br.s IL_016c + + IL_0163: nop + IL_0164: ldstr "Default" + IL_0169: stloc.0 + IL_016a: br.s IL_016c + + IL_016c: ldloc.0 + IL_016d: ret } // end of method Switch::SwitchOverString2 .method public hidebysig static string @@ -974,7 +1028,7 @@ .method public hidebysig static void SwitchInLoop(int32 i) cil managed { - // Code size 146 (0x92) + // Code size 132 (0x84) .maxstack 2 .locals init (int32 V_0, bool V_1) @@ -986,7 +1040,7 @@ object) IL_0011: call void [mscorlib]System.Console::WriteLine(string) IL_0016: nop - IL_0017: br.s IL_008d + IL_0017: br.s IL_007f IL_0019: nop IL_001a: ldarg.0 @@ -997,53 +1051,47 @@ IL_001f: switch ( IL_0036, IL_0044, - IL_0052, - IL_0060) - IL_0034: br.s IL_006e + IL_0060, + IL_0052) + IL_0034: br.s IL_0060 IL_0036: nop IL_0037: ldstr "one" IL_003c: call void [mscorlib]System.Console::WriteLine(string) IL_0041: nop - IL_0042: br.s IL_0087 + IL_0042: br.s IL_0079 IL_0044: nop IL_0045: ldstr "two" IL_004a: call void [mscorlib]System.Console::WriteLine(string) IL_004f: nop - IL_0050: br.s IL_0087 + IL_0050: br.s IL_0079 IL_0052: nop - IL_0053: ldstr "three" + IL_0053: ldstr "four" IL_0058: call void [mscorlib]System.Console::WriteLine(string) IL_005d: nop - IL_005e: br.s IL_008d + IL_005e: br.s IL_0083 IL_0060: nop - IL_0061: ldstr "four" + IL_0061: ldstr "default" IL_0066: call void [mscorlib]System.Console::WriteLine(string) IL_006b: nop - IL_006c: br.s IL_0091 - - IL_006e: nop - IL_006f: ldstr "default" - IL_0074: call void [mscorlib]System.Console::WriteLine(string) - IL_0079: nop - IL_007a: ldstr "more code" - IL_007f: call void [mscorlib]System.Console::WriteLine(string) - IL_0084: nop - IL_0085: br.s IL_0091 - - IL_0087: ldarg.0 - IL_0088: ldc.i4.1 - IL_0089: add - IL_008a: starg.s i - IL_008c: nop - IL_008d: ldc.i4.1 - IL_008e: stloc.1 - IL_008f: br.s IL_0019 - - IL_0091: ret + IL_006c: ldstr "more code" + IL_0071: call void [mscorlib]System.Console::WriteLine(string) + IL_0076: nop + IL_0077: br.s IL_0083 + + IL_0079: ldarg.0 + IL_007a: ldc.i4.1 + IL_007b: add + IL_007c: starg.s i + IL_007e: nop + IL_007f: ldc.i4.1 + IL_0080: stloc.1 + IL_0081: br.s IL_0019 + + IL_0083: ret } // end of method Switch::SwitchInLoop .method public hidebysig static void SwitchWithGoto(int32 i) cil managed @@ -1125,7 +1173,7 @@ .method public hidebysig static void SwitchOnStringInForLoop() cil managed { - // Code size 334 (0x14e) + // Code size 330 (0x14a) .maxstack 4 .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, class [mscorlib]System.Collections.Generic.List`1 V_1, @@ -1133,9 +1181,8 @@ int32 V_3, class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty V_4, string V_5, - string V_6, - int32 V_7, - bool V_8) + int32 V_6, + bool V_7) IL_0000: nop IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() IL_0006: stloc.0 @@ -1145,7 +1192,7 @@ IL_0012: stloc.2 IL_0013: ldc.i4.0 IL_0014: stloc.3 - IL_0015: br IL_013e + IL_0015: br IL_013a IL_001a: nop IL_001b: ldloc.2 @@ -1157,144 +1204,142 @@ IL_0027: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() IL_002c: stloc.s V_5 IL_002e: ldloc.s V_5 - IL_0030: stloc.s V_6 - IL_0032: ldloc.s V_6 - IL_0034: brfalse IL_012d - - IL_0039: volatile. - IL_003b: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x600000e-1' - IL_0040: brtrue.s IL_0097 - - IL_0042: ldc.i4.6 - IL_0043: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) - IL_0048: dup - IL_0049: ldstr "Name1" - IL_004e: ldc.i4.0 - IL_004f: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0030: brfalse IL_0129 + + IL_0035: volatile. + IL_0037: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x600000f-1' + IL_003c: brtrue.s IL_0093 + + IL_003e: ldc.i4.6 + IL_003f: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_0044: dup + IL_0045: ldstr "Name1" + IL_004a: ldc.i4.0 + IL_004b: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0054: dup - IL_0055: ldstr "Name2" - IL_005a: ldc.i4.1 - IL_005b: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0050: dup + IL_0051: ldstr "Name2" + IL_0056: ldc.i4.1 + IL_0057: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0060: dup - IL_0061: ldstr "Name3" - IL_0066: ldc.i4.2 - IL_0067: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_005c: dup + IL_005d: ldstr "Name3" + IL_0062: ldc.i4.2 + IL_0063: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_006c: dup - IL_006d: ldstr "Name4" - IL_0072: ldc.i4.3 - IL_0073: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0068: dup + IL_0069: ldstr "Name4" + IL_006e: ldc.i4.3 + IL_006f: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0078: dup - IL_0079: ldstr "Name5" - IL_007e: ldc.i4.4 - IL_007f: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0074: dup + IL_0075: ldstr "Name5" + IL_007a: ldc.i4.4 + IL_007b: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0084: dup - IL_0085: ldstr "Name6" - IL_008a: ldc.i4.5 - IL_008b: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0080: dup + IL_0081: ldstr "Name6" + IL_0086: ldc.i4.5 + IL_0087: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0090: volatile. - IL_0092: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x600000e-1' - IL_0097: volatile. - IL_0099: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{85E7C039-2097-47F9-A636-4F4E3015541A}'::'$$method0x600000e-1' - IL_009e: ldloc.s V_6 - IL_00a0: ldloca.s V_7 - IL_00a2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + IL_008c: volatile. + IL_008e: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x600000f-1' + IL_0093: volatile. + IL_0095: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x600000f-1' + IL_009a: ldloc.s V_5 + IL_009c: ldloca.s V_6 + IL_009e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, !1&) - IL_00a7: brfalse IL_012d - - IL_00ac: ldloc.s V_7 - IL_00ae: switch ( - IL_00cd, - IL_00e2, - IL_00f7, - IL_010c, - IL_0121, - IL_0121) - IL_00cb: br.s IL_012d - - IL_00cd: nop - IL_00ce: ldloc.s V_4 - IL_00d0: ldc.i4.1 - IL_00d1: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00d6: nop - IL_00d7: ldloc.0 - IL_00d8: ldloc.s V_4 - IL_00da: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00df: nop - IL_00e0: br.s IL_0139 - - IL_00e2: nop - IL_00e3: ldloc.s V_4 - IL_00e5: ldc.i4.2 - IL_00e6: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00eb: nop - IL_00ec: ldloc.0 - IL_00ed: ldloc.s V_4 - IL_00ef: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00f4: nop - IL_00f5: br.s IL_0139 - - IL_00f7: nop - IL_00f8: ldloc.s V_4 - IL_00fa: ldc.i4.3 - IL_00fb: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_0100: nop - IL_0101: ldloc.0 - IL_0102: ldloc.s V_4 - IL_0104: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_0109: nop - IL_010a: br.s IL_0139 - - IL_010c: nop - IL_010d: ldloc.s V_4 - IL_010f: ldc.i4.4 - IL_0110: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_0115: nop - IL_0116: ldloc.0 - IL_0117: ldloc.s V_4 - IL_0119: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_011e: nop - IL_011f: br.s IL_0139 - - IL_0121: nop - IL_0122: ldloc.0 - IL_0123: ldloc.s V_4 - IL_0125: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_012a: nop - IL_012b: br.s IL_0139 - - IL_012d: nop - IL_012e: ldloc.1 - IL_012f: ldloc.s V_4 - IL_0131: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_0136: nop - IL_0137: br.s IL_0139 + IL_00a3: brfalse IL_0129 + + IL_00a8: ldloc.s V_6 + IL_00aa: switch ( + IL_00c9, + IL_00de, + IL_00f3, + IL_0108, + IL_011d, + IL_011d) + IL_00c7: br.s IL_0129 + + IL_00c9: nop + IL_00ca: ldloc.s V_4 + IL_00cc: ldc.i4.1 + IL_00cd: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00d2: nop + IL_00d3: ldloc.0 + IL_00d4: ldloc.s V_4 + IL_00d6: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00db: nop + IL_00dc: br.s IL_0135 + + IL_00de: nop + IL_00df: ldloc.s V_4 + IL_00e1: ldc.i4.2 + IL_00e2: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00e7: nop + IL_00e8: ldloc.0 + IL_00e9: ldloc.s V_4 + IL_00eb: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00f0: nop + IL_00f1: br.s IL_0135 + + IL_00f3: nop + IL_00f4: ldloc.s V_4 + IL_00f6: ldc.i4.3 + IL_00f7: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00fc: nop + IL_00fd: ldloc.0 + IL_00fe: ldloc.s V_4 + IL_0100: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0105: nop + IL_0106: br.s IL_0135 + + IL_0108: nop + IL_0109: ldloc.s V_4 + IL_010b: ldc.i4.4 + IL_010c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_0111: nop + IL_0112: ldloc.0 + IL_0113: ldloc.s V_4 + IL_0115: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_011a: nop + IL_011b: br.s IL_0135 - IL_0139: nop + IL_011d: nop + IL_011e: ldloc.0 + IL_011f: ldloc.s V_4 + IL_0121: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0126: nop + IL_0127: br.s IL_0135 + + IL_0129: nop + IL_012a: ldloc.1 + IL_012b: ldloc.s V_4 + IL_012d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0132: nop + IL_0133: br.s IL_0135 + + IL_0135: nop + IL_0136: ldloc.3 + IL_0137: ldc.i4.1 + IL_0138: add + IL_0139: stloc.3 IL_013a: ldloc.3 - IL_013b: ldc.i4.1 - IL_013c: add - IL_013d: stloc.3 - IL_013e: ldloc.3 - IL_013f: ldloc.2 - IL_0140: ldlen - IL_0141: conv.i4 - IL_0142: clt - IL_0144: stloc.s V_8 - IL_0146: ldloc.s V_8 - IL_0148: brtrue IL_001a - - IL_014d: ret + IL_013b: ldloc.2 + IL_013c: ldlen + IL_013d: conv.i4 + IL_013e: clt + IL_0140: stloc.s V_7 + IL_0142: ldloc.s V_7 + IL_0144: brtrue IL_001a + + IL_0149: ret } // end of method Switch::SwitchOnStringInForLoop .method public hidebysig static void SwitchWithComplexCondition(string[] args) cil managed { - // Code size 139 (0x8b) + // Code size 143 (0x8f) .maxstack 2 .locals init (string V_0) IL_0000: nop @@ -1312,7 +1357,7 @@ IL_0010: nop IL_0011: stloc.0 IL_0012: ldloc.0 - IL_0013: brfalse.s IL_007f + IL_0013: brfalse.s IL_0083 IL_0015: ldloc.0 IL_0016: ldstr "a" @@ -1324,51 +1369,55 @@ IL_0023: ldstr "b" IL_0028: call bool [mscorlib]System.String::op_Equality(string, string) - IL_002d: brtrue.s IL_0058 + IL_002d: brtrue.s IL_0059 IL_002f: ldloc.0 IL_0030: ldstr "c" IL_0035: call bool [mscorlib]System.String::op_Equality(string, string) - IL_003a: brtrue.s IL_0065 + IL_003a: brtrue.s IL_0067 IL_003c: ldloc.0 IL_003d: ldstr "d" IL_0042: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0047: brtrue.s IL_0072 - - IL_0049: br.s IL_007f - - IL_004b: ldstr "a" - IL_0050: call void [mscorlib]System.Console::WriteLine(string) - IL_0055: nop - IL_0056: br.s IL_007f - - IL_0058: ldstr "b" - IL_005d: call void [mscorlib]System.Console::WriteLine(string) - IL_0062: nop - IL_0063: br.s IL_007f - - IL_0065: ldstr "c" - IL_006a: call void [mscorlib]System.Console::WriteLine(string) - IL_006f: nop - IL_0070: br.s IL_007f - - IL_0072: ldstr "d" - IL_0077: call void [mscorlib]System.Console::WriteLine(string) - IL_007c: nop - IL_007d: br.s IL_007f - - IL_007f: ldstr "end" - IL_0084: call void [mscorlib]System.Console::WriteLine(string) - IL_0089: nop - IL_008a: ret + IL_0047: brtrue.s IL_0075 + + IL_0049: br.s IL_0083 + + IL_004b: nop + IL_004c: ldstr "a" + IL_0051: call void [mscorlib]System.Console::WriteLine(string) + IL_0056: nop + IL_0057: br.s IL_0083 + + IL_0059: nop + IL_005a: ldstr "b" + IL_005f: call void [mscorlib]System.Console::WriteLine(string) + IL_0064: nop + IL_0065: br.s IL_0083 + + IL_0067: nop + IL_0068: ldstr "c" + IL_006d: call void [mscorlib]System.Console::WriteLine(string) + IL_0072: nop + IL_0073: br.s IL_0083 + + IL_0075: nop + IL_0076: ldstr "d" + IL_007b: call void [mscorlib]System.Console::WriteLine(string) + IL_0080: nop + IL_0081: br.s IL_0083 + + IL_0083: ldstr "end" + IL_0088: call void [mscorlib]System.Console::WriteLine(string) + IL_008d: nop + IL_008e: ret } // end of method Switch::SwitchWithComplexCondition .method public hidebysig static void SwitchWithArray(string[] args) cil managed { - // Code size 126 (0x7e) + // Code size 130 (0x82) .maxstack 2 .locals init (string V_0) IL_0000: nop @@ -1377,7 +1426,7 @@ IL_0003: ldelem.ref IL_0004: stloc.0 IL_0005: ldloc.0 - IL_0006: brfalse.s IL_0072 + IL_0006: brfalse.s IL_0076 IL_0008: ldloc.0 IL_0009: ldstr "a" @@ -1389,58 +1438,62 @@ IL_0016: ldstr "b" IL_001b: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0020: brtrue.s IL_004b + IL_0020: brtrue.s IL_004c IL_0022: ldloc.0 IL_0023: ldstr "c" IL_0028: call bool [mscorlib]System.String::op_Equality(string, string) - IL_002d: brtrue.s IL_0058 + IL_002d: brtrue.s IL_005a IL_002f: ldloc.0 IL_0030: ldstr "d" IL_0035: call bool [mscorlib]System.String::op_Equality(string, string) - IL_003a: brtrue.s IL_0065 - - IL_003c: br.s IL_0072 - - IL_003e: ldstr "a" - IL_0043: call void [mscorlib]System.Console::WriteLine(string) - IL_0048: nop - IL_0049: br.s IL_0072 - - IL_004b: ldstr "b" - IL_0050: call void [mscorlib]System.Console::WriteLine(string) - IL_0055: nop - IL_0056: br.s IL_0072 - - IL_0058: ldstr "c" - IL_005d: call void [mscorlib]System.Console::WriteLine(string) - IL_0062: nop - IL_0063: br.s IL_0072 - - IL_0065: ldstr "d" - IL_006a: call void [mscorlib]System.Console::WriteLine(string) - IL_006f: nop - IL_0070: br.s IL_0072 - - IL_0072: ldstr "end" - IL_0077: call void [mscorlib]System.Console::WriteLine(string) - IL_007c: nop - IL_007d: ret + IL_003a: brtrue.s IL_0068 + + IL_003c: br.s IL_0076 + + IL_003e: nop + IL_003f: ldstr "a" + IL_0044: call void [mscorlib]System.Console::WriteLine(string) + IL_0049: nop + IL_004a: br.s IL_0076 + + IL_004c: nop + IL_004d: ldstr "b" + IL_0052: call void [mscorlib]System.Console::WriteLine(string) + IL_0057: nop + IL_0058: br.s IL_0076 + + IL_005a: nop + IL_005b: ldstr "c" + IL_0060: call void [mscorlib]System.Console::WriteLine(string) + IL_0065: nop + IL_0066: br.s IL_0076 + + IL_0068: nop + IL_0069: ldstr "d" + IL_006e: call void [mscorlib]System.Console::WriteLine(string) + IL_0073: nop + IL_0074: br.s IL_0076 + + IL_0076: ldstr "end" + IL_007b: call void [mscorlib]System.Console::WriteLine(string) + IL_0080: nop + IL_0081: ret } // end of method Switch::SwitchWithArray } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{85E7C039-2097-47F9-A636-4F4E3015541A}' +.class private auto ansi '{7A918135-BE28-4F14-9240-86E34BA33540}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000008-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000009-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000e-1' -} // end of class '{85E7C039-2097-47F9-A636-4F4E3015541A}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000a-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000f-1' +} // end of class '{7A918135-BE28-4F14-9240-86E34BA33540}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il index 85eea31f3..c951dbce9 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly nwkzngd2 +.assembly '4wc22bae' { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module nwkzngd2.dll -// MVID: {2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5} +.module '4wc22bae.dll' +// MVID: {B84EA70D-C67F-455B-9708-0E39585F7DA1} .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: 0x008E0000 +// Image base: 0x01140000 // =============== CLASS MEMBERS DECLARATION =================== @@ -509,6 +509,49 @@ IL_0055: ret } // end of method Switch::ShortSwitchOverString + .method public hidebysig static string + ShortSwitchOverStringWithNullCase(string text) cil managed + { + // Code size 73 (0x49) + .maxstack 2 + .locals init (string V_0) + IL_0000: ldstr "ShortSwitchOverStringWithNullCase: " + IL_0005: ldarg.0 + IL_0006: call string [mscorlib]System.String::Concat(string, + string) + IL_000b: call void [mscorlib]System.Console::WriteLine(string) + IL_0010: ldarg.0 + IL_0011: dup + IL_0012: stloc.0 + IL_0013: brfalse.s IL_003d + + IL_0015: ldloc.0 + IL_0016: ldstr "First case" + IL_001b: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0020: brtrue.s IL_0031 + + IL_0022: ldloc.0 + IL_0023: ldstr "Second case" + IL_0028: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_002d: brtrue.s IL_0037 + + IL_002f: br.s IL_0043 + + IL_0031: ldstr "Text1" + IL_0036: ret + + IL_0037: ldstr "Text2" + IL_003c: ret + + IL_003d: ldstr "null" + IL_0042: ret + + IL_0043: ldstr "Default" + IL_0048: ret + } // end of method Switch::ShortSwitchOverStringWithNullCase + .method public hidebysig static string SwitchOverString1(string text) cil managed { @@ -527,7 +570,7 @@ IL_0013: brfalse IL_00db IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x6000008-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x6000009-1' IL_001f: brtrue.s IL_0082 IL_0021: ldc.i4.7 @@ -568,9 +611,9 @@ IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007b: volatile. - IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x6000008-1' + IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x6000009-1' IL_0082: volatile. - IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x6000008-1' + IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x6000009-1' IL_0089: ldloc.0 IL_008a: ldloca.s V_1 IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -616,141 +659,138 @@ .method public hidebysig static string SwitchOverString2() cil managed { - // Code size 325 (0x145) + // Code size 323 (0x143) .maxstack 4 .locals init (string V_0, - string V_1, - int32 V_2) + int32 V_1) IL_0000: ldstr "SwitchOverString2:" IL_0005: call void [mscorlib]System.Console::WriteLine(string) IL_000a: call string [mscorlib]System.Environment::get_UserName() - IL_000f: stloc.0 - IL_0010: ldloc.0 - IL_0011: dup - IL_0012: stloc.1 - IL_0013: brfalse IL_013f - - IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x6000009-1' - IL_001f: brtrue IL_00b8 - - IL_0024: ldc.i4.s 11 - IL_0026: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) - IL_002b: dup - IL_002c: ldstr "First case" - IL_0031: ldc.i4.0 - IL_0032: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_000f: dup + IL_0010: stloc.0 + IL_0011: brfalse IL_013d + + IL_0016: volatile. + IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x600000a-1' + IL_001d: brtrue IL_00b6 + + IL_0022: ldc.i4.s 11 + IL_0024: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_0029: dup + IL_002a: ldstr "First case" + IL_002f: ldc.i4.0 + IL_0030: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0037: dup - IL_0038: ldstr "Second case" - IL_003d: ldc.i4.1 - IL_003e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0035: dup + IL_0036: ldstr "Second case" + IL_003b: ldc.i4.1 + IL_003c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0043: dup - IL_0044: ldstr "Third case" - IL_0049: ldc.i4.2 - IL_004a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0041: dup + IL_0042: ldstr "Third case" + IL_0047: ldc.i4.2 + IL_0048: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_004f: dup - IL_0050: ldstr "Fourth case" - IL_0055: ldc.i4.3 - IL_0056: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_004d: dup + IL_004e: ldstr "Fourth case" + IL_0053: ldc.i4.3 + IL_0054: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_005b: dup - IL_005c: ldstr "Fifth case" - IL_0061: ldc.i4.4 - IL_0062: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0059: dup + IL_005a: ldstr "Fifth case" + IL_005f: ldc.i4.4 + IL_0060: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0067: dup - IL_0068: ldstr "Sixth case" - IL_006d: ldc.i4.5 - IL_006e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0065: dup + IL_0066: ldstr "Sixth case" + IL_006b: ldc.i4.5 + IL_006c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0073: dup - IL_0074: ldstr "Seventh case" - IL_0079: ldc.i4.6 - IL_007a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0071: dup + IL_0072: ldstr "Seventh case" + IL_0077: ldc.i4.6 + IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_007f: dup - IL_0080: ldstr "Eighth case" - IL_0085: ldc.i4.7 - IL_0086: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_007d: dup + IL_007e: ldstr "Eighth case" + IL_0083: ldc.i4.7 + IL_0084: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_008b: dup - IL_008c: ldstr "Ninth case" - IL_0091: ldc.i4.8 - IL_0092: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0089: dup + IL_008a: ldstr "Ninth case" + IL_008f: ldc.i4.8 + IL_0090: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0097: dup - IL_0098: ldstr "Tenth case" - IL_009d: ldc.i4.s 9 - IL_009f: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0095: dup + IL_0096: ldstr "Tenth case" + IL_009b: ldc.i4.s 9 + IL_009d: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_00a4: dup - IL_00a5: ldstr "Eleventh case" - IL_00aa: ldc.i4.s 10 - IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_00a2: dup + IL_00a3: ldstr "Eleventh case" + IL_00a8: ldc.i4.s 10 + IL_00aa: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_00b1: volatile. - IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x6000009-1' - IL_00b8: volatile. - IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x6000009-1' - IL_00bf: ldloc.1 - IL_00c0: ldloca.s V_2 - IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + IL_00af: volatile. + IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x600000a-1' + IL_00b6: volatile. + IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x600000a-1' + IL_00bd: ldloc.0 + IL_00be: ldloca.s V_1 + IL_00c0: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, !1&) - IL_00c7: brfalse.s IL_013f + IL_00c5: brfalse.s IL_013d - IL_00c9: ldloc.2 - IL_00ca: switch ( - IL_00fd, - IL_0103, - IL_0109, - IL_010f, - IL_0115, - IL_011b, - IL_0121, - IL_0127, - IL_012d, - IL_0133, - IL_0139) - IL_00fb: br.s IL_013f + IL_00c7: ldloc.1 + IL_00c8: switch ( + IL_00fb, + IL_0101, + IL_0107, + IL_010d, + IL_0113, + IL_0119, + IL_011f, + IL_0125, + IL_012b, + IL_0131, + IL_0137) + IL_00f9: br.s IL_013d - IL_00fd: ldstr "Text1" - IL_0102: ret + IL_00fb: ldstr "Text1" + IL_0100: ret - IL_0103: ldstr "Text2" - IL_0108: ret + IL_0101: ldstr "Text2" + IL_0106: ret - IL_0109: ldstr "Text3" - IL_010e: ret + IL_0107: ldstr "Text3" + IL_010c: ret - IL_010f: ldstr "Text4" - IL_0114: ret + IL_010d: ldstr "Text4" + IL_0112: ret - IL_0115: ldstr "Text5" - IL_011a: ret + IL_0113: ldstr "Text5" + IL_0118: ret - IL_011b: ldstr "Text6" - IL_0120: ret + IL_0119: ldstr "Text6" + IL_011e: ret - IL_0121: ldstr "Text7" - IL_0126: ret + IL_011f: ldstr "Text7" + IL_0124: ret - IL_0127: ldstr "Text8" - IL_012c: ret + IL_0125: ldstr "Text8" + IL_012a: ret - IL_012d: ldstr "Text9" - IL_0132: ret + IL_012b: ldstr "Text9" + IL_0130: ret - IL_0133: ldstr "Text10" - IL_0138: ret + IL_0131: ldstr "Text10" + IL_0136: ret - IL_0139: ldstr "Text11" - IL_013e: ret + IL_0137: ldstr "Text11" + IL_013c: ret - IL_013f: ldstr "Default" - IL_0144: ret + IL_013d: ldstr "Default" + IL_0142: ret } // end of method Switch::SwitchOverString2 .method public hidebysig static string @@ -785,7 +825,7 @@ .method public hidebysig static void SwitchInLoop(int32 i) cil managed { - // Code size 124 (0x7c) + // Code size 112 (0x70) .maxstack 2 .locals init (int32 V_0) IL_0000: ldstr "SwitchInLoop: " @@ -802,37 +842,33 @@ IL_001a: switch ( IL_0031, IL_003d, - IL_0049, - IL_0055) - IL_002f: br.s IL_0060 + IL_0054, + IL_0049) + IL_002f: br.s IL_0054 IL_0031: ldstr "one" IL_0036: call void [mscorlib]System.Console::WriteLine(string) - IL_003b: br.s IL_0075 + IL_003b: br.s IL_0069 IL_003d: ldstr "two" IL_0042: call void [mscorlib]System.Console::WriteLine(string) - IL_0047: br.s IL_0075 + IL_0047: br.s IL_0069 - IL_0049: ldstr "three" + IL_0049: ldstr "four" IL_004e: call void [mscorlib]System.Console::WriteLine(string) - IL_0053: br.s IL_0015 + IL_0053: ret - IL_0055: ldstr "four" - IL_005a: call void [mscorlib]System.Console::WriteLine(string) - IL_005f: ret - - IL_0060: ldstr "default" - IL_0065: call void [mscorlib]System.Console::WriteLine(string) - IL_006a: ldstr "more code" - IL_006f: call void [mscorlib]System.Console::WriteLine(string) - IL_0074: ret - - IL_0075: ldarg.0 - IL_0076: ldc.i4.1 - IL_0077: add - IL_0078: starg.s i - IL_007a: br.s IL_0015 + IL_0054: ldstr "default" + IL_0059: call void [mscorlib]System.Console::WriteLine(string) + IL_005e: ldstr "more code" + IL_0063: call void [mscorlib]System.Console::WriteLine(string) + IL_0068: ret + + IL_0069: ldarg.0 + IL_006a: ldc.i4.1 + IL_006b: add + IL_006c: starg.s i + IL_006e: br.s IL_0015 } // end of method Switch::SwitchInLoop .method public hidebysig static void SwitchWithGoto(int32 i) cil managed @@ -891,7 +927,7 @@ .method public hidebysig static void SwitchOnStringInForLoop() cil managed { - // Code size 303 (0x12f) + // Code size 299 (0x12b) .maxstack 4 .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, class [mscorlib]System.Collections.Generic.List`1 V_1, @@ -899,8 +935,7 @@ int32 V_3, class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty V_4, string V_5, - string V_6, - int32 V_7) + int32 V_6) IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() IL_0005: stloc.0 IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() @@ -909,7 +944,7 @@ IL_0011: stloc.2 IL_0012: ldc.i4.0 IL_0013: stloc.3 - IL_0014: br IL_0125 + IL_0014: br IL_0121 IL_0019: ldloc.2 IL_001a: ldloc.3 @@ -918,119 +953,117 @@ IL_001e: ldloc.s V_4 IL_0020: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property IL_0025: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() - IL_002a: stloc.s V_5 - IL_002c: ldloc.s V_5 - IL_002e: dup - IL_002f: stloc.s V_6 - IL_0031: brfalse IL_0119 - - IL_0036: volatile. - IL_0038: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x600000e-1' - IL_003d: brtrue.s IL_0094 - - IL_003f: ldc.i4.6 - IL_0040: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) - IL_0045: dup - IL_0046: ldstr "Name1" - IL_004b: ldc.i4.0 - IL_004c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_002a: dup + IL_002b: stloc.s V_5 + IL_002d: brfalse IL_0115 + + IL_0032: volatile. + IL_0034: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x600000f-1' + IL_0039: brtrue.s IL_0090 + + IL_003b: ldc.i4.6 + IL_003c: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_0041: dup + IL_0042: ldstr "Name1" + IL_0047: ldc.i4.0 + IL_0048: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0051: dup - IL_0052: ldstr "Name2" - IL_0057: ldc.i4.1 - IL_0058: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_004d: dup + IL_004e: ldstr "Name2" + IL_0053: ldc.i4.1 + IL_0054: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_005d: dup - IL_005e: ldstr "Name3" - IL_0063: ldc.i4.2 - IL_0064: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0059: dup + IL_005a: ldstr "Name3" + IL_005f: ldc.i4.2 + IL_0060: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0069: dup - IL_006a: ldstr "Name4" - IL_006f: ldc.i4.3 - IL_0070: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0065: dup + IL_0066: ldstr "Name4" + IL_006b: ldc.i4.3 + IL_006c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0075: dup - IL_0076: ldstr "Name5" - IL_007b: ldc.i4.4 - IL_007c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0071: dup + IL_0072: ldstr "Name5" + IL_0077: ldc.i4.4 + IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0081: dup - IL_0082: ldstr "Name6" - IL_0087: ldc.i4.5 - IL_0088: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_007d: dup + IL_007e: ldstr "Name6" + IL_0083: ldc.i4.5 + IL_0084: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_008d: volatile. - IL_008f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x600000e-1' - IL_0094: volatile. - IL_0096: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}'::'$$method0x600000e-1' - IL_009b: ldloc.s V_6 - IL_009d: ldloca.s V_7 - IL_009f: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + IL_0089: volatile. + IL_008b: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x600000f-1' + IL_0090: volatile. + IL_0092: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x600000f-1' + IL_0097: ldloc.s V_5 + IL_0099: ldloca.s V_6 + IL_009b: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, !1&) - IL_00a4: brfalse.s IL_0119 - - IL_00a6: ldloc.s V_7 - IL_00a8: switch ( - IL_00c7, - IL_00d9, - IL_00eb, - IL_00fd, - IL_010f, - IL_010f) - IL_00c5: br.s IL_0119 - - IL_00c7: ldloc.s V_4 - IL_00c9: ldc.i4.1 - IL_00ca: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00cf: ldloc.0 - IL_00d0: ldloc.s V_4 - IL_00d2: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00d7: br.s IL_0121 - - IL_00d9: ldloc.s V_4 - IL_00db: ldc.i4.2 - IL_00dc: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00e1: ldloc.0 - IL_00e2: ldloc.s V_4 - IL_00e4: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00e9: br.s IL_0121 - - IL_00eb: ldloc.s V_4 - IL_00ed: ldc.i4.3 - IL_00ee: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00f3: ldloc.0 - IL_00f4: ldloc.s V_4 - IL_00f6: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00fb: br.s IL_0121 - - IL_00fd: ldloc.s V_4 - IL_00ff: ldc.i4.4 - IL_0100: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_0105: ldloc.0 - IL_0106: ldloc.s V_4 - IL_0108: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_010d: br.s IL_0121 - - IL_010f: ldloc.0 - IL_0110: ldloc.s V_4 - IL_0112: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_0117: br.s IL_0121 - - IL_0119: ldloc.1 - IL_011a: ldloc.s V_4 - IL_011c: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00a0: brfalse.s IL_0115 + + IL_00a2: ldloc.s V_6 + IL_00a4: switch ( + IL_00c3, + IL_00d5, + IL_00e7, + IL_00f9, + IL_010b, + IL_010b) + IL_00c1: br.s IL_0115 + + IL_00c3: ldloc.s V_4 + IL_00c5: ldc.i4.1 + IL_00c6: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00cb: ldloc.0 + IL_00cc: ldloc.s V_4 + IL_00ce: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00d3: br.s IL_011d + + IL_00d5: ldloc.s V_4 + IL_00d7: ldc.i4.2 + IL_00d8: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00dd: ldloc.0 + IL_00de: ldloc.s V_4 + IL_00e0: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00e5: br.s IL_011d + + IL_00e7: ldloc.s V_4 + IL_00e9: ldc.i4.3 + IL_00ea: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00ef: ldloc.0 + IL_00f0: ldloc.s V_4 + IL_00f2: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00f7: br.s IL_011d + + IL_00f9: ldloc.s V_4 + IL_00fb: ldc.i4.4 + IL_00fc: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_0101: ldloc.0 + IL_0102: ldloc.s V_4 + IL_0104: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0109: br.s IL_011d + + IL_010b: ldloc.0 + IL_010c: ldloc.s V_4 + IL_010e: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0113: br.s IL_011d + + IL_0115: ldloc.1 + IL_0116: ldloc.s V_4 + IL_0118: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_011d: ldloc.3 + IL_011e: ldc.i4.1 + IL_011f: add + IL_0120: stloc.3 IL_0121: ldloc.3 - IL_0122: ldc.i4.1 - IL_0123: add - IL_0124: stloc.3 - IL_0125: ldloc.3 - IL_0126: ldloc.2 - IL_0127: ldlen - IL_0128: conv.i4 - IL_0129: blt IL_0019 - - IL_012e: ret + IL_0122: ldloc.2 + IL_0123: ldlen + IL_0124: conv.i4 + IL_0125: blt IL_0019 + + IL_012a: ret } // end of method Switch::SwitchOnStringInForLoop .method public hidebysig static void SwitchWithComplexCondition(string[] args) cil managed @@ -1157,14 +1190,14 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}' +.class private auto ansi '{B84EA70D-C67F-455B-9708-0E39585F7DA1}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000008-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000009-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000e-1' -} // end of class '{2FE2A6DB-2DD1-4526-BE2D-8029A91D5DA5}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000a-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000f-1' +} // end of class '{B84EA70D-C67F-455B-9708-0E39585F7DA1}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il index c28f0e721..00d6cacd1 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {94058166-F81D-4A82-ABCC-FB400C785214} +// MVID: {F38BF1C4-C0E5-4BAD-8838-849DFFFA97DF} .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: 0x00EF0000 +// Image base: 0x00300000 // =============== CLASS MEMBERS DECLARATION =================== @@ -510,6 +510,46 @@ IL_0050: ret } // end of method Switch::ShortSwitchOverString + .method public hidebysig static string + ShortSwitchOverStringWithNullCase(string text) cil managed + { + // Code size 71 (0x47) + .maxstack 2 + IL_0000: ldstr "ShortSwitchOverStringWithNullCase: " + IL_0005: ldarg.0 + IL_0006: call string [mscorlib]System.String::Concat(string, + string) + IL_000b: call void [mscorlib]System.Console::WriteLine(string) + IL_0010: ldarg.0 + IL_0011: ldstr "First case" + IL_0016: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_001b: brtrue.s IL_002f + + IL_001d: ldarg.0 + IL_001e: ldstr "Second case" + IL_0023: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0028: brtrue.s IL_0035 + + IL_002a: ldarg.0 + IL_002b: brfalse.s IL_003b + + IL_002d: br.s IL_0041 + + IL_002f: ldstr "Text1" + IL_0034: ret + + IL_0035: ldstr "Text2" + IL_003a: ret + + IL_003b: ldstr "null" + IL_0040: ret + + IL_0041: ldstr "Default" + IL_0046: ret + } // end of method Switch::ShortSwitchOverStringWithNullCase + .method public hidebysig static string SwitchOverString1(string text) cil managed { @@ -894,7 +934,7 @@ .method public hidebysig static void SwitchInLoop(int32 i) cil managed { - // Code size 122 (0x7a) + // Code size 110 (0x6e) .maxstack 2 IL_0000: ldstr "SwitchInLoop: " IL_0005: ldarg.0 @@ -908,37 +948,33 @@ IL_0018: switch ( IL_002f, IL_003b, - IL_0047, - IL_0053) - IL_002d: br.s IL_005e + IL_0052, + IL_0047) + IL_002d: br.s IL_0052 IL_002f: ldstr "one" IL_0034: call void [mscorlib]System.Console::WriteLine(string) - IL_0039: br.s IL_0073 + IL_0039: br.s IL_0067 IL_003b: ldstr "two" IL_0040: call void [mscorlib]System.Console::WriteLine(string) - IL_0045: br.s IL_0073 + IL_0045: br.s IL_0067 - IL_0047: ldstr "three" + IL_0047: ldstr "four" IL_004c: call void [mscorlib]System.Console::WriteLine(string) - IL_0051: br.s IL_0015 - - IL_0053: ldstr "four" - IL_0058: call void [mscorlib]System.Console::WriteLine(string) - IL_005d: ret + IL_0051: ret - IL_005e: ldstr "default" - IL_0063: call void [mscorlib]System.Console::WriteLine(string) - IL_0068: ldstr "more code" - IL_006d: call void [mscorlib]System.Console::WriteLine(string) - IL_0072: ret + IL_0052: ldstr "default" + IL_0057: call void [mscorlib]System.Console::WriteLine(string) + IL_005c: ldstr "more code" + IL_0061: call void [mscorlib]System.Console::WriteLine(string) + IL_0066: ret - IL_0073: ldarg.0 - IL_0074: ldc.i4.1 - IL_0075: add - IL_0076: starg.s i - IL_0078: br.s IL_0015 + IL_0067: ldarg.0 + IL_0068: ldc.i4.1 + IL_0069: add + IL_006a: starg.s i + IL_006c: br.s IL_0015 } // end of method Switch::SwitchInLoop .method public hidebysig static void SwitchWithGoto(int32 i) cil managed diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il index b74cb403c..0ce401e0a 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {1E0E6114-7796-44C6-B88B-AA126D09F561} +// MVID: {25920C54-28DD-4B8C-9EBF-16E716D0EC15} .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: 0x02FE0000 +// Image base: 0x01040000 // =============== CLASS MEMBERS DECLARATION =================== @@ -683,6 +683,63 @@ IL_0062: ret } // end of method Switch::ShortSwitchOverString + .method public hidebysig static string + ShortSwitchOverStringWithNullCase(string text) cil managed + { + // Code size 89 (0x59) + .maxstack 2 + .locals init (string V_0, + string V_1) + IL_0000: nop + IL_0001: ldstr "ShortSwitchOverStringWithNullCase: " + IL_0006: ldarg.0 + IL_0007: call string [mscorlib]System.String::Concat(string, + string) + IL_000c: call void [mscorlib]System.Console::WriteLine(string) + IL_0011: nop + IL_0012: ldarg.0 + IL_0013: stloc.0 + IL_0014: ldloc.0 + IL_0015: ldstr "First case" + IL_001a: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_001f: brtrue.s IL_0033 + + IL_0021: ldloc.0 + IL_0022: ldstr "Second case" + IL_0027: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_002c: brtrue.s IL_003c + + IL_002e: ldloc.0 + IL_002f: brfalse.s IL_0045 + + IL_0031: br.s IL_004e + + IL_0033: nop + IL_0034: ldstr "Text1" + IL_0039: stloc.1 + IL_003a: br.s IL_0057 + + IL_003c: nop + IL_003d: ldstr "Text2" + IL_0042: stloc.1 + IL_0043: br.s IL_0057 + + IL_0045: nop + IL_0046: ldstr "null" + IL_004b: stloc.1 + IL_004c: br.s IL_0057 + + IL_004e: nop + IL_004f: ldstr "Default" + IL_0054: stloc.1 + IL_0055: br.s IL_0057 + + IL_0057: ldloc.1 + IL_0058: ret + } // end of method Switch::ShortSwitchOverStringWithNullCase + .method public hidebysig static string SwitchOverString1(string text) cil managed { @@ -870,12 +927,11 @@ .method public hidebysig static string SwitchOverString2() cil managed { - // Code size 520 (0x208) + // Code size 518 (0x206) .maxstack 2 .locals init (string V_0, - string V_1, - uint32 V_2, - string V_3) + uint32 V_1, + string V_2) IL_0000: nop IL_0001: ldstr "SwitchOverString2:" IL_0006: call void [mscorlib]System.Console::WriteLine(string) @@ -883,238 +939,236 @@ IL_000c: call string [mscorlib]System.Environment::get_UserName() IL_0011: stloc.0 IL_0012: ldloc.0 - IL_0013: stloc.1 - IL_0014: ldloc.1 - IL_0015: call uint32 ''::ComputeStringHash(string) - IL_001a: stloc.2 - IL_001b: ldloc.2 - IL_001c: ldc.i4 0x4c7c71f6 - IL_0021: bgt.un.s IL_0072 + IL_0013: call uint32 ''::ComputeStringHash(string) + IL_0018: stloc.1 + IL_0019: ldloc.1 + IL_001a: ldc.i4 0x4c7c71f6 + IL_001f: bgt.un.s IL_0070 - IL_0023: ldloc.2 - IL_0024: ldc.i4 0xc9a8f4f - IL_0029: bgt.un.s IL_0048 + IL_0021: ldloc.1 + IL_0022: ldc.i4 0xc9a8f4f + IL_0027: bgt.un.s IL_0046 - IL_002b: ldloc.2 - IL_002c: ldc.i4 0x8861b86 - IL_0031: beq IL_011c + IL_0029: ldloc.1 + IL_002a: ldc.i4 0x8861b86 + IL_002f: beq IL_011a - IL_0036: br.s IL_0038 + IL_0034: br.s IL_0036 - IL_0038: ldloc.2 - IL_0039: ldc.i4 0xc9a8f4f - IL_003e: beq IL_00c8 + IL_0036: ldloc.1 + IL_0037: ldc.i4 0xc9a8f4f + IL_003c: beq IL_00c6 - IL_0043: br IL_01fd + IL_0041: br IL_01fb - IL_0048: ldloc.2 - IL_0049: ldc.i4 0xf3d44a6 - IL_004e: beq IL_00f2 + IL_0046: ldloc.1 + IL_0047: ldc.i4 0xf3d44a6 + IL_004c: beq IL_00f0 - IL_0053: br.s IL_0055 + IL_0051: br.s IL_0053 - IL_0055: ldloc.2 - IL_0056: ldc.i4 0x20289804 - IL_005b: beq IL_0158 + IL_0053: ldloc.1 + IL_0054: ldc.i4 0x20289804 + IL_0059: beq IL_0156 - IL_0060: br.s IL_0062 + IL_005e: br.s IL_0060 - IL_0062: ldloc.2 - IL_0063: ldc.i4 0x4c7c71f6 - IL_0068: beq IL_016a + IL_0060: ldloc.1 + IL_0061: ldc.i4 0x4c7c71f6 + IL_0066: beq IL_0168 - IL_006d: br IL_01fd + IL_006b: br IL_01fb - IL_0072: ldloc.2 - IL_0073: ldc.i4 0xa151b28a - IL_0078: bgt.un.s IL_00a4 + IL_0070: ldloc.1 + IL_0071: ldc.i4 0xa151b28a + IL_0076: bgt.un.s IL_00a2 - IL_007a: ldloc.2 - IL_007b: ldc.i4 0x4d0cea48 - IL_0080: beq IL_018b + IL_0078: ldloc.1 + IL_0079: ldc.i4 0x4d0cea48 + IL_007e: beq IL_0189 - IL_0085: br.s IL_0087 + IL_0083: br.s IL_0085 - IL_0087: ldloc.2 - IL_0088: ldc.i4 0x51650fb9 - IL_008d: beq IL_0131 + IL_0085: ldloc.1 + IL_0086: ldc.i4 0x51650fb9 + IL_008b: beq IL_012f - IL_0092: br.s IL_0094 + IL_0090: br.s IL_0092 - IL_0094: ldloc.2 - IL_0095: ldc.i4 0xa151b28a - IL_009a: beq IL_0146 + IL_0092: ldloc.1 + IL_0093: ldc.i4 0xa151b28a + IL_0098: beq IL_0144 - IL_009f: br IL_01fd + IL_009d: br IL_01fb - IL_00a4: ldloc.2 - IL_00a5: ldc.i4 0xea3d096b - IL_00aa: beq.s IL_00dd + IL_00a2: ldloc.1 + IL_00a3: ldc.i4 0xea3d096b + IL_00a8: beq.s IL_00db - IL_00ac: br.s IL_00ae + IL_00aa: br.s IL_00ac - IL_00ae: ldloc.2 - IL_00af: ldc.i4 0xed5134d4 - IL_00b4: beq IL_017c + IL_00ac: ldloc.1 + IL_00ad: ldc.i4 0xed5134d4 + IL_00b2: beq IL_017a - IL_00b9: br.s IL_00bb + IL_00b7: br.s IL_00b9 - IL_00bb: ldloc.2 - IL_00bc: ldc.i4 0xf701cc7f - IL_00c1: beq.s IL_0107 + IL_00b9: ldloc.1 + IL_00ba: ldc.i4 0xf701cc7f + IL_00bf: beq.s IL_0105 - IL_00c3: br IL_01fd + IL_00c1: br IL_01fb - IL_00c8: ldloc.1 - IL_00c9: ldstr "First case" - IL_00ce: call bool [mscorlib]System.String::op_Equality(string, + IL_00c6: ldloc.0 + IL_00c7: ldstr "First case" + IL_00cc: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00d3: brtrue IL_019a + IL_00d1: brtrue IL_0198 - IL_00d8: br IL_01fd + IL_00d6: br IL_01fb - IL_00dd: ldloc.1 - IL_00de: ldstr "Second case" - IL_00e3: call bool [mscorlib]System.String::op_Equality(string, + IL_00db: ldloc.0 + IL_00dc: ldstr "Second case" + IL_00e1: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00e8: brtrue IL_01a3 + IL_00e6: brtrue IL_01a1 - IL_00ed: br IL_01fd + IL_00eb: br IL_01fb - IL_00f2: ldloc.1 - IL_00f3: ldstr "Third case" - IL_00f8: call bool [mscorlib]System.String::op_Equality(string, + IL_00f0: ldloc.0 + IL_00f1: ldstr "Third case" + IL_00f6: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00fd: brtrue IL_01ac + IL_00fb: brtrue IL_01aa - IL_0102: br IL_01fd + IL_0100: br IL_01fb - IL_0107: ldloc.1 - IL_0108: ldstr "Fourth case" - IL_010d: call bool [mscorlib]System.String::op_Equality(string, + IL_0105: ldloc.0 + IL_0106: ldstr "Fourth case" + IL_010b: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0112: brtrue IL_01b5 + IL_0110: brtrue IL_01b3 - IL_0117: br IL_01fd + IL_0115: br IL_01fb - IL_011c: ldloc.1 - IL_011d: ldstr "Fifth case" - IL_0122: call bool [mscorlib]System.String::op_Equality(string, + IL_011a: ldloc.0 + IL_011b: ldstr "Fifth case" + IL_0120: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0127: brtrue IL_01be + IL_0125: brtrue IL_01bc - IL_012c: br IL_01fd + IL_012a: br IL_01fb - IL_0131: ldloc.1 - IL_0132: ldstr "Sixth case" - IL_0137: call bool [mscorlib]System.String::op_Equality(string, + IL_012f: ldloc.0 + IL_0130: ldstr "Sixth case" + IL_0135: call bool [mscorlib]System.String::op_Equality(string, string) - IL_013c: brtrue IL_01c7 + IL_013a: brtrue IL_01c5 - IL_0141: br IL_01fd + IL_013f: br IL_01fb - IL_0146: ldloc.1 - IL_0147: ldstr "Seventh case" - IL_014c: call bool [mscorlib]System.String::op_Equality(string, + IL_0144: ldloc.0 + IL_0145: ldstr "Seventh case" + IL_014a: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0151: brtrue.s IL_01d0 + IL_014f: brtrue.s IL_01ce - IL_0153: br IL_01fd + IL_0151: br IL_01fb - IL_0158: ldloc.1 - IL_0159: ldstr "Eighth case" - IL_015e: call bool [mscorlib]System.String::op_Equality(string, + IL_0156: ldloc.0 + IL_0157: ldstr "Eighth case" + IL_015c: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0163: brtrue.s IL_01d9 + IL_0161: brtrue.s IL_01d7 - IL_0165: br IL_01fd + IL_0163: br IL_01fb - IL_016a: ldloc.1 - IL_016b: ldstr "Ninth case" - IL_0170: call bool [mscorlib]System.String::op_Equality(string, + IL_0168: ldloc.0 + IL_0169: ldstr "Ninth case" + IL_016e: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0175: brtrue.s IL_01e2 + IL_0173: brtrue.s IL_01e0 - IL_0177: br IL_01fd + IL_0175: br IL_01fb - IL_017c: ldloc.1 - IL_017d: ldstr "Tenth case" - IL_0182: call bool [mscorlib]System.String::op_Equality(string, + IL_017a: ldloc.0 + IL_017b: ldstr "Tenth case" + IL_0180: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0187: brtrue.s IL_01eb + IL_0185: brtrue.s IL_01e9 - IL_0189: br.s IL_01fd + IL_0187: br.s IL_01fb - IL_018b: ldloc.1 - IL_018c: ldstr "Eleventh case" - IL_0191: call bool [mscorlib]System.String::op_Equality(string, + IL_0189: ldloc.0 + IL_018a: ldstr "Eleventh case" + IL_018f: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0196: brtrue.s IL_01f4 - - IL_0198: br.s IL_01fd - - IL_019a: nop - IL_019b: ldstr "Text1" - IL_01a0: stloc.3 - IL_01a1: br.s IL_0206 - - IL_01a3: nop - IL_01a4: ldstr "Text2" - IL_01a9: stloc.3 - IL_01aa: br.s IL_0206 - - IL_01ac: nop - IL_01ad: ldstr "Text3" - IL_01b2: stloc.3 - IL_01b3: br.s IL_0206 - - IL_01b5: nop - IL_01b6: ldstr "Text4" - IL_01bb: stloc.3 - IL_01bc: br.s IL_0206 - - IL_01be: nop - IL_01bf: ldstr "Text5" - IL_01c4: stloc.3 - IL_01c5: br.s IL_0206 - - IL_01c7: nop - IL_01c8: ldstr "Text6" - IL_01cd: stloc.3 - IL_01ce: br.s IL_0206 - - IL_01d0: nop - IL_01d1: ldstr "Text7" - IL_01d6: stloc.3 - IL_01d7: br.s IL_0206 - - IL_01d9: nop - IL_01da: ldstr "Text8" - IL_01df: stloc.3 - IL_01e0: br.s IL_0206 - - IL_01e2: nop - IL_01e3: ldstr "Text9" - IL_01e8: stloc.3 - IL_01e9: br.s IL_0206 - - IL_01eb: nop - IL_01ec: ldstr "Text10" - IL_01f1: stloc.3 - IL_01f2: br.s IL_0206 - - IL_01f4: nop - IL_01f5: ldstr "Text11" - IL_01fa: stloc.3 - IL_01fb: br.s IL_0206 - - IL_01fd: nop - IL_01fe: ldstr "Default" - IL_0203: stloc.3 - IL_0204: br.s IL_0206 - - IL_0206: ldloc.3 - IL_0207: ret + IL_0194: brtrue.s IL_01f2 + + IL_0196: br.s IL_01fb + + IL_0198: nop + IL_0199: ldstr "Text1" + IL_019e: stloc.2 + IL_019f: br.s IL_0204 + + IL_01a1: nop + IL_01a2: ldstr "Text2" + IL_01a7: stloc.2 + IL_01a8: br.s IL_0204 + + IL_01aa: nop + IL_01ab: ldstr "Text3" + IL_01b0: stloc.2 + IL_01b1: br.s IL_0204 + + IL_01b3: nop + IL_01b4: ldstr "Text4" + IL_01b9: stloc.2 + IL_01ba: br.s IL_0204 + + IL_01bc: nop + IL_01bd: ldstr "Text5" + IL_01c2: stloc.2 + IL_01c3: br.s IL_0204 + + IL_01c5: nop + IL_01c6: ldstr "Text6" + IL_01cb: stloc.2 + IL_01cc: br.s IL_0204 + + IL_01ce: nop + IL_01cf: ldstr "Text7" + IL_01d4: stloc.2 + IL_01d5: br.s IL_0204 + + IL_01d7: nop + IL_01d8: ldstr "Text8" + IL_01dd: stloc.2 + IL_01de: br.s IL_0204 + + IL_01e0: nop + IL_01e1: ldstr "Text9" + IL_01e6: stloc.2 + IL_01e7: br.s IL_0204 + + IL_01e9: nop + IL_01ea: ldstr "Text10" + IL_01ef: stloc.2 + IL_01f0: br.s IL_0204 + + IL_01f2: nop + IL_01f3: ldstr "Text11" + IL_01f8: stloc.2 + IL_01f9: br.s IL_0204 + + IL_01fb: nop + IL_01fc: ldstr "Default" + IL_0201: stloc.2 + IL_0202: br.s IL_0204 + + IL_0204: ldloc.2 + IL_0205: ret } // end of method Switch::SwitchOverString2 .method public hidebysig static string @@ -1166,7 +1220,7 @@ .method public hidebysig static void SwitchInLoop(int32 i) cil managed { - // Code size 146 (0x92) + // Code size 132 (0x84) .maxstack 2 .locals init (int32 V_0, bool V_1) @@ -1178,7 +1232,7 @@ object) IL_0011: call void [mscorlib]System.Console::WriteLine(string) IL_0016: nop - IL_0017: br.s IL_008d + IL_0017: br.s IL_007f IL_0019: nop IL_001a: ldarg.0 @@ -1189,53 +1243,47 @@ IL_001f: switch ( IL_0036, IL_0044, - IL_0052, - IL_0060) - IL_0034: br.s IL_006e + IL_0060, + IL_0052) + IL_0034: br.s IL_0060 IL_0036: nop IL_0037: ldstr "one" IL_003c: call void [mscorlib]System.Console::WriteLine(string) IL_0041: nop - IL_0042: br.s IL_0087 + IL_0042: br.s IL_0079 IL_0044: nop IL_0045: ldstr "two" IL_004a: call void [mscorlib]System.Console::WriteLine(string) IL_004f: nop - IL_0050: br.s IL_0087 + IL_0050: br.s IL_0079 IL_0052: nop - IL_0053: ldstr "three" + IL_0053: ldstr "four" IL_0058: call void [mscorlib]System.Console::WriteLine(string) IL_005d: nop - IL_005e: br.s IL_008d + IL_005e: br.s IL_0083 IL_0060: nop - IL_0061: ldstr "four" + IL_0061: ldstr "default" IL_0066: call void [mscorlib]System.Console::WriteLine(string) IL_006b: nop - IL_006c: br.s IL_0091 - - IL_006e: nop - IL_006f: ldstr "default" - IL_0074: call void [mscorlib]System.Console::WriteLine(string) - IL_0079: nop - IL_007a: ldstr "more code" - IL_007f: call void [mscorlib]System.Console::WriteLine(string) - IL_0084: nop - IL_0085: br.s IL_0091 - - IL_0087: ldarg.0 - IL_0088: ldc.i4.1 - IL_0089: add - IL_008a: starg.s i - IL_008c: nop - IL_008d: ldc.i4.1 - IL_008e: stloc.1 - IL_008f: br.s IL_0019 - - IL_0091: ret + IL_006c: ldstr "more code" + IL_0071: call void [mscorlib]System.Console::WriteLine(string) + IL_0076: nop + IL_0077: br.s IL_0083 + + IL_0079: ldarg.0 + IL_007a: ldc.i4.1 + IL_007b: add + IL_007c: starg.s i + IL_007e: nop + IL_007f: ldc.i4.1 + IL_0080: stloc.1 + IL_0081: br.s IL_0019 + + IL_0083: ret } // end of method Switch::SwitchInLoop .method public hidebysig static void SwitchWithGoto(int32 i) cil managed @@ -1317,7 +1365,7 @@ .method public hidebysig static void SwitchOnStringInForLoop() cil managed { - // Code size 265 (0x109) + // Code size 261 (0x105) .maxstack 2 .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, class [mscorlib]System.Collections.Generic.List`1 V_1, @@ -1325,8 +1373,7 @@ int32 V_3, class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty V_4, string V_5, - string V_6, - bool V_7) + bool V_6) IL_0000: nop IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() IL_0006: stloc.0 @@ -1336,7 +1383,7 @@ IL_0012: stloc.2 IL_0013: ldc.i4.0 IL_0014: stloc.3 - IL_0015: br IL_00f9 + IL_0015: br IL_00f5 IL_001a: nop IL_001b: ldloc.2 @@ -1348,123 +1395,121 @@ IL_0027: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() IL_002c: stloc.s V_5 IL_002e: ldloc.s V_5 - IL_0030: stloc.s V_6 - IL_0032: ldloc.s V_6 - IL_0034: ldstr "Name1" - IL_0039: call bool [mscorlib]System.String::op_Equality(string, + IL_0030: ldstr "Name1" + IL_0035: call bool [mscorlib]System.String::op_Equality(string, string) - IL_003e: brtrue.s IL_0088 + IL_003a: brtrue.s IL_0084 - IL_0040: ldloc.s V_6 - IL_0042: ldstr "Name2" - IL_0047: call bool [mscorlib]System.String::op_Equality(string, + IL_003c: ldloc.s V_5 + IL_003e: ldstr "Name2" + IL_0043: call bool [mscorlib]System.String::op_Equality(string, string) - IL_004c: brtrue.s IL_009d + IL_0048: brtrue.s IL_0099 - IL_004e: ldloc.s V_6 - IL_0050: ldstr "Name3" - IL_0055: call bool [mscorlib]System.String::op_Equality(string, + IL_004a: ldloc.s V_5 + IL_004c: ldstr "Name3" + IL_0051: call bool [mscorlib]System.String::op_Equality(string, string) - IL_005a: brtrue.s IL_00b2 + IL_0056: brtrue.s IL_00ae - IL_005c: ldloc.s V_6 - IL_005e: ldstr "Name4" - IL_0063: call bool [mscorlib]System.String::op_Equality(string, + IL_0058: ldloc.s V_5 + IL_005a: ldstr "Name4" + IL_005f: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0068: brtrue.s IL_00c7 + IL_0064: brtrue.s IL_00c3 - IL_006a: ldloc.s V_6 - IL_006c: ldstr "Name5" - IL_0071: call bool [mscorlib]System.String::op_Equality(string, + IL_0066: ldloc.s V_5 + IL_0068: ldstr "Name5" + IL_006d: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0076: brtrue.s IL_00dc + IL_0072: brtrue.s IL_00d8 - IL_0078: ldloc.s V_6 - IL_007a: ldstr "Name6" - IL_007f: call bool [mscorlib]System.String::op_Equality(string, + IL_0074: ldloc.s V_5 + IL_0076: ldstr "Name6" + IL_007b: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0084: brtrue.s IL_00dc + IL_0080: brtrue.s IL_00d8 - IL_0086: br.s IL_00e8 + IL_0082: br.s IL_00e4 - IL_0088: nop - IL_0089: ldloc.s V_4 - IL_008b: ldc.i4.1 - IL_008c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_0091: nop - IL_0092: ldloc.0 - IL_0093: ldloc.s V_4 - IL_0095: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_009a: nop - IL_009b: br.s IL_00f4 - - IL_009d: nop - IL_009e: ldloc.s V_4 - IL_00a0: ldc.i4.2 - IL_00a1: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00a6: nop - IL_00a7: ldloc.0 - IL_00a8: ldloc.s V_4 - IL_00aa: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00af: nop - IL_00b0: br.s IL_00f4 - - IL_00b2: nop - IL_00b3: ldloc.s V_4 - IL_00b5: ldc.i4.3 - IL_00b6: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00bb: nop - IL_00bc: ldloc.0 - IL_00bd: ldloc.s V_4 - IL_00bf: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00c4: nop - IL_00c5: br.s IL_00f4 - - IL_00c7: nop - IL_00c8: ldloc.s V_4 - IL_00ca: ldc.i4.4 - IL_00cb: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00d0: nop - IL_00d1: ldloc.0 - IL_00d2: ldloc.s V_4 - IL_00d4: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00d9: nop - IL_00da: br.s IL_00f4 - - IL_00dc: nop - IL_00dd: ldloc.0 - IL_00de: ldloc.s V_4 - IL_00e0: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00e5: nop - IL_00e6: br.s IL_00f4 - - IL_00e8: nop - IL_00e9: ldloc.1 - IL_00ea: ldloc.s V_4 - IL_00ec: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00f1: nop - IL_00f2: br.s IL_00f4 - - IL_00f4: nop + IL_0084: nop + IL_0085: ldloc.s V_4 + IL_0087: ldc.i4.1 + IL_0088: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_008d: nop + IL_008e: ldloc.0 + IL_008f: ldloc.s V_4 + IL_0091: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0096: nop + IL_0097: br.s IL_00f0 + + IL_0099: nop + IL_009a: ldloc.s V_4 + IL_009c: ldc.i4.2 + IL_009d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00a2: nop + IL_00a3: ldloc.0 + IL_00a4: ldloc.s V_4 + IL_00a6: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00ab: nop + IL_00ac: br.s IL_00f0 + + IL_00ae: nop + IL_00af: ldloc.s V_4 + IL_00b1: ldc.i4.3 + IL_00b2: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00b7: nop + IL_00b8: ldloc.0 + IL_00b9: ldloc.s V_4 + IL_00bb: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00c0: nop + IL_00c1: br.s IL_00f0 + + IL_00c3: nop + IL_00c4: ldloc.s V_4 + IL_00c6: ldc.i4.4 + IL_00c7: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00cc: nop + IL_00cd: ldloc.0 + IL_00ce: ldloc.s V_4 + IL_00d0: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00d5: nop + IL_00d6: br.s IL_00f0 + + IL_00d8: nop + IL_00d9: ldloc.0 + IL_00da: ldloc.s V_4 + IL_00dc: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00e1: nop + IL_00e2: br.s IL_00f0 + + IL_00e4: nop + IL_00e5: ldloc.1 + IL_00e6: ldloc.s V_4 + IL_00e8: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00ed: nop + IL_00ee: br.s IL_00f0 + + IL_00f0: nop + IL_00f1: ldloc.3 + IL_00f2: ldc.i4.1 + IL_00f3: add + IL_00f4: stloc.3 IL_00f5: ldloc.3 - IL_00f6: ldc.i4.1 - IL_00f7: add - IL_00f8: stloc.3 - IL_00f9: ldloc.3 - IL_00fa: ldloc.2 - IL_00fb: ldlen - IL_00fc: conv.i4 - IL_00fd: clt - IL_00ff: stloc.s V_7 - IL_0101: ldloc.s V_7 - IL_0103: brtrue IL_001a - - IL_0108: ret + IL_00f6: ldloc.2 + IL_00f7: ldlen + IL_00f8: conv.i4 + IL_00f9: clt + IL_00fb: stloc.s V_6 + IL_00fd: ldloc.s V_6 + IL_00ff: brtrue IL_001a + + IL_0104: ret } // end of method Switch::SwitchOnStringInForLoop .method public hidebysig static void SwitchWithComplexCondition(string[] args) cil managed { - // Code size 134 (0x86) + // Code size 138 (0x8a) .maxstack 2 .locals init (string V_0) IL_0000: nop @@ -1489,51 +1534,55 @@ IL_001e: ldstr "b" IL_0023: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0028: brtrue.s IL_0053 + IL_0028: brtrue.s IL_0054 IL_002a: ldloc.0 IL_002b: ldstr "c" IL_0030: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0035: brtrue.s IL_0060 + IL_0035: brtrue.s IL_0062 IL_0037: ldloc.0 IL_0038: ldstr "d" IL_003d: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0042: brtrue.s IL_006d + IL_0042: brtrue.s IL_0070 - IL_0044: br.s IL_007a + IL_0044: br.s IL_007e - IL_0046: ldstr "a" - IL_004b: call void [mscorlib]System.Console::WriteLine(string) - IL_0050: nop - IL_0051: br.s IL_007a + IL_0046: nop + IL_0047: ldstr "a" + IL_004c: call void [mscorlib]System.Console::WriteLine(string) + IL_0051: nop + IL_0052: br.s IL_007e - IL_0053: ldstr "b" - IL_0058: call void [mscorlib]System.Console::WriteLine(string) - IL_005d: nop - IL_005e: br.s IL_007a + IL_0054: nop + IL_0055: ldstr "b" + IL_005a: call void [mscorlib]System.Console::WriteLine(string) + IL_005f: nop + IL_0060: br.s IL_007e - IL_0060: ldstr "c" - IL_0065: call void [mscorlib]System.Console::WriteLine(string) - IL_006a: nop - IL_006b: br.s IL_007a + IL_0062: nop + IL_0063: ldstr "c" + IL_0068: call void [mscorlib]System.Console::WriteLine(string) + IL_006d: nop + IL_006e: br.s IL_007e - IL_006d: ldstr "d" - IL_0072: call void [mscorlib]System.Console::WriteLine(string) - IL_0077: nop - IL_0078: br.s IL_007a + IL_0070: nop + IL_0071: ldstr "d" + IL_0076: call void [mscorlib]System.Console::WriteLine(string) + IL_007b: nop + IL_007c: br.s IL_007e - IL_007a: ldstr "end" - IL_007f: call void [mscorlib]System.Console::WriteLine(string) - IL_0084: nop - IL_0085: ret + IL_007e: ldstr "end" + IL_0083: call void [mscorlib]System.Console::WriteLine(string) + IL_0088: nop + IL_0089: ret } // end of method Switch::SwitchWithComplexCondition .method public hidebysig static void SwitchWithArray(string[] args) cil managed { - // Code size 123 (0x7b) + // Code size 127 (0x7f) .maxstack 2 .locals init (string V_0) IL_0000: nop @@ -1551,46 +1600,50 @@ IL_0013: ldstr "b" IL_0018: call bool [mscorlib]System.String::op_Equality(string, string) - IL_001d: brtrue.s IL_0048 + IL_001d: brtrue.s IL_0049 IL_001f: ldloc.0 IL_0020: ldstr "c" IL_0025: call bool [mscorlib]System.String::op_Equality(string, string) - IL_002a: brtrue.s IL_0055 + IL_002a: brtrue.s IL_0057 IL_002c: ldloc.0 IL_002d: ldstr "d" IL_0032: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0037: brtrue.s IL_0062 - - IL_0039: br.s IL_006f + IL_0037: brtrue.s IL_0065 - IL_003b: ldstr "a" - IL_0040: call void [mscorlib]System.Console::WriteLine(string) - IL_0045: nop - IL_0046: br.s IL_006f + IL_0039: br.s IL_0073 - IL_0048: ldstr "b" - IL_004d: call void [mscorlib]System.Console::WriteLine(string) - IL_0052: nop - IL_0053: br.s IL_006f + IL_003b: nop + IL_003c: ldstr "a" + IL_0041: call void [mscorlib]System.Console::WriteLine(string) + IL_0046: nop + IL_0047: br.s IL_0073 - IL_0055: ldstr "c" - IL_005a: call void [mscorlib]System.Console::WriteLine(string) - IL_005f: nop - IL_0060: br.s IL_006f + IL_0049: nop + IL_004a: ldstr "b" + IL_004f: call void [mscorlib]System.Console::WriteLine(string) + IL_0054: nop + IL_0055: br.s IL_0073 - IL_0062: ldstr "d" - IL_0067: call void [mscorlib]System.Console::WriteLine(string) - IL_006c: nop - IL_006d: br.s IL_006f + IL_0057: nop + IL_0058: ldstr "c" + IL_005d: call void [mscorlib]System.Console::WriteLine(string) + IL_0062: nop + IL_0063: br.s IL_0073 - IL_006f: ldstr "end" - IL_0074: call void [mscorlib]System.Console::WriteLine(string) - IL_0079: nop - IL_007a: ret + IL_0065: nop + IL_0066: ldstr "d" + IL_006b: call void [mscorlib]System.Console::WriteLine(string) + IL_0070: nop + IL_0071: br.s IL_0073 + + IL_0073: ldstr "end" + IL_0078: call void [mscorlib]System.Console::WriteLine(string) + IL_007d: nop + IL_007e: ret } // end of method Switch::SwitchWithArray } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch From b7a5924b25699ae275fed677ac0a279ebeede283 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 13 Oct 2017 13:38:52 +0200 Subject: [PATCH 107/190] When possible, use implicit method group conversions to construct delegates. --- .../TestCases/Pretty/DelegateConstruction.cs | 6 +++--- ICSharpCode.Decompiler/CSharp/CallBuilder.cs | 15 +++++++++------ .../CSharp/TranslatedExpression.cs | 11 +++++++---- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs index cd9681ddc..d4033768b 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs @@ -88,17 +88,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static Action ExtensionMethodUnbound() { - return new Action(DelegateConstruction.Test); + return DelegateConstruction.Test; } public static Action ExtensionMethodBound() { - return new Action("abc".Test); + return "abc".Test; } public static Action ExtensionMethodBoundOnNull() { - return new Action(((string)null).Test); + return ((string)null).Test; } public static object StaticMethod() diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index 2a57d77e7..23f0add1a 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -339,18 +339,21 @@ namespace ICSharpCode.Decompiler.CSharp } var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly); var or = new OverloadResolution(resolver.Compilation, method.Parameters.SelectArray(p => new TypeResolveResult(p.Type))); - var result = lookup.Lookup(target.ResolveResult, method.Name, method.TypeArguments, true) as MethodGroupResolveResult; + var result = lookup.Lookup(target.ResolveResult, method.Name, method.TypeArguments, false); - if (result == null) { + bool needsCast = true; + if (result is MethodGroupResolveResult mgrr) { + or.AddMethodLists(mgrr.MethodsGroupedByDeclaringType.ToArray()); + needsCast = (or.BestCandidateErrors != OverloadResolutionErrors.None || !IsAppropriateCallTarget(method, or.BestCandidate, func.OpCode == OpCode.LdVirtFtn)); + } + if (needsCast) { target = target.ConvertTo(targetType, expressionBuilder); - } else { - or.AddMethodLists(result.MethodsGroupedByDeclaringType.ToArray()); - if (or.BestCandidateErrors != OverloadResolutionErrors.None || !IsAppropriateCallTarget(method, or.BestCandidate, func.OpCode == OpCode.LdVirtFtn)) - target = target.ConvertTo(targetType, expressionBuilder); + result = lookup.Lookup(target.ResolveResult, method.Name, method.TypeArguments, false); } var mre = new MemberReferenceExpression(target, method.Name); mre.TypeArguments.AddRange(method.TypeArguments.Select(expressionBuilder.ConvertType)); + mre.WithRR(result); var oce = new ObjectCreateExpression(expressionBuilder.ConvertType(inst.Method.DeclaringType), mre) .WithILInstruction(inst) .WithRR(new ConversionResolveResult( diff --git a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs index a4f9f2bdd..ad82d776f 100644 --- a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs @@ -173,11 +173,14 @@ namespace ICSharpCode.Decompiler.CSharp var type = this.Type; if (type.Equals(targetType)) { // Make explicit conversion implicit, if possible - if (allowImplicitConversion && Expression is CastExpression cast && ResolveResult is ConversionResolveResult conversion) { - if (type.IsKnownType(KnownTypeCode.Object) && conversion.Conversion.IsBoxingConversion - || type.Kind == TypeKind.Delegate && conversion.Conversion.IsAnonymousFunctionConversion) - { + if (allowImplicitConversion && ResolveResult is ConversionResolveResult conversion) { + if (Expression is CastExpression cast + && (type.IsKnownType(KnownTypeCode.Object) && conversion.Conversion.IsBoxingConversion + || type.Kind == TypeKind.Delegate && conversion.Conversion.IsAnonymousFunctionConversion + )) { return this.UnwrapChild(cast.Expression); + } else if (Expression is ObjectCreateExpression oce && conversion.Conversion.IsMethodGroupConversion && oce.Arguments.Count == 1) { + return this.UnwrapChild(oce.Arguments.Single()); } } return this; From 7ae44fcdc6559f051448dfc19c102fc6857cd8bf Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 13 Oct 2017 13:50:12 +0200 Subject: [PATCH 108/190] Add FlattenSwitchBlocks transform + update test cases. --- .../TestCases/Pretty/Switch.cs | 512 +++++++----------- .../CSharp/CSharpDecompiler.cs | 2 +- .../CSharp/Transforms/FlattenSwitchBlocks.cs | 6 +- .../ICSharpCode.Decompiler.csproj | 1 + 4 files changed, 215 insertions(+), 306 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index 45c1c8274..462330e92 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -43,154 +43,117 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { Console.WriteLine("SparseIntegerSwitch: " + i); switch (i) { - case -10000000: { - return "-10 mln"; - } - case -100: { - return "-hundred"; - } - case -1: { - return "-1"; - } - case 0: { - return "0"; - } - case 1: { - return "1"; - } - case 2: { - return "2"; - } - case 4: { - return "4"; - } - case 100: { - return "hundred"; - } - case 10000: { - return "ten thousand"; - } - case 10001: { - return "ten thousand and one"; - } - case 2147483647: { - return "int.MaxValue"; - } - default: { - return "something else"; - } + case -10000000: + return "-10 mln"; + case -100: + return "-hundred"; + case -1: + return "-1"; + case 0: + return "0"; + case 1: + return "1"; + case 2: + return "2"; + case 4: + return "4"; + case 100: + return "hundred"; + case 10000: + return "ten thousand"; + case 10001: + return "ten thousand and one"; + case 2147483647: + return "int.MaxValue"; + default: + return "something else"; } } public static string SwitchOverNullableInt(int? i) { switch (i) { - case null: { - return "null"; - } - case 0: { - return "zero"; - } - case 5: { - return "five"; - } - case 10: { - return "ten"; - } - default: { - return "large"; - } + case null: + return "null"; + case 0: + return "zero"; + case 5: + return "five"; + case 10: + return "ten"; + default: + return "large"; } } public static string SwitchOverNullableIntShifted(int? i) { switch (i + 5) { - case null: { - return "null"; - } - case 0: { - return "zero"; - } - case 5: { - return "five"; - } - case 10: { - return "ten"; - } - default: { - return "large"; - } + case null: + return "null"; + case 0: + return "zero"; + case 5: + return "five"; + case 10: + return "ten"; + default: + return "large"; } } public static string SwitchOverNullableIntNoNullCase(int? i) { switch (i) { - case 0: { - return "zero"; - } - case 5: { - return "five"; - } - case 10: { - return "ten"; - } - default: { - return "other"; - } + case 0: + return "zero"; + case 5: + return "five"; + case 10: + return "ten"; + default: + return "other"; } } public static string SwitchOverNullableIntNoNullCaseShifted(int? i) { switch (i + 5) { - case 0: { - return "zero"; - } - case 5: { - return "five"; - } - case 10: { - return "ten"; - } - default: { - return "other"; - } + case 0: + return "zero"; + case 5: + return "five"; + case 10: + return "ten"; + default: + return "other"; } } public static void SwitchOverInt(int i) { switch (i) { - case 0: { - Console.WriteLine("zero"); - break; - } - case 5: { - Console.WriteLine("five"); - break; - } - case 10: { - Console.WriteLine("ten"); - break; - } - case 15: { - Console.WriteLine("fifteen"); - break; - } - case 20: { - Console.WriteLine("twenty"); - break; - } - case 25: { - Console.WriteLine("twenty-five"); - break; - } - case 30: { - Console.WriteLine("thirty"); - break; - } + case 0: + Console.WriteLine("zero"); + break; + case 5: + Console.WriteLine("five"); + break; + case 10: + Console.WriteLine("ten"); + break; + case 15: + Console.WriteLine("fifteen"); + break; + case 20: + Console.WriteLine("twenty"); + break; + case 25: + Console.WriteLine("twenty-five"); + break; + case 30: + Console.WriteLine("thirty"); + break; } } @@ -198,18 +161,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { Console.WriteLine("ShortSwitchOverString: " + text); switch (text) { - case "First case": { - return "Text1"; - } - case "Second case": { - return "Text2"; - } - case "Third case": { - return "Text3"; - } - default: { - return "Default"; - } + case "First case": + return "Text1"; + case "Second case": + return "Text2"; + case "Third case": + return "Text3"; + default: + return "Default"; } } @@ -217,18 +176,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { Console.WriteLine("ShortSwitchOverStringWithNullCase: " + text); switch (text) { - case "First case": { - return "Text1"; - } - case "Second case": { - return "Text2"; - } - case null: { - return "null"; - } - default: { - return "Default"; - } + case "First case": + return "Text1"; + case "Second case": + return "Text2"; + case null: + return "null"; + default: + return "Default"; } } @@ -236,31 +191,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { Console.WriteLine("SwitchOverString1: " + text); switch (text) { - case "First case": { - return "Text1"; - } + case "First case": + return "Text1"; case "Second case": - case "2nd case": { - return "Text2"; - } - case "Third case": { - return "Text3"; - } - case "Fourth case": { - return "Text4"; - } - case "Fifth case": { - return "Text5"; - } - case "Sixth case": { - return "Text6"; - } - case null: { - return null; - } - default: { - return "Default"; - } + case "2nd case": + return "Text2"; + case "Third case": + return "Text3"; + case "Fourth case": + return "Text4"; + case "Fifth case": + return "Text5"; + case "Sixth case": + return "Text6"; + case null: + return null; + default: + return "Default"; } } @@ -268,42 +215,30 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { Console.WriteLine("SwitchOverString2:"); switch (Environment.UserName) { - case "First case": { - return "Text1"; - } - case "Second case": { - return "Text2"; - } - case "Third case": { - return "Text3"; - } - case "Fourth case": { - return "Text4"; - } - case "Fifth case": { - return "Text5"; - } - case "Sixth case": { - return "Text6"; - } - case "Seventh case": { - return "Text7"; - } - case "Eighth case": { - return "Text8"; - } - case "Ninth case": { - return "Text9"; - } - case "Tenth case": { - return "Text10"; - } - case "Eleventh case": { - return "Text11"; - } - default: { - return "Default"; - } + case "First case": + return "Text1"; + case "Second case": + return "Text2"; + case "Third case": + return "Text3"; + case "Fourth case": + return "Text4"; + case "Fifth case": + return "Text5"; + case "Sixth case": + return "Text6"; + case "Seventh case": + return "Text7"; + case "Eighth case": + return "Text8"; + case "Ninth case": + return "Text9"; + case "Tenth case": + return "Text10"; + case "Eleventh case": + return "Text11"; + default: + return "Default"; } } @@ -311,15 +246,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { Console.WriteLine("SwitchOverBool: " + b.ToString()); switch (b) { - case true: { - return bool.TrueString; - } - case false: { - return bool.FalseString; - } - default: { - return null; - } + case true: + return bool.TrueString; + case false: + return bool.FalseString; + default: + return null; } } @@ -328,27 +260,22 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("SwitchInLoop: " + i); while (true) { switch (i) { - case 1: { - Console.WriteLine("one"); - break; - } - case 2: { - Console.WriteLine("two"); - break; - } - //case 3: { + case 1: + Console.WriteLine("one"); + break; + case 2: + Console.WriteLine("two"); + break; + //case 3: // Console.WriteLine("three"); // continue; - // } - case 4: { - Console.WriteLine("four"); - return; - } - default: { - Console.WriteLine("default"); - Console.WriteLine("more code"); - return; - } + case 4: + Console.WriteLine("four"); + return; + default: + Console.WriteLine("default"); + Console.WriteLine("more code"); + return; } i++; } @@ -358,26 +285,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { Console.WriteLine("SwitchWithGoto: " + i); switch (i) { - case 1: { - Console.WriteLine("one"); - goto default; - } - case 2: { - Console.WriteLine("two"); - goto case 3; - } - case 3: { - Console.WriteLine("three"); - break; - } - case 4: { - Console.WriteLine("four"); - return; - } - default: { - Console.WriteLine("default"); - break; - } + case 1: + Console.WriteLine("one"); + goto default; + case 2: + Console.WriteLine("two"); + goto case 3; + case 3: + Console.WriteLine("three"); + break; + case 4: + Console.WriteLine("four"); + return; + default: + Console.WriteLine("default"); + break; } Console.WriteLine("End of method"); } @@ -395,35 +317,29 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty for (int i = 0; i < properties.Length; i++) { SetProperty setProperty = properties[i]; switch (setProperty.Property.Name) { - case "Name1": { - setProperty.Set = 1; - list.Add(setProperty); - break; - } - case "Name2": { - setProperty.Set = 2; - list.Add(setProperty); - break; - } - case "Name3": { - setProperty.Set = 3; - list.Add(setProperty); - break; - } - case "Name4": { - setProperty.Set = 4; - list.Add(setProperty); - break; - } + case "Name1": + setProperty.Set = 1; + list.Add(setProperty); + break; + case "Name2": + setProperty.Set = 2; + list.Add(setProperty); + break; + case "Name3": + setProperty.Set = 3; + list.Add(setProperty); + break; + case "Name4": + setProperty.Set = 4; + list.Add(setProperty); + break; case "Name5": - case "Name6": { - list.Add(setProperty); - break; - } - default: { - list2.Add(setProperty); - break; - } + case "Name6": + list.Add(setProperty); + break; + default: + list2.Add(setProperty); + break; } } } @@ -431,22 +347,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SwitchWithComplexCondition(string[] args) { switch ((args.Length == 0) ? "dummy" : args[0]) { - case "a": { - Console.WriteLine("a"); - break; - } - case "b": { - Console.WriteLine("b"); - break; - } - case "c": { - Console.WriteLine("c"); - break; - } - case "d": { - Console.WriteLine("d"); - break; - } + case "a": + Console.WriteLine("a"); + break; + case "b": + Console.WriteLine("b"); + break; + case "c": + Console.WriteLine("c"); + break; + case "d": + Console.WriteLine("d"); + break; } Console.WriteLine("end"); } @@ -454,22 +366,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SwitchWithArray(string[] args) { switch (args[0]) { - case "a": { + case "a": Console.WriteLine("a"); break; - } - case "b": { + case "b": Console.WriteLine("b"); break; - } - case "c": { + case "c": Console.WriteLine("c"); break; - } - case "d": { + case "d": Console.WriteLine("d"); break; - } } Console.WriteLine("end"); } diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index dff75e4c8..801b95b7c 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -144,7 +144,7 @@ namespace ICSharpCode.Decompiler.CSharp new IntroduceExtensionMethods(), // must run after IntroduceUsingDeclarations new IntroduceQueryExpressions(), // must run after IntroduceExtensionMethods new CombineQueryExpressions(), - //new FlattenSwitchBlocks(), + new FlattenSwitchBlocks(), new FixNameCollisions(), new AddXmlDocumentationTransform(), }; diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/FlattenSwitchBlocks.cs b/ICSharpCode.Decompiler/CSharp/Transforms/FlattenSwitchBlocks.cs index 4eed055f4..68bb7c47f 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/FlattenSwitchBlocks.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/FlattenSwitchBlocks.cs @@ -2,15 +2,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using ICSharpCode.NRefactory.CSharp; +using ICSharpCode.Decompiler.CSharp.Syntax; namespace ICSharpCode.Decompiler.CSharp.Transforms { class FlattenSwitchBlocks : IAstTransform { - public void Run(AstNode compilationUnit) + public void Run(AstNode rootNode, TransformContext context) { - foreach (var switchSection in compilationUnit.Descendants.OfType()) + foreach (var switchSection in rootNode.Descendants.OfType()) { if (switchSection.Statements.Count != 1) continue; diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 48313b70c..a1e17edfd 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -224,6 +224,7 @@ + From d6d702089309681f74cd3de97136dbdd45d84153 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 13 Oct 2017 14:57:03 +0200 Subject: [PATCH 109/190] Add test cases for nullable switch --- .../TestCases/Pretty/Switch.cs | 30 + .../TestCases/Pretty/Switch.il | 1415 ++++++++-------- .../TestCases/Pretty/Switch.opt.il | 136 +- .../TestCases/Pretty/Switch.opt.roslyn.il | 105 +- .../TestCases/Pretty/Switch.roslyn.il | 1450 +++++++++-------- 5 files changed, 1718 insertions(+), 1418 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index 462330e92..1f6ec6f17 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -86,6 +86,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } + public static string SwitchOverNullableIntNullCaseCombined(int? i) + { + switch (i) { + case null: + case 0: + return "zero"; + case 5: + return "five"; + case 10: + return "ten"; + default: + return "large"; + } + } + public static string SwitchOverNullableIntShifted(int? i) { switch (i + 5) { @@ -102,6 +117,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } + public static string SwitchOverNullableIntShiftedNullCaseCombined(int? i) + { + switch (i + 5) { + case null: + case 0: + return "zero"; + case 5: + return "five"; + case 10: + return "ten"; + default: + return "large"; + } + } + public static string SwitchOverNullableIntNoNullCase(int? i) { switch (i) { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il index e4f06b1f6..40a21bc93 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly yojdxjhu +.assembly '4doqvnxq' { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module yojdxjhu.dll -// MVID: {7A918135-BE28-4F14-9240-86E34BA33540} +.module '4doqvnxq.dll' +// MVID: {5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF} .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: 0x032F0000 +// Image base: 0x03320000 // =============== CLASS MEMBERS DECLARATION =================== @@ -96,7 +96,7 @@ .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { - // Code size 224 (0xe0) + // Code size 209 (0xd1) .maxstack 2 .locals init (string V_0, int32 V_1) @@ -112,112 +112,100 @@ IL_0018: stloc.1 IL_0019: ldloc.1 IL_001a: ldc.i4.4 - IL_001b: bgt.s IL_004f + IL_001b: bgt.s IL_004c IL_001d: ldloc.1 IL_001e: ldc.i4 0xff676980 - IL_0023: beq.s IL_0072 + IL_0023: beq.s IL_006f IL_0025: ldloc.1 IL_0026: ldc.i4.s -100 - IL_0028: beq.s IL_007b + IL_0028: beq.s IL_0077 IL_002a: ldloc.1 IL_002b: ldc.i4.m1 IL_002c: sub IL_002d: switch ( - IL_0084, - IL_008d, - IL_0096, - IL_009f, - IL_00d5, - IL_00a8) - IL_004a: br IL_00d5 - - IL_004f: ldloc.1 - IL_0050: ldc.i4.s 100 - IL_0052: beq.s IL_00b1 - - IL_0054: ldloc.1 - IL_0055: ldc.i4 0x2710 - IL_005a: sub - IL_005b: switch ( - IL_00ba, - IL_00c3) - IL_0068: ldloc.1 - IL_0069: ldc.i4 0x7fffffff - IL_006e: beq.s IL_00cc - - IL_0070: br.s IL_00d5 - - IL_0072: nop - IL_0073: ldstr "-10 mln" - IL_0078: stloc.0 - IL_0079: br.s IL_00de - - IL_007b: nop - IL_007c: ldstr "-hundred" - IL_0081: stloc.0 - IL_0082: br.s IL_00de - - IL_0084: nop - IL_0085: ldstr "-1" - IL_008a: stloc.0 - IL_008b: br.s IL_00de - - IL_008d: nop - IL_008e: ldstr "0" - IL_0093: stloc.0 - IL_0094: br.s IL_00de - - IL_0096: nop - IL_0097: ldstr "1" + IL_007f, + IL_0087, + IL_008f, + IL_0097, + IL_00c7, + IL_009f) + IL_004a: br.s IL_00c7 + + IL_004c: ldloc.1 + IL_004d: ldc.i4.s 100 + IL_004f: beq.s IL_00a7 + + IL_0051: ldloc.1 + IL_0052: ldc.i4 0x2710 + IL_0057: sub + IL_0058: switch ( + IL_00af, + IL_00b7) + IL_0065: ldloc.1 + IL_0066: ldc.i4 0x7fffffff + IL_006b: beq.s IL_00bf + + IL_006d: br.s IL_00c7 + + IL_006f: ldstr "-10 mln" + IL_0074: stloc.0 + IL_0075: br.s IL_00cf + + IL_0077: ldstr "-hundred" + IL_007c: stloc.0 + IL_007d: br.s IL_00cf + + IL_007f: ldstr "-1" + IL_0084: stloc.0 + IL_0085: br.s IL_00cf + + IL_0087: ldstr "0" + IL_008c: stloc.0 + IL_008d: br.s IL_00cf + + IL_008f: ldstr "1" + IL_0094: stloc.0 + IL_0095: br.s IL_00cf + + IL_0097: ldstr "2" IL_009c: stloc.0 - IL_009d: br.s IL_00de - - IL_009f: nop - IL_00a0: ldstr "2" - IL_00a5: stloc.0 - IL_00a6: br.s IL_00de - - IL_00a8: nop - IL_00a9: ldstr "4" - IL_00ae: stloc.0 - IL_00af: br.s IL_00de - - IL_00b1: nop - IL_00b2: ldstr "hundred" - IL_00b7: stloc.0 - IL_00b8: br.s IL_00de - - IL_00ba: nop - IL_00bb: ldstr "ten thousand" - IL_00c0: stloc.0 - IL_00c1: br.s IL_00de - - IL_00c3: nop - IL_00c4: ldstr "ten thousand and one" - IL_00c9: stloc.0 - IL_00ca: br.s IL_00de - - IL_00cc: nop - IL_00cd: ldstr "int.MaxValue" - IL_00d2: stloc.0 - IL_00d3: br.s IL_00de - - IL_00d5: nop - IL_00d6: ldstr "something else" - IL_00db: stloc.0 - IL_00dc: br.s IL_00de - - IL_00de: ldloc.0 - IL_00df: ret + IL_009d: br.s IL_00cf + + IL_009f: ldstr "4" + IL_00a4: stloc.0 + IL_00a5: br.s IL_00cf + + IL_00a7: ldstr "hundred" + IL_00ac: stloc.0 + IL_00ad: br.s IL_00cf + + IL_00af: ldstr "ten thousand" + IL_00b4: stloc.0 + IL_00b5: br.s IL_00cf + + IL_00b7: ldstr "ten thousand and one" + IL_00bc: stloc.0 + IL_00bd: br.s IL_00cf + + IL_00bf: ldstr "int.MaxValue" + IL_00c4: stloc.0 + IL_00c5: br.s IL_00cf + + IL_00c7: ldstr "something else" + IL_00cc: stloc.0 + IL_00cd: br.s IL_00cf + + IL_00cf: ldloc.0 + IL_00d0: ret } // end of method Switch::SparseIntegerSwitch .method public hidebysig static string SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed { - // Code size 79 (0x4f) + // Code size 74 (0x4a) .maxstack 2 .locals init (string V_0, int32 V_1) @@ -231,51 +219,95 @@ IL_0011: ldloc.1 IL_0012: ldc.i4.0 - IL_0013: beq.s IL_0029 + IL_0013: beq.s IL_0028 IL_0015: ldloc.1 IL_0016: ldc.i4.5 - IL_0017: beq.s IL_0032 + IL_0017: beq.s IL_0030 IL_0019: ldloc.1 IL_001a: ldc.i4.s 10 - IL_001c: beq.s IL_003b + IL_001c: beq.s IL_0038 - IL_001e: br.s IL_0044 + IL_001e: br.s IL_0040 - IL_0020: nop - IL_0021: ldstr "null" - IL_0026: stloc.0 - IL_0027: br.s IL_004d + IL_0020: ldstr "null" + IL_0025: stloc.0 + IL_0026: br.s IL_0048 - IL_0029: nop - IL_002a: ldstr "zero" - IL_002f: stloc.0 - IL_0030: br.s IL_004d + IL_0028: ldstr "zero" + IL_002d: stloc.0 + IL_002e: br.s IL_0048 - IL_0032: nop - IL_0033: ldstr "five" - IL_0038: stloc.0 - IL_0039: br.s IL_004d + IL_0030: ldstr "five" + IL_0035: stloc.0 + IL_0036: br.s IL_0048 - IL_003b: nop - IL_003c: ldstr "ten" - IL_0041: stloc.0 - IL_0042: br.s IL_004d + IL_0038: ldstr "ten" + IL_003d: stloc.0 + IL_003e: br.s IL_0048 - IL_0044: nop - IL_0045: ldstr "large" - IL_004a: stloc.0 - IL_004b: br.s IL_004d + IL_0040: ldstr "large" + IL_0045: stloc.0 + IL_0046: br.s IL_0048 - IL_004d: ldloc.0 - IL_004e: ret + IL_0048: ldloc.0 + IL_0049: ret } // end of method Switch::SwitchOverNullableInt + .method public hidebysig static string + SwitchOverNullableIntNullCaseCombined(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 66 (0x42) + .maxstack 2 + .locals init (string V_0, + int32 V_1) + IL_0000: nop + IL_0001: ldarga.s i + IL_0003: dup + IL_0004: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0009: stloc.1 + IL_000a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000f: brfalse.s IL_0020 + + IL_0011: ldloc.1 + IL_0012: ldc.i4.0 + IL_0013: beq.s IL_0020 + + IL_0015: ldloc.1 + IL_0016: ldc.i4.5 + IL_0017: beq.s IL_0028 + + IL_0019: ldloc.1 + IL_001a: ldc.i4.s 10 + IL_001c: beq.s IL_0030 + + IL_001e: br.s IL_0038 + + IL_0020: ldstr "zero" + IL_0025: stloc.0 + IL_0026: br.s IL_0040 + + IL_0028: ldstr "five" + IL_002d: stloc.0 + IL_002e: br.s IL_0040 + + IL_0030: ldstr "ten" + IL_0035: stloc.0 + IL_0036: br.s IL_0040 + + IL_0038: ldstr "large" + IL_003d: stloc.0 + IL_003e: br.s IL_0040 + + IL_0040: ldloc.0 + IL_0041: ret + } // end of method Switch::SwitchOverNullableIntNullCaseCombined + .method public hidebysig static string SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed { - // Code size 117 (0x75) + // Code size 112 (0x70) .maxstack 2 .locals init (string V_0, valuetype [mscorlib]System.Nullable`1 V_1, @@ -309,51 +341,115 @@ IL_0037: ldloc.3 IL_0038: ldc.i4.0 - IL_0039: beq.s IL_004f + IL_0039: beq.s IL_004e IL_003b: ldloc.3 IL_003c: ldc.i4.5 - IL_003d: beq.s IL_0058 + IL_003d: beq.s IL_0056 IL_003f: ldloc.3 IL_0040: ldc.i4.s 10 - IL_0042: beq.s IL_0061 + IL_0042: beq.s IL_005e - IL_0044: br.s IL_006a + IL_0044: br.s IL_0066 - IL_0046: nop - IL_0047: ldstr "null" - IL_004c: stloc.0 - IL_004d: br.s IL_0073 + IL_0046: ldstr "null" + IL_004b: stloc.0 + IL_004c: br.s IL_006e - IL_004f: nop - IL_0050: ldstr "zero" - IL_0055: stloc.0 - IL_0056: br.s IL_0073 + IL_004e: ldstr "zero" + IL_0053: stloc.0 + IL_0054: br.s IL_006e - IL_0058: nop - IL_0059: ldstr "five" - IL_005e: stloc.0 - IL_005f: br.s IL_0073 - - IL_0061: nop - IL_0062: ldstr "ten" - IL_0067: stloc.0 - IL_0068: br.s IL_0073 - - IL_006a: nop - IL_006b: ldstr "large" - IL_0070: stloc.0 - IL_0071: br.s IL_0073 - - IL_0073: ldloc.0 - IL_0074: ret + IL_0056: ldstr "five" + IL_005b: stloc.0 + IL_005c: br.s IL_006e + + IL_005e: ldstr "ten" + IL_0063: stloc.0 + IL_0064: br.s IL_006e + + IL_0066: ldstr "large" + IL_006b: stloc.0 + IL_006c: br.s IL_006e + + IL_006e: ldloc.0 + IL_006f: ret } // end of method Switch::SwitchOverNullableIntShifted + .method public hidebysig static string + SwitchOverNullableIntShiftedNullCaseCombined(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 104 (0x68) + .maxstack 2 + .locals init (string V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloca.s V_1 + IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000a: brtrue.s IL_0017 + + IL_000c: ldloca.s V_2 + IL_000e: initobj valuetype [mscorlib]System.Nullable`1 + IL_0014: ldloc.2 + IL_0015: br.s IL_0025 + + IL_0017: ldloca.s V_1 + IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001e: ldc.i4.5 + IL_001f: add + IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0025: nop + IL_0026: stloc.2 + IL_0027: ldloca.s V_2 + IL_0029: dup + IL_002a: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_002f: stloc.3 + IL_0030: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0035: brfalse.s IL_0046 + + IL_0037: ldloc.3 + IL_0038: ldc.i4.0 + IL_0039: beq.s IL_0046 + + IL_003b: ldloc.3 + IL_003c: ldc.i4.5 + IL_003d: beq.s IL_004e + + IL_003f: ldloc.3 + IL_0040: ldc.i4.s 10 + IL_0042: beq.s IL_0056 + + IL_0044: br.s IL_005e + + IL_0046: ldstr "zero" + IL_004b: stloc.0 + IL_004c: br.s IL_0066 + + IL_004e: ldstr "five" + IL_0053: stloc.0 + IL_0054: br.s IL_0066 + + IL_0056: ldstr "ten" + IL_005b: stloc.0 + IL_005c: br.s IL_0066 + + IL_005e: ldstr "large" + IL_0063: stloc.0 + IL_0064: br.s IL_0066 + + IL_0066: ldloc.0 + IL_0067: ret + } // end of method Switch::SwitchOverNullableIntShiftedNullCaseCombined + .method public hidebysig static string SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed { - // Code size 70 (0x46) + // Code size 66 (0x42) .maxstack 2 .locals init (string V_0, int32 V_1) @@ -363,7 +459,7 @@ IL_0004: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() IL_0009: stloc.1 IL_000a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_000f: brfalse.s IL_003b + IL_000f: brfalse.s IL_0038 IL_0011: ldloc.1 IL_0012: ldc.i4.0 @@ -371,42 +467,38 @@ IL_0015: ldloc.1 IL_0016: ldc.i4.5 - IL_0017: beq.s IL_0029 + IL_0017: beq.s IL_0028 IL_0019: ldloc.1 IL_001a: ldc.i4.s 10 - IL_001c: beq.s IL_0032 + IL_001c: beq.s IL_0030 - IL_001e: br.s IL_003b + IL_001e: br.s IL_0038 - IL_0020: nop - IL_0021: ldstr "zero" - IL_0026: stloc.0 - IL_0027: br.s IL_0044 + IL_0020: ldstr "zero" + IL_0025: stloc.0 + IL_0026: br.s IL_0040 - IL_0029: nop - IL_002a: ldstr "five" - IL_002f: stloc.0 - IL_0030: br.s IL_0044 + IL_0028: ldstr "five" + IL_002d: stloc.0 + IL_002e: br.s IL_0040 - IL_0032: nop - IL_0033: ldstr "ten" - IL_0038: stloc.0 - IL_0039: br.s IL_0044 + IL_0030: ldstr "ten" + IL_0035: stloc.0 + IL_0036: br.s IL_0040 - IL_003b: nop - IL_003c: ldstr "other" - IL_0041: stloc.0 - IL_0042: br.s IL_0044 + IL_0038: ldstr "other" + IL_003d: stloc.0 + IL_003e: br.s IL_0040 - IL_0044: ldloc.0 - IL_0045: ret + IL_0040: ldloc.0 + IL_0041: ret } // end of method Switch::SwitchOverNullableIntNoNullCase .method public hidebysig static string SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed { - // Code size 108 (0x6c) + // Code size 104 (0x68) .maxstack 2 .locals init (string V_0, valuetype [mscorlib]System.Nullable`1 V_1, @@ -436,7 +528,7 @@ IL_002a: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() IL_002f: stloc.3 IL_0030: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_0035: brfalse.s IL_0061 + IL_0035: brfalse.s IL_005e IL_0037: ldloc.3 IL_0038: ldc.i4.0 @@ -444,41 +536,37 @@ IL_003b: ldloc.3 IL_003c: ldc.i4.5 - IL_003d: beq.s IL_004f + IL_003d: beq.s IL_004e IL_003f: ldloc.3 IL_0040: ldc.i4.s 10 - IL_0042: beq.s IL_0058 + IL_0042: beq.s IL_0056 - IL_0044: br.s IL_0061 + IL_0044: br.s IL_005e - IL_0046: nop - IL_0047: ldstr "zero" - IL_004c: stloc.0 - IL_004d: br.s IL_006a + IL_0046: ldstr "zero" + IL_004b: stloc.0 + IL_004c: br.s IL_0066 - IL_004f: nop - IL_0050: ldstr "five" - IL_0055: stloc.0 - IL_0056: br.s IL_006a + IL_004e: ldstr "five" + IL_0053: stloc.0 + IL_0054: br.s IL_0066 - IL_0058: nop - IL_0059: ldstr "ten" - IL_005e: stloc.0 - IL_005f: br.s IL_006a + IL_0056: ldstr "ten" + IL_005b: stloc.0 + IL_005c: br.s IL_0066 - IL_0061: nop - IL_0062: ldstr "other" - IL_0067: stloc.0 - IL_0068: br.s IL_006a + IL_005e: ldstr "other" + IL_0063: stloc.0 + IL_0064: br.s IL_0066 - IL_006a: ldloc.0 - IL_006b: ret + IL_0066: ldloc.0 + IL_0067: ret } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted .method public hidebysig static void SwitchOverInt(int32 i) cil managed { - // Code size 151 (0x97) + // Code size 144 (0x90) .maxstack 2 .locals init (int32 V_0) IL_0000: nop @@ -494,13 +582,13 @@ IL_000c: ldloc.0 IL_000d: ldc.i4.5 - IL_000e: beq.s IL_0042 + IL_000e: beq.s IL_0041 IL_0010: ldloc.0 IL_0011: ldc.i4.s 10 - IL_0013: beq.s IL_0050 + IL_0013: beq.s IL_004e - IL_0015: br.s IL_0096 + IL_0015: br.s IL_008f IL_0017: ldloc.0 IL_0018: ldc.i4.s 20 @@ -508,73 +596,66 @@ IL_001c: ldloc.0 IL_001d: ldc.i4.s 15 - IL_001f: beq.s IL_005e + IL_001f: beq.s IL_005b IL_0021: ldloc.0 IL_0022: ldc.i4.s 20 - IL_0024: beq.s IL_006c + IL_0024: beq.s IL_0068 - IL_0026: br.s IL_0096 + IL_0026: br.s IL_008f IL_0028: ldloc.0 IL_0029: ldc.i4.s 25 - IL_002b: beq.s IL_007a + IL_002b: beq.s IL_0075 IL_002d: ldloc.0 IL_002e: ldc.i4.s 30 - IL_0030: beq.s IL_0088 + IL_0030: beq.s IL_0082 - IL_0032: br.s IL_0096 + IL_0032: br.s IL_008f - IL_0034: nop - IL_0035: ldstr "zero" - IL_003a: call void [mscorlib]System.Console::WriteLine(string) - IL_003f: nop - IL_0040: br.s IL_0096 + IL_0034: ldstr "zero" + IL_0039: call void [mscorlib]System.Console::WriteLine(string) + IL_003e: nop + IL_003f: br.s IL_008f - IL_0042: nop - IL_0043: ldstr "five" - IL_0048: call void [mscorlib]System.Console::WriteLine(string) - IL_004d: nop - IL_004e: br.s IL_0096 - - IL_0050: nop - IL_0051: ldstr "ten" - IL_0056: call void [mscorlib]System.Console::WriteLine(string) - IL_005b: nop - IL_005c: br.s IL_0096 - - IL_005e: nop - IL_005f: ldstr "fifteen" - IL_0064: call void [mscorlib]System.Console::WriteLine(string) - IL_0069: nop - IL_006a: br.s IL_0096 - - IL_006c: nop - IL_006d: ldstr "twenty" - IL_0072: call void [mscorlib]System.Console::WriteLine(string) - IL_0077: nop - IL_0078: br.s IL_0096 + IL_0041: ldstr "five" + IL_0046: call void [mscorlib]System.Console::WriteLine(string) + IL_004b: nop + IL_004c: br.s IL_008f - IL_007a: nop - IL_007b: ldstr "twenty-five" - IL_0080: call void [mscorlib]System.Console::WriteLine(string) - IL_0085: nop - IL_0086: br.s IL_0096 - - IL_0088: nop - IL_0089: ldstr "thirty" - IL_008e: call void [mscorlib]System.Console::WriteLine(string) - IL_0093: nop - IL_0094: br.s IL_0096 - - IL_0096: ret + IL_004e: ldstr "ten" + IL_0053: call void [mscorlib]System.Console::WriteLine(string) + IL_0058: nop + IL_0059: br.s IL_008f + + IL_005b: ldstr "fifteen" + IL_0060: call void [mscorlib]System.Console::WriteLine(string) + IL_0065: nop + IL_0066: br.s IL_008f + + IL_0068: ldstr "twenty" + IL_006d: call void [mscorlib]System.Console::WriteLine(string) + IL_0072: nop + IL_0073: br.s IL_008f + + IL_0075: ldstr "twenty-five" + IL_007a: call void [mscorlib]System.Console::WriteLine(string) + IL_007f: nop + IL_0080: br.s IL_008f + + IL_0082: ldstr "thirty" + IL_0087: call void [mscorlib]System.Console::WriteLine(string) + IL_008c: nop + IL_008d: br.s IL_008f + + IL_008f: ret } // end of method Switch::SwitchOverInt .method public hidebysig static string ShortSwitchOverString(string text) cil managed { - // Code size 102 (0x66) + // Code size 98 (0x62) .maxstack 2 .locals init (string V_0, string V_1) @@ -588,7 +669,7 @@ IL_0012: ldarg.0 IL_0013: stloc.1 IL_0014: ldloc.1 - IL_0015: brfalse.s IL_005b + IL_0015: brfalse.s IL_0058 IL_0017: ldloc.1 IL_0018: ldstr "First case" @@ -600,44 +681,40 @@ IL_0025: ldstr "Second case" IL_002a: call bool [mscorlib]System.String::op_Equality(string, string) - IL_002f: brtrue.s IL_0049 + IL_002f: brtrue.s IL_0048 IL_0031: ldloc.1 IL_0032: ldstr "Third case" IL_0037: call bool [mscorlib]System.String::op_Equality(string, string) - IL_003c: brtrue.s IL_0052 + IL_003c: brtrue.s IL_0050 - IL_003e: br.s IL_005b + IL_003e: br.s IL_0058 - IL_0040: nop - IL_0041: ldstr "Text1" - IL_0046: stloc.0 - IL_0047: br.s IL_0064 - - IL_0049: nop - IL_004a: ldstr "Text2" - IL_004f: stloc.0 - IL_0050: br.s IL_0064 - - IL_0052: nop - IL_0053: ldstr "Text3" - IL_0058: stloc.0 - IL_0059: br.s IL_0064 - - IL_005b: nop - IL_005c: ldstr "Default" - IL_0061: stloc.0 - IL_0062: br.s IL_0064 - - IL_0064: ldloc.0 - IL_0065: ret + IL_0040: ldstr "Text1" + IL_0045: stloc.0 + IL_0046: br.s IL_0060 + + IL_0048: ldstr "Text2" + IL_004d: stloc.0 + IL_004e: br.s IL_0060 + + IL_0050: ldstr "Text3" + IL_0055: stloc.0 + IL_0056: br.s IL_0060 + + IL_0058: ldstr "Default" + IL_005d: stloc.0 + IL_005e: br.s IL_0060 + + IL_0060: ldloc.0 + IL_0061: ret } // end of method Switch::ShortSwitchOverString .method public hidebysig static string ShortSwitchOverStringWithNullCase(string text) cil managed { - // Code size 89 (0x59) + // Code size 85 (0x55) .maxstack 2 .locals init (string V_0, string V_1) @@ -651,7 +728,7 @@ IL_0012: ldarg.0 IL_0013: stloc.1 IL_0014: ldloc.1 - IL_0015: brfalse.s IL_0045 + IL_0015: brfalse.s IL_0043 IL_0017: ldloc.1 IL_0018: ldstr "First case" @@ -663,38 +740,34 @@ IL_0025: ldstr "Second case" IL_002a: call bool [mscorlib]System.String::op_Equality(string, string) - IL_002f: brtrue.s IL_003c + IL_002f: brtrue.s IL_003b - IL_0031: br.s IL_004e + IL_0031: br.s IL_004b - IL_0033: nop - IL_0034: ldstr "Text1" - IL_0039: stloc.0 - IL_003a: br.s IL_0057 + IL_0033: ldstr "Text1" + IL_0038: stloc.0 + IL_0039: br.s IL_0053 - IL_003c: nop - IL_003d: ldstr "Text2" - IL_0042: stloc.0 - IL_0043: br.s IL_0057 + IL_003b: ldstr "Text2" + IL_0040: stloc.0 + IL_0041: br.s IL_0053 - IL_0045: nop - IL_0046: ldstr "null" - IL_004b: stloc.0 - IL_004c: br.s IL_0057 + IL_0043: ldstr "null" + IL_0048: stloc.0 + IL_0049: br.s IL_0053 - IL_004e: nop - IL_004f: ldstr "Default" - IL_0054: stloc.0 - IL_0055: br.s IL_0057 + IL_004b: ldstr "Default" + IL_0050: stloc.0 + IL_0051: br.s IL_0053 - IL_0057: ldloc.0 - IL_0058: ret + IL_0053: ldloc.0 + IL_0054: ret } // end of method Switch::ShortSwitchOverStringWithNullCase .method public hidebysig static string SwitchOverString1(string text) cil managed { - // Code size 255 (0xff) + // Code size 247 (0xf7) .maxstack 4 .locals init (string V_0, string V_1, @@ -709,10 +782,10 @@ IL_0012: ldarg.0 IL_0013: stloc.1 IL_0014: ldloc.1 - IL_0015: brfalse IL_00ef + IL_0015: brfalse IL_00e9 IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x6000009-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000b-1' IL_0021: brtrue.s IL_0084 IL_0023: ldc.i4.7 @@ -753,74 +826,66 @@ IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007d: volatile. - IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x6000009-1' + IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000b-1' IL_0084: volatile. - IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x6000009-1' + IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000b-1' IL_008b: ldloc.1 IL_008c: ldloca.s V_2 IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, !1&) - IL_0093: brfalse.s IL_00f4 + IL_0093: brfalse.s IL_00ed IL_0095: ldloc.2 IL_0096: switch ( IL_00b9, - IL_00c2, - IL_00c2, - IL_00cb, - IL_00d4, - IL_00dd, - IL_00e6) - IL_00b7: br.s IL_00f4 - - IL_00b9: nop - IL_00ba: ldstr "Text1" - IL_00bf: stloc.0 - IL_00c0: br.s IL_00fd - - IL_00c2: nop - IL_00c3: ldstr "Text2" - IL_00c8: stloc.0 - IL_00c9: br.s IL_00fd - - IL_00cb: nop - IL_00cc: ldstr "Text3" - IL_00d1: stloc.0 - IL_00d2: br.s IL_00fd - - IL_00d4: nop - IL_00d5: ldstr "Text4" - IL_00da: stloc.0 - IL_00db: br.s IL_00fd - - IL_00dd: nop - IL_00de: ldstr "Text5" - IL_00e3: stloc.0 - IL_00e4: br.s IL_00fd - - IL_00e6: nop - IL_00e7: ldstr "Text6" - IL_00ec: stloc.0 - IL_00ed: br.s IL_00fd - - IL_00ef: nop - IL_00f0: ldnull - IL_00f1: stloc.0 - IL_00f2: br.s IL_00fd - - IL_00f4: nop - IL_00f5: ldstr "Default" - IL_00fa: stloc.0 - IL_00fb: br.s IL_00fd - - IL_00fd: ldloc.0 - IL_00fe: ret + IL_00c1, + IL_00c1, + IL_00c9, + IL_00d1, + IL_00d9, + IL_00e1) + IL_00b7: br.s IL_00ed + + IL_00b9: ldstr "Text1" + IL_00be: stloc.0 + IL_00bf: br.s IL_00f5 + + IL_00c1: ldstr "Text2" + IL_00c6: stloc.0 + IL_00c7: br.s IL_00f5 + + IL_00c9: ldstr "Text3" + IL_00ce: stloc.0 + IL_00cf: br.s IL_00f5 + + IL_00d1: ldstr "Text4" + IL_00d6: stloc.0 + IL_00d7: br.s IL_00f5 + + IL_00d9: ldstr "Text5" + IL_00de: stloc.0 + IL_00df: br.s IL_00f5 + + IL_00e1: ldstr "Text6" + IL_00e6: stloc.0 + IL_00e7: br.s IL_00f5 + + IL_00e9: ldnull + IL_00ea: stloc.0 + IL_00eb: br.s IL_00f5 + + IL_00ed: ldstr "Default" + IL_00f2: stloc.0 + IL_00f3: br.s IL_00f5 + + IL_00f5: ldloc.0 + IL_00f6: ret } // end of method Switch::SwitchOverString1 .method public hidebysig static string SwitchOverString2() cil managed { - // Code size 366 (0x16e) + // Code size 354 (0x162) .maxstack 4 .locals init (string V_0, string V_1, @@ -832,10 +897,10 @@ IL_000c: call string [mscorlib]System.Environment::get_UserName() IL_0011: stloc.1 IL_0012: ldloc.1 - IL_0013: brfalse IL_0163 + IL_0013: brfalse IL_0158 IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x600000a-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000c-1' IL_001f: brtrue IL_00b8 IL_0024: ldc.i4.s 11 @@ -896,98 +961,86 @@ IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00b1: volatile. - IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x600000a-1' + IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000c-1' IL_00b8: volatile. - IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x600000a-1' + IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000c-1' IL_00bf: ldloc.1 IL_00c0: ldloca.s V_2 IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, !1&) - IL_00c7: brfalse IL_0163 + IL_00c7: brfalse IL_0158 IL_00cc: ldloc.2 IL_00cd: switch ( IL_0100, - IL_0109, - IL_0112, - IL_011b, - IL_0124, - IL_012d, - IL_0136, - IL_013f, + IL_0108, + IL_0110, + IL_0118, + IL_0120, + IL_0128, + IL_0130, + IL_0138, + IL_0140, IL_0148, - IL_0151, - IL_015a) - IL_00fe: br.s IL_0163 - - IL_0100: nop - IL_0101: ldstr "Text1" - IL_0106: stloc.0 - IL_0107: br.s IL_016c - - IL_0109: nop - IL_010a: ldstr "Text2" - IL_010f: stloc.0 - IL_0110: br.s IL_016c - - IL_0112: nop - IL_0113: ldstr "Text3" - IL_0118: stloc.0 - IL_0119: br.s IL_016c - - IL_011b: nop - IL_011c: ldstr "Text4" - IL_0121: stloc.0 - IL_0122: br.s IL_016c - - IL_0124: nop - IL_0125: ldstr "Text5" - IL_012a: stloc.0 - IL_012b: br.s IL_016c - - IL_012d: nop - IL_012e: ldstr "Text6" - IL_0133: stloc.0 - IL_0134: br.s IL_016c - - IL_0136: nop - IL_0137: ldstr "Text7" - IL_013c: stloc.0 - IL_013d: br.s IL_016c - - IL_013f: nop - IL_0140: ldstr "Text8" + IL_0150) + IL_00fe: br.s IL_0158 + + IL_0100: ldstr "Text1" + IL_0105: stloc.0 + IL_0106: br.s IL_0160 + + IL_0108: ldstr "Text2" + IL_010d: stloc.0 + IL_010e: br.s IL_0160 + + IL_0110: ldstr "Text3" + IL_0115: stloc.0 + IL_0116: br.s IL_0160 + + IL_0118: ldstr "Text4" + IL_011d: stloc.0 + IL_011e: br.s IL_0160 + + IL_0120: ldstr "Text5" + IL_0125: stloc.0 + IL_0126: br.s IL_0160 + + IL_0128: ldstr "Text6" + IL_012d: stloc.0 + IL_012e: br.s IL_0160 + + IL_0130: ldstr "Text7" + IL_0135: stloc.0 + IL_0136: br.s IL_0160 + + IL_0138: ldstr "Text8" + IL_013d: stloc.0 + IL_013e: br.s IL_0160 + + IL_0140: ldstr "Text9" IL_0145: stloc.0 - IL_0146: br.s IL_016c - - IL_0148: nop - IL_0149: ldstr "Text9" - IL_014e: stloc.0 - IL_014f: br.s IL_016c - - IL_0151: nop - IL_0152: ldstr "Text10" - IL_0157: stloc.0 - IL_0158: br.s IL_016c - - IL_015a: nop - IL_015b: ldstr "Text11" - IL_0160: stloc.0 - IL_0161: br.s IL_016c - - IL_0163: nop - IL_0164: ldstr "Default" - IL_0169: stloc.0 - IL_016a: br.s IL_016c - - IL_016c: ldloc.0 - IL_016d: ret + IL_0146: br.s IL_0160 + + IL_0148: ldstr "Text10" + IL_014d: stloc.0 + IL_014e: br.s IL_0160 + + IL_0150: ldstr "Text11" + IL_0155: stloc.0 + IL_0156: br.s IL_0160 + + IL_0158: ldstr "Default" + IL_015d: stloc.0 + IL_015e: br.s IL_0160 + + IL_0160: ldloc.0 + IL_0161: ret } // end of method Switch::SwitchOverString2 .method public hidebysig static string SwitchOverBool(bool b) cil managed { - // Code size 67 (0x43) + // Code size 64 (0x40) .maxstack 2 .locals init (string V_0, bool V_1) @@ -1003,32 +1056,29 @@ IL_0019: stloc.1 IL_001a: ldloc.1 IL_001b: switch ( - IL_0033, + IL_0032, IL_002a) - IL_0028: br.s IL_003c + IL_0028: br.s IL_003a - IL_002a: nop - IL_002b: ldsfld string [mscorlib]System.Boolean::TrueString - IL_0030: stloc.0 - IL_0031: br.s IL_0041 + IL_002a: ldsfld string [mscorlib]System.Boolean::TrueString + IL_002f: stloc.0 + IL_0030: br.s IL_003e - IL_0033: nop - IL_0034: ldsfld string [mscorlib]System.Boolean::FalseString - IL_0039: stloc.0 - IL_003a: br.s IL_0041 + IL_0032: ldsfld string [mscorlib]System.Boolean::FalseString + IL_0037: stloc.0 + IL_0038: br.s IL_003e - IL_003c: nop - IL_003d: ldnull - IL_003e: stloc.0 - IL_003f: br.s IL_0041 + IL_003a: ldnull + IL_003b: stloc.0 + IL_003c: br.s IL_003e - IL_0041: ldloc.0 - IL_0042: ret + IL_003e: ldloc.0 + IL_003f: ret } // end of method Switch::SwitchOverBool .method public hidebysig static void SwitchInLoop(int32 i) cil managed { - // Code size 132 (0x84) + // Code size 128 (0x80) .maxstack 2 .locals init (int32 V_0, bool V_1) @@ -1040,7 +1090,7 @@ object) IL_0011: call void [mscorlib]System.Console::WriteLine(string) IL_0016: nop - IL_0017: br.s IL_007f + IL_0017: br.s IL_007b IL_0019: nop IL_001a: ldarg.0 @@ -1050,53 +1100,49 @@ IL_001e: sub IL_001f: switch ( IL_0036, - IL_0044, - IL_0060, - IL_0052) - IL_0034: br.s IL_0060 - - IL_0036: nop - IL_0037: ldstr "one" - IL_003c: call void [mscorlib]System.Console::WriteLine(string) - IL_0041: nop - IL_0042: br.s IL_0079 - - IL_0044: nop - IL_0045: ldstr "two" - IL_004a: call void [mscorlib]System.Console::WriteLine(string) - IL_004f: nop - IL_0050: br.s IL_0079 - - IL_0052: nop - IL_0053: ldstr "four" - IL_0058: call void [mscorlib]System.Console::WriteLine(string) - IL_005d: nop - IL_005e: br.s IL_0083 - - IL_0060: nop - IL_0061: ldstr "default" - IL_0066: call void [mscorlib]System.Console::WriteLine(string) - IL_006b: nop - IL_006c: ldstr "more code" - IL_0071: call void [mscorlib]System.Console::WriteLine(string) - IL_0076: nop - IL_0077: br.s IL_0083 - - IL_0079: ldarg.0 - IL_007a: ldc.i4.1 - IL_007b: add - IL_007c: starg.s i - IL_007e: nop - IL_007f: ldc.i4.1 - IL_0080: stloc.1 - IL_0081: br.s IL_0019 + IL_0043, + IL_005d, + IL_0050) + IL_0034: br.s IL_005d + + IL_0036: ldstr "one" + IL_003b: call void [mscorlib]System.Console::WriteLine(string) + IL_0040: nop + IL_0041: br.s IL_0075 + + IL_0043: ldstr "two" + IL_0048: call void [mscorlib]System.Console::WriteLine(string) + IL_004d: nop + IL_004e: br.s IL_0075 + + IL_0050: ldstr "four" + IL_0055: call void [mscorlib]System.Console::WriteLine(string) + IL_005a: nop + IL_005b: br.s IL_007f + + IL_005d: ldstr "default" + IL_0062: call void [mscorlib]System.Console::WriteLine(string) + IL_0067: nop + IL_0068: ldstr "more code" + IL_006d: call void [mscorlib]System.Console::WriteLine(string) + IL_0072: nop + IL_0073: br.s IL_007f - IL_0083: ret + IL_0075: ldarg.0 + IL_0076: ldc.i4.1 + IL_0077: add + IL_0078: starg.s i + IL_007a: nop + IL_007b: ldc.i4.1 + IL_007c: stloc.1 + IL_007d: br.s IL_0019 + + IL_007f: ret } // end of method Switch::SwitchInLoop .method public hidebysig static void SwitchWithGoto(int32 i) cil managed { - // Code size 133 (0x85) + // Code size 128 (0x80) .maxstack 2 .locals init (int32 V_0) IL_0000: nop @@ -1114,45 +1160,40 @@ IL_001b: sub IL_001c: switch ( IL_0033, - IL_0041, - IL_004f, - IL_005d) - IL_0031: br.s IL_006b + IL_0040, + IL_004d, + IL_005a) + IL_0031: br.s IL_0067 + + IL_0033: ldstr "one" + IL_0038: call void [mscorlib]System.Console::WriteLine(string) + IL_003d: nop + IL_003e: br.s IL_0067 + + IL_0040: ldstr "two" + IL_0045: call void [mscorlib]System.Console::WriteLine(string) + IL_004a: nop + IL_004b: br.s IL_004d - IL_0033: nop - IL_0034: ldstr "one" - IL_0039: call void [mscorlib]System.Console::WriteLine(string) - IL_003e: nop - IL_003f: br.s IL_006b + IL_004d: ldstr "three" + IL_0052: call void [mscorlib]System.Console::WriteLine(string) + IL_0057: nop + IL_0058: br.s IL_0074 - IL_0041: nop - IL_0042: ldstr "two" - IL_0047: call void [mscorlib]System.Console::WriteLine(string) - IL_004c: nop - IL_004d: br.s IL_004f + IL_005a: ldstr "four" + IL_005f: call void [mscorlib]System.Console::WriteLine(string) + IL_0064: nop + IL_0065: br.s IL_007f - IL_004f: nop - IL_0050: ldstr "three" - IL_0055: call void [mscorlib]System.Console::WriteLine(string) - IL_005a: nop - IL_005b: br.s IL_0079 - - IL_005d: nop - IL_005e: ldstr "four" - IL_0063: call void [mscorlib]System.Console::WriteLine(string) - IL_0068: nop - IL_0069: br.s IL_0084 - - IL_006b: nop - IL_006c: ldstr "default" - IL_0071: call void [mscorlib]System.Console::WriteLine(string) - IL_0076: nop - IL_0077: br.s IL_0079 - - IL_0079: ldstr "End of method" - IL_007e: call void [mscorlib]System.Console::WriteLine(string) - IL_0083: nop - IL_0084: ret + IL_0067: ldstr "default" + IL_006c: call void [mscorlib]System.Console::WriteLine(string) + IL_0071: nop + IL_0072: br.s IL_0074 + + IL_0074: ldstr "End of method" + IL_0079: call void [mscorlib]System.Console::WriteLine(string) + IL_007e: nop + IL_007f: ret } // end of method Switch::SwitchWithGoto .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] @@ -1173,7 +1214,7 @@ .method public hidebysig static void SwitchOnStringInForLoop() cil managed { - // Code size 330 (0x14a) + // Code size 321 (0x141) .maxstack 4 .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, class [mscorlib]System.Collections.Generic.List`1 V_1, @@ -1192,7 +1233,7 @@ IL_0012: stloc.2 IL_0013: ldc.i4.0 IL_0014: stloc.3 - IL_0015: br IL_013a + IL_0015: br IL_0131 IL_001a: nop IL_001b: ldloc.2 @@ -1204,10 +1245,10 @@ IL_0027: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() IL_002c: stloc.s V_5 IL_002e: ldloc.s V_5 - IL_0030: brfalse IL_0129 + IL_0030: brfalse IL_0121 IL_0035: volatile. - IL_0037: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x600000f-1' + IL_0037: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x6000011-1' IL_003c: brtrue.s IL_0093 IL_003e: ldc.i4.6 @@ -1243,103 +1284,97 @@ IL_0087: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_008c: volatile. - IL_008e: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x600000f-1' + IL_008e: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x6000011-1' IL_0093: volatile. - IL_0095: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7A918135-BE28-4F14-9240-86E34BA33540}'::'$$method0x600000f-1' + IL_0095: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x6000011-1' IL_009a: ldloc.s V_5 IL_009c: ldloca.s V_6 IL_009e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, !1&) - IL_00a3: brfalse IL_0129 - - IL_00a8: ldloc.s V_6 - IL_00aa: switch ( - IL_00c9, - IL_00de, - IL_00f3, - IL_0108, - IL_011d, - IL_011d) - IL_00c7: br.s IL_0129 - - IL_00c9: nop - IL_00ca: ldloc.s V_4 - IL_00cc: ldc.i4.1 - IL_00cd: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00d2: nop - IL_00d3: ldloc.0 - IL_00d4: ldloc.s V_4 - IL_00d6: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00db: nop - IL_00dc: br.s IL_0135 - - IL_00de: nop - IL_00df: ldloc.s V_4 - IL_00e1: ldc.i4.2 - IL_00e2: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00e7: nop - IL_00e8: ldloc.0 - IL_00e9: ldloc.s V_4 - IL_00eb: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00f0: nop - IL_00f1: br.s IL_0135 - - IL_00f3: nop - IL_00f4: ldloc.s V_4 - IL_00f6: ldc.i4.3 - IL_00f7: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00fc: nop - IL_00fd: ldloc.0 - IL_00fe: ldloc.s V_4 - IL_0100: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_0105: nop - IL_0106: br.s IL_0135 - - IL_0108: nop - IL_0109: ldloc.s V_4 - IL_010b: ldc.i4.4 - IL_010c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_0111: nop - IL_0112: ldloc.0 - IL_0113: ldloc.s V_4 - IL_0115: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_011a: nop - IL_011b: br.s IL_0135 - - IL_011d: nop - IL_011e: ldloc.0 - IL_011f: ldloc.s V_4 - IL_0121: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_0126: nop - IL_0127: br.s IL_0135 - + IL_00a3: brfalse.s IL_0121 + + IL_00a5: ldloc.s V_6 + IL_00a7: switch ( + IL_00c6, + IL_00da, + IL_00ee, + IL_0102, + IL_0116, + IL_0116) + IL_00c4: br.s IL_0121 + + IL_00c6: ldloc.s V_4 + IL_00c8: ldc.i4.1 + IL_00c9: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00ce: nop + IL_00cf: ldloc.0 + IL_00d0: ldloc.s V_4 + IL_00d2: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00d7: nop + IL_00d8: br.s IL_012c + + IL_00da: ldloc.s V_4 + IL_00dc: ldc.i4.2 + IL_00dd: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00e2: nop + IL_00e3: ldloc.0 + IL_00e4: ldloc.s V_4 + IL_00e6: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00eb: nop + IL_00ec: br.s IL_012c + + IL_00ee: ldloc.s V_4 + IL_00f0: ldc.i4.3 + IL_00f1: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00f6: nop + IL_00f7: ldloc.0 + IL_00f8: ldloc.s V_4 + IL_00fa: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00ff: nop + IL_0100: br.s IL_012c + + IL_0102: ldloc.s V_4 + IL_0104: ldc.i4.4 + IL_0105: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_010a: nop + IL_010b: ldloc.0 + IL_010c: ldloc.s V_4 + IL_010e: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0113: nop + IL_0114: br.s IL_012c + + IL_0116: ldloc.0 + IL_0117: ldloc.s V_4 + IL_0119: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_011e: nop + IL_011f: br.s IL_012c + + IL_0121: ldloc.1 + IL_0122: ldloc.s V_4 + IL_0124: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) IL_0129: nop - IL_012a: ldloc.1 - IL_012b: ldloc.s V_4 - IL_012d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_0132: nop - IL_0133: br.s IL_0135 - - IL_0135: nop - IL_0136: ldloc.3 - IL_0137: ldc.i4.1 - IL_0138: add - IL_0139: stloc.3 - IL_013a: ldloc.3 - IL_013b: ldloc.2 - IL_013c: ldlen - IL_013d: conv.i4 - IL_013e: clt - IL_0140: stloc.s V_7 - IL_0142: ldloc.s V_7 - IL_0144: brtrue IL_001a - - IL_0149: ret + IL_012a: br.s IL_012c + + IL_012c: nop + IL_012d: ldloc.3 + IL_012e: ldc.i4.1 + IL_012f: add + IL_0130: stloc.3 + IL_0131: ldloc.3 + IL_0132: ldloc.2 + IL_0133: ldlen + IL_0134: conv.i4 + IL_0135: clt + IL_0137: stloc.s V_7 + IL_0139: ldloc.s V_7 + IL_013b: brtrue IL_001a + + IL_0140: ret } // end of method Switch::SwitchOnStringInForLoop .method public hidebysig static void SwitchWithComplexCondition(string[] args) cil managed { - // Code size 143 (0x8f) + // Code size 139 (0x8b) .maxstack 2 .locals init (string V_0) IL_0000: nop @@ -1357,7 +1392,7 @@ IL_0010: nop IL_0011: stloc.0 IL_0012: ldloc.0 - IL_0013: brfalse.s IL_0083 + IL_0013: brfalse.s IL_007f IL_0015: ldloc.0 IL_0016: ldstr "a" @@ -1369,55 +1404,51 @@ IL_0023: ldstr "b" IL_0028: call bool [mscorlib]System.String::op_Equality(string, string) - IL_002d: brtrue.s IL_0059 + IL_002d: brtrue.s IL_0058 IL_002f: ldloc.0 IL_0030: ldstr "c" IL_0035: call bool [mscorlib]System.String::op_Equality(string, string) - IL_003a: brtrue.s IL_0067 + IL_003a: brtrue.s IL_0065 IL_003c: ldloc.0 IL_003d: ldstr "d" IL_0042: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0047: brtrue.s IL_0075 - - IL_0049: br.s IL_0083 - - IL_004b: nop - IL_004c: ldstr "a" - IL_0051: call void [mscorlib]System.Console::WriteLine(string) - IL_0056: nop - IL_0057: br.s IL_0083 - - IL_0059: nop - IL_005a: ldstr "b" - IL_005f: call void [mscorlib]System.Console::WriteLine(string) - IL_0064: nop - IL_0065: br.s IL_0083 - - IL_0067: nop - IL_0068: ldstr "c" - IL_006d: call void [mscorlib]System.Console::WriteLine(string) - IL_0072: nop - IL_0073: br.s IL_0083 - - IL_0075: nop - IL_0076: ldstr "d" - IL_007b: call void [mscorlib]System.Console::WriteLine(string) - IL_0080: nop - IL_0081: br.s IL_0083 - - IL_0083: ldstr "end" - IL_0088: call void [mscorlib]System.Console::WriteLine(string) - IL_008d: nop - IL_008e: ret + IL_0047: brtrue.s IL_0072 + + IL_0049: br.s IL_007f + + IL_004b: ldstr "a" + IL_0050: call void [mscorlib]System.Console::WriteLine(string) + IL_0055: nop + IL_0056: br.s IL_007f + + IL_0058: ldstr "b" + IL_005d: call void [mscorlib]System.Console::WriteLine(string) + IL_0062: nop + IL_0063: br.s IL_007f + + IL_0065: ldstr "c" + IL_006a: call void [mscorlib]System.Console::WriteLine(string) + IL_006f: nop + IL_0070: br.s IL_007f + + IL_0072: ldstr "d" + IL_0077: call void [mscorlib]System.Console::WriteLine(string) + IL_007c: nop + IL_007d: br.s IL_007f + + IL_007f: ldstr "end" + IL_0084: call void [mscorlib]System.Console::WriteLine(string) + IL_0089: nop + IL_008a: ret } // end of method Switch::SwitchWithComplexCondition .method public hidebysig static void SwitchWithArray(string[] args) cil managed { - // Code size 130 (0x82) + // Code size 126 (0x7e) .maxstack 2 .locals init (string V_0) IL_0000: nop @@ -1426,7 +1457,7 @@ IL_0003: ldelem.ref IL_0004: stloc.0 IL_0005: ldloc.0 - IL_0006: brfalse.s IL_0076 + IL_0006: brfalse.s IL_0072 IL_0008: ldloc.0 IL_0009: ldstr "a" @@ -1438,62 +1469,58 @@ IL_0016: ldstr "b" IL_001b: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0020: brtrue.s IL_004c + IL_0020: brtrue.s IL_004b IL_0022: ldloc.0 IL_0023: ldstr "c" IL_0028: call bool [mscorlib]System.String::op_Equality(string, string) - IL_002d: brtrue.s IL_005a + IL_002d: brtrue.s IL_0058 IL_002f: ldloc.0 IL_0030: ldstr "d" IL_0035: call bool [mscorlib]System.String::op_Equality(string, string) - IL_003a: brtrue.s IL_0068 - - IL_003c: br.s IL_0076 - - IL_003e: nop - IL_003f: ldstr "a" - IL_0044: call void [mscorlib]System.Console::WriteLine(string) - IL_0049: nop - IL_004a: br.s IL_0076 - - IL_004c: nop - IL_004d: ldstr "b" - IL_0052: call void [mscorlib]System.Console::WriteLine(string) - IL_0057: nop - IL_0058: br.s IL_0076 - - IL_005a: nop - IL_005b: ldstr "c" - IL_0060: call void [mscorlib]System.Console::WriteLine(string) - IL_0065: nop - IL_0066: br.s IL_0076 - - IL_0068: nop - IL_0069: ldstr "d" - IL_006e: call void [mscorlib]System.Console::WriteLine(string) - IL_0073: nop - IL_0074: br.s IL_0076 - - IL_0076: ldstr "end" - IL_007b: call void [mscorlib]System.Console::WriteLine(string) - IL_0080: nop - IL_0081: ret + IL_003a: brtrue.s IL_0065 + + IL_003c: br.s IL_0072 + + IL_003e: ldstr "a" + IL_0043: call void [mscorlib]System.Console::WriteLine(string) + IL_0048: nop + IL_0049: br.s IL_0072 + + IL_004b: ldstr "b" + IL_0050: call void [mscorlib]System.Console::WriteLine(string) + IL_0055: nop + IL_0056: br.s IL_0072 + + IL_0058: ldstr "c" + IL_005d: call void [mscorlib]System.Console::WriteLine(string) + IL_0062: nop + IL_0063: br.s IL_0072 + + IL_0065: ldstr "d" + IL_006a: call void [mscorlib]System.Console::WriteLine(string) + IL_006f: nop + IL_0070: br.s IL_0072 + + IL_0072: ldstr "end" + IL_0077: call void [mscorlib]System.Console::WriteLine(string) + IL_007c: nop + IL_007d: ret } // end of method Switch::SwitchWithArray } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{7A918135-BE28-4F14-9240-86E34BA33540}' +.class private auto ansi '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000009-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000a-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000f-1' -} // end of class '{7A918135-BE28-4F14-9240-86E34BA33540}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000b-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000c-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000011-1' +} // end of class '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il index c951dbce9..44acd173c 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly '4wc22bae' +.assembly jfao3dmb { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module '4wc22bae.dll' -// MVID: {B84EA70D-C67F-455B-9708-0E39585F7DA1} +.module jfao3dmb.dll +// MVID: {96F356C7-71A4-48B4-BE55-B48554E94654} .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: 0x01140000 +// Image base: 0x01900000 // =============== CLASS MEMBERS DECLARATION =================== @@ -219,6 +219,46 @@ IL_003c: ret } // end of method Switch::SwitchOverNullableInt + .method public hidebysig static string + SwitchOverNullableIntNullCaseCombined(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 55 (0x37) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldarga.s i + IL_0002: dup + IL_0003: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0008: stloc.0 + IL_0009: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000e: brfalse.s IL_001f + + IL_0010: ldloc.0 + IL_0011: ldc.i4.0 + IL_0012: beq.s IL_001f + + IL_0014: ldloc.0 + IL_0015: ldc.i4.5 + IL_0016: beq.s IL_0025 + + IL_0018: ldloc.0 + IL_0019: ldc.i4.s 10 + IL_001b: beq.s IL_002b + + IL_001d: br.s IL_0031 + + IL_001f: ldstr "zero" + IL_0024: ret + + IL_0025: ldstr "five" + IL_002a: ret + + IL_002b: ldstr "ten" + IL_0030: ret + + IL_0031: ldstr "large" + IL_0036: ret + } // end of method Switch::SwitchOverNullableIntNullCaseCombined + .method public hidebysig static string SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed { @@ -282,6 +322,66 @@ IL_0061: ret } // end of method Switch::SwitchOverNullableIntShifted + .method public hidebysig static string + SwitchOverNullableIntShiftedNullCaseCombined(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 92 (0x5c) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brtrue.s IL_0016 + + IL_000b: ldloca.s V_1 + IL_000d: initobj valuetype [mscorlib]System.Nullable`1 + IL_0013: ldloc.1 + IL_0014: br.s IL_0024 + + IL_0016: ldloca.s V_0 + IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001d: ldc.i4.5 + IL_001e: add + IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0024: stloc.2 + IL_0025: ldloca.s V_2 + IL_0027: dup + IL_0028: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_002d: stloc.3 + IL_002e: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0033: brfalse.s IL_0044 + + IL_0035: ldloc.3 + IL_0036: ldc.i4.0 + IL_0037: beq.s IL_0044 + + IL_0039: ldloc.3 + IL_003a: ldc.i4.5 + IL_003b: beq.s IL_004a + + IL_003d: ldloc.3 + IL_003e: ldc.i4.s 10 + IL_0040: beq.s IL_0050 + + IL_0042: br.s IL_0056 + + IL_0044: ldstr "zero" + IL_0049: ret + + IL_004a: ldstr "five" + IL_004f: ret + + IL_0050: ldstr "ten" + IL_0055: ret + + IL_0056: ldstr "large" + IL_005b: ret + } // end of method Switch::SwitchOverNullableIntShiftedNullCaseCombined + .method public hidebysig static string SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed { @@ -570,7 +670,7 @@ IL_0013: brfalse IL_00db IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x6000009-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000b-1' IL_001f: brtrue.s IL_0082 IL_0021: ldc.i4.7 @@ -611,9 +711,9 @@ IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007b: volatile. - IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x6000009-1' + IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000b-1' IL_0082: volatile. - IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x6000009-1' + IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000b-1' IL_0089: ldloc.0 IL_008a: ldloca.s V_1 IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -671,7 +771,7 @@ IL_0011: brfalse IL_013d IL_0016: volatile. - IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x600000a-1' + IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000c-1' IL_001d: brtrue IL_00b6 IL_0022: ldc.i4.s 11 @@ -732,9 +832,9 @@ IL_00aa: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00af: volatile. - IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x600000a-1' + IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000c-1' IL_00b6: volatile. - IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x600000a-1' + IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000c-1' IL_00bd: ldloc.0 IL_00be: ldloca.s V_1 IL_00c0: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -958,7 +1058,7 @@ IL_002d: brfalse IL_0115 IL_0032: volatile. - IL_0034: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x600000f-1' + IL_0034: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x6000011-1' IL_0039: brtrue.s IL_0090 IL_003b: ldc.i4.6 @@ -994,9 +1094,9 @@ IL_0084: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_0089: volatile. - IL_008b: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x600000f-1' + IL_008b: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x6000011-1' IL_0090: volatile. - IL_0092: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{B84EA70D-C67F-455B-9708-0E39585F7DA1}'::'$$method0x600000f-1' + IL_0092: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x6000011-1' IL_0097: ldloc.s V_5 IL_0099: ldloca.s V_6 IL_009b: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1190,14 +1290,14 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{B84EA70D-C67F-455B-9708-0E39585F7DA1}' +.class private auto ansi '{96F356C7-71A4-48B4-BE55-B48554E94654}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000009-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000a-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000f-1' -} // end of class '{B84EA70D-C67F-455B-9708-0E39585F7DA1}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000b-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000c-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000011-1' +} // end of class '{96F356C7-71A4-48B4-BE55-B48554E94654}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il index 00d6cacd1..3c4b7ec5b 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {F38BF1C4-C0E5-4BAD-8838-849DFFFA97DF} +// MVID: {4366DF41-DCD0-42E1-B99D-7B67787ECEA9} .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: 0x00300000 +// Image base: 0x00690000 // =============== CLASS MEMBERS DECLARATION =================== @@ -230,6 +230,48 @@ IL_003e: ret } // end of method Switch::SwitchOverNullableInt + .method public hidebysig static string + SwitchOverNullableIntNullCaseCombined(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 57 (0x39) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brfalse.s IL_0021 + + IL_000b: ldloca.s V_0 + IL_000d: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0012: stloc.1 + IL_0013: ldloc.1 + IL_0014: brfalse.s IL_0021 + + IL_0016: ldloc.1 + IL_0017: ldc.i4.5 + IL_0018: beq.s IL_0027 + + IL_001a: ldloc.1 + IL_001b: ldc.i4.s 10 + IL_001d: beq.s IL_002d + + IL_001f: br.s IL_0033 + + IL_0021: ldstr "zero" + IL_0026: ret + + IL_0027: ldstr "five" + IL_002c: ret + + IL_002d: ldstr "ten" + IL_0032: ret + + IL_0033: ldstr "large" + IL_0038: ret + } // end of method Switch::SwitchOverNullableIntNullCaseCombined + .method public hidebysig static string SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed { @@ -292,6 +334,65 @@ IL_0061: ret } // end of method Switch::SwitchOverNullableIntShifted + .method public hidebysig static string + SwitchOverNullableIntShiftedNullCaseCombined(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 92 (0x5c) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.1 + IL_0002: ldloca.s V_1 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brtrue.s IL_0016 + + IL_000b: ldloca.s V_2 + IL_000d: initobj valuetype [mscorlib]System.Nullable`1 + IL_0013: ldloc.2 + IL_0014: br.s IL_0024 + + IL_0016: ldloca.s V_1 + IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001d: ldc.i4.5 + IL_001e: add + IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0024: stloc.0 + IL_0025: ldloca.s V_0 + IL_0027: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_002c: brfalse.s IL_0044 + + IL_002e: ldloca.s V_0 + IL_0030: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0035: stloc.3 + IL_0036: ldloc.3 + IL_0037: brfalse.s IL_0044 + + IL_0039: ldloc.3 + IL_003a: ldc.i4.5 + IL_003b: beq.s IL_004a + + IL_003d: ldloc.3 + IL_003e: ldc.i4.s 10 + IL_0040: beq.s IL_0050 + + IL_0042: br.s IL_0056 + + IL_0044: ldstr "zero" + IL_0049: ret + + IL_004a: ldstr "five" + IL_004f: ret + + IL_0050: ldstr "ten" + IL_0055: ret + + IL_0056: ldstr "large" + IL_005b: ret + } // end of method Switch::SwitchOverNullableIntShiftedNullCaseCombined + .method public hidebysig static string SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il index 0ce401e0a..47d88ae31 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {25920C54-28DD-4B8C-9EBF-16E716D0EC15} +// MVID: {0EBEAA6B-55A7-4255-9CA2-CE888E0F54BA} .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: 0x01040000 +// Image base: 0x00690000 // =============== CLASS MEMBERS DECLARATION =================== @@ -95,7 +95,7 @@ .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { - // Code size 238 (0xee) + // Code size 226 (0xe2) .maxstack 2 .locals init (int32 V_0, string V_1) @@ -121,7 +121,7 @@ IL_0027: ldloc.0 IL_0028: ldc.i4.s -100 - IL_002a: beq.s IL_0089 + IL_002a: beq.s IL_0088 IL_002c: br.s IL_002e @@ -129,13 +129,13 @@ IL_002f: ldc.i4.m1 IL_0030: sub IL_0031: switch ( - IL_0092, - IL_009b, - IL_00a4, - IL_00ad, - IL_00e3, - IL_00b6) - IL_004e: br IL_00e3 + IL_0090, + IL_0098, + IL_00a0, + IL_00a8, + IL_00d8, + IL_00b0) + IL_004e: br IL_00d8 IL_0053: ldloc.0 IL_0054: ldc.i4 0x2710 @@ -143,96 +143,84 @@ IL_005b: ldloc.0 IL_005c: ldc.i4.s 100 - IL_005e: beq.s IL_00bf + IL_005e: beq.s IL_00b8 IL_0060: br.s IL_0062 IL_0062: ldloc.0 IL_0063: ldc.i4 0x2710 - IL_0068: beq.s IL_00c8 + IL_0068: beq.s IL_00c0 - IL_006a: br.s IL_00e3 + IL_006a: br.s IL_00d8 IL_006c: ldloc.0 IL_006d: ldc.i4 0x2711 - IL_0072: beq.s IL_00d1 + IL_0072: beq.s IL_00c8 IL_0074: br.s IL_0076 IL_0076: ldloc.0 IL_0077: ldc.i4 0x7fffffff - IL_007c: beq.s IL_00da - - IL_007e: br.s IL_00e3 - - IL_0080: nop - IL_0081: ldstr "-10 mln" - IL_0086: stloc.1 - IL_0087: br.s IL_00ec - - IL_0089: nop - IL_008a: ldstr "-hundred" - IL_008f: stloc.1 - IL_0090: br.s IL_00ec - - IL_0092: nop - IL_0093: ldstr "-1" - IL_0098: stloc.1 - IL_0099: br.s IL_00ec - - IL_009b: nop - IL_009c: ldstr "0" - IL_00a1: stloc.1 - IL_00a2: br.s IL_00ec - - IL_00a4: nop - IL_00a5: ldstr "1" - IL_00aa: stloc.1 - IL_00ab: br.s IL_00ec - - IL_00ad: nop - IL_00ae: ldstr "2" - IL_00b3: stloc.1 - IL_00b4: br.s IL_00ec - - IL_00b6: nop - IL_00b7: ldstr "4" - IL_00bc: stloc.1 - IL_00bd: br.s IL_00ec - - IL_00bf: nop - IL_00c0: ldstr "hundred" + IL_007c: beq.s IL_00d0 + + IL_007e: br.s IL_00d8 + + IL_0080: ldstr "-10 mln" + IL_0085: stloc.1 + IL_0086: br.s IL_00e0 + + IL_0088: ldstr "-hundred" + IL_008d: stloc.1 + IL_008e: br.s IL_00e0 + + IL_0090: ldstr "-1" + IL_0095: stloc.1 + IL_0096: br.s IL_00e0 + + IL_0098: ldstr "0" + IL_009d: stloc.1 + IL_009e: br.s IL_00e0 + + IL_00a0: ldstr "1" + IL_00a5: stloc.1 + IL_00a6: br.s IL_00e0 + + IL_00a8: ldstr "2" + IL_00ad: stloc.1 + IL_00ae: br.s IL_00e0 + + IL_00b0: ldstr "4" + IL_00b5: stloc.1 + IL_00b6: br.s IL_00e0 + + IL_00b8: ldstr "hundred" + IL_00bd: stloc.1 + IL_00be: br.s IL_00e0 + + IL_00c0: ldstr "ten thousand" IL_00c5: stloc.1 - IL_00c6: br.s IL_00ec + IL_00c6: br.s IL_00e0 - IL_00c8: nop - IL_00c9: ldstr "ten thousand" - IL_00ce: stloc.1 - IL_00cf: br.s IL_00ec + IL_00c8: ldstr "ten thousand and one" + IL_00cd: stloc.1 + IL_00ce: br.s IL_00e0 - IL_00d1: nop - IL_00d2: ldstr "ten thousand and one" - IL_00d7: stloc.1 - IL_00d8: br.s IL_00ec - - IL_00da: nop - IL_00db: ldstr "int.MaxValue" - IL_00e0: stloc.1 - IL_00e1: br.s IL_00ec - - IL_00e3: nop - IL_00e4: ldstr "something else" - IL_00e9: stloc.1 - IL_00ea: br.s IL_00ec - - IL_00ec: ldloc.1 - IL_00ed: ret + IL_00d0: ldstr "int.MaxValue" + IL_00d5: stloc.1 + IL_00d6: br.s IL_00e0 + + IL_00d8: ldstr "something else" + IL_00dd: stloc.1 + IL_00de: br.s IL_00e0 + + IL_00e0: ldloc.1 + IL_00e1: ret } // end of method Switch::SparseIntegerSwitch .method public hidebysig static string SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1 i) cil managed { - // Code size 87 (0x57) + // Code size 82 (0x52) .maxstack 2 .locals init (valuetype [mscorlib]System.Nullable`1 V_0, valuetype [mscorlib]System.Nullable`1 V_1, @@ -251,55 +239,108 @@ IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() IL_0015: stloc.2 IL_0016: ldloc.2 - IL_0017: brfalse.s IL_0031 + IL_0017: brfalse.s IL_0030 IL_0019: br.s IL_001b IL_001b: ldloc.2 IL_001c: ldc.i4.5 - IL_001d: beq.s IL_003a + IL_001d: beq.s IL_0038 IL_001f: br.s IL_0021 IL_0021: ldloc.2 IL_0022: ldc.i4.s 10 - IL_0024: beq.s IL_0043 + IL_0024: beq.s IL_0040 - IL_0026: br.s IL_004c + IL_0026: br.s IL_0048 - IL_0028: nop - IL_0029: ldstr "null" - IL_002e: stloc.3 - IL_002f: br.s IL_0055 + IL_0028: ldstr "null" + IL_002d: stloc.3 + IL_002e: br.s IL_0050 - IL_0031: nop - IL_0032: ldstr "zero" - IL_0037: stloc.3 - IL_0038: br.s IL_0055 + IL_0030: ldstr "zero" + IL_0035: stloc.3 + IL_0036: br.s IL_0050 - IL_003a: nop - IL_003b: ldstr "five" - IL_0040: stloc.3 - IL_0041: br.s IL_0055 + IL_0038: ldstr "five" + IL_003d: stloc.3 + IL_003e: br.s IL_0050 - IL_0043: nop - IL_0044: ldstr "ten" - IL_0049: stloc.3 - IL_004a: br.s IL_0055 + IL_0040: ldstr "ten" + IL_0045: stloc.3 + IL_0046: br.s IL_0050 - IL_004c: nop - IL_004d: ldstr "large" - IL_0052: stloc.3 - IL_0053: br.s IL_0055 + IL_0048: ldstr "large" + IL_004d: stloc.3 + IL_004e: br.s IL_0050 - IL_0055: ldloc.3 - IL_0056: ret + IL_0050: ldloc.3 + IL_0051: ret } // end of method Switch::SwitchOverNullableInt + .method public hidebysig static string + SwitchOverNullableIntNullCaseCombined(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 74 (0x4a) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + int32 V_2, + string V_3) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: stloc.0 + IL_0005: ldloca.s V_0 + IL_0007: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000c: brfalse.s IL_0028 + + IL_000e: ldloca.s V_0 + IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0015: stloc.2 + IL_0016: ldloc.2 + IL_0017: brfalse.s IL_0028 + + IL_0019: br.s IL_001b + + IL_001b: ldloc.2 + IL_001c: ldc.i4.5 + IL_001d: beq.s IL_0030 + + IL_001f: br.s IL_0021 + + IL_0021: ldloc.2 + IL_0022: ldc.i4.s 10 + IL_0024: beq.s IL_0038 + + IL_0026: br.s IL_0040 + + IL_0028: ldstr "zero" + IL_002d: stloc.3 + IL_002e: br.s IL_0048 + + IL_0030: ldstr "five" + IL_0035: stloc.3 + IL_0036: br.s IL_0048 + + IL_0038: ldstr "ten" + IL_003d: stloc.3 + IL_003e: br.s IL_0048 + + IL_0040: ldstr "large" + IL_0045: stloc.3 + IL_0046: br.s IL_0048 + + IL_0048: ldloc.3 + IL_0049: ret + } // end of method Switch::SwitchOverNullableIntNullCaseCombined + .method public hidebysig static string SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed { - // Code size 132 (0x84) + // Code size 127 (0x7f) .maxstack 2 .locals init (valuetype [mscorlib]System.Nullable`1 V_0, valuetype [mscorlib]System.Nullable`1 V_1, @@ -335,55 +376,125 @@ IL_0033: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() IL_0038: stloc.s V_4 IL_003a: ldloc.s V_4 - IL_003c: brfalse.s IL_0059 + IL_003c: brfalse.s IL_0058 IL_003e: br.s IL_0040 IL_0040: ldloc.s V_4 IL_0042: ldc.i4.5 - IL_0043: beq.s IL_0063 + IL_0043: beq.s IL_0061 IL_0045: br.s IL_0047 IL_0047: ldloc.s V_4 IL_0049: ldc.i4.s 10 - IL_004b: beq.s IL_006d + IL_004b: beq.s IL_006a - IL_004d: br.s IL_0077 + IL_004d: br.s IL_0073 - IL_004f: nop - IL_0050: ldstr "null" - IL_0055: stloc.s V_5 - IL_0057: br.s IL_0081 + IL_004f: ldstr "null" + IL_0054: stloc.s V_5 + IL_0056: br.s IL_007c - IL_0059: nop - IL_005a: ldstr "zero" - IL_005f: stloc.s V_5 - IL_0061: br.s IL_0081 + IL_0058: ldstr "zero" + IL_005d: stloc.s V_5 + IL_005f: br.s IL_007c - IL_0063: nop - IL_0064: ldstr "five" - IL_0069: stloc.s V_5 - IL_006b: br.s IL_0081 + IL_0061: ldstr "five" + IL_0066: stloc.s V_5 + IL_0068: br.s IL_007c - IL_006d: nop - IL_006e: ldstr "ten" - IL_0073: stloc.s V_5 - IL_0075: br.s IL_0081 + IL_006a: ldstr "ten" + IL_006f: stloc.s V_5 + IL_0071: br.s IL_007c - IL_0077: nop - IL_0078: ldstr "large" - IL_007d: stloc.s V_5 - IL_007f: br.s IL_0081 + IL_0073: ldstr "large" + IL_0078: stloc.s V_5 + IL_007a: br.s IL_007c - IL_0081: ldloc.s V_5 - IL_0083: ret + IL_007c: ldloc.s V_5 + IL_007e: ret } // end of method Switch::SwitchOverNullableIntShifted + .method public hidebysig static string + SwitchOverNullableIntShiftedNullCaseCombined(valuetype [mscorlib]System.Nullable`1 i) cil managed + { + // Code size 118 (0x76) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype [mscorlib]System.Nullable`1 V_2, + valuetype [mscorlib]System.Nullable`1 V_3, + int32 V_4, + string V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.2 + IL_0003: ldloca.s V_2 + IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000a: brtrue.s IL_0017 + + IL_000c: ldloca.s V_3 + IL_000e: initobj valuetype [mscorlib]System.Nullable`1 + IL_0014: ldloc.3 + IL_0015: br.s IL_0025 + + IL_0017: ldloca.s V_2 + IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_001e: ldc.i4.5 + IL_001f: add + IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0025: stloc.1 + IL_0026: ldloc.1 + IL_0027: stloc.0 + IL_0028: ldloca.s V_0 + IL_002a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_002f: brfalse.s IL_004f + + IL_0031: ldloca.s V_0 + IL_0033: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0038: stloc.s V_4 + IL_003a: ldloc.s V_4 + IL_003c: brfalse.s IL_004f + + IL_003e: br.s IL_0040 + + IL_0040: ldloc.s V_4 + IL_0042: ldc.i4.5 + IL_0043: beq.s IL_0058 + + IL_0045: br.s IL_0047 + + IL_0047: ldloc.s V_4 + IL_0049: ldc.i4.s 10 + IL_004b: beq.s IL_0061 + + IL_004d: br.s IL_006a + + IL_004f: ldstr "zero" + IL_0054: stloc.s V_5 + IL_0056: br.s IL_0073 + + IL_0058: ldstr "five" + IL_005d: stloc.s V_5 + IL_005f: br.s IL_0073 + + IL_0061: ldstr "ten" + IL_0066: stloc.s V_5 + IL_0068: br.s IL_0073 + + IL_006a: ldstr "large" + IL_006f: stloc.s V_5 + IL_0071: br.s IL_0073 + + IL_0073: ldloc.s V_5 + IL_0075: ret + } // end of method Switch::SwitchOverNullableIntShiftedNullCaseCombined + .method public hidebysig static string SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1 i) cil managed { - // Code size 78 (0x4e) + // Code size 74 (0x4a) .maxstack 2 .locals init (valuetype [mscorlib]System.Nullable`1 V_0, valuetype [mscorlib]System.Nullable`1 V_1, @@ -396,7 +507,7 @@ IL_0004: stloc.0 IL_0005: ldloca.s V_0 IL_0007: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_000c: brfalse.s IL_0043 + IL_000c: brfalse.s IL_0040 IL_000e: ldloca.s V_0 IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() @@ -408,44 +519,40 @@ IL_001b: ldloc.2 IL_001c: ldc.i4.5 - IL_001d: beq.s IL_0031 + IL_001d: beq.s IL_0030 IL_001f: br.s IL_0021 IL_0021: ldloc.2 IL_0022: ldc.i4.s 10 - IL_0024: beq.s IL_003a + IL_0024: beq.s IL_0038 - IL_0026: br.s IL_0043 + IL_0026: br.s IL_0040 - IL_0028: nop - IL_0029: ldstr "zero" - IL_002e: stloc.3 - IL_002f: br.s IL_004c + IL_0028: ldstr "zero" + IL_002d: stloc.3 + IL_002e: br.s IL_0048 - IL_0031: nop - IL_0032: ldstr "five" - IL_0037: stloc.3 - IL_0038: br.s IL_004c + IL_0030: ldstr "five" + IL_0035: stloc.3 + IL_0036: br.s IL_0048 - IL_003a: nop - IL_003b: ldstr "ten" - IL_0040: stloc.3 - IL_0041: br.s IL_004c + IL_0038: ldstr "ten" + IL_003d: stloc.3 + IL_003e: br.s IL_0048 - IL_0043: nop - IL_0044: ldstr "other" - IL_0049: stloc.3 - IL_004a: br.s IL_004c + IL_0040: ldstr "other" + IL_0045: stloc.3 + IL_0046: br.s IL_0048 - IL_004c: ldloc.3 - IL_004d: ret + IL_0048: ldloc.3 + IL_0049: ret } // end of method Switch::SwitchOverNullableIntNoNullCase .method public hidebysig static string SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1 i) cil managed { - // Code size 122 (0x7a) + // Code size 118 (0x76) .maxstack 2 .locals init (valuetype [mscorlib]System.Nullable`1 V_0, valuetype [mscorlib]System.Nullable`1 V_1, @@ -475,7 +582,7 @@ IL_0027: stloc.0 IL_0028: ldloca.s V_0 IL_002a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() - IL_002f: brfalse.s IL_006d + IL_002f: brfalse.s IL_006a IL_0031: ldloca.s V_0 IL_0033: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() @@ -487,43 +594,39 @@ IL_0040: ldloc.s V_4 IL_0042: ldc.i4.5 - IL_0043: beq.s IL_0059 + IL_0043: beq.s IL_0058 IL_0045: br.s IL_0047 IL_0047: ldloc.s V_4 IL_0049: ldc.i4.s 10 - IL_004b: beq.s IL_0063 + IL_004b: beq.s IL_0061 - IL_004d: br.s IL_006d + IL_004d: br.s IL_006a - IL_004f: nop - IL_0050: ldstr "zero" - IL_0055: stloc.s V_5 - IL_0057: br.s IL_0077 + IL_004f: ldstr "zero" + IL_0054: stloc.s V_5 + IL_0056: br.s IL_0073 - IL_0059: nop - IL_005a: ldstr "five" - IL_005f: stloc.s V_5 - IL_0061: br.s IL_0077 + IL_0058: ldstr "five" + IL_005d: stloc.s V_5 + IL_005f: br.s IL_0073 - IL_0063: nop - IL_0064: ldstr "ten" - IL_0069: stloc.s V_5 - IL_006b: br.s IL_0077 + IL_0061: ldstr "ten" + IL_0066: stloc.s V_5 + IL_0068: br.s IL_0073 - IL_006d: nop - IL_006e: ldstr "other" - IL_0073: stloc.s V_5 - IL_0075: br.s IL_0077 + IL_006a: ldstr "other" + IL_006f: stloc.s V_5 + IL_0071: br.s IL_0073 - IL_0077: ldloc.s V_5 - IL_0079: ret + IL_0073: ldloc.s V_5 + IL_0075: ret } // end of method Switch::SwitchOverNullableIntNoNullCaseShifted .method public hidebysig static void SwitchOverInt(int32 i) cil managed { - // Code size 161 (0xa1) + // Code size 151 (0x97) .maxstack 2 .locals init (int32 V_0) IL_0000: nop @@ -531,102 +634,95 @@ IL_0002: stloc.0 IL_0003: ldloc.0 IL_0004: ldc.i4.s 10 - IL_0006: bgt.s IL_001d + IL_0006: bgt.s IL_001a IL_0008: ldloc.0 - IL_0009: brfalse.s IL_003e + IL_0009: brfalse.s IL_003b IL_000b: br.s IL_000d IL_000d: ldloc.0 IL_000e: ldc.i4.5 - IL_000f: beq.s IL_004c + IL_000f: beq.s IL_0048 IL_0011: br.s IL_0013 IL_0013: ldloc.0 IL_0014: ldc.i4.s 10 - IL_0016: beq.s IL_005a + IL_0016: beq.s IL_0055 - IL_0018: br IL_00a0 + IL_0018: br.s IL_0096 - IL_001d: ldloc.0 - IL_001e: ldc.i4.s 20 - IL_0020: bgt.s IL_0030 + IL_001a: ldloc.0 + IL_001b: ldc.i4.s 20 + IL_001d: bgt.s IL_002d + + IL_001f: ldloc.0 + IL_0020: ldc.i4.s 15 + IL_0022: beq.s IL_0062 - IL_0022: ldloc.0 - IL_0023: ldc.i4.s 15 - IL_0025: beq.s IL_0068 + IL_0024: br.s IL_0026 - IL_0027: br.s IL_0029 + IL_0026: ldloc.0 + IL_0027: ldc.i4.s 20 + IL_0029: beq.s IL_006f - IL_0029: ldloc.0 - IL_002a: ldc.i4.s 20 - IL_002c: beq.s IL_0076 + IL_002b: br.s IL_0096 - IL_002e: br.s IL_00a0 + IL_002d: ldloc.0 + IL_002e: ldc.i4.s 25 + IL_0030: beq.s IL_007c - IL_0030: ldloc.0 - IL_0031: ldc.i4.s 25 - IL_0033: beq.s IL_0084 + IL_0032: br.s IL_0034 - IL_0035: br.s IL_0037 + IL_0034: ldloc.0 + IL_0035: ldc.i4.s 30 + IL_0037: beq.s IL_0089 - IL_0037: ldloc.0 - IL_0038: ldc.i4.s 30 - IL_003a: beq.s IL_0092 + IL_0039: br.s IL_0096 - IL_003c: br.s IL_00a0 + IL_003b: ldstr "zero" + IL_0040: call void [mscorlib]System.Console::WriteLine(string) + IL_0045: nop + IL_0046: br.s IL_0096 - IL_003e: nop - IL_003f: ldstr "zero" - IL_0044: call void [mscorlib]System.Console::WriteLine(string) - IL_0049: nop - IL_004a: br.s IL_00a0 + IL_0048: ldstr "five" + IL_004d: call void [mscorlib]System.Console::WriteLine(string) + IL_0052: nop + IL_0053: br.s IL_0096 - IL_004c: nop - IL_004d: ldstr "five" - IL_0052: call void [mscorlib]System.Console::WriteLine(string) - IL_0057: nop - IL_0058: br.s IL_00a0 + IL_0055: ldstr "ten" + IL_005a: call void [mscorlib]System.Console::WriteLine(string) + IL_005f: nop + IL_0060: br.s IL_0096 - IL_005a: nop - IL_005b: ldstr "ten" - IL_0060: call void [mscorlib]System.Console::WriteLine(string) - IL_0065: nop - IL_0066: br.s IL_00a0 - - IL_0068: nop - IL_0069: ldstr "fifteen" - IL_006e: call void [mscorlib]System.Console::WriteLine(string) - IL_0073: nop - IL_0074: br.s IL_00a0 - - IL_0076: nop - IL_0077: ldstr "twenty" - IL_007c: call void [mscorlib]System.Console::WriteLine(string) - IL_0081: nop - IL_0082: br.s IL_00a0 + IL_0062: ldstr "fifteen" + IL_0067: call void [mscorlib]System.Console::WriteLine(string) + IL_006c: nop + IL_006d: br.s IL_0096 - IL_0084: nop - IL_0085: ldstr "twenty-five" - IL_008a: call void [mscorlib]System.Console::WriteLine(string) - IL_008f: nop - IL_0090: br.s IL_00a0 - - IL_0092: nop - IL_0093: ldstr "thirty" - IL_0098: call void [mscorlib]System.Console::WriteLine(string) - IL_009d: nop - IL_009e: br.s IL_00a0 - - IL_00a0: ret + IL_006f: ldstr "twenty" + IL_0074: call void [mscorlib]System.Console::WriteLine(string) + IL_0079: nop + IL_007a: br.s IL_0096 + + IL_007c: ldstr "twenty-five" + IL_0081: call void [mscorlib]System.Console::WriteLine(string) + IL_0086: nop + IL_0087: br.s IL_0096 + + IL_0089: ldstr "thirty" + IL_008e: call void [mscorlib]System.Console::WriteLine(string) + IL_0093: nop + IL_0094: br.s IL_0096 + + IL_0096: ret } // end of method Switch::SwitchOverInt .method public hidebysig static string ShortSwitchOverString(string text) cil managed { - // Code size 99 (0x63) + // Code size 95 (0x5f) .maxstack 2 .locals init (string V_0, string V_1) @@ -649,44 +745,40 @@ IL_0022: ldstr "Second case" IL_0027: call bool [mscorlib]System.String::op_Equality(string, string) - IL_002c: brtrue.s IL_0046 + IL_002c: brtrue.s IL_0045 IL_002e: ldloc.0 IL_002f: ldstr "Third case" IL_0034: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0039: brtrue.s IL_004f + IL_0039: brtrue.s IL_004d - IL_003b: br.s IL_0058 + IL_003b: br.s IL_0055 - IL_003d: nop - IL_003e: ldstr "Text1" - IL_0043: stloc.1 - IL_0044: br.s IL_0061 - - IL_0046: nop - IL_0047: ldstr "Text2" - IL_004c: stloc.1 - IL_004d: br.s IL_0061 - - IL_004f: nop - IL_0050: ldstr "Text3" - IL_0055: stloc.1 - IL_0056: br.s IL_0061 - - IL_0058: nop - IL_0059: ldstr "Default" - IL_005e: stloc.1 - IL_005f: br.s IL_0061 - - IL_0061: ldloc.1 - IL_0062: ret + IL_003d: ldstr "Text1" + IL_0042: stloc.1 + IL_0043: br.s IL_005d + + IL_0045: ldstr "Text2" + IL_004a: stloc.1 + IL_004b: br.s IL_005d + + IL_004d: ldstr "Text3" + IL_0052: stloc.1 + IL_0053: br.s IL_005d + + IL_0055: ldstr "Default" + IL_005a: stloc.1 + IL_005b: br.s IL_005d + + IL_005d: ldloc.1 + IL_005e: ret } // end of method Switch::ShortSwitchOverString .method public hidebysig static string ShortSwitchOverStringWithNullCase(string text) cil managed { - // Code size 89 (0x59) + // Code size 85 (0x55) .maxstack 2 .locals init (string V_0, string V_1) @@ -709,41 +801,37 @@ IL_0022: ldstr "Second case" IL_0027: call bool [mscorlib]System.String::op_Equality(string, string) - IL_002c: brtrue.s IL_003c + IL_002c: brtrue.s IL_003b IL_002e: ldloc.0 - IL_002f: brfalse.s IL_0045 + IL_002f: brfalse.s IL_0043 - IL_0031: br.s IL_004e + IL_0031: br.s IL_004b - IL_0033: nop - IL_0034: ldstr "Text1" - IL_0039: stloc.1 - IL_003a: br.s IL_0057 + IL_0033: ldstr "Text1" + IL_0038: stloc.1 + IL_0039: br.s IL_0053 - IL_003c: nop - IL_003d: ldstr "Text2" - IL_0042: stloc.1 - IL_0043: br.s IL_0057 + IL_003b: ldstr "Text2" + IL_0040: stloc.1 + IL_0041: br.s IL_0053 - IL_0045: nop - IL_0046: ldstr "null" - IL_004b: stloc.1 - IL_004c: br.s IL_0057 + IL_0043: ldstr "null" + IL_0048: stloc.1 + IL_0049: br.s IL_0053 - IL_004e: nop - IL_004f: ldstr "Default" - IL_0054: stloc.1 - IL_0055: br.s IL_0057 + IL_004b: ldstr "Default" + IL_0050: stloc.1 + IL_0051: br.s IL_0053 - IL_0057: ldloc.1 - IL_0058: ret + IL_0053: ldloc.1 + IL_0054: ret } // end of method Switch::ShortSwitchOverStringWithNullCase .method public hidebysig static string SwitchOverString1(string text) cil managed { - // Code size 333 (0x14d) + // Code size 325 (0x145) .maxstack 2 .locals init (string V_0, uint32 V_1, @@ -777,7 +865,7 @@ IL_0034: ldc.i4 0x8861b86 IL_0039: beq IL_00e4 - IL_003e: br IL_0142 + IL_003e: br IL_013b IL_0043: ldloc.1 IL_0044: ldc.i4 0xc9a8f4f @@ -789,7 +877,7 @@ IL_004e: ldc.i4 0xf3d44a6 IL_0053: beq.s IL_00c6 - IL_0055: br IL_0142 + IL_0055: br IL_013b IL_005a: ldloc.1 IL_005b: ldc.i4 0x652a1179 @@ -805,7 +893,7 @@ IL_0070: ldc.i4 0x652a1179 IL_0075: beq.s IL_00b7 - IL_0077: br IL_0142 + IL_0077: br IL_013b IL_007c: ldloc.1 IL_007d: ldc.i4 0xea3d096b @@ -817,7 +905,7 @@ IL_0087: ldc.i4 0xf701cc7f IL_008c: beq.s IL_00d5 - IL_008e: br IL_0142 + IL_008e: br IL_013b IL_0093: ldloc.0 IL_0094: ldstr "First case" @@ -825,109 +913,101 @@ string) IL_009e: brtrue.s IL_0107 - IL_00a0: br IL_0142 + IL_00a0: br IL_013b IL_00a5: ldloc.0 IL_00a6: ldstr "Second case" IL_00ab: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00b0: brtrue.s IL_0110 + IL_00b0: brtrue.s IL_010f - IL_00b2: br IL_0142 + IL_00b2: br IL_013b IL_00b7: ldloc.0 IL_00b8: ldstr "2nd case" IL_00bd: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00c2: brtrue.s IL_0110 + IL_00c2: brtrue.s IL_010f - IL_00c4: br.s IL_0142 + IL_00c4: br.s IL_013b IL_00c6: ldloc.0 IL_00c7: ldstr "Third case" IL_00cc: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00d1: brtrue.s IL_0119 + IL_00d1: brtrue.s IL_0117 - IL_00d3: br.s IL_0142 + IL_00d3: br.s IL_013b IL_00d5: ldloc.0 IL_00d6: ldstr "Fourth case" IL_00db: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00e0: brtrue.s IL_0122 + IL_00e0: brtrue.s IL_011f - IL_00e2: br.s IL_0142 + IL_00e2: br.s IL_013b IL_00e4: ldloc.0 IL_00e5: ldstr "Fifth case" IL_00ea: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00ef: brtrue.s IL_012b + IL_00ef: brtrue.s IL_0127 - IL_00f1: br.s IL_0142 + IL_00f1: br.s IL_013b IL_00f3: ldloc.0 IL_00f4: ldstr "Sixth case" IL_00f9: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00fe: brtrue.s IL_0134 + IL_00fe: brtrue.s IL_012f - IL_0100: br.s IL_0142 + IL_0100: br.s IL_013b IL_0102: ldloc.0 - IL_0103: brfalse.s IL_013d - - IL_0105: br.s IL_0142 - - IL_0107: nop - IL_0108: ldstr "Text1" - IL_010d: stloc.2 - IL_010e: br.s IL_014b - - IL_0110: nop - IL_0111: ldstr "Text2" - IL_0116: stloc.2 - IL_0117: br.s IL_014b - - IL_0119: nop - IL_011a: ldstr "Text3" - IL_011f: stloc.2 - IL_0120: br.s IL_014b - - IL_0122: nop - IL_0123: ldstr "Text4" - IL_0128: stloc.2 - IL_0129: br.s IL_014b - - IL_012b: nop - IL_012c: ldstr "Text5" - IL_0131: stloc.2 - IL_0132: br.s IL_014b - - IL_0134: nop - IL_0135: ldstr "Text6" - IL_013a: stloc.2 - IL_013b: br.s IL_014b - - IL_013d: nop - IL_013e: ldnull - IL_013f: stloc.2 - IL_0140: br.s IL_014b - - IL_0142: nop - IL_0143: ldstr "Default" - IL_0148: stloc.2 - IL_0149: br.s IL_014b - - IL_014b: ldloc.2 - IL_014c: ret + IL_0103: brfalse.s IL_0137 + + IL_0105: br.s IL_013b + + IL_0107: ldstr "Text1" + IL_010c: stloc.2 + IL_010d: br.s IL_0143 + + IL_010f: ldstr "Text2" + IL_0114: stloc.2 + IL_0115: br.s IL_0143 + + IL_0117: ldstr "Text3" + IL_011c: stloc.2 + IL_011d: br.s IL_0143 + + IL_011f: ldstr "Text4" + IL_0124: stloc.2 + IL_0125: br.s IL_0143 + + IL_0127: ldstr "Text5" + IL_012c: stloc.2 + IL_012d: br.s IL_0143 + + IL_012f: ldstr "Text6" + IL_0134: stloc.2 + IL_0135: br.s IL_0143 + + IL_0137: ldnull + IL_0138: stloc.2 + IL_0139: br.s IL_0143 + + IL_013b: ldstr "Default" + IL_0140: stloc.2 + IL_0141: br.s IL_0143 + + IL_0143: ldloc.2 + IL_0144: ret } // end of method Switch::SwitchOverString1 .method public hidebysig static string SwitchOverString2() cil managed { - // Code size 518 (0x206) + // Code size 500 (0x1f4) .maxstack 2 .locals init (string V_0, uint32 V_1, @@ -959,7 +1039,7 @@ IL_0037: ldc.i4 0xc9a8f4f IL_003c: beq IL_00c6 - IL_0041: br IL_01fb + IL_0041: br IL_01ea IL_0046: ldloc.1 IL_0047: ldc.i4 0xf3d44a6 @@ -969,15 +1049,15 @@ IL_0053: ldloc.1 IL_0054: ldc.i4 0x20289804 - IL_0059: beq IL_0156 + IL_0059: beq IL_0153 IL_005e: br.s IL_0060 IL_0060: ldloc.1 IL_0061: ldc.i4 0x4c7c71f6 - IL_0066: beq IL_0168 + IL_0066: beq IL_0165 - IL_006b: br IL_01fb + IL_006b: br IL_01ea IL_0070: ldloc.1 IL_0071: ldc.i4 0xa151b28a @@ -985,7 +1065,7 @@ IL_0078: ldloc.1 IL_0079: ldc.i4 0x4d0cea48 - IL_007e: beq IL_0189 + IL_007e: beq IL_0183 IL_0083: br.s IL_0085 @@ -997,9 +1077,9 @@ IL_0092: ldloc.1 IL_0093: ldc.i4 0xa151b28a - IL_0098: beq IL_0144 + IL_0098: beq IL_0141 - IL_009d: br IL_01fb + IL_009d: br IL_01ea IL_00a2: ldloc.1 IL_00a3: ldc.i4 0xea3d096b @@ -1009,7 +1089,7 @@ IL_00ac: ldloc.1 IL_00ad: ldc.i4 0xed5134d4 - IL_00b2: beq IL_017a + IL_00b2: beq IL_0174 IL_00b7: br.s IL_00b9 @@ -1017,164 +1097,152 @@ IL_00ba: ldc.i4 0xf701cc7f IL_00bf: beq.s IL_0105 - IL_00c1: br IL_01fb + IL_00c1: br IL_01ea IL_00c6: ldloc.0 IL_00c7: ldstr "First case" IL_00cc: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00d1: brtrue IL_0198 + IL_00d1: brtrue IL_0192 - IL_00d6: br IL_01fb + IL_00d6: br IL_01ea IL_00db: ldloc.0 IL_00dc: ldstr "Second case" IL_00e1: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00e6: brtrue IL_01a1 + IL_00e6: brtrue IL_019a - IL_00eb: br IL_01fb + IL_00eb: br IL_01ea IL_00f0: ldloc.0 IL_00f1: ldstr "Third case" IL_00f6: call bool [mscorlib]System.String::op_Equality(string, string) - IL_00fb: brtrue IL_01aa + IL_00fb: brtrue IL_01a2 - IL_0100: br IL_01fb + IL_0100: br IL_01ea IL_0105: ldloc.0 IL_0106: ldstr "Fourth case" IL_010b: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0110: brtrue IL_01b3 + IL_0110: brtrue IL_01aa - IL_0115: br IL_01fb + IL_0115: br IL_01ea IL_011a: ldloc.0 IL_011b: ldstr "Fifth case" IL_0120: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0125: brtrue IL_01bc + IL_0125: brtrue IL_01b2 - IL_012a: br IL_01fb + IL_012a: br IL_01ea IL_012f: ldloc.0 IL_0130: ldstr "Sixth case" IL_0135: call bool [mscorlib]System.String::op_Equality(string, string) - IL_013a: brtrue IL_01c5 + IL_013a: brtrue.s IL_01ba - IL_013f: br IL_01fb + IL_013c: br IL_01ea - IL_0144: ldloc.0 - IL_0145: ldstr "Seventh case" - IL_014a: call bool [mscorlib]System.String::op_Equality(string, + IL_0141: ldloc.0 + IL_0142: ldstr "Seventh case" + IL_0147: call bool [mscorlib]System.String::op_Equality(string, string) - IL_014f: brtrue.s IL_01ce + IL_014c: brtrue.s IL_01c2 - IL_0151: br IL_01fb + IL_014e: br IL_01ea - IL_0156: ldloc.0 - IL_0157: ldstr "Eighth case" - IL_015c: call bool [mscorlib]System.String::op_Equality(string, + IL_0153: ldloc.0 + IL_0154: ldstr "Eighth case" + IL_0159: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0161: brtrue.s IL_01d7 + IL_015e: brtrue.s IL_01ca - IL_0163: br IL_01fb + IL_0160: br IL_01ea - IL_0168: ldloc.0 - IL_0169: ldstr "Ninth case" - IL_016e: call bool [mscorlib]System.String::op_Equality(string, + IL_0165: ldloc.0 + IL_0166: ldstr "Ninth case" + IL_016b: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0173: brtrue.s IL_01e0 + IL_0170: brtrue.s IL_01d2 - IL_0175: br IL_01fb + IL_0172: br.s IL_01ea - IL_017a: ldloc.0 - IL_017b: ldstr "Tenth case" - IL_0180: call bool [mscorlib]System.String::op_Equality(string, + IL_0174: ldloc.0 + IL_0175: ldstr "Tenth case" + IL_017a: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0185: brtrue.s IL_01e9 + IL_017f: brtrue.s IL_01da - IL_0187: br.s IL_01fb + IL_0181: br.s IL_01ea - IL_0189: ldloc.0 - IL_018a: ldstr "Eleventh case" - IL_018f: call bool [mscorlib]System.String::op_Equality(string, + IL_0183: ldloc.0 + IL_0184: ldstr "Eleventh case" + IL_0189: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0194: brtrue.s IL_01f2 + IL_018e: brtrue.s IL_01e2 + + IL_0190: br.s IL_01ea - IL_0196: br.s IL_01fb + IL_0192: ldstr "Text1" + IL_0197: stloc.2 + IL_0198: br.s IL_01f2 - IL_0198: nop - IL_0199: ldstr "Text1" - IL_019e: stloc.2 - IL_019f: br.s IL_0204 + IL_019a: ldstr "Text2" + IL_019f: stloc.2 + IL_01a0: br.s IL_01f2 - IL_01a1: nop - IL_01a2: ldstr "Text2" + IL_01a2: ldstr "Text3" IL_01a7: stloc.2 - IL_01a8: br.s IL_0204 - - IL_01aa: nop - IL_01ab: ldstr "Text3" - IL_01b0: stloc.2 - IL_01b1: br.s IL_0204 - - IL_01b3: nop - IL_01b4: ldstr "Text4" - IL_01b9: stloc.2 - IL_01ba: br.s IL_0204 - - IL_01bc: nop - IL_01bd: ldstr "Text5" - IL_01c2: stloc.2 - IL_01c3: br.s IL_0204 - - IL_01c5: nop - IL_01c6: ldstr "Text6" - IL_01cb: stloc.2 - IL_01cc: br.s IL_0204 - - IL_01ce: nop - IL_01cf: ldstr "Text7" - IL_01d4: stloc.2 - IL_01d5: br.s IL_0204 - - IL_01d7: nop - IL_01d8: ldstr "Text8" - IL_01dd: stloc.2 - IL_01de: br.s IL_0204 - - IL_01e0: nop - IL_01e1: ldstr "Text9" - IL_01e6: stloc.2 - IL_01e7: br.s IL_0204 - - IL_01e9: nop - IL_01ea: ldstr "Text10" - IL_01ef: stloc.2 - IL_01f0: br.s IL_0204 + IL_01a8: br.s IL_01f2 + + IL_01aa: ldstr "Text4" + IL_01af: stloc.2 + IL_01b0: br.s IL_01f2 + + IL_01b2: ldstr "Text5" + IL_01b7: stloc.2 + IL_01b8: br.s IL_01f2 + + IL_01ba: ldstr "Text6" + IL_01bf: stloc.2 + IL_01c0: br.s IL_01f2 - IL_01f2: nop - IL_01f3: ldstr "Text11" - IL_01f8: stloc.2 - IL_01f9: br.s IL_0204 + IL_01c2: ldstr "Text7" + IL_01c7: stloc.2 + IL_01c8: br.s IL_01f2 - IL_01fb: nop - IL_01fc: ldstr "Default" - IL_0201: stloc.2 - IL_0202: br.s IL_0204 + IL_01ca: ldstr "Text8" + IL_01cf: stloc.2 + IL_01d0: br.s IL_01f2 - IL_0204: ldloc.2 - IL_0205: ret + IL_01d2: ldstr "Text9" + IL_01d7: stloc.2 + IL_01d8: br.s IL_01f2 + + IL_01da: ldstr "Text10" + IL_01df: stloc.2 + IL_01e0: br.s IL_01f2 + + IL_01e2: ldstr "Text11" + IL_01e7: stloc.2 + IL_01e8: br.s IL_01f2 + + IL_01ea: ldstr "Default" + IL_01ef: stloc.2 + IL_01f0: br.s IL_01f2 + + IL_01f2: ldloc.2 + IL_01f3: ret } // end of method Switch::SwitchOverString2 .method public hidebysig static string SwitchOverBool(bool b) cil managed { - // Code size 62 (0x3e) + // Code size 59 (0x3b) .maxstack 2 .locals init (bool V_0, string V_1) @@ -1189,7 +1257,7 @@ IL_0018: ldarg.0 IL_0019: stloc.0 IL_001a: ldloc.0 - IL_001b: brfalse.s IL_002e + IL_001b: brfalse.s IL_002d IL_001d: br.s IL_001f @@ -1197,30 +1265,27 @@ IL_0020: ldc.i4.1 IL_0021: beq.s IL_0025 - IL_0023: br.s IL_0037 + IL_0023: br.s IL_0035 - IL_0025: nop - IL_0026: ldsfld string [mscorlib]System.Boolean::TrueString - IL_002b: stloc.1 - IL_002c: br.s IL_003c + IL_0025: ldsfld string [mscorlib]System.Boolean::TrueString + IL_002a: stloc.1 + IL_002b: br.s IL_0039 - IL_002e: nop - IL_002f: ldsfld string [mscorlib]System.Boolean::FalseString - IL_0034: stloc.1 - IL_0035: br.s IL_003c + IL_002d: ldsfld string [mscorlib]System.Boolean::FalseString + IL_0032: stloc.1 + IL_0033: br.s IL_0039 - IL_0037: nop - IL_0038: ldnull - IL_0039: stloc.1 - IL_003a: br.s IL_003c + IL_0035: ldnull + IL_0036: stloc.1 + IL_0037: br.s IL_0039 - IL_003c: ldloc.1 - IL_003d: ret + IL_0039: ldloc.1 + IL_003a: ret } // end of method Switch::SwitchOverBool .method public hidebysig static void SwitchInLoop(int32 i) cil managed { - // Code size 132 (0x84) + // Code size 128 (0x80) .maxstack 2 .locals init (int32 V_0, bool V_1) @@ -1232,7 +1297,7 @@ object) IL_0011: call void [mscorlib]System.Console::WriteLine(string) IL_0016: nop - IL_0017: br.s IL_007f + IL_0017: br.s IL_007b IL_0019: nop IL_001a: ldarg.0 @@ -1242,53 +1307,49 @@ IL_001e: sub IL_001f: switch ( IL_0036, - IL_0044, - IL_0060, - IL_0052) - IL_0034: br.s IL_0060 - - IL_0036: nop - IL_0037: ldstr "one" - IL_003c: call void [mscorlib]System.Console::WriteLine(string) - IL_0041: nop - IL_0042: br.s IL_0079 - - IL_0044: nop - IL_0045: ldstr "two" - IL_004a: call void [mscorlib]System.Console::WriteLine(string) - IL_004f: nop - IL_0050: br.s IL_0079 - - IL_0052: nop - IL_0053: ldstr "four" - IL_0058: call void [mscorlib]System.Console::WriteLine(string) - IL_005d: nop - IL_005e: br.s IL_0083 - - IL_0060: nop - IL_0061: ldstr "default" - IL_0066: call void [mscorlib]System.Console::WriteLine(string) - IL_006b: nop - IL_006c: ldstr "more code" - IL_0071: call void [mscorlib]System.Console::WriteLine(string) - IL_0076: nop - IL_0077: br.s IL_0083 - - IL_0079: ldarg.0 - IL_007a: ldc.i4.1 - IL_007b: add - IL_007c: starg.s i - IL_007e: nop - IL_007f: ldc.i4.1 - IL_0080: stloc.1 - IL_0081: br.s IL_0019 - - IL_0083: ret + IL_0043, + IL_005d, + IL_0050) + IL_0034: br.s IL_005d + + IL_0036: ldstr "one" + IL_003b: call void [mscorlib]System.Console::WriteLine(string) + IL_0040: nop + IL_0041: br.s IL_0075 + + IL_0043: ldstr "two" + IL_0048: call void [mscorlib]System.Console::WriteLine(string) + IL_004d: nop + IL_004e: br.s IL_0075 + + IL_0050: ldstr "four" + IL_0055: call void [mscorlib]System.Console::WriteLine(string) + IL_005a: nop + IL_005b: br.s IL_007f + + IL_005d: ldstr "default" + IL_0062: call void [mscorlib]System.Console::WriteLine(string) + IL_0067: nop + IL_0068: ldstr "more code" + IL_006d: call void [mscorlib]System.Console::WriteLine(string) + IL_0072: nop + IL_0073: br.s IL_007f + + IL_0075: ldarg.0 + IL_0076: ldc.i4.1 + IL_0077: add + IL_0078: starg.s i + IL_007a: nop + IL_007b: ldc.i4.1 + IL_007c: stloc.1 + IL_007d: br.s IL_0019 + + IL_007f: ret } // end of method Switch::SwitchInLoop .method public hidebysig static void SwitchWithGoto(int32 i) cil managed { - // Code size 133 (0x85) + // Code size 128 (0x80) .maxstack 2 .locals init (int32 V_0) IL_0000: nop @@ -1306,45 +1367,40 @@ IL_001b: sub IL_001c: switch ( IL_0033, - IL_0041, - IL_004f, - IL_005d) - IL_0031: br.s IL_006b - - IL_0033: nop - IL_0034: ldstr "one" - IL_0039: call void [mscorlib]System.Console::WriteLine(string) - IL_003e: nop - IL_003f: br.s IL_006b - - IL_0041: nop - IL_0042: ldstr "two" - IL_0047: call void [mscorlib]System.Console::WriteLine(string) - IL_004c: nop - IL_004d: br.s IL_004f - - IL_004f: nop - IL_0050: ldstr "three" - IL_0055: call void [mscorlib]System.Console::WriteLine(string) - IL_005a: nop - IL_005b: br.s IL_0079 + IL_0040, + IL_004d, + IL_005a) + IL_0031: br.s IL_0067 - IL_005d: nop - IL_005e: ldstr "four" - IL_0063: call void [mscorlib]System.Console::WriteLine(string) - IL_0068: nop - IL_0069: br.s IL_0084 - - IL_006b: nop - IL_006c: ldstr "default" - IL_0071: call void [mscorlib]System.Console::WriteLine(string) - IL_0076: nop - IL_0077: br.s IL_0079 - - IL_0079: ldstr "End of method" - IL_007e: call void [mscorlib]System.Console::WriteLine(string) - IL_0083: nop - IL_0084: ret + IL_0033: ldstr "one" + IL_0038: call void [mscorlib]System.Console::WriteLine(string) + IL_003d: nop + IL_003e: br.s IL_0067 + + IL_0040: ldstr "two" + IL_0045: call void [mscorlib]System.Console::WriteLine(string) + IL_004a: nop + IL_004b: br.s IL_004d + + IL_004d: ldstr "three" + IL_0052: call void [mscorlib]System.Console::WriteLine(string) + IL_0057: nop + IL_0058: br.s IL_0074 + + IL_005a: ldstr "four" + IL_005f: call void [mscorlib]System.Console::WriteLine(string) + IL_0064: nop + IL_0065: br.s IL_007f + + IL_0067: ldstr "default" + IL_006c: call void [mscorlib]System.Console::WriteLine(string) + IL_0071: nop + IL_0072: br.s IL_0074 + + IL_0074: ldstr "End of method" + IL_0079: call void [mscorlib]System.Console::WriteLine(string) + IL_007e: nop + IL_007f: ret } // end of method Switch::SwitchWithGoto .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] @@ -1365,7 +1421,7 @@ .method public hidebysig static void SwitchOnStringInForLoop() cil managed { - // Code size 261 (0x105) + // Code size 255 (0xff) .maxstack 2 .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, class [mscorlib]System.Collections.Generic.List`1 V_1, @@ -1383,7 +1439,7 @@ IL_0012: stloc.2 IL_0013: ldc.i4.0 IL_0014: stloc.3 - IL_0015: br IL_00f5 + IL_0015: br IL_00ef IL_001a: nop IL_001b: ldloc.2 @@ -1404,112 +1460,106 @@ IL_003e: ldstr "Name2" IL_0043: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0048: brtrue.s IL_0099 + IL_0048: brtrue.s IL_0098 IL_004a: ldloc.s V_5 IL_004c: ldstr "Name3" IL_0051: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0056: brtrue.s IL_00ae + IL_0056: brtrue.s IL_00ac IL_0058: ldloc.s V_5 IL_005a: ldstr "Name4" IL_005f: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0064: brtrue.s IL_00c3 + IL_0064: brtrue.s IL_00c0 IL_0066: ldloc.s V_5 IL_0068: ldstr "Name5" IL_006d: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0072: brtrue.s IL_00d8 + IL_0072: brtrue.s IL_00d4 IL_0074: ldloc.s V_5 IL_0076: ldstr "Name6" IL_007b: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0080: brtrue.s IL_00d8 - - IL_0082: br.s IL_00e4 - - IL_0084: nop - IL_0085: ldloc.s V_4 - IL_0087: ldc.i4.1 - IL_0088: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_008d: nop - IL_008e: ldloc.0 - IL_008f: ldloc.s V_4 - IL_0091: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_0096: nop - IL_0097: br.s IL_00f0 - - IL_0099: nop - IL_009a: ldloc.s V_4 - IL_009c: ldc.i4.2 - IL_009d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00a2: nop - IL_00a3: ldloc.0 - IL_00a4: ldloc.s V_4 - IL_00a6: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00ab: nop - IL_00ac: br.s IL_00f0 - - IL_00ae: nop - IL_00af: ldloc.s V_4 - IL_00b1: ldc.i4.3 - IL_00b2: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00b7: nop - IL_00b8: ldloc.0 - IL_00b9: ldloc.s V_4 - IL_00bb: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00c0: nop - IL_00c1: br.s IL_00f0 - - IL_00c3: nop - IL_00c4: ldloc.s V_4 - IL_00c6: ldc.i4.4 - IL_00c7: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00cc: nop - IL_00cd: ldloc.0 - IL_00ce: ldloc.s V_4 - IL_00d0: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00d5: nop - IL_00d6: br.s IL_00f0 - - IL_00d8: nop - IL_00d9: ldloc.0 - IL_00da: ldloc.s V_4 - IL_00dc: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00e1: nop - IL_00e2: br.s IL_00f0 - - IL_00e4: nop - IL_00e5: ldloc.1 - IL_00e6: ldloc.s V_4 - IL_00e8: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00ed: nop - IL_00ee: br.s IL_00f0 - - IL_00f0: nop - IL_00f1: ldloc.3 - IL_00f2: ldc.i4.1 - IL_00f3: add - IL_00f4: stloc.3 - IL_00f5: ldloc.3 - IL_00f6: ldloc.2 - IL_00f7: ldlen - IL_00f8: conv.i4 - IL_00f9: clt - IL_00fb: stloc.s V_6 - IL_00fd: ldloc.s V_6 - IL_00ff: brtrue IL_001a - - IL_0104: ret + IL_0080: brtrue.s IL_00d4 + + IL_0082: br.s IL_00df + + IL_0084: ldloc.s V_4 + IL_0086: ldc.i4.1 + IL_0087: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_008c: nop + IL_008d: ldloc.0 + IL_008e: ldloc.s V_4 + IL_0090: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0095: nop + IL_0096: br.s IL_00ea + + IL_0098: ldloc.s V_4 + IL_009a: ldc.i4.2 + IL_009b: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00a0: nop + IL_00a1: ldloc.0 + IL_00a2: ldloc.s V_4 + IL_00a4: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00a9: nop + IL_00aa: br.s IL_00ea + + IL_00ac: ldloc.s V_4 + IL_00ae: ldc.i4.3 + IL_00af: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00b4: nop + IL_00b5: ldloc.0 + IL_00b6: ldloc.s V_4 + IL_00b8: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00bd: nop + IL_00be: br.s IL_00ea + + IL_00c0: ldloc.s V_4 + IL_00c2: ldc.i4.4 + IL_00c3: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00c8: nop + IL_00c9: ldloc.0 + IL_00ca: ldloc.s V_4 + IL_00cc: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00d1: nop + IL_00d2: br.s IL_00ea + + IL_00d4: ldloc.0 + IL_00d5: ldloc.s V_4 + IL_00d7: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00dc: nop + IL_00dd: br.s IL_00ea + + IL_00df: ldloc.1 + IL_00e0: ldloc.s V_4 + IL_00e2: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00e7: nop + IL_00e8: br.s IL_00ea + + IL_00ea: nop + IL_00eb: ldloc.3 + IL_00ec: ldc.i4.1 + IL_00ed: add + IL_00ee: stloc.3 + IL_00ef: ldloc.3 + IL_00f0: ldloc.2 + IL_00f1: ldlen + IL_00f2: conv.i4 + IL_00f3: clt + IL_00f5: stloc.s V_6 + IL_00f7: ldloc.s V_6 + IL_00f9: brtrue IL_001a + + IL_00fe: ret } // end of method Switch::SwitchOnStringInForLoop .method public hidebysig static void SwitchWithComplexCondition(string[] args) cil managed { - // Code size 138 (0x8a) + // Code size 134 (0x86) .maxstack 2 .locals init (string V_0) IL_0000: nop @@ -1534,55 +1584,51 @@ IL_001e: ldstr "b" IL_0023: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0028: brtrue.s IL_0054 + IL_0028: brtrue.s IL_0053 IL_002a: ldloc.0 IL_002b: ldstr "c" IL_0030: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0035: brtrue.s IL_0062 + IL_0035: brtrue.s IL_0060 IL_0037: ldloc.0 IL_0038: ldstr "d" IL_003d: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0042: brtrue.s IL_0070 + IL_0042: brtrue.s IL_006d - IL_0044: br.s IL_007e + IL_0044: br.s IL_007a - IL_0046: nop - IL_0047: ldstr "a" - IL_004c: call void [mscorlib]System.Console::WriteLine(string) - IL_0051: nop - IL_0052: br.s IL_007e + IL_0046: ldstr "a" + IL_004b: call void [mscorlib]System.Console::WriteLine(string) + IL_0050: nop + IL_0051: br.s IL_007a - IL_0054: nop - IL_0055: ldstr "b" - IL_005a: call void [mscorlib]System.Console::WriteLine(string) - IL_005f: nop - IL_0060: br.s IL_007e - - IL_0062: nop - IL_0063: ldstr "c" - IL_0068: call void [mscorlib]System.Console::WriteLine(string) - IL_006d: nop - IL_006e: br.s IL_007e - - IL_0070: nop - IL_0071: ldstr "d" - IL_0076: call void [mscorlib]System.Console::WriteLine(string) - IL_007b: nop - IL_007c: br.s IL_007e - - IL_007e: ldstr "end" - IL_0083: call void [mscorlib]System.Console::WriteLine(string) - IL_0088: nop - IL_0089: ret + IL_0053: ldstr "b" + IL_0058: call void [mscorlib]System.Console::WriteLine(string) + IL_005d: nop + IL_005e: br.s IL_007a + + IL_0060: ldstr "c" + IL_0065: call void [mscorlib]System.Console::WriteLine(string) + IL_006a: nop + IL_006b: br.s IL_007a + + IL_006d: ldstr "d" + IL_0072: call void [mscorlib]System.Console::WriteLine(string) + IL_0077: nop + IL_0078: br.s IL_007a + + IL_007a: ldstr "end" + IL_007f: call void [mscorlib]System.Console::WriteLine(string) + IL_0084: nop + IL_0085: ret } // end of method Switch::SwitchWithComplexCondition .method public hidebysig static void SwitchWithArray(string[] args) cil managed { - // Code size 127 (0x7f) + // Code size 123 (0x7b) .maxstack 2 .locals init (string V_0) IL_0000: nop @@ -1600,50 +1646,46 @@ IL_0013: ldstr "b" IL_0018: call bool [mscorlib]System.String::op_Equality(string, string) - IL_001d: brtrue.s IL_0049 + IL_001d: brtrue.s IL_0048 IL_001f: ldloc.0 IL_0020: ldstr "c" IL_0025: call bool [mscorlib]System.String::op_Equality(string, string) - IL_002a: brtrue.s IL_0057 + IL_002a: brtrue.s IL_0055 IL_002c: ldloc.0 IL_002d: ldstr "d" IL_0032: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0037: brtrue.s IL_0065 + IL_0037: brtrue.s IL_0062 - IL_0039: br.s IL_0073 + IL_0039: br.s IL_006f - IL_003b: nop - IL_003c: ldstr "a" - IL_0041: call void [mscorlib]System.Console::WriteLine(string) - IL_0046: nop - IL_0047: br.s IL_0073 + IL_003b: ldstr "a" + IL_0040: call void [mscorlib]System.Console::WriteLine(string) + IL_0045: nop + IL_0046: br.s IL_006f - IL_0049: nop - IL_004a: ldstr "b" - IL_004f: call void [mscorlib]System.Console::WriteLine(string) - IL_0054: nop - IL_0055: br.s IL_0073 + IL_0048: ldstr "b" + IL_004d: call void [mscorlib]System.Console::WriteLine(string) + IL_0052: nop + IL_0053: br.s IL_006f - IL_0057: nop - IL_0058: ldstr "c" - IL_005d: call void [mscorlib]System.Console::WriteLine(string) - IL_0062: nop - IL_0063: br.s IL_0073 - - IL_0065: nop - IL_0066: ldstr "d" - IL_006b: call void [mscorlib]System.Console::WriteLine(string) - IL_0070: nop - IL_0071: br.s IL_0073 + IL_0055: ldstr "c" + IL_005a: call void [mscorlib]System.Console::WriteLine(string) + IL_005f: nop + IL_0060: br.s IL_006f - IL_0073: ldstr "end" - IL_0078: call void [mscorlib]System.Console::WriteLine(string) - IL_007d: nop - IL_007e: ret + IL_0062: ldstr "d" + IL_0067: call void [mscorlib]System.Console::WriteLine(string) + IL_006c: nop + IL_006d: br.s IL_006f + + IL_006f: ldstr "end" + IL_0074: call void [mscorlib]System.Console::WriteLine(string) + IL_0079: nop + IL_007a: ret } // end of method Switch::SwitchWithArray } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch From 6272c21ece4c61233644adbe09a98673dc3b481b Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 13 Oct 2017 14:57:43 +0200 Subject: [PATCH 110/190] Simplify SwitchOnNullableTransform. --- .../IL/Transforms/NullableLiftingTransform.cs | 41 +++++++++----- .../Transforms/SwitchOnNullableTransform.cs | 53 ++++++------------- .../IL/Transforms/UsingTransform.cs | 2 +- 3 files changed, 45 insertions(+), 51 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/NullableLiftingTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/NullableLiftingTransform.cs index 8d11720be..20c63b6c8 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/NullableLiftingTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/NullableLiftingTransform.cs @@ -102,7 +102,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms #region AnalyzeCondition bool AnalyzeCondition(ILInstruction condition) { - if (MatchHasValueCall(condition, out var v)) { + if (MatchHasValueCall(condition, out ILVariable v)) { if (nullableVars == null) nullableVars = new List(); nullableVars.Add(v); @@ -387,9 +387,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms // Comparing two nullables: HasValue comparison must be the same operator as the Value comparison if ((hasValueTestNegated ? hasValueComp.Kind.Negate() : hasValueComp.Kind) != newComparisonKind) return null; - if (!MatchHasValueCall(hasValueComp.Left, out var leftVar)) + if (!MatchHasValueCall(hasValueComp.Left, out ILVariable leftVar)) return null; - if (!MatchHasValueCall(hasValueComp.Right, out var rightVar)) + if (!MatchHasValueCall(hasValueComp.Right, out ILVariable rightVar)) return null; nullableVars = new List { leftVar }; var (left, leftBits) = DoLift(valueComp.Left); @@ -401,7 +401,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms context.Step("NullableLiftingTransform: C# (in)equality comparison", valueComp.Instruction); return valueComp.MakeLifted(newComparisonKind, left, right); } - } else if (newComparisonKind == ComparisonKind.Equality && !hasValueTestNegated && MatchHasValueCall(hasValueTest, out var v)) { + } else if (newComparisonKind == ComparisonKind.Equality && !hasValueTestNegated && MatchHasValueCall(hasValueTest, out ILVariable v)) { // Comparing nullable with non-nullable -> we can fall back to the normal comparison code. nullableVars = new List { v }; return LiftCSharpComparison(valueComp, newComparisonKind); @@ -461,13 +461,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms // else // ldc.i4 0 - if (!MatchHasValueCall(hasValueComp.Left, out var nullable1)) + if (!MatchHasValueCall(hasValueComp.Left, out ILVariable nullable1)) return null; - if (!MatchHasValueCall(hasValueComp.Right, out var nullable2)) + if (!MatchHasValueCall(hasValueComp.Right, out ILVariable nullable2)) return null; if (!nestedIfInst.MatchIfInstructionPositiveCondition(out var condition, out var trueInst, out var falseInst)) return null; - if (!MatchHasValueCall(condition, out var nullable)) + if (!MatchHasValueCall(condition, out ILVariable nullable)) return null; if (nullable != nullable1 && nullable != nullable2) return null; @@ -516,7 +516,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (trueInst.MatchIfInstructionPositiveCondition(out var nestedCondition, out var nestedTrue, out var nestedFalse)) { // Sometimes Roslyn generates pointless conditions like: // if (nullable.HasValue && (!nullable.HasValue || nullable.GetValueOrDefault() == b)) - if (MatchHasValueCall(nestedCondition, out var v) && nullableVars.Contains(v)) { + if (MatchHasValueCall(nestedCondition, out ILVariable v) && nullableVars.Contains(v)) { trueInst = nestedTrue; } } @@ -758,11 +758,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms #region Match...Call /// - /// Matches 'call get_HasValue(ldloca v)' + /// Matches 'call get_HasValue(arg)' /// - internal static bool MatchHasValueCall(ILInstruction inst, out ILVariable v) + internal static bool MatchHasValueCall(ILInstruction inst, out ILInstruction arg) { - v = null; + arg = null; if (!(inst is Call call)) return false; if (call.Arguments.Count != 1) @@ -771,7 +771,20 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (call.Method.DeclaringTypeDefinition?.KnownTypeCode != KnownTypeCode.NullableOfT) return false; - return call.Arguments[0].MatchLdLoca(out v); + arg = call.Arguments[0]; + return true; + } + + /// + /// Matches 'call get_HasValue(ldloca v)' + /// + internal static bool MatchHasValueCall(ILInstruction inst, out ILVariable v) + { + if (MatchHasValueCall(inst, out ILInstruction arg)) { + return arg.MatchLdLoca(out v); + } + v = null; + return false; } /// @@ -779,7 +792,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms /// internal static bool MatchHasValueCall(ILInstruction inst, ILVariable v) { - return MatchHasValueCall(inst, out var v2) && v == v2; + return MatchHasValueCall(inst, out ILVariable v2) && v == v2; } /// @@ -811,7 +824,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms /// /// Matches 'call Nullable{T}.GetValueOrDefault(arg)' /// - static bool MatchGetValueOrDefault(ILInstruction inst, out ILInstruction arg) + internal static bool MatchGetValueOrDefault(ILInstruction inst, out ILInstruction arg) { arg = null; if (!(inst is Call call)) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs index 6e01731fc..ed538ca8b 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs @@ -92,15 +92,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!condition.MatchLogicNot(out var getHasValue)) return false; - if (!(getValueOrDefault is Call getValueOrDefaultCall) || getValueOrDefaultCall.Method.FullName != "System.Nullable.GetValueOrDefault" || - getValueOrDefaultCall.Method.DeclaringType.TypeParameterCount != 1) + if (!NullableLiftingTransform.MatchGetValueOrDefault(getValueOrDefault, out ILInstruction getValueOrDefaultArg)) return false; - if (!(getHasValue is Call getHasValueCall) || !getHasValueCall.Method.IsAccessor || getHasValueCall.Method.FullName != "System.Nullable.get_HasValue" || - getHasValueCall.Method.DeclaringType.TypeParameterCount != 1) + if (!NullableLiftingTransform.MatchHasValueCall(getHasValue, out ILInstruction getHasValueArg)) return false; - if (getHasValueCall.Arguments.Count != 1 || getValueOrDefaultCall.Arguments.Count != 1) - return false; - if (!getHasValueCall.Arguments[0].MatchLdLoc(tmp) || !getValueOrDefaultCall.Arguments[0].MatchLdLoc(tmp)) + if (!(getHasValueArg.MatchLdLoc(tmp) && getValueOrDefaultArg.MatchLdLoc(tmp))) return false; // match second block: switchBlock // switch (ldloc switchVariable) { @@ -112,22 +108,19 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!(switchBlock.Instructions[0] is SwitchInstruction switchInst)) return false; - newSwitch = new SwitchInstruction(new LdLoc(switchValueVar)); - newSwitch.IsLifted = true; - SwitchSection defaultSection = null; - foreach (var section in switchInst.Sections) { - if (defaultSection == null || section.Labels.Count() >= defaultSection.Labels.Count()) - defaultSection = section; - newSwitch.Sections.Add(section); - } - if (defaultSection.Body.MatchBranch(out var defaultBlock) && defaultBlock == nullCaseBlock) - defaultSection.HasNullLabel = true; - else { - newSwitch.Sections.Add(new SwitchSection { Body = new Branch(nullCaseBlock), HasNullLabel = true }); - } + newSwitch = BuildLiftedSwitch(nullCaseBlock, switchInst, new LdLoc(switchValueVar)); return true; } + static SwitchInstruction BuildLiftedSwitch(Block nullCaseBlock, SwitchInstruction switchInst, ILInstruction switchValue) + { + SwitchInstruction newSwitch = new SwitchInstruction(switchValue); + newSwitch.IsLifted = true; + newSwitch.Sections.AddRange(switchInst.Sections); + newSwitch.Sections.Add(new SwitchSection { Body = new Branch(nullCaseBlock), HasNullLabel = true }); + return newSwitch; + } + /// /// Matches Roslyn C# switch on nullable. /// @@ -142,11 +135,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!instructions[i - 1].MatchStLoc(out var tmp, out var switchValue) || !instructions[i].MatchIfInstruction(out var condition, out var trueInst)) return false; - if (tmp.StoreCount != 1 || tmp.AddressCount != 2) + if (tmp.StoreCount != 1 || tmp.AddressCount != 2 || tmp.LoadCount != 0) return false; if (!instructions[i + 1].MatchBranch(out var switchBlock) || !trueInst.MatchBranch(out var nullCaseBlock)) return false; - if (!condition.MatchLogicNot(out var getHasValue) || !NullableLiftingTransform.MatchHasValueCall(getHasValue, out var target1) || target1 != tmp) + if (!condition.MatchLogicNot(out var getHasValue) || !NullableLiftingTransform.MatchHasValueCall(getHasValue, out ILVariable target1) || target1 != tmp) return false; // match second block: switchBlock // stloc switchVar(call GetValueOrDefault(ldloca tmp)) @@ -161,23 +154,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!switchVar.IsSingleDefinition || switchVar.LoadCount != 1) return false; - if (!NullableLiftingTransform.MatchGetValueOrDefault(getValueOrDefault, out var target2) || target2 != tmp) + if (!NullableLiftingTransform.MatchGetValueOrDefault(getValueOrDefault, tmp)) return false; if (!(switchBlock.Instructions[1] is SwitchInstruction switchInst)) return false; - newSwitch = new SwitchInstruction(switchValue); - newSwitch.IsLifted = true; - SwitchSection defaultSection = null; - foreach (var section in switchInst.Sections) { - if (defaultSection == null || section.Labels.Count() >= defaultSection.Labels.Count()) - defaultSection = section; - newSwitch.Sections.Add(section); - } - if (defaultSection.Body.MatchBranch(out var defaultBlock) && defaultBlock == nullCaseBlock) - defaultSection.HasNullLabel = true; - else { - newSwitch.Sections.Add(new SwitchSection { Body = new Branch(nullCaseBlock), HasNullLabel = true }); - } + newSwitch = BuildLiftedSwitch(nullCaseBlock, switchInst, switchValue); return true; } } diff --git a/ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs index e0993d6ce..1c64d2983 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs @@ -188,7 +188,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (objVar.Type.IsKnownType(KnownTypeCode.NullableOfT)) { if (!entryPoint.Instructions[checkIndex].MatchIfInstruction(out var condition, out var disposeInst)) return false; - if (!(NullableLiftingTransform.MatchHasValueCall(condition, out var v) && v == objVar)) + if (!NullableLiftingTransform.MatchHasValueCall(condition, objVar)) return false; if (!(disposeInst is Block disposeBlock) || disposeBlock.Instructions.Count != 1) return false; From f988c112298ff9999e31784f09f5f6ee91579144 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 13 Oct 2017 15:35:29 +0200 Subject: [PATCH 111/190] Refactor SwitchOnStringTransform.Run --- .../IL/Transforms/SwitchOnStringTransform.cs | 107 +++++++++--------- 1 file changed, 52 insertions(+), 55 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 2ff02e41f..ddc9ab01d 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -40,52 +40,19 @@ namespace ICSharpCode.Decompiler.IL.Transforms foreach (var block in function.Descendants.OfType()) { bool changed = false; for (int i = block.Instructions.Count - 1; i >= 0; i--) { - SwitchInstruction newSwitch; - if (SimplifyCascadingIfStatements(block.Instructions, i, out newSwitch, out var extraLoad, out var keepAssignmentBefore)) { - if (extraLoad) { - block.Instructions[i - 2].ReplaceWith(newSwitch); - block.Instructions.RemoveRange(i - 1, 3); - i -= 2; - } else { - if (keepAssignmentBefore) { - block.Instructions[i].ReplaceWith(newSwitch); - block.Instructions.RemoveAt(i + 1); - } else { - block.Instructions[i - 1].ReplaceWith(newSwitch); - block.Instructions.RemoveRange(i, 2); - i--; - } - } + if (SimplifyCascadingIfStatements(block.Instructions, ref i)) { changed = true; continue; } - if (MatchLegacySwitchOnStringWithHashtable(block.Instructions, i, out newSwitch)) { - block.Instructions[i + 1].ReplaceWith(newSwitch); - block.Instructions.RemoveAt(i); + if (MatchLegacySwitchOnStringWithHashtable(block.Instructions, ref i)) { changed = true; continue; } - if (MatchLegacySwitchOnStringWithDict(block.Instructions, i, out newSwitch, out keepAssignmentBefore)) { - block.Instructions[i + 1].ReplaceWith(newSwitch); - if (keepAssignmentBefore) { - block.Instructions.RemoveAt(i); - i--; - } else { - block.Instructions.RemoveRange(i - 1, 2); - i -= 2; - } + if (MatchLegacySwitchOnStringWithDict(block.Instructions, ref i)) { changed = true; continue; } - if (MatchRoslynSwitchOnString(block.Instructions, i, out newSwitch, out keepAssignmentBefore)) { - block.Instructions[i].ReplaceWith(newSwitch); - if (keepAssignmentBefore) { - block.Instructions.RemoveAt(i - 1); - i--; - } else { - block.Instructions.RemoveRange(i - 2, 2); - i -= 2; - } + if (MatchRoslynSwitchOnString(block.Instructions, ref i)) { changed = true; continue; } @@ -100,11 +67,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms container.SortBlocks(deleteUnreachableBlocks: true); } - bool SimplifyCascadingIfStatements(InstructionCollection instructions, int i, out SwitchInstruction inst, out bool extraLoad, out bool keepAssignmentBefore) + bool SimplifyCascadingIfStatements(InstructionCollection instructions, ref int i) { - inst = null; - extraLoad = false; - keepAssignmentBefore = false; if (i < 1) return false; // match first block: checking switch-value for null or first value (Roslyn) // if (call op_Equality(ldloc switchValueVar, ldstr value)) br firstBlock @@ -116,6 +80,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; List<(string, Block)> values = new List<(string, Block)>(); ILInstruction switchValue = null; + bool extraLoad = false; + bool keepAssignmentBefore = false; + // Roslyn: match call to operator ==(string, string) if (MatchStringEqualityComparison(condition, out var switchValueVar, out string value)) { values.Add((value, firstBlock)); @@ -165,8 +132,22 @@ namespace ICSharpCode.Decompiler.IL.Transforms var sections = new List(values.SelectWithIndex((index, b) => new SwitchSection { Labels = new LongSet(index), Body = new Branch(b.Item2) })); sections.Add(new SwitchSection { Labels = new LongSet(new LongInterval(0, sections.Count)).Invert(), Body = new Branch(currentCaseBlock) }); var stringToInt = new StringToInt(switchValue, values.SelectArray(item => item.Item1)); - inst = new SwitchInstruction(stringToInt); + var inst = new SwitchInstruction(stringToInt); inst.Sections.AddRange(sections); + if (extraLoad) { + instructions[i - 2].ReplaceWith(inst); + instructions.RemoveRange(i - 1, 3); + i -= 2; + } else { + if (keepAssignmentBefore) { + instructions[i].ReplaceWith(inst); + instructions.RemoveAt(i + 1); + } else { + instructions[i - 1].ReplaceWith(inst); + instructions.RemoveRange(i, 2); + i--; + } + } return true; } @@ -234,10 +215,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms /// /// Matches the C# 2.0 switch-on-string pattern, which uses Dictionary<string, int>. /// - bool MatchLegacySwitchOnStringWithDict(InstructionCollection instructions, int i, out SwitchInstruction inst, out bool keepAssignmentBefore) + bool MatchLegacySwitchOnStringWithDict(InstructionCollection instructions, ref int i) { - inst = null; - keepAssignmentBefore = false; if (i < 1) return false; // match first block: checking switch-value for null if (!(instructions[i].MatchIfInstruction(out var condition, out var exitBlockJump) && @@ -299,13 +278,22 @@ namespace ICSharpCode.Decompiler.IL.Transforms stringValues.Add(null); sections.Add(new SwitchSection() { Labels = label, Body = new Branch(nullValueCaseBlock) }); } + bool keepAssignmentBefore = false; if (switchValueVar.LoadCount > 2) { switchValue = new LdLoc(switchValueVar); keepAssignmentBefore = true; } var stringToInt = new StringToInt(switchValue, stringValues.ToArray()); - inst = new SwitchInstruction(stringToInt); + var inst = new SwitchInstruction(stringToInt); inst.Sections.AddRange(sections); + instructions[i + 1].ReplaceWith(inst); + if (keepAssignmentBefore) { + instructions.RemoveAt(i); + i--; + } else { + instructions.RemoveRange(i - 1, 2); + i -= 2; + } return true; } @@ -365,9 +353,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; } - bool MatchLegacySwitchOnStringWithHashtable(InstructionCollection instructions, int i, out SwitchInstruction inst) + bool MatchLegacySwitchOnStringWithHashtable(InstructionCollection instructions, ref int i) { - inst = null; // match first block: checking compiler-generated Hashtable for null // if (comp(volatile.ldobj System.Collections.Hashtable(ldsflda $$method0x600003f-1) != ldnull)) br switchHeadBlock // br tableInitBlock @@ -453,15 +440,15 @@ namespace ICSharpCode.Decompiler.IL.Transforms sections.Add(new SwitchSection() { Labels = label, Body = new Branch(nullCaseBlock) }); } var stringToInt = new StringToInt(switchValue, stringValues.ToArray()); - inst = new SwitchInstruction(stringToInt); + var inst = new SwitchInstruction(stringToInt); inst.Sections.AddRange(sections); + instructions[i + 1].ReplaceWith(inst); + instructions.RemoveAt(i); return true; } - bool MatchRoslynSwitchOnString(InstructionCollection instructions, int i, out SwitchInstruction inst, out bool keepAssignmentBefore) + bool MatchRoslynSwitchOnString(InstructionCollection instructions, ref int i) { - inst = null; - keepAssignmentBefore = false; if (i < 1) return false; if (!(instructions[i] is SwitchInstruction switchInst && switchInst.Value.MatchLdLoc(out var targetVar) && MatchComputeStringHashCall(instructions[i - 1], targetVar, out var switchValue))) @@ -499,17 +486,27 @@ namespace ICSharpCode.Decompiler.IL.Transforms stringValues.Add((index++, stringValue, body)); } ILInstruction switchValueInst = switchValue; + bool keepAssignmentBefore; if (i > 1 && instructions[i - 2].MatchStLoc(switchValue.Variable, out var switchValueTmp) && switchValue.Variable.IsSingleDefinition && switchValue.Variable.LoadCount == switchInst.Sections.Count) { switchValueInst = switchValueTmp; + keepAssignmentBefore = false; } else { keepAssignmentBefore = true; } var defaultLabel = new LongSet(new LongInterval(0, index)).Invert(); var value = new StringToInt(switchValueInst, stringValues.Select(item => item.Item2).ToArray()); - inst = new SwitchInstruction(value); - inst.Sections.AddRange(stringValues.Select(section => new SwitchSection { Labels = new Util.LongSet(section.Item1), Body = new Branch(section.Item3) })); - inst.Sections.Add(new SwitchSection { Labels = defaultLabel, Body = defaultBranch }); + var newSwitch = new SwitchInstruction(value); + newSwitch.Sections.AddRange(stringValues.Select(section => new SwitchSection { Labels = new Util.LongSet(section.Item1), Body = new Branch(section.Item3) })); + newSwitch.Sections.Add(new SwitchSection { Labels = defaultLabel, Body = defaultBranch }); + instructions[i].ReplaceWith(newSwitch); + if (keepAssignmentBefore) { + instructions.RemoveAt(i - 1); + i--; + } else { + instructions.RemoveRange(i - 2, 2); + i -= 2; + } return true; } From 9fcee831d25af86e36bf2f741415ef884d50d428 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 13 Oct 2017 16:04:24 +0200 Subject: [PATCH 112/190] Simplify SimplifyCascadingIfStatements --- .../IL/Instructions/PatternMatching.cs | 21 ++++ .../IL/Transforms/SwitchOnStringTransform.cs | 109 +++++++----------- 2 files changed, 63 insertions(+), 67 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Instructions/PatternMatching.cs b/ICSharpCode.Decompiler/IL/Instructions/PatternMatching.cs index 26b33c0f6..0510b8c87 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/PatternMatching.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/PatternMatching.cs @@ -321,6 +321,27 @@ namespace ICSharpCode.Decompiler.IL } } + /// + /// Matches 'comp(arg == ldnull)' + /// + public bool MatchCompEqualsNull(out ILInstruction arg) + { + if (!MatchCompEquals(out var left, out var right)) { + arg = null; + return false; + } + if (right.MatchLdNull()) { + arg = left; + return true; + } else if (left.MatchLdNull()) { + arg = right; + return true; + } else { + arg = null; + return false; + } + } + /// /// Matches comp(left != right) or logic.not(comp(left == right)). /// diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index ddc9ab01d..c37b8fe15 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -80,44 +80,40 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; List<(string, Block)> values = new List<(string, Block)>(); ILInstruction switchValue = null; - bool extraLoad = false; - bool keepAssignmentBefore = false; - // Roslyn: match call to operator ==(string, string) - if (MatchStringEqualityComparison(condition, out var switchValueVar, out string value)) { - values.Add((value, firstBlock)); - if(!instructions[i - 1].MatchStLoc(switchValueVar, out switchValue)) { - switchValue = new LdLoc(switchValueVar); - } - } else { - // match null check with different variable: - // this is used by the old C# compiler. - if (MatchCompEqualsNull(condition, out var otherSwitchValueVar)) { - values.Add((null, firstBlock)); - } else { - return false; - } + // match call to operator ==(string, string) + if (!MatchStringEqualityComparison(condition, out var switchValueVar, out string firstBlockValue)) + return false; + values.Add((firstBlockValue, firstBlock)); + bool extraLoad = false; + if (instructions[i - 1].MatchStLoc(switchValueVar, out switchValue)) { + // stloc switchValueVar(switchValue) + // if (call op_Equality(ldloc switchValueVar, ldstr value)) br firstBlock + } else if (instructions[i - 1] is StLoc stloc && stloc.Value.MatchLdLoc(switchValueVar)) { // in case of optimized legacy code there are two stlocs: // stloc otherSwitchValueVar(ldloc switchValue) // stloc switchValueVar(ldloc otherSwitchValueVar) - // if (comp(ldloc otherSwitchValueVar == ldnull)) br nullCase - if (i > 1 && otherSwitchValueVar != null && instructions[i - 2].MatchStLoc(otherSwitchValueVar, out switchValue) - && instructions[i - 1].MatchStLoc(out switchValueVar, out var switchValueCopyInst) - && switchValueCopyInst.MatchLdLoc(otherSwitchValueVar) && otherSwitchValueVar.IsSingleDefinition && otherSwitchValueVar.LoadCount == 2) { + // if (call op_Equality(ldloc otherSwitchValueVar, ldstr value)) br firstBlock + var otherSwitchValueVar = switchValueVar; + switchValueVar = stloc.Variable; + if (i >= 2 && instructions[i - 2].MatchStLoc(otherSwitchValueVar, out switchValue) + && otherSwitchValueVar.IsSingleDefinition && otherSwitchValueVar.LoadCount == 2) + { extraLoad = true; - } else if (instructions[i - 1].MatchStLoc(out switchValueVar, out switchValue)) { - // unoptimized legacy switch + } else { + switchValue = new LdLoc(otherSwitchValueVar); } + } else { + switchValue = new LdLoc(switchValueVar); } - // if instruction must be followed by a branch to the next case if (!(instructions.ElementAtOrDefault(i + 1) is Branch nextCaseJump)) return false; // extract all cases and add them to the values list. Block currentCaseBlock = nextCaseJump.TargetBlock; Block nextCaseBlock; - while ((nextCaseBlock = MatchCaseBlock(currentCaseBlock, switchValueVar, out value, out Block block)) != null) { + while ((nextCaseBlock = MatchCaseBlock(currentCaseBlock, switchValueVar, out string value, out Block block)) != null) { values.Add((value, block)); currentCaseBlock = nextCaseBlock; } @@ -125,6 +121,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (values.Count < 3) return false; // if the switchValueVar is used in other places as well, do not eliminate the store. + bool keepAssignmentBefore = false; if (switchValueVar.LoadCount > values.Count) { keepAssignmentBefore = true; switchValue = new LdLoc(switchValueVar); @@ -187,31 +184,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!currentBlock.Instructions[1].MatchBranch(out nextBlock)) return null; } - if (!MatchStringEqualityComparison(condition, out var v, out value)) { - if (MatchCompEqualsNull(condition, out v)) { - value = null; - } else { + if (!MatchStringEqualityComparison(condition, switchVariable, out value)) { return null; } - } - if (v != switchVariable) - return null; return nextBlock; } - - /// - /// Returns true if is only assigned once and the initialization is done by copying . - /// - bool IsInitializedBy(ILVariable left, ILVariable right) - { - if (!left.IsSingleDefinition) - return false; - var storeInst = left.StoreInstructions.OfType().SingleOrDefault(); - if (storeInst == null) - return false; - return storeInst.Value.MatchLdLoc(right); - } - + /// /// Matches the C# 2.0 switch-on-string pattern, which uses Dictionary<string, int>. /// @@ -475,8 +453,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!bodyBranch.MatchBranch(out Block body)) return false; - if (!MatchStringEqualityOrNullComparison(condition, switchValue.Variable, out string stringValue)) { - if (condition.MatchLogicNot(out condition) && MatchStringEqualityOrNullComparison(condition, switchValue.Variable, out stringValue)) { + if (!MatchStringEqualityComparison(condition, switchValue.Variable, out string stringValue)) { + if (condition.MatchLogicNot(out condition) && MatchStringEqualityComparison(condition, switchValue.Variable, out stringValue)) { if (!target.Instructions[1].MatchBranch(out Block exit)) return false; body = exit; @@ -523,39 +501,36 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; } - bool MatchStringEqualityOrNullComparison(ILInstruction condition, ILVariable variable, out string stringValue) + /// + /// Matches 'call string.op_Equality(ldloc(variable), ldstr(stringValue))' + /// or 'comp(ldloc(variable) == ldnull)' + /// + bool MatchStringEqualityComparison(ILInstruction condition, ILVariable variable, out string stringValue) { - if (!MatchStringEqualityComparison(condition, out var v, out stringValue)) { - if (!MatchCompEqualsNull(condition, out v)) - return false; - stringValue = null; + return MatchStringEqualityComparison(condition, out var v, out stringValue) && v == variable; } - return v == variable; - } - + /// + /// Matches 'call string.op_Equality(ldloc(variable), ldstr(stringValue))' + /// or 'comp(ldloc(variable) == ldnull)' + /// bool MatchStringEqualityComparison(ILInstruction condition, out ILVariable variable, out string stringValue) { stringValue = null; variable = null; ILInstruction left, right; - if (condition is Call c && c.Method.IsOperator && c.Method.Name == "op_Equality" && c.Arguments.Count == 2) { + if (condition is Call c && c.Method.IsOperator && c.Method.Name == "op_Equality" + && c.Method.DeclaringType.IsKnownType(KnownTypeCode.String) && c.Arguments.Count == 2) + { left = c.Arguments[0]; right = c.Arguments[1]; - if (!right.MatchLdStr(out stringValue)) - return false; + return left.MatchLdLoc(out variable) && right.MatchLdStr(out stringValue); + } else if (condition.MatchCompEqualsNull(out var arg)) { + stringValue = null; + return arg.MatchLdLoc(out variable); } else { return false; } - return left.MatchLdLoc(out variable); } - - bool MatchCompEqualsNull(ILInstruction condition, out ILVariable variable) - { - variable = null; - if (!condition.MatchCompEquals(out var left, out var right)) - return false; - return right.MatchLdNull() && left.MatchLdLoc(out variable); } } -} From b94088fbc92c78ad32233a709b8bafe9215f73c0 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 13 Oct 2017 17:12:34 +0200 Subject: [PATCH 113/190] Add MaxBy, MaxOrDefault, MinBy extension methods --- .../Util/CollectionExtensions.cs | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/ICSharpCode.Decompiler/Util/CollectionExtensions.cs b/ICSharpCode.Decompiler/Util/CollectionExtensions.cs index 0223d4f1e..d6f67cae8 100644 --- a/ICSharpCode.Decompiler/Util/CollectionExtensions.cs +++ b/ICSharpCode.Decompiler/Util/CollectionExtensions.cs @@ -114,5 +114,81 @@ namespace ICSharpCode.Decompiler.Util moreB = enumB.MoveNext(); } } + + /// + /// Returns the minimum element. + /// + /// The input sequence is empty + public static T MinBy(this IEnumerable source, Func keySelector) where K : IComparable + { + return source.MinBy(keySelector, Comparer.Default); + } + + /// + /// Returns the minimum element. + /// + /// The input sequence is empty + public static T MinBy(this IEnumerable source, Func keySelector, IComparer keyComparer) + { + if (source == null) + throw new ArgumentNullException(nameof(source)); + if (keySelector == null) + throw new ArgumentNullException(nameof(keySelector)); + if (keyComparer == null) + keyComparer = Comparer.Default; + using (var enumerator = source.GetEnumerator()) { + if (!enumerator.MoveNext()) + throw new InvalidOperationException("Sequence contains no elements"); + T minElement = enumerator.Current; + K minKey = keySelector(minElement); + while (enumerator.MoveNext()) { + T element = enumerator.Current; + K key = keySelector(element); + if (keyComparer.Compare(key, minKey) < 0) { + minElement = element; + minKey = key; + } + } + return minElement; + } + } + + /// + /// Returns the maximum element. + /// + /// The input sequence is empty + public static T MaxBy(this IEnumerable source, Func keySelector) where K : IComparable + { + return source.MaxBy(keySelector, Comparer.Default); + } + + /// + /// Returns the maximum element. + /// + /// The input sequence is empty + public static T MaxBy(this IEnumerable source, Func keySelector, IComparer keyComparer) + { + if (source == null) + throw new ArgumentNullException(nameof(source)); + if (keySelector == null) + throw new ArgumentNullException(nameof(keySelector)); + if (keyComparer == null) + keyComparer = Comparer.Default; + using (var enumerator = source.GetEnumerator()) { + if (!enumerator.MoveNext()) + throw new InvalidOperationException("Sequence contains no elements"); + T maxElement = enumerator.Current; + K maxKey = keySelector(maxElement); + while (enumerator.MoveNext()) { + T element = enumerator.Current; + K key = keySelector(element); + if (keyComparer.Compare(key, maxKey) > 0) { + maxElement = element; + maxKey = key; + } + } + return maxElement; + } + } } } From e6608832a4b4fdec6c5886727aa7c2fbc943b485 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 13 Oct 2017 18:03:53 +0200 Subject: [PATCH 114/190] Add documentation to SwitchOnStringTransform --- .../IL/Transforms/SwitchOnStringTransform.cs | 127 ++++++++++++------ 1 file changed, 87 insertions(+), 40 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index c37b8fe15..1f7d0f232 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -185,11 +185,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms return null; } if (!MatchStringEqualityComparison(condition, switchVariable, out value)) { - return null; - } + return null; + } return nextBlock; } - + /// /// Matches the C# 2.0 switch-on-string pattern, which uses Dictionary<string, int>. /// @@ -197,6 +197,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms { if (i < 1) return false; // match first block: checking switch-value for null + // stloc switchValueVar(switchValue) + // if (comp(ldloc switchValueVar == ldnull)) br nullCase + // br nextBlock if (!(instructions[i].MatchIfInstruction(out var condition, out var exitBlockJump) && instructions[i - 1].MatchStLoc(out var switchValueVar, out var switchValue) && switchValueVar.Type.IsKnownType(KnownTypeCode.String))) return false; @@ -210,6 +213,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (nextBlockJump == null || nextBlockJump.TargetBlock.IncomingEdgeCount != 1) return false; // match second block: checking compiler-generated Dictionary for null + // if (comp(volatile.ldobj System.Collections.Generic.Dictionary`2[[System.String],[System.Int32]](ldsflda $$method0x600000c-1) != ldnull)) br caseNullBlock + // br dictInitBlock var nextBlock = nextBlockJump.TargetBlock; if (nextBlock.Instructions.Count != 2 || !nextBlock.Instructions[0].MatchIfInstruction(out condition, out var tryGetValueBlockJump)) return false; @@ -221,11 +226,18 @@ namespace ICSharpCode.Decompiler.IL.Transforms MatchDictionaryFieldLoad(left, IsStringToIntDictionary, out var dictField, out var dictionaryType))) return false; // match third block: initialization of compiler-generated Dictionary + // stloc dict(newobj Dictionary..ctor(ldc.i4 valuesLength)) + // call Add(ldloc dict, ldstr value, ldc.i4 index) + // ... more calls to Add ... + // volatile.stobj System.Collections.Generic.Dictionary`2[[System.String],[System.Int32]](ldsflda $$method0x600003f-1, ldloc dict) + // br switchHeadBlock if (dictInitBlock.IncomingEdgeCount != 1 || dictInitBlock.Instructions.Count < 3) return false; if (!ExtractStringValuesFromInitBlock(dictInitBlock, out var stringValues, tryGetValueBlock, dictionaryType, dictField)) return false; // match fourth block: TryGetValue on compiler-generated Dictionary + // if (logic.not(call TryGetValue(volatile.ldobj System.Collections.Generic.Dictionary`2[[System.String],[System.Int32]](ldsflda $$method0x600000c-1), ldloc switchValueVar, ldloca switchIndexVar))) br defaultBlock + // br switchBlock if (tryGetValueBlock.IncomingEdgeCount != 2 || tryGetValueBlock.Instructions.Count != 2) return false; if (!tryGetValueBlock.Instructions[0].MatchIfInstruction(out condition, out var defaultBlockJump)) @@ -240,6 +252,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!tryGetValueBlock.Instructions[1].MatchBranch(out var switchBlock)) return false; // match fifth block: switch-instruction block + // switch (ldloc switchVariable) { + // case [0..1): br caseBlock1 + // ... more cases ... + // case [long.MinValue..0),[13..long.MaxValue]: br defaultBlock + // } if (switchBlock.IncomingEdgeCount != 1 || switchBlock.Instructions.Count != 1) return false; if (!(switchBlock.Instructions[0] is SwitchInstruction switchInst && switchInst.Value.MatchLdLoc(switchIndexVar))) @@ -275,6 +292,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; } + /// + /// Matches 'volatile.ldobj dictionaryType(ldsflda dictField)' + /// bool MatchDictionaryFieldLoad(ILInstruction inst, Func typeMatcher, out IField dictField, out IType dictionaryType) { dictField = null; @@ -285,6 +305,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms (dictField.IsCompilerGeneratedOrIsInCompilerGeneratedClass() || dictField.Name.StartsWith("$$method", StringComparison.Ordinal)); } + /// + /// Matches and extracts values from Add-call sequences. + /// bool ExtractStringValuesFromInitBlock(Block block, out List values, Block targetBlock, IType dictionaryType, IField dictionaryField) { values = null; @@ -304,12 +327,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms return block.Instructions[i + 2].MatchBranch(targetBlock); } - bool MatchAddCall(ILInstruction inst, ILVariable dictVar, int i, out string value) + /// + /// call Add(ldloc dictVar, ldstr value, ldc.i4 index) + /// -or- + /// call Add(ldloc dictVar, ldstr value, box System.Int32(ldc.i4 index)) + /// + bool MatchAddCall(ILInstruction inst, ILVariable dictVar, int index, out string value) { value = null; return inst is Call c && c.Method.Name == "Add" && c.Arguments.Count == 3 && c.Arguments[0].MatchLdLoc(dictVar) && c.Arguments[1].MatchLdStr(out value) && - (c.Arguments[2].MatchLdcI4(i) || (c.Arguments[2].MatchBox(out var arg, out _) && arg.MatchLdcI4(i))); + (c.Arguments[2].MatchLdcI4(index) || (c.Arguments[2].MatchBox(out var arg, out _) && arg.MatchLdcI4(index))); } bool IsStringToIntDictionary(IType dictionaryType) @@ -428,55 +456,45 @@ namespace ICSharpCode.Decompiler.IL.Transforms bool MatchRoslynSwitchOnString(InstructionCollection instructions, ref int i) { if (i < 1) return false; - if (!(instructions[i] is SwitchInstruction switchInst && switchInst.Value.MatchLdLoc(out var targetVar) && - MatchComputeStringHashCall(instructions[i - 1], targetVar, out var switchValue))) + // stloc switchValueVar(call ComputeStringHash(switchValue)) + // switch (ldloc switchValueVar) { + // case [211455823..211455824): br caseBlock1 + // ... more cases ... + // case [long.MinValue..-365098645),...,[1697255802..long.MaxValue]: br defaultBlock + // } + if (!(instructions[i] is SwitchInstruction switchInst && switchInst.Value.MatchLdLoc(out var switchValueVar) && + MatchComputeStringHashCall(instructions[i - 1], switchValueVar, out LdLoc switchValueLoad))) return false; var stringValues = new List<(int, string, Block)>(); int index = 0; - ILInstruction defaultBranch = null; + SwitchSection defaultSection = switchInst.Sections.MaxBy(s => s.Labels.Count()); foreach (var section in switchInst.Sections) { - if (!section.Body.MatchBranch(out Block target)) { - if (section.Body is Leave leave) { - defaultBranch = leave; - continue; - } + if (section == defaultSection) continue; + // extract target block + if (!section.Body.MatchBranch(out Block target)) return false; - } - if (target.IncomingEdgeCount > 1) { - defaultBranch = new Branch(target); - continue; - } - if (target.Instructions.Count != 2) - return false; - if (!target.Instructions[0].MatchIfInstruction(out var condition, out var bodyBranch)) - return false; - if (!bodyBranch.MatchBranch(out Block body)) + if (!MatchRoslynCaseBlockHead(target, switchValueLoad.Variable, out Block body, out string stringValue)) return false; - if (!MatchStringEqualityComparison(condition, switchValue.Variable, out string stringValue)) { - if (condition.MatchLogicNot(out condition) && MatchStringEqualityComparison(condition, switchValue.Variable, out stringValue)) { - if (!target.Instructions[1].MatchBranch(out Block exit)) - return false; - body = exit; - } else - return false; - } stringValues.Add((index++, stringValue, body)); } - ILInstruction switchValueInst = switchValue; + ILInstruction switchValueInst = switchValueLoad; + // stloc switchValueLoadVariable(switchValue) + // stloc switchValueVar(call ComputeStringHash(ldloc V_0)) + // switch (ldloc switchValueVar) { bool keepAssignmentBefore; - if (i > 1 && instructions[i - 2].MatchStLoc(switchValue.Variable, out var switchValueTmp) && - switchValue.Variable.IsSingleDefinition && switchValue.Variable.LoadCount == switchInst.Sections.Count) { + // if the switchValueLoad.Variable is only used in the compiler generated case equality checks, we can remove it. + if (i > 1 && instructions[i - 2].MatchStLoc(switchValueLoad.Variable, out var switchValueTmp) && + switchValueLoad.Variable.IsSingleDefinition && switchValueLoad.Variable.LoadCount == switchInst.Sections.Count) { switchValueInst = switchValueTmp; keepAssignmentBefore = false; } else { keepAssignmentBefore = true; } var defaultLabel = new LongSet(new LongInterval(0, index)).Invert(); - var value = new StringToInt(switchValueInst, stringValues.Select(item => item.Item2).ToArray()); - var newSwitch = new SwitchInstruction(value); + var newSwitch = new SwitchInstruction(new StringToInt(switchValueInst, stringValues.Select(item => item.Item2).ToArray())); newSwitch.Sections.AddRange(stringValues.Select(section => new SwitchSection { Labels = new Util.LongSet(section.Item1), Body = new Branch(section.Item3) })); - newSwitch.Sections.Add(new SwitchSection { Labels = defaultLabel, Body = defaultBranch }); + newSwitch.Sections.Add(new SwitchSection { Labels = defaultLabel, Body = defaultSection.Body }); instructions[i].ReplaceWith(newSwitch); if (keepAssignmentBefore) { instructions.RemoveAt(i - 1); @@ -488,6 +506,35 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; } + /// + /// Matches and the negated version: + /// if (call op_Equality(ldloc V_0, ldstr "Fifth case")) br body + /// br exit + /// + bool MatchRoslynCaseBlockHead(Block target, ILVariable switchValueVar, out Block body, out string stringValue) + { + body = null; + stringValue = null; + if (target.Instructions.Count != 2) + return false; + if (!target.Instructions[0].MatchIfInstruction(out var condition, out var bodyBranch)) + return false; + if (!bodyBranch.MatchBranch(out body)) + return false; + if (!MatchStringEqualityComparison(condition, switchValueVar, out stringValue)) { + if (condition.MatchLogicNot(out condition) && MatchStringEqualityComparison(condition, switchValueVar, out stringValue)) { + if (!target.Instructions[1].MatchBranch(out Block exit)) + return false; + body = exit; + } else + return false; + } + return body != null; + } + + /// + /// Matches 'stloc(targetVar, call ComputeStringHash(ldloc(switchValue)))' + /// bool MatchComputeStringHashCall(ILInstruction inst, ILVariable targetVar, out LdLoc switchValue) { switchValue = null; @@ -508,8 +555,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms bool MatchStringEqualityComparison(ILInstruction condition, ILVariable variable, out string stringValue) { return MatchStringEqualityComparison(condition, out var v, out stringValue) && v == variable; - } - + } + /// /// Matches 'call string.op_Equality(ldloc(variable), ldstr(stringValue))' /// or 'comp(ldloc(variable) == ldnull)' @@ -532,5 +579,5 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; } } - } } +} From a423e7da9ccd2b513dfc1c8eedd3cc343e05301b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 13 Oct 2017 19:41:31 +0200 Subject: [PATCH 115/190] Expand checks in ExtractStringValuesFromInitBlock and MatchAddCall --- .../IL/Instructions/PatternMatching.cs | 5 +++ .../IL/Transforms/SwitchOnStringTransform.cs | 37 +++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Instructions/PatternMatching.cs b/ICSharpCode.Decompiler/IL/Instructions/PatternMatching.cs index 0510b8c87..3382d6926 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/PatternMatching.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/PatternMatching.cs @@ -27,6 +27,11 @@ namespace ICSharpCode.Decompiler.IL return OpCode == OpCode.LdcI4 && ((LdcI4)this).Value == val; } + public bool MatchLdcF(double value) + { + return MatchLdcF(out var v) && v == value; + } + /// /// Matches either LdcI4 or LdcI8. /// diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 1f7d0f232..670e870c8 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -207,7 +207,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!exitBlockJump.MatchBranch(out var nullValueCaseBlock)) return false; - if (!(condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && (left.Match(switchValue).Success || left.MatchLdLoc(switchValueVar)))) + if (!(condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() + && ((SemanticHelper.IsPure(switchValue.Flags) && left.Match(switchValue).Success) || left.MatchLdLoc(switchValueVar)))) return false; var nextBlockJump = instructions.ElementAtOrDefault(i + 1) as Branch; if (nextBlockJump == null || nextBlockJump.TargetBlock.IncomingEdgeCount != 1) @@ -311,15 +312,31 @@ namespace ICSharpCode.Decompiler.IL.Transforms bool ExtractStringValuesFromInitBlock(Block block, out List values, Block targetBlock, IType dictionaryType, IField dictionaryField) { values = null; - if (!(block.Instructions[0].MatchStLoc(out var dictVar, out var newObjDict) && - newObjDict is NewObj newObj && newObj.Arguments.Count >= 1 && newObj.Arguments[0].MatchLdcI4(out var valuesLength))) + // stloc dictVar(newobj Dictionary..ctor(ldc.i4 valuesLength)) + // -or- + // stloc dictVar(newobj Hashtable..ctor(ldc.i4 capacity, ldc.f loadFactor)) + if (!(block.Instructions[0].MatchStLoc(out var dictVar, out var newObjDict) && newObjDict is NewObj newObj)) + return false; + if (!newObj.Method.DeclaringType.Equals(dictionaryType)) return false; + int valuesLength = 0; + if (newObj.Arguments.Count == 2) { + if (!newObj.Arguments[0].MatchLdcI4(out valuesLength)) + return false; + if (!newObj.Arguments[1].MatchLdcF(0.5)) + return false; + } else if (newObj.Arguments.Count == 1) { + if (!newObj.Arguments[0].MatchLdcI4(out valuesLength)) + return false; + } values = new List(valuesLength); int i = 0; - while (i + 1 < block.Instructions.Count - 2 && MatchAddCall(block.Instructions[i + 1], dictVar, i, out var value)) { + while (MatchAddCall(dictionaryType, block.Instructions[i + 1], dictVar, i, out var value)) { values.Add(value); i++; } + // final store to compiler-generated variable: + // volatile.stobj dictionaryType(ldsflda dictionaryField, ldloc dictVar) if (!(block.Instructions[i + 1].MatchStObj(out var loadField, out var dictVarLoad, out var dictType) && dictType.Equals(dictionaryType) && loadField.MatchLdsFlda(out var dictField) && dictField.Equals(dictionaryField)) && dictVarLoad.MatchLdLoc(dictVar)) @@ -332,12 +349,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms /// -or- /// call Add(ldloc dictVar, ldstr value, box System.Int32(ldc.i4 index)) /// - bool MatchAddCall(ILInstruction inst, ILVariable dictVar, int index, out string value) + bool MatchAddCall(IType dictionaryType, ILInstruction inst, ILVariable dictVar, int index, out string value) { value = null; - return inst is Call c && c.Method.Name == "Add" && c.Arguments.Count == 3 && - c.Arguments[0].MatchLdLoc(dictVar) && c.Arguments[1].MatchLdStr(out value) && - (c.Arguments[2].MatchLdcI4(index) || (c.Arguments[2].MatchBox(out var arg, out _) && arg.MatchLdcI4(index))); + if (!(inst is Call c && c.Method.Name == "Add" && c.Arguments.Count == 3)) + return false; + if (!(c.Arguments[0].MatchLdLoc(dictVar) && c.Arguments[1].MatchLdStr(out value))) + return false; + if (!(c.Method.DeclaringType.Equals(dictionaryType) && c.Method.IsStatic)) + return false; + return (c.Arguments[2].MatchLdcI4(index) || (c.Arguments[2].MatchBox(out var arg, out _) && arg.MatchLdcI4(index))); } bool IsStringToIntDictionary(IType dictionaryType) From 1ac631b3f1442ccca667da228466d84b4d2cb228 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 13 Oct 2017 20:04:20 +0200 Subject: [PATCH 116/190] SwitchOnStringTransform: fix bugs in ExtractStringValuesFromInitBlock and MatchAddCall --- .../IL/Transforms/SwitchOnStringTransform.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 670e870c8..278520689 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -338,8 +338,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms // final store to compiler-generated variable: // volatile.stobj dictionaryType(ldsflda dictionaryField, ldloc dictVar) if (!(block.Instructions[i + 1].MatchStObj(out var loadField, out var dictVarLoad, out var dictType) && - dictType.Equals(dictionaryType) && loadField.MatchLdsFlda(out var dictField) && dictField.Equals(dictionaryField)) && - dictVarLoad.MatchLdLoc(dictVar)) + dictType.Equals(dictionaryType) && loadField.MatchLdsFlda(out var dictField) && dictField.Equals(dictionaryField) && + dictVarLoad.MatchLdLoc(dictVar))) return false; return block.Instructions[i + 2].MatchBranch(targetBlock); } @@ -356,7 +356,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!(c.Arguments[0].MatchLdLoc(dictVar) && c.Arguments[1].MatchLdStr(out value))) return false; - if (!(c.Method.DeclaringType.Equals(dictionaryType) && c.Method.IsStatic)) + if (!(c.Method.DeclaringType.Equals(dictionaryType) && !c.Method.IsStatic)) return false; return (c.Arguments[2].MatchLdcI4(index) || (c.Arguments[2].MatchBox(out var arg, out _) && arg.MatchLdcI4(index))); } From 2824906f8fb6f74f918a87ba9d70ebae981daf6a Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 13 Oct 2017 20:07:13 +0200 Subject: [PATCH 117/190] Code cleanup SwitchOnStringTransform. --- .../IL/Transforms/SwitchOnStringTransform.cs | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 278520689..7dffaf2b4 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -265,14 +265,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms var sections = new List(switchInst.Sections); // switch contains case null: if (nullValueCaseBlock != defaultBlock) { - var label = new Util.LongSet(switchInst.Sections.Count); - var possibleConflicts = switchInst.Sections.Where(sec => sec.Labels.Overlaps(label)).ToArray(); - if (possibleConflicts.Length > 1) + if (!AddNullSection(sections, stringValues, nullValueCaseBlock)) { return false; - else if (possibleConflicts.Length == 1) - possibleConflicts[0].Labels = possibleConflicts[0].Labels.ExceptWith(label); - stringValues.Add(null); - sections.Add(new SwitchSection() { Labels = label, Body = new Branch(nullValueCaseBlock) }); + } } bool keepAssignmentBefore = false; if (switchValueVar.LoadCount > 2) { @@ -284,15 +279,33 @@ namespace ICSharpCode.Decompiler.IL.Transforms inst.Sections.AddRange(sections); instructions[i + 1].ReplaceWith(inst); if (keepAssignmentBefore) { + // delete if (comp(ldloc switchValueVar == ldnull)) instructions.RemoveAt(i); i--; } else { + // delete both the if and the assignment before instructions.RemoveRange(i - 1, 2); i -= 2; } return true; } + private bool AddNullSection(List sections, List stringValues, Block nullValueCaseBlock) + { + var label = new LongSet(sections.Count); + var possibleConflicts = sections.Where(sec => sec.Labels.Overlaps(label)).ToArray(); + if (possibleConflicts.Length > 1) + return false; + else if (possibleConflicts.Length == 1) { + if (possibleConflicts[0].Labels.Count() == 1) + return false; // cannot remove only label + possibleConflicts[0].Labels = possibleConflicts[0].Labels.ExceptWith(label); + } + stringValues.Add(null); + sections.Add(new SwitchSection() { Labels = label, Body = new Branch(nullValueCaseBlock) }); + return true; + } + /// /// Matches 'volatile.ldobj dictionaryType(ldsflda dictField)' /// @@ -457,14 +470,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms var sections = new List(switchInst.Sections); // switch contains case null: if (nullCaseBlock != defaultBlock) { - var label = new Util.LongSet(switchInst.Sections.Count); - var possibleConflicts = switchInst.Sections.Where(sec => sec.Labels.Overlaps(label)).ToArray(); - if (possibleConflicts.Length > 1) + if (!AddNullSection(sections, stringValues, nullCaseBlock)) { return false; - else if (possibleConflicts.Length == 1) - possibleConflicts[0].Labels = possibleConflicts[0].Labels.ExceptWith(label); - stringValues.Add(null); - sections.Add(new SwitchSection() { Labels = label, Body = new Branch(nullCaseBlock) }); + } } var stringToInt = new StringToInt(switchValue, stringValues.ToArray()); var inst = new SwitchInstruction(stringToInt); @@ -501,12 +509,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms } ILInstruction switchValueInst = switchValueLoad; // stloc switchValueLoadVariable(switchValue) - // stloc switchValueVar(call ComputeStringHash(ldloc V_0)) + // stloc switchValueVar(call ComputeStringHash(ldloc switchValueLoadVariable)) // switch (ldloc switchValueVar) { bool keepAssignmentBefore; // if the switchValueLoad.Variable is only used in the compiler generated case equality checks, we can remove it. if (i > 1 && instructions[i - 2].MatchStLoc(switchValueLoad.Variable, out var switchValueTmp) && - switchValueLoad.Variable.IsSingleDefinition && switchValueLoad.Variable.LoadCount == switchInst.Sections.Count) { + switchValueLoad.Variable.IsSingleDefinition && switchValueLoad.Variable.LoadCount == switchInst.Sections.Count) + { switchValueInst = switchValueTmp; keepAssignmentBefore = false; } else { @@ -542,19 +551,20 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!bodyBranch.MatchBranch(out body)) return false; - if (!MatchStringEqualityComparison(condition, switchValueVar, out stringValue)) { - if (condition.MatchLogicNot(out condition) && MatchStringEqualityComparison(condition, switchValueVar, out stringValue)) { - if (!target.Instructions[1].MatchBranch(out Block exit)) - return false; - body = exit; - } else + if (MatchStringEqualityComparison(condition, switchValueVar, out stringValue)) { + return body != null; + } else if (condition.MatchLogicNot(out condition) && MatchStringEqualityComparison(condition, switchValueVar, out stringValue)) { + if (!target.Instructions[1].MatchBranch(out Block exit)) return false; + body = exit; + return true; + } else { + return false; } - return body != null; } /// - /// Matches 'stloc(targetVar, call ComputeStringHash(ldloc(switchValue)))' + /// Matches 'stloc(targetVar, call ComputeStringHash(ldloc switchValue))' /// bool MatchComputeStringHashCall(ILInstruction inst, ILVariable targetVar, out LdLoc switchValue) { From 63493f1feee0289f31e9d65d89d5db885f46e98c Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 13 Oct 2017 20:37:49 +0200 Subject: [PATCH 118/190] #912: add setting for turning off implicit method group conversions --- .../CSharp/ExpressionBuilder.cs | 2 +- .../CSharp/TranslatedExpression.cs | 4 +++- ICSharpCode.Decompiler/DecompilerSettings.cs | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 0fdd45467..2b75c6983 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -69,7 +69,7 @@ namespace ICSharpCode.Decompiler.CSharp internal readonly ICompilation compilation; internal readonly CSharpResolver resolver; readonly TypeSystemAstBuilder astBuilder; - readonly DecompilerSettings settings; + internal readonly DecompilerSettings settings; readonly CancellationToken cancellationToken; public ExpressionBuilder(IDecompilerTypeSystem typeSystem, ITypeResolveContext decompilationContext, DecompilerSettings settings, CancellationToken cancellationToken) diff --git a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs index ad82d776f..0a64e70ca 100644 --- a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs @@ -179,7 +179,9 @@ namespace ICSharpCode.Decompiler.CSharp || type.Kind == TypeKind.Delegate && conversion.Conversion.IsAnonymousFunctionConversion )) { return this.UnwrapChild(cast.Expression); - } else if (Expression is ObjectCreateExpression oce && conversion.Conversion.IsMethodGroupConversion && oce.Arguments.Count == 1) { + } else if (Expression is ObjectCreateExpression oce && conversion.Conversion.IsMethodGroupConversion + && oce.Arguments.Count == 1 && expressionBuilder.settings.UseImplicitMethodGroupConversion) + { return this.UnwrapChild(oce.Arguments.Single()); } } diff --git a/ICSharpCode.Decompiler/DecompilerSettings.cs b/ICSharpCode.Decompiler/DecompilerSettings.cs index 18deb2e8a..50f744e6d 100644 --- a/ICSharpCode.Decompiler/DecompilerSettings.cs +++ b/ICSharpCode.Decompiler/DecompilerSettings.cs @@ -228,7 +228,24 @@ namespace ICSharpCode.Decompiler } } } - + + bool useImplicitMethodGroupConversion = true; + + /// + /// Gets/Sets whether to use C# 2.0 method group conversions. + /// true: EventHandler h = this.OnClick; + /// false: EventHandler h = new EventHandler(this.OnClick); + /// + public bool UseImplicitMethodGroupConversion { + get { return useImplicitMethodGroupConversion; } + set { + if (useImplicitMethodGroupConversion != value) { + useImplicitMethodGroupConversion = value; + OnPropertyChanged(); + } + } + } + bool fullyQualifyAmbiguousTypeNames = true; public bool FullyQualifyAmbiguousTypeNames { From 4d755a7ccf93d481736deb44c07627fecb8115c9 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 13 Oct 2017 22:01:54 +0200 Subject: [PATCH 119/190] Put generated test assemblies in same folder as test cases, instead of %TMP% This makes it easier to open them in ILSpy for debugging. --- .gitignore | 3 ++- .../CorrectnessTestRunner.cs | 5 ++-- .../Helpers/Tester.cs | 23 ++++++++++++++++--- .../PrettyTestRunner.cs | 11 +-------- .../TestCases/Pretty/.gitignore | 2 ++ 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index a4055404f..86be8d458 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ _ReSharper*/ *.ReSharper *.patch .vs/ -/ILSpy.AddIn/Packages/* \ No newline at end of file +/ILSpy.AddIn/Packages/* +/ICSharpCode.Decompiler.Tests/TestCases/Correctness/*.exe diff --git a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs index 510ee1067..cd774b27f 100644 --- a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs @@ -213,17 +213,18 @@ namespace ICSharpCode.Decompiler.Tests void RunCS([CallerMemberName] string testName = null, CompilerOptions options = CompilerOptions.UseDebug) { string testFileName = testName + ".cs"; + string testOutputFileName = testName + Tester.GetSuffix(options) + ".exe"; CompilerResults outputFile = null, decompiledOutputFile = null; try { - outputFile = Tester.CompileCSharp(Path.Combine(TestCasePath, testFileName), options); + outputFile = Tester.CompileCSharp(Path.Combine(TestCasePath, testFileName), options, + outputFileName: Path.Combine(TestCasePath, testOutputFileName)); string decompiledCodeFile = Tester.DecompileCSharp(outputFile.PathToAssembly); decompiledOutputFile = Tester.CompileCSharp(decompiledCodeFile, options); Tester.RunAndCompareOutput(testFileName, outputFile.PathToAssembly, decompiledOutputFile.PathToAssembly, decompiledCodeFile); File.Delete(decompiledCodeFile); - File.Delete(outputFile.PathToAssembly); File.Delete(decompiledOutputFile.PathToAssembly); } finally { if (outputFile != null) diff --git a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs index 1a3420fc9..3fa97ed6f 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs @@ -65,7 +65,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers public static string AssembleIL(string sourceFileName, AssemblerOptions options = AssemblerOptions.UseDebug) { string ilasmPath = Path.Combine(Environment.GetEnvironmentVariable("windir"), @"Microsoft.NET\Framework\v4.0.30319\ilasm.exe"); - string outputFile = Path.GetFileNameWithoutExtension(sourceFileName); + string outputFile = Path.Combine(Path.GetDirectoryName(sourceFileName), Path.GetFileNameWithoutExtension(sourceFileName)); string otherOptions = " "; if (options.HasFlag(AssemblerOptions.Library)) { outputFile += ".dll"; @@ -156,7 +156,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers }; }); - public static CompilerResults CompileCSharp(string sourceFileName, CompilerOptions flags = CompilerOptions.UseDebug) + public static CompilerResults CompileCSharp(string sourceFileName, CompilerOptions flags = CompilerOptions.UseDebug, string outputFileName = null) { List sourceFileNames = new List { sourceFileName }; foreach (Match match in Regex.Matches(File.ReadAllText(sourceFileName), @"#include ""([\w\d./]+)""")) { @@ -181,7 +181,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers deterministic: true )); CompilerResults results = new CompilerResults(new TempFileCollection()); - results.PathToAssembly = Path.GetTempFileName(); + results.PathToAssembly = outputFileName ?? Path.GetTempFileName(); var emitResult = compilation.Emit(results.PathToAssembly); if (!emitResult.Success) { StringBuilder b = new StringBuilder("Compiler error:"); @@ -202,6 +202,9 @@ namespace ICSharpCode.Decompiler.Tests.Helpers if (preprocessorSymbols.Count > 0) { options.CompilerOptions += " /d:" + string.Join(";", preprocessorSymbols); } + if (outputFileName != null) { + options.OutputAssembly = outputFileName; + } options.ReferencedAssemblies.Add("System.Core.dll"); CompilerResults results = provider.CompileAssemblyFromFile(options, sourceFileNames.ToArray()); @@ -216,6 +219,20 @@ namespace ICSharpCode.Decompiler.Tests.Helpers } } + internal static string GetSuffix(CompilerOptions cscOptions) + { + string suffix = ""; + if ((cscOptions & CompilerOptions.Optimize) != 0) + suffix += ".opt"; + if ((cscOptions & CompilerOptions.Force32Bit) != 0) + suffix += ".32"; + if ((cscOptions & CompilerOptions.UseDebug) != 0) + suffix += ".dbg"; + if ((cscOptions & CompilerOptions.UseRoslyn) != 0) + suffix += ".roslyn"; + return suffix; + } + public static int Run(string assemblyFileName, out string output, out string error) { ProcessStartInfo info = new ProcessStartInfo(assemblyFileName); diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index 6e340a2d3..f5eee0fb8 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -196,16 +196,7 @@ namespace ICSharpCode.Decompiler.Tests void Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None) { - var ilFile = Path.Combine(TestCasePath, testName); - if ((cscOptions & CompilerOptions.Optimize) != 0) - ilFile += ".opt"; - if ((cscOptions & CompilerOptions.Force32Bit) != 0) - ilFile += ".32"; - if ((cscOptions & CompilerOptions.UseDebug) != 0) - ilFile += ".dbg"; - if ((cscOptions & CompilerOptions.UseRoslyn) != 0) - ilFile += ".roslyn"; - ilFile += ".il"; + var ilFile = Path.Combine(TestCasePath, testName) + Tester.GetSuffix(cscOptions) + ".il"; var csFile = Path.Combine(TestCasePath, testName + ".cs"); if (!File.Exists(ilFile)) { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/.gitignore b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/.gitignore index 95060aaca..a520eba40 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/.gitignore +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/.gitignore @@ -1 +1,3 @@ /*.res +/*.dll +/*.exe From 25cdf7d16a0abb764b9496fe12c7371ce66e1ccb Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 10:27:31 +0200 Subject: [PATCH 120/190] Add CSharpILMixedLanguage --- ILSpy/ILSpy.csproj | 1 + ILSpy/Languages/CSharpILMixedLanguage.cs | 26 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 ILSpy/Languages/CSharpILMixedLanguage.cs diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index f61c643c4..db6d26eab 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -106,6 +106,7 @@ DebugSteps.xaml + diff --git a/ILSpy/Languages/CSharpILMixedLanguage.cs b/ILSpy/Languages/CSharpILMixedLanguage.cs new file mode 100644 index 000000000..9be3e0092 --- /dev/null +++ b/ILSpy/Languages/CSharpILMixedLanguage.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.Composition; +using System.Linq; +using ICSharpCode.Decompiler; +using ICSharpCode.Decompiler.Disassembler; +using Mono.Cecil; + +namespace ICSharpCode.ILSpy +{ + [Export(typeof(Language))] + class CSharpILMixedLanguage : Language + { + private readonly bool detectControlStructure = true; + + public override string Name => "IL with C#"; + + public override string FileExtension => ".il"; + + public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options) + { + var dis = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken); + dis.DisassembleMethod(method); + } + } +} From 4347fab625661926df360c84f3fc2354a2f3b616 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 14 Oct 2017 12:13:04 +0200 Subject: [PATCH 121/190] Add SequencePointBuilder. --- .../CSharp/CSharpDecompiler.cs | 14 ++ .../CSharp/SequencePointBuilder.cs | 147 ++++++++++++++++++ .../ICSharpCode.Decompiler.csproj | 2 + ICSharpCode.Decompiler/IL/SequencePoint.cs | 26 ++++ 4 files changed, 189 insertions(+) create mode 100644 ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs create mode 100644 ICSharpCode.Decompiler/IL/SequencePoint.cs diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 801b95b7c..1bba92164 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -30,6 +30,7 @@ using ICSharpCode.Decompiler.IL; using ICSharpCode.Decompiler.IL.ControlFlow; using ICSharpCode.Decompiler.IL.Transforms; using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler.CSharp { @@ -982,6 +983,19 @@ namespace ICSharpCode.Decompiler.CSharp } #endregion + #region Sequence Points + /// + /// Creates sequence points for the given syntax tree. + /// + /// This only works correctly when the nodes in the syntax tree have line/column information. + /// + public Dictionary> CreateSequencePoints(SyntaxTree syntaxTree) + { + SequencePointBuilder spb = new SequencePointBuilder(); + syntaxTree.AcceptVisitor(spb); + return spb.GetSequencePoints(); + } + #endregion } [Flags] diff --git a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs new file mode 100644 index 000000000..eaf3367b7 --- /dev/null +++ b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs @@ -0,0 +1,147 @@ +// Copyright (c) 2017 Daniel Grunwald +// +// 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.Collections.Generic; +using System.Linq; +using ICSharpCode.Decompiler.CSharp.Syntax; +using ICSharpCode.Decompiler.IL; +using ICSharpCode.Decompiler.Util; + +namespace ICSharpCode.Decompiler.CSharp +{ + /// + /// Given a SyntaxTree that was output from the decompiler, constructs the list of sequence points. + /// + class SequencePointBuilder : DepthFirstAstVisitor + { + struct StatePerSequencePoint + { + internal readonly AstNode PrimaryNode; + internal readonly List Intervals; + internal ILFunction Function; + + public StatePerSequencePoint(AstNode primaryNode) + { + this.PrimaryNode = primaryNode; + this.Intervals = new List(); + this.Function = null; + } + } + + readonly List<(ILFunction, SequencePoint)> sequencePoints = new List<(ILFunction, SequencePoint)>(); + readonly HashSet mappedInstructions = new HashSet(); + readonly Stack outerStates = new Stack(); + StatePerSequencePoint current = new StatePerSequencePoint(); + + void VisitAsSequencePoint(AstNode node) + { + StartSequencePoint(node); + node.AcceptVisitor(this); + EndSequencePoint(node.StartLocation, node.EndLocation); + } + + protected override void VisitChildren(AstNode node) + { + base.VisitChildren(node); + AddToSequencePoint(node); + } + + public override void VisitBlockStatement(BlockStatement blockStatement) + { + foreach (var stmt in blockStatement.Statements) { + VisitAsSequencePoint(stmt); + } + } + + public override void VisitForStatement(ForStatement forStatement) + { + foreach (var init in forStatement.Initializers) { + VisitAsSequencePoint(init); + } + VisitAsSequencePoint(forStatement.Condition); + foreach (var inc in forStatement.Iterators) { + VisitAsSequencePoint(inc); + } + VisitAsSequencePoint(forStatement.EmbeddedStatement); + } + + /// + /// Start a new C# statement = new sequence point. + /// + void StartSequencePoint(AstNode primaryNode) + { + outerStates.Push(current); + current = new StatePerSequencePoint(primaryNode); + } + + void EndSequencePoint(TextLocation startLocation, TextLocation endLocation) + { + if (current.Intervals.Count > 0 && current.Function != null) { + sequencePoints.Add((current.Function, new SequencePoint { + Offset = current.Intervals.Select(i => i.Start).Min(), + StartLine = startLocation.Line, + StartColumn = startLocation.Column, + EndLine = endLocation.Line, + EndColumn = endLocation.Column + })); + } + current = outerStates.Pop(); + } + + void AddToSequencePoint(AstNode node) + { + foreach (var inst in node.Annotations.OfType()) { + AddToSequencePoint(inst); + } + } + + void AddToSequencePoint(ILInstruction inst) + { + if (!mappedInstructions.Add(inst)) { + // inst was already used by a nested sequence point within this sequence point + return; + } + // Add the IL range associated with this instruction to the current sequence point. + if (!inst.ILRange.IsEmpty) { + current.Intervals.Add(inst.ILRange); + current.Function = inst.Ancestors.OfType().FirstOrDefault(); + } + // Also add the child IL instructions, unless they were already processed by + // another C# expression. + foreach (var child in inst.Children) { + AddToSequencePoint(child); + } + } + + internal Dictionary> GetSequencePoints() + { + var dict = new Dictionary>(); + foreach (var (function, sequencePoint) in this.sequencePoints) { + if (!dict.TryGetValue(function, out var list)) { + dict.Add(function, list = new List()); + } + list.Add(sequencePoint); + } + foreach (var list in dict.Values) { + list.Sort((a, b) => a.Offset.CompareTo(b.Offset)); + } + return dict; + } + } +} diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index a1e17edfd..93e3c5389 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -60,6 +60,7 @@ + @@ -272,6 +273,7 @@ + diff --git a/ICSharpCode.Decompiler/IL/SequencePoint.cs b/ICSharpCode.Decompiler/IL/SequencePoint.cs new file mode 100644 index 000000000..568953c35 --- /dev/null +++ b/ICSharpCode.Decompiler/IL/SequencePoint.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ICSharpCode.Decompiler.IL +{ + /// + /// A sequence point produced by the decompiler. + /// + public struct SequencePoint + { + /// + /// IL offset. + /// + public int Offset { get; set; } + + public int StartLine { get; set; } + public int StartColumn { get; set; } + public int EndLine { get; set; } + public int EndColumn { get; set; } + + public bool IsHidden { + get { return StartLine == 0xfeefee && StartLine == EndLine; } + } + } +} From 1eb8caa013b0a5cd471aed98f68215906d622f6d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 13:33:48 +0200 Subject: [PATCH 122/190] Move CSharpHighlightingTokenWriter to outer class --- ILSpy/ILSpy.csproj | 1 + .../CSharpHighlightingTokenWriter.cs | 429 ++++++++++++++++++ ILSpy/Languages/CSharpLanguage.cs | 420 +---------------- 3 files changed, 431 insertions(+), 419 deletions(-) create mode 100644 ILSpy/Languages/CSharpHighlightingTokenWriter.cs diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index db6d26eab..ab3db44d7 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -116,6 +116,7 @@ + diff --git a/ILSpy/Languages/CSharpHighlightingTokenWriter.cs b/ILSpy/Languages/CSharpHighlightingTokenWriter.cs new file mode 100644 index 000000000..633ac75e6 --- /dev/null +++ b/ILSpy/Languages/CSharpHighlightingTokenWriter.cs @@ -0,0 +1,429 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using ICSharpCode.AvalonEdit.Highlighting; +using ICSharpCode.Decompiler.CSharp; +using ICSharpCode.Decompiler.CSharp.OutputVisitor; +using ICSharpCode.Decompiler.CSharp.Syntax; +using ICSharpCode.Decompiler.TypeSystem; + +namespace ICSharpCode.ILSpy +{ + class CSharpHighlightingTokenWriter : DecoratingTokenWriter + { + ISmartTextOutput textOutput; + + HighlightingColor visibilityKeywordsColor; + HighlightingColor namespaceKeywordsColor; + HighlightingColor structureKeywordsColor; + HighlightingColor gotoKeywordsColor; + HighlightingColor queryKeywordsColor; + HighlightingColor exceptionKeywordsColor; + HighlightingColor checkedKeywordColor; + HighlightingColor unsafeKeywordsColor; + HighlightingColor valueTypeKeywordsColor; + HighlightingColor referenceTypeKeywordsColor; + HighlightingColor operatorKeywordsColor; + HighlightingColor parameterModifierColor; + HighlightingColor modifiersColor; + HighlightingColor accessorKeywordsColor; + HighlightingColor attributeKeywordsColor; + + HighlightingColor referenceTypeColor; + HighlightingColor valueTypeColor; + HighlightingColor interfaceTypeColor; + HighlightingColor enumerationTypeColor; + HighlightingColor typeParameterTypeColor; + HighlightingColor delegateTypeColor; + + HighlightingColor methodCallColor; + HighlightingColor methodDeclarationColor; + + HighlightingColor fieldDeclarationColor; + HighlightingColor fieldAccessColor; + + HighlightingColor valueKeywordColor; + HighlightingColor thisKeywordColor; + HighlightingColor trueKeywordColor; + HighlightingColor typeKeywordsColor; + + public CSharpHighlightingTokenWriter(TokenWriter decoratedWriter, ISmartTextOutput textOutput) : base(decoratedWriter) + { + this.textOutput = textOutput; + var highlighting = HighlightingManager.Instance.GetDefinition("C#"); + + //this.defaultTextColor = ???; + + this.visibilityKeywordsColor = highlighting.GetNamedColor("Visibility"); + this.namespaceKeywordsColor = highlighting.GetNamedColor("NamespaceKeywords"); + this.structureKeywordsColor = highlighting.GetNamedColor("Keywords"); + this.gotoKeywordsColor = highlighting.GetNamedColor("GotoKeywords"); + this.queryKeywordsColor = highlighting.GetNamedColor("QueryKeywords"); + this.exceptionKeywordsColor = highlighting.GetNamedColor("ExceptionKeywords"); + this.checkedKeywordColor = highlighting.GetNamedColor("CheckedKeyword"); + this.unsafeKeywordsColor = highlighting.GetNamedColor("UnsafeKeywords"); + this.valueTypeKeywordsColor = highlighting.GetNamedColor("ValueTypeKeywords"); + this.referenceTypeKeywordsColor = highlighting.GetNamedColor("ReferenceTypeKeywords"); + this.operatorKeywordsColor = highlighting.GetNamedColor("OperatorKeywords"); + this.parameterModifierColor = highlighting.GetNamedColor("ParameterModifiers"); + this.modifiersColor = highlighting.GetNamedColor("Modifiers"); + this.accessorKeywordsColor = highlighting.GetNamedColor("GetSetAddRemove"); + + this.referenceTypeColor = highlighting.GetNamedColor("ReferenceTypes"); + this.valueTypeColor = highlighting.GetNamedColor("ValueTypes"); + this.interfaceTypeColor = highlighting.GetNamedColor("InterfaceTypes"); + this.enumerationTypeColor = highlighting.GetNamedColor("EnumTypes"); + this.typeParameterTypeColor = highlighting.GetNamedColor("TypeParameters"); + this.delegateTypeColor = highlighting.GetNamedColor("DelegateTypes"); + this.methodDeclarationColor = this.methodCallColor = highlighting.GetNamedColor("MethodCall"); + //this.eventDeclarationColor = this.eventAccessColor = defaultTextColor; + //this.propertyDeclarationColor = this.propertyAccessColor = defaultTextColor; + this.fieldDeclarationColor = this.fieldAccessColor = highlighting.GetNamedColor("FieldAccess"); + //this.variableDeclarationColor = this.variableAccessColor = defaultTextColor; + //this.parameterDeclarationColor = this.parameterAccessColor = defaultTextColor; + this.valueKeywordColor = highlighting.GetNamedColor("NullOrValueKeywords"); + this.thisKeywordColor = highlighting.GetNamedColor("ThisOrBaseReference"); + this.trueKeywordColor = highlighting.GetNamedColor("TrueFalse"); + this.typeKeywordsColor = highlighting.GetNamedColor("TypeKeywords"); + this.attributeKeywordsColor = highlighting.GetNamedColor("AttributeKeywords"); + //this.externAliasKeywordColor = ...; + } + + public override void WriteKeyword(Role role, string keyword) + { + HighlightingColor color = null; + switch (keyword) { + case "namespace": + case "using": + if (role == UsingStatement.UsingKeywordRole) + color = structureKeywordsColor; + else + color = namespaceKeywordsColor; + break; + case "this": + case "base": + color = thisKeywordColor; + break; + case "true": + case "false": + color = trueKeywordColor; + break; + case "public": + case "internal": + case "protected": + case "private": + color = visibilityKeywordsColor; + break; + case "if": + case "else": + case "switch": + case "case": + case "default": + case "while": + case "do": + case "for": + case "foreach": + case "lock": + case "global": + case "dynamic": + case "await": + case "where": + color = structureKeywordsColor; + break; + case "in": + if (nodeStack.PeekOrDefault() is ForeachStatement) + color = structureKeywordsColor; + else if (nodeStack.PeekOrDefault() is QueryClause) + color = queryKeywordsColor; + else + color = parameterModifierColor; + break; + case "as": + case "is": + case "new": + case "sizeof": + case "typeof": + case "nameof": + case "stackalloc": + color = typeKeywordsColor; + break; + case "try": + case "throw": + case "catch": + case "finally": + color = exceptionKeywordsColor; + break; + case "when": + if (role == CatchClause.WhenKeywordRole) + color = exceptionKeywordsColor; + break; + case "get": + case "set": + case "add": + case "remove": + if (role == PropertyDeclaration.GetKeywordRole || + role == PropertyDeclaration.SetKeywordRole || + role == CustomEventDeclaration.AddKeywordRole || + role == CustomEventDeclaration.RemoveKeywordRole) + color = accessorKeywordsColor; + break; + case "abstract": + case "const": + case "event": + case "extern": + case "override": + case "readonly": + case "sealed": + case "static": + case "virtual": + case "volatile": + case "async": + case "partial": + color = modifiersColor; + break; + case "checked": + case "unchecked": + color = checkedKeywordColor; + break; + case "fixed": + case "unsafe": + color = unsafeKeywordsColor; + break; + case "enum": + case "struct": + color = valueTypeKeywordsColor; + break; + case "class": + case "interface": + case "delegate": + color = referenceTypeKeywordsColor; + break; + case "select": + case "group": + case "by": + case "into": + case "from": + case "ascending": + case "descending": + case "orderby": + case "let": + case "join": + case "on": + case "equals": + if (nodeStack.PeekOrDefault() is QueryClause) + color = queryKeywordsColor; + break; + case "explicit": + case "implicit": + case "operator": + color = operatorKeywordsColor; + break; + case "params": + case "ref": + case "out": + color = parameterModifierColor; + break; + case "break": + case "continue": + case "goto": + case "yield": + case "return": + color = gotoKeywordsColor; + break; + } + if (nodeStack.PeekOrDefault() is AttributeSection) + color = attributeKeywordsColor; + if (color != null) { + textOutput.BeginSpan(color); + } + base.WriteKeyword(role, keyword); + if (color != null) { + textOutput.EndSpan(); + } + } + + public override void WritePrimitiveType(string type) + { + HighlightingColor color = null; + switch (type) { + case "new": + color = typeKeywordsColor; + break; + case "bool": + case "byte": + case "char": + case "decimal": + case "double": + case "enum": + case "float": + case "int": + case "long": + case "sbyte": + case "short": + case "struct": + case "uint": + case "ushort": + case "ulong": + color = valueTypeKeywordsColor; + break; + case "object": + case "string": + case "void": + color = referenceTypeKeywordsColor; + break; + } + if (color != null) { + textOutput.BeginSpan(color); + } + base.WritePrimitiveType(type); + if (color != null) { + textOutput.EndSpan(); + } + } + + public override void WriteIdentifier(Identifier identifier) + { + HighlightingColor color = null; + if (identifier.Name == "value" && nodeStack.PeekOrDefault() is Accessor accessor && accessor.Role != PropertyDeclaration.GetterRole) + color = valueKeywordColor; + switch (GetCurrentDefinition()) { + case ITypeDefinition t: + switch (t.Kind) { + case TypeKind.Delegate: + color = delegateTypeColor; + break; + case TypeKind.Class: + color = referenceTypeColor; + break; + case TypeKind.Interface: + color = interfaceTypeColor; + break; + case TypeKind.Enum: + color = enumerationTypeColor; + break; + case TypeKind.Struct: + color = valueTypeColor; + break; + } + break; + case IMethod m: + color = methodDeclarationColor; + break; + case IField f: + color = fieldDeclarationColor; + break; + } + switch (GetCurrentMemberReference()) { + case IType t: + switch (t.Kind) { + case TypeKind.Delegate: + color = delegateTypeColor; + break; + case TypeKind.Class: + color = referenceTypeColor; + break; + case TypeKind.Interface: + color = interfaceTypeColor; + break; + case TypeKind.Enum: + color = enumerationTypeColor; + break; + case TypeKind.Struct: + color = valueTypeColor; + break; + } + break; + case IMethod m: + color = methodCallColor; + break; + case IField f: + color = fieldAccessColor; + break; + } + if (color != null) { + textOutput.BeginSpan(color); + } + base.WriteIdentifier(identifier); + if (color != null) { + textOutput.EndSpan(); + } + } + + public override void WritePrimitiveValue(object value, string literalValue = null) + { + HighlightingColor color = null; + if (value is null) { + color = valueKeywordColor; + } + if (value is true || value is false) { + color = trueKeywordColor; + } + if (color != null) { + textOutput.BeginSpan(color); + } + base.WritePrimitiveValue(value, literalValue); + if (color != null) { + textOutput.EndSpan(); + } + } + + ISymbol GetCurrentDefinition() + { + if (nodeStack == null || nodeStack.Count == 0) + return null; + + var node = nodeStack.Peek(); + if (node is Identifier) + node = node.Parent; + if (IsDefinition(ref node)) + return node.GetSymbol(); + + return null; + } + + static bool IsDefinition(ref AstNode node) + { + if (node is EntityDeclaration) + return true; + if (node is VariableInitializer && node.Parent is FieldDeclaration) { + node = node.Parent; + return true; + } + if (node is FixedVariableInitializer) + return true; + return false; + } + + ISymbol GetCurrentMemberReference() + { + AstNode node = nodeStack.Peek(); + var symbol = node.GetSymbol(); + if (symbol == null && node.Role == Roles.TargetExpression && node.Parent is InvocationExpression) { + symbol = node.Parent.GetSymbol(); + } + if (symbol != null && node.Parent is ObjectCreateExpression) { + symbol = node.Parent.GetSymbol(); + } + if (node is IdentifierExpression && node.Role == Roles.TargetExpression && node.Parent is InvocationExpression && symbol is IMember member) { + var declaringType = member.DeclaringType; + if (declaringType != null && declaringType.Kind == TypeKind.Delegate) + return null; + } + return symbol; + } + + Stack nodeStack = new Stack(); + + public override void StartNode(AstNode node) + { + nodeStack.Push(node); + base.StartNode(node); + } + + public override void EndNode(AstNode node) + { + base.EndNode(node); + nodeStack.Pop(); + } + } +} diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index c9ef04f3d..0c1836845 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -100,7 +100,7 @@ namespace ICSharpCode.ILSpy syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); TokenWriter tokenWriter = new TextTokenWriter(output, settings, typeSystem) { FoldBraces = settings.FoldBraces }; if (output is ISmartTextOutput highlightingOutput) { - tokenWriter = new HighlightingTokenWriter(tokenWriter, highlightingOutput); + tokenWriter = new CSharpHighlightingTokenWriter(tokenWriter, highlightingOutput); } syntaxTree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, settings.CSharpFormattingOptions)); } @@ -518,423 +518,5 @@ namespace ICSharpCode.ILSpy var flags = ConversionFlags.All & ~ConversionFlags.ShowBody; return new CSharpAmbience() { ConversionFlags = flags }.ConvertSymbol(symbol); } - - class HighlightingTokenWriter : DecoratingTokenWriter - { - ISmartTextOutput textOutput; - - HighlightingColor visibilityKeywordsColor; - HighlightingColor namespaceKeywordsColor; - HighlightingColor structureKeywordsColor; - HighlightingColor gotoKeywordsColor; - HighlightingColor queryKeywordsColor; - HighlightingColor exceptionKeywordsColor; - HighlightingColor checkedKeywordColor; - HighlightingColor unsafeKeywordsColor; - HighlightingColor valueTypeKeywordsColor; - HighlightingColor referenceTypeKeywordsColor; - HighlightingColor operatorKeywordsColor; - HighlightingColor parameterModifierColor; - HighlightingColor modifiersColor; - HighlightingColor accessorKeywordsColor; - HighlightingColor attributeKeywordsColor; - - HighlightingColor referenceTypeColor; - HighlightingColor valueTypeColor; - HighlightingColor interfaceTypeColor; - HighlightingColor enumerationTypeColor; - HighlightingColor typeParameterTypeColor; - HighlightingColor delegateTypeColor; - - HighlightingColor methodCallColor; - HighlightingColor methodDeclarationColor; - - HighlightingColor fieldDeclarationColor; - HighlightingColor fieldAccessColor; - - HighlightingColor valueKeywordColor; - HighlightingColor thisKeywordColor; - HighlightingColor trueKeywordColor; - HighlightingColor typeKeywordsColor; - - public HighlightingTokenWriter(TokenWriter decoratedWriter, ISmartTextOutput textOutput) : base(decoratedWriter) - { - this.textOutput = textOutput; - var highlighting = HighlightingManager.Instance.GetDefinition("C#"); - - //this.defaultTextColor = ???; - - this.visibilityKeywordsColor = highlighting.GetNamedColor("Visibility"); - this.namespaceKeywordsColor = highlighting.GetNamedColor("NamespaceKeywords"); - this.structureKeywordsColor = highlighting.GetNamedColor("Keywords"); - this.gotoKeywordsColor = highlighting.GetNamedColor("GotoKeywords"); - this.queryKeywordsColor = highlighting.GetNamedColor("QueryKeywords"); - this.exceptionKeywordsColor = highlighting.GetNamedColor("ExceptionKeywords"); - this.checkedKeywordColor = highlighting.GetNamedColor("CheckedKeyword"); - this.unsafeKeywordsColor = highlighting.GetNamedColor("UnsafeKeywords"); - this.valueTypeKeywordsColor = highlighting.GetNamedColor("ValueTypeKeywords"); - this.referenceTypeKeywordsColor = highlighting.GetNamedColor("ReferenceTypeKeywords"); - this.operatorKeywordsColor = highlighting.GetNamedColor("OperatorKeywords"); - this.parameterModifierColor = highlighting.GetNamedColor("ParameterModifiers"); - this.modifiersColor = highlighting.GetNamedColor("Modifiers"); - this.accessorKeywordsColor = highlighting.GetNamedColor("GetSetAddRemove"); - - this.referenceTypeColor = highlighting.GetNamedColor("ReferenceTypes"); - this.valueTypeColor = highlighting.GetNamedColor("ValueTypes"); - this.interfaceTypeColor = highlighting.GetNamedColor("InterfaceTypes"); - this.enumerationTypeColor = highlighting.GetNamedColor("EnumTypes"); - this.typeParameterTypeColor = highlighting.GetNamedColor("TypeParameters"); - this.delegateTypeColor = highlighting.GetNamedColor("DelegateTypes"); - this.methodDeclarationColor = this.methodCallColor = highlighting.GetNamedColor("MethodCall"); - //this.eventDeclarationColor = this.eventAccessColor = defaultTextColor; - //this.propertyDeclarationColor = this.propertyAccessColor = defaultTextColor; - this.fieldDeclarationColor = this.fieldAccessColor = highlighting.GetNamedColor("FieldAccess"); - //this.variableDeclarationColor = this.variableAccessColor = defaultTextColor; - //this.parameterDeclarationColor = this.parameterAccessColor = defaultTextColor; - this.valueKeywordColor = highlighting.GetNamedColor("NullOrValueKeywords"); - this.thisKeywordColor = highlighting.GetNamedColor("ThisOrBaseReference"); - this.trueKeywordColor = highlighting.GetNamedColor("TrueFalse"); - this.typeKeywordsColor = highlighting.GetNamedColor("TypeKeywords"); - this.attributeKeywordsColor = highlighting.GetNamedColor("AttributeKeywords"); - //this.externAliasKeywordColor = ...; - } - - public override void WriteKeyword(Role role, string keyword) - { - HighlightingColor color = null; - switch (keyword) { - case "namespace": - case "using": - if (role == UsingStatement.UsingKeywordRole) - color = structureKeywordsColor; - else - color = namespaceKeywordsColor; - break; - case "this": - case "base": - color = thisKeywordColor; - break; - case "true": - case "false": - color = trueKeywordColor; - break; - case "public": - case "internal": - case "protected": - case "private": - color = visibilityKeywordsColor; - break; - case "if": - case "else": - case "switch": - case "case": - case "default": - case "while": - case "do": - case "for": - case "foreach": - case "lock": - case "global": - case "dynamic": - case "await": - case "where": - color = structureKeywordsColor; - break; - case "in": - if (nodeStack.PeekOrDefault() is ForeachStatement) - color = structureKeywordsColor; - else if (nodeStack.PeekOrDefault() is QueryClause) - color = queryKeywordsColor; - else - color = parameterModifierColor; - break; - case "as": - case "is": - case "new": - case "sizeof": - case "typeof": - case "nameof": - case "stackalloc": - color = typeKeywordsColor; - break; - case "try": - case "throw": - case "catch": - case "finally": - color = exceptionKeywordsColor; - break; - case "when": - if (role == CatchClause.WhenKeywordRole) - color = exceptionKeywordsColor; - break; - case "get": - case "set": - case "add": - case "remove": - if (role == PropertyDeclaration.GetKeywordRole || - role == PropertyDeclaration.SetKeywordRole || - role == CustomEventDeclaration.AddKeywordRole || - role == CustomEventDeclaration.RemoveKeywordRole) - color = accessorKeywordsColor; - break; - case "abstract": - case "const": - case "event": - case "extern": - case "override": - case "readonly": - case "sealed": - case "static": - case "virtual": - case "volatile": - case "async": - case "partial": - color = modifiersColor; - break; - case "checked": - case "unchecked": - color = checkedKeywordColor; - break; - case "fixed": - case "unsafe": - color = unsafeKeywordsColor; - break; - case "enum": - case "struct": - color = valueTypeKeywordsColor; - break; - case "class": - case "interface": - case "delegate": - color = referenceTypeKeywordsColor; - break; - case "select": - case "group": - case "by": - case "into": - case "from": - case "ascending": - case "descending": - case "orderby": - case "let": - case "join": - case "on": - case "equals": - if (nodeStack.PeekOrDefault() is QueryClause) - color = queryKeywordsColor; - break; - case "explicit": - case "implicit": - case "operator": - color = operatorKeywordsColor; - break; - case "params": - case "ref": - case "out": - color = parameterModifierColor; - break; - case "break": - case "continue": - case "goto": - case "yield": - case "return": - color = gotoKeywordsColor; - break; - } - if (nodeStack.PeekOrDefault() is AttributeSection) - color = attributeKeywordsColor; - if (color != null) { - textOutput.BeginSpan(color); - } - base.WriteKeyword(role, keyword); - if (color != null) { - textOutput.EndSpan(); - } - } - - public override void WritePrimitiveType(string type) - { - HighlightingColor color = null; - switch (type) { - case "new": - color = typeKeywordsColor; - break; - case "bool": - case "byte": - case "char": - case "decimal": - case "double": - case "enum": - case "float": - case "int": - case "long": - case "sbyte": - case "short": - case "struct": - case "uint": - case "ushort": - case "ulong": - color = valueTypeKeywordsColor; - break; - case "object": - case "string": - case "void": - color = referenceTypeKeywordsColor; - break; - } - if (color != null) { - textOutput.BeginSpan(color); - } - base.WritePrimitiveType(type); - if (color != null) { - textOutput.EndSpan(); - } - } - - public override void WriteIdentifier(Identifier identifier) - { - HighlightingColor color = null; - if (identifier.Name == "value" && nodeStack.PeekOrDefault() is Accessor accessor && accessor.Role != PropertyDeclaration.GetterRole) - color = valueKeywordColor; - switch (GetCurrentDefinition()) { - case ITypeDefinition t: - switch (t.Kind) { - case TypeKind.Delegate: - color = delegateTypeColor; - break; - case TypeKind.Class: - color = referenceTypeColor; - break; - case TypeKind.Interface: - color = interfaceTypeColor; - break; - case TypeKind.Enum: - color = enumerationTypeColor; - break; - case TypeKind.Struct: - color = valueTypeColor; - break; - } - break; - case IMethod m: - color = methodDeclarationColor; - break; - case IField f: - color = fieldDeclarationColor; - break; - } - switch (GetCurrentMemberReference()) { - case IType t: - switch (t.Kind) { - case TypeKind.Delegate: - color = delegateTypeColor; - break; - case TypeKind.Class: - color = referenceTypeColor; - break; - case TypeKind.Interface: - color = interfaceTypeColor; - break; - case TypeKind.Enum: - color = enumerationTypeColor; - break; - case TypeKind.Struct: - color = valueTypeColor; - break; - } - break; - case IMethod m: - color = methodCallColor; - break; - case IField f: - color = fieldAccessColor; - break; - } - if (color != null) { - textOutput.BeginSpan(color); - } - base.WriteIdentifier(identifier); - if (color != null) { - textOutput.EndSpan(); - } - } - - public override void WritePrimitiveValue(object value, string literalValue = null) - { - HighlightingColor color = null; - if (value is null) { - color = valueKeywordColor; - } - if (value is true || value is false) { - color = trueKeywordColor; - } - if (color != null) { - textOutput.BeginSpan(color); - } - base.WritePrimitiveValue(value, literalValue); - if (color != null) { - textOutput.EndSpan(); - } - } - - ISymbol GetCurrentDefinition() - { - if (nodeStack == null || nodeStack.Count == 0) - return null; - - var node = nodeStack.Peek(); - if (node is Identifier) - node = node.Parent; - if (IsDefinition(ref node)) - return node.GetSymbol(); - - return null; - } - - static bool IsDefinition(ref AstNode node) - { - if (node is EntityDeclaration) - return true; - if (node is VariableInitializer && node.Parent is FieldDeclaration) { - node = node.Parent; - return true; - } - if (node is FixedVariableInitializer) - return true; - return false; - } - - ISymbol GetCurrentMemberReference() - { - AstNode node = nodeStack.Peek(); - var symbol = node.GetSymbol(); - if (symbol == null && node.Role == Roles.TargetExpression && node.Parent is InvocationExpression) { - symbol = node.Parent.GetSymbol(); - } - if (symbol != null && node.Parent is ObjectCreateExpression) { - symbol = node.Parent.GetSymbol(); - } - if (node is IdentifierExpression && node.Role == Roles.TargetExpression && node.Parent is InvocationExpression && symbol is IMember member) { - var declaringType = member.DeclaringType; - if (declaringType != null && declaringType.Kind == TypeKind.Delegate) - return null; - } - return symbol; - } - - Stack nodeStack = new Stack(); - - public override void StartNode(AstNode node) - { - nodeStack.Push(node); - base.StartNode(node); - } - - public override void EndNode(AstNode node) - { - base.EndNode(node); - nodeStack.Pop(); - } - } } } From 98719849915bb68b97db804e73c667900b49ef22 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 13:34:25 +0200 Subject: [PATCH 123/190] Fix end location of PrimitiveExpression --- .../CSharp/OutputVisitor/InsertMissingTokensDecorator.cs | 7 ++++--- .../CSharp/Syntax/Expressions/PrimitiveExpression.cs | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs index 203e29c43..1e20d061a 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs @@ -103,13 +103,14 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor public override void WritePrimitiveValue(object value, string literalValue = null) { Expression node = nodes.Peek().LastOrDefault() as Expression; + var startLocation = locationProvider.Location; + base.WritePrimitiveValue(value, literalValue); if (node is PrimitiveExpression) { - ((PrimitiveExpression)node).SetStartLocation(locationProvider.Location); + ((PrimitiveExpression)node).SetLocation(startLocation, locationProvider.Location); } if (node is NullReferenceExpression) { - ((NullReferenceExpression)node).SetStartLocation(locationProvider.Location); + ((NullReferenceExpression)node).SetStartLocation(startLocation); } - base.WritePrimitiveValue(value, literalValue); } public override void WritePrimitiveType(string type) diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs index af3818269..3e6d49724 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs @@ -43,11 +43,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - internal void SetStartLocation(TextLocation value) + internal void SetLocation(TextLocation startLocation, TextLocation endLocation) { ThrowIfFrozen(); - this.startLocation = value; - this.endLocation = null; + this.startLocation = startLocation; + this.endLocation = endLocation; } string literalValue; From d871960bec338c2550af40b8ba87d3ad893b1cb2 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 13:35:06 +0200 Subject: [PATCH 124/190] Add WriteInstruction to MethodBodyDisassembler --- .../Disassembler/MethodBodyDisassembler.cs | 38 +++++-------------- .../Disassembler/ReflectionDisassembler.cs | 7 +++- ICSharpCode.Decompiler/IL/SequencePoint.cs | 4 +- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs b/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs index a3f85c9a4..ec65a8371 100644 --- a/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs +++ b/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs @@ -27,7 +27,7 @@ namespace ICSharpCode.Decompiler.Disassembler /// /// Disassembles a method body. /// - public sealed class MethodBodyDisassembler + public class MethodBodyDisassembler { readonly ITextOutput output; readonly bool detectControlStructure; @@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.Disassembler this.cancellationToken = cancellationToken; } - public void Disassemble(MethodBody body/*, MemberMapping methodMapping*/) + public void Disassemble(MethodBody body) { // start writing IL code MethodDefinition method = body.Method; @@ -61,20 +61,7 @@ namespace ICSharpCode.Decompiler.Disassembler WriteStructureBody(new ILStructure(body), branchTargets, ref inst, method.Body.CodeSize); } else { foreach (var inst in method.Body.Instructions) { - //var startLocation = output.Location; - inst.WriteTo(output); - - /* - if (debugSymbols != null) { - // add IL code mappings - used in debugger - debugSymbols.SequencePoints.Add( - new SequencePoint() { - StartLocation = output.Location, - EndLocation = output.Location, - ILRanges = new ILRange[] { new ILRange(inst.Offset, inst.Next == null ? method.Body.CodeSize : inst.Next.Offset) } - }); - }*/ - + WriteInstruction(output, inst); output.WriteLine(); } WriteExceptionHandlers(body); @@ -191,19 +178,7 @@ namespace ICSharpCode.Decompiler.Disassembler if (!isFirstInstructionInStructure && (prevInstructionWasBranch || branchTargets.Contains(offset))) { output.WriteLine(); // put an empty line after branches, and in front of branch targets } - //var startLocation = output.Location; - inst.WriteTo(output); - - /*// add IL code mappings - used in debugger - if (debugSymbols != null) { - debugSymbols.SequencePoints.Add( - new SequencePoint() { - StartLocation = startLocation, - EndLocation = output.Location, - ILRanges = new ILRange[] { new ILRange(inst.Offset, inst.Next == null ? codeSize : inst.Next.Offset) } - }); - }*/ - + WriteInstruction(output, inst); output.WriteLine(); prevInstructionWasBranch = inst.OpCode.FlowControl == FlowControl.Branch @@ -237,5 +212,10 @@ namespace ICSharpCode.Decompiler.Disassembler throw new NotSupportedException(); } } + + protected virtual void WriteInstruction(ITextOutput output, Instruction instruction) + { + instruction.WriteTo(output); + } } } diff --git a/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs b/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs index 7707f7791..6137fc0d5 100644 --- a/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs +++ b/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs @@ -36,12 +36,17 @@ namespace ICSharpCode.Decompiler.Disassembler MemberReference currentMember; public ReflectionDisassembler(ITextOutput output, bool detectControlStructure, CancellationToken cancellationToken) + : this(output, new MethodBodyDisassembler(output, detectControlStructure, cancellationToken), cancellationToken) + { + } + + public ReflectionDisassembler(ITextOutput output, MethodBodyDisassembler methodBodyDisassembler, CancellationToken cancellationToken) { if (output == null) throw new ArgumentNullException(nameof(output)); this.output = output; this.cancellationToken = cancellationToken; - this.methodBodyDisassembler = new MethodBodyDisassembler(output, detectControlStructure, cancellationToken); + this.methodBodyDisassembler = methodBodyDisassembler; } #region Disassemble Method diff --git a/ICSharpCode.Decompiler/IL/SequencePoint.cs b/ICSharpCode.Decompiler/IL/SequencePoint.cs index 568953c35..ec2ac3d45 100644 --- a/ICSharpCode.Decompiler/IL/SequencePoint.cs +++ b/ICSharpCode.Decompiler/IL/SequencePoint.cs @@ -7,8 +7,8 @@ namespace ICSharpCode.Decompiler.IL /// /// A sequence point produced by the decompiler. /// - public struct SequencePoint - { + public struct SequencePoint + { /// /// IL offset. /// From a663b5b0dfc79c4799461848c2e4fe8370428835 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 13:35:28 +0200 Subject: [PATCH 125/190] Implement basic mixed view in CSharpILMixedLanguage --- ILSpy/ExtensionMethods.cs | 25 ++++++ ILSpy/Languages/CSharpILMixedLanguage.cs | 103 ++++++++++++++++++++++- 2 files changed, 127 insertions(+), 1 deletion(-) diff --git a/ILSpy/ExtensionMethods.cs b/ILSpy/ExtensionMethods.cs index 32cd8ea30..c83d09f4e 100644 --- a/ILSpy/ExtensionMethods.cs +++ b/ILSpy/ExtensionMethods.cs @@ -64,6 +64,31 @@ namespace ICSharpCode.ILSpy return ~start; } + public static int BinarySearch(this IList instance, TKey itemKey, Func keySelector) + where TKey : IComparable, IComparable + { + if (instance == null) + throw new ArgumentNullException(nameof(instance)); + if (keySelector == null) + throw new ArgumentNullException(nameof(keySelector)); + + int start = 0; + int end = instance.Count - 1; + + while (start <= end) { + int m = (start + end) / 2; + TKey key = keySelector(instance[m]); + int result = key.CompareTo(itemKey); + if (result == 0) + return m; + if (result < 0) + start = m + 1; + else + end = m - 1; + } + return ~start; + } + public static bool IsCustomAttribute(this TypeDefinition type) { while (type.FullName != "System.Object") { diff --git a/ILSpy/Languages/CSharpILMixedLanguage.cs b/ILSpy/Languages/CSharpILMixedLanguage.cs index 9be3e0092..a51ed133c 100644 --- a/ILSpy/Languages/CSharpILMixedLanguage.cs +++ b/ILSpy/Languages/CSharpILMixedLanguage.cs @@ -1,9 +1,20 @@ using System; using System.Collections.Generic; using System.ComponentModel.Composition; +using System.IO; using System.Linq; +using System.Threading; +using System.Windows; +using System.Windows.Media; +using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.Decompiler; +using ICSharpCode.Decompiler.CSharp; +using ICSharpCode.Decompiler.CSharp.OutputVisitor; +using ICSharpCode.Decompiler.CSharp.Syntax; using ICSharpCode.Decompiler.Disassembler; +using ICSharpCode.Decompiler.IL; +using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.Decompiler.Util; using Mono.Cecil; namespace ICSharpCode.ILSpy @@ -17,10 +28,100 @@ namespace ICSharpCode.ILSpy public override string FileExtension => ".il"; + CSharpDecompiler CreateDecompiler(ModuleDefinition module, DecompilationOptions options) + { + CSharpDecompiler decompiler = new CSharpDecompiler(module, options.DecompilerSettings); + decompiler.CancellationToken = options.CancellationToken; + return decompiler; + } + + void WriteCode(TextWriter output, DecompilerSettings settings, SyntaxTree syntaxTree, IDecompilerTypeSystem typeSystem) + { + syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); + TokenWriter tokenWriter = new TextWriterTokenWriter(output); + tokenWriter = TokenWriter.WrapInWriterThatSetsLocationsInAST(tokenWriter); + syntaxTree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, settings.CSharpFormattingOptions)); + } + public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options) { - var dis = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken); + //AddReferenceWarningMessage(method.Module.Assembly, output); + var csharpOutput = new StringWriter(); + CSharpDecompiler decompiler = CreateDecompiler(method.Module, options); + var st = decompiler.Decompile(method); + WriteCode(csharpOutput, options.DecompilerSettings, st, decompiler.TypeSystem); + var sequencePoints = (IList)decompiler.CreateSequencePoints(st).FirstOrDefault(kvp => kvp.Key.CecilMethod == method).Value ?? EmptyList.Instance; + var codeLines = csharpOutput.ToString().Split(new[] { Environment.NewLine }, StringSplitOptions.None); + WriteCommentLine(output, TypeToString(method.DeclaringType, includeNamespace: true)); + var methodDisassembler = new MixedMethodBodyDisassembler(output, codeLines, sequencePoints, detectControlStructure, options.CancellationToken); + var dis = new ReflectionDisassembler(output, methodDisassembler, options.CancellationToken); dis.DisassembleMethod(method); } + + class MixedMethodBodyDisassembler : MethodBodyDisassembler + { + // list sorted by IL offset + IList sequencePoints; + // lines of raw c# source code + string[] codeLines; + + public MixedMethodBodyDisassembler(ITextOutput output, string[] codeLines, IList sequencePoints, bool detectControlStructure, CancellationToken cancellationToken) + : base(output, detectControlStructure, cancellationToken) + { + if (codeLines == null) + throw new ArgumentNullException(nameof(codeLines)); + if (sequencePoints == null) + throw new ArgumentNullException(nameof(sequencePoints)); + + this.codeLines = codeLines; + this.sequencePoints = sequencePoints; + } + + protected override void WriteInstruction(ITextOutput output, Mono.Cecil.Cil.Instruction instruction) + { + int index = sequencePoints.BinarySearch(instruction.Offset, seq => seq.Offset); + if (index >= 0) { + var info = sequencePoints[index]; + if (!info.IsHidden) { + for (int line = info.StartLine; line <= info.EndLine; line++) { + if (output is ISmartTextOutput highlightingOutput) { + string text = codeLines[line - 1]; + int startColumn = 1; + int endColumn = text.Length + 1; + if (line == info.StartLine) + startColumn = info.StartColumn; + if (line == info.EndLine) + endColumn = info.EndColumn; + WriteHighlightedCommentLine(highlightingOutput, text, startColumn - 1, endColumn - 1); + } else + WriteCommentLine(output, codeLines[line - 1]); + } + } else { + WriteCommentLine(output, "no code"); + } + } + base.WriteInstruction(output, instruction); + } + + HighlightingColor gray = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Colors.DarkGray) }; + HighlightingColor black = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Colors.Black) }; + + void WriteHighlightedCommentLine(ISmartTextOutput output, string text, int startColumn, int endColumn) + { + output.BeginSpan(gray); + output.Write("// " + text.Substring(0, startColumn)); + output.BeginSpan(black); + output.Write(text.Substring(startColumn, endColumn - startColumn)); + output.EndSpan(); + output.Write(text.Substring(endColumn)); + output.EndSpan(); + output.WriteLine(); + } + + void WriteCommentLine(ITextOutput output, string text) + { + output.WriteLine("// " + text); + } + } } } From 682ca234d597e8b3ef6446030e57b51e3b9cf91f Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 14:07:59 +0200 Subject: [PATCH 126/190] [csilview] remove indentation from single-line C# code in C#-IL view. --- ILSpy/Languages/CSharpILMixedLanguage.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ILSpy/Languages/CSharpILMixedLanguage.cs b/ILSpy/Languages/CSharpILMixedLanguage.cs index a51ed133c..08e0fb58a 100644 --- a/ILSpy/Languages/CSharpILMixedLanguage.cs +++ b/ILSpy/Languages/CSharpILMixedLanguage.cs @@ -92,7 +92,7 @@ namespace ICSharpCode.ILSpy startColumn = info.StartColumn; if (line == info.EndLine) endColumn = info.EndColumn; - WriteHighlightedCommentLine(highlightingOutput, text, startColumn - 1, endColumn - 1); + WriteHighlightedCommentLine(highlightingOutput, text, startColumn - 1, endColumn - 1, info.StartLine == info.EndLine); } else WriteCommentLine(output, codeLines[line - 1]); } @@ -106,10 +106,13 @@ namespace ICSharpCode.ILSpy HighlightingColor gray = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Colors.DarkGray) }; HighlightingColor black = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Colors.Black) }; - void WriteHighlightedCommentLine(ISmartTextOutput output, string text, int startColumn, int endColumn) + void WriteHighlightedCommentLine(ISmartTextOutput output, string text, int startColumn, int endColumn, bool isSingleLine) { output.BeginSpan(gray); - output.Write("// " + text.Substring(0, startColumn)); + if (isSingleLine) + output.Write("// " + text.Substring(0, startColumn).TrimStart()); + else + output.Write("// " + text.Substring(0, startColumn)); output.BeginSpan(black); output.Write(text.Substring(startColumn, endColumn - startColumn)); output.EndSpan(); From 809f2c1c9c7e36b87130e9bce5afc5a77571ee78 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 14:08:35 +0200 Subject: [PATCH 127/190] Sort languages in drop-down by name (except for debug 'languages') --- ILSpy/Languages/Languages.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ILSpy/Languages/Languages.cs b/ILSpy/Languages/Languages.cs index 2cf2e5632..2312f7ec5 100644 --- a/ILSpy/Languages/Languages.cs +++ b/ILSpy/Languages/Languages.cs @@ -43,6 +43,7 @@ namespace ICSharpCode.ILSpy { List languages = new List(); languages.AddRange(composition.GetExportedValues()); + languages.Sort((a, b) => a.Name.CompareTo(b.Name)); #if DEBUG languages.AddRange(ILAstLanguage.GetDebugLanguages()); languages.AddRange(CSharpLanguage.GetDebugLanguages()); From bc430a93587aa5287810b29443d8f0144e4e854a Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 14 Oct 2017 14:16:54 +0200 Subject: [PATCH 128/190] Support SwitchStatement in SequencePointBuilder. --- .../CSharp/SequencePointBuilder.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs index eaf3367b7..a361005b5 100644 --- a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs @@ -32,8 +32,19 @@ namespace ICSharpCode.Decompiler.CSharp { struct StatePerSequencePoint { + /// + /// Main AST node associated with this sequence point. + /// internal readonly AstNode PrimaryNode; + + /// + /// List of IL intervals that are associated with this sequence point. + /// internal readonly List Intervals; + + /// + /// The function containing this sequence point. + /// internal ILFunction Function; public StatePerSequencePoint(AstNode primaryNode) @@ -46,7 +57,11 @@ namespace ICSharpCode.Decompiler.CSharp readonly List<(ILFunction, SequencePoint)> sequencePoints = new List<(ILFunction, SequencePoint)>(); readonly HashSet mappedInstructions = new HashSet(); + + // Stack holding information for outer statements. readonly Stack outerStates = new Stack(); + + // Collects information for the current sequence point. StatePerSequencePoint current = new StatePerSequencePoint(); void VisitAsSequencePoint(AstNode node) @@ -71,6 +86,7 @@ namespace ICSharpCode.Decompiler.CSharp public override void VisitForStatement(ForStatement forStatement) { + // Every element of a for-statement is it's own sequence point. foreach (var init in forStatement.Initializers) { VisitAsSequencePoint(init); } @@ -80,6 +96,28 @@ namespace ICSharpCode.Decompiler.CSharp } VisitAsSequencePoint(forStatement.EmbeddedStatement); } + + public override void VisitSwitchStatement(SwitchStatement switchStatement) + { + StartSequencePoint(switchStatement); + switchStatement.Expression.AcceptVisitor(this); + foreach (var section in switchStatement.SwitchSections) { + // note: sections will not contribute to the current sequence point + section.AcceptVisitor(this); + } + // add switch statement itself to sequence point + // (call only after the sections are visited) + AddToSequencePoint(switchStatement); + EndSequencePoint(switchStatement.StartLocation, switchStatement.RParToken.EndLocation); + } + + public override void VisitSwitchSection(Syntax.SwitchSection switchSection) + { + // every statement in the switch section is its own sequence point + foreach (var stmt in switchSection.Statements) { + VisitAsSequencePoint(stmt); + } + } /// /// Start a new C# statement = new sequence point. @@ -104,6 +142,10 @@ namespace ICSharpCode.Decompiler.CSharp current = outerStates.Pop(); } + /// + /// Add the ILAst instruction associated with the AstNode to the sequence point. + /// Also add all its ILAst sub-instructions (unless they were already added to another sequence point). + /// void AddToSequencePoint(AstNode node) { foreach (var inst in node.Annotations.OfType()) { @@ -129,6 +171,9 @@ namespace ICSharpCode.Decompiler.CSharp } } + /// + /// Called after the visitor is done to return the results. + /// internal Dictionary> GetSequencePoints() { var dict = new Dictionary>(); From 9d7fb0627dddb38d7b07187315e6d7bc91a60464 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 14 Oct 2017 14:55:19 +0200 Subject: [PATCH 129/190] Add hidden sequence points for unmapped code. --- .../CSharp/SequencePointBuilder.cs | 27 ++++++++++++++++--- ICSharpCode.Decompiler/IL/SequencePoint.cs | 17 +++++++++++- ILSpy/Languages/CSharpILMixedLanguage.cs | 18 ++++++++----- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs index a361005b5..716710e01 100644 --- a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using ICSharpCode.Decompiler.CSharp.Syntax; using ICSharpCode.Decompiler.IL; @@ -131,8 +132,12 @@ namespace ICSharpCode.Decompiler.CSharp void EndSequencePoint(TextLocation startLocation, TextLocation endLocation) { if (current.Intervals.Count > 0 && current.Function != null) { + // use LongSet to deduplicate and merge the intervals + var longSet = new LongSet(current.Intervals.Select(i => new LongInterval(i.Start, i.End))); + Debug.Assert(!longSet.IsEmpty); sequencePoints.Add((current.Function, new SequencePoint { - Offset = current.Intervals.Select(i => i.Start).Min(), + Offset = (int)longSet.Intervals[0].Start, + EndOffset = (int)longSet.Intervals[0].End, StartLine = startLocation.Line, StartColumn = startLocation.Column, EndLine = endLocation.Line, @@ -183,8 +188,24 @@ namespace ICSharpCode.Decompiler.CSharp } list.Add(sequencePoint); } - foreach (var list in dict.Values) { - list.Sort((a, b) => a.Offset.CompareTo(b.Offset)); + foreach (var (function, list) in dict.ToList()) { + // For each function, sort sequence points + // and insert hidden sequence points in the gaps. + var newList = new List(); + int pos = 0; + foreach (var sequencePoint in list.OrderBy(sp => sp.Offset)) { + Debug.Assert(sequencePoint.Offset >= pos); + if (sequencePoint.Offset > pos) { + var hidden = new SequencePoint(); + hidden.Offset = pos; + hidden.EndOffset = sequencePoint.Offset; + hidden.SetHidden(); + newList.Add(hidden); + } + newList.Add(sequencePoint); + pos = sequencePoint.EndOffset; + } + dict[function] = newList; } return dict; } diff --git a/ICSharpCode.Decompiler/IL/SequencePoint.cs b/ICSharpCode.Decompiler/IL/SequencePoint.cs index ec2ac3d45..d313fa73d 100644 --- a/ICSharpCode.Decompiler/IL/SequencePoint.cs +++ b/ICSharpCode.Decompiler/IL/SequencePoint.cs @@ -10,10 +10,20 @@ namespace ICSharpCode.Decompiler.IL public struct SequencePoint { /// - /// IL offset. + /// IL start offset. /// public int Offset { get; set; } + /// + /// IL end offset. + /// + /// + /// This does not get stored in debug information; + /// it is used internally to create hidden sequence points + /// for the IL fragments not covered by any sequence point. + /// + public int EndOffset { get; set; } + public int StartLine { get; set; } public int StartColumn { get; set; } public int EndLine { get; set; } @@ -22,5 +32,10 @@ namespace ICSharpCode.Decompiler.IL public bool IsHidden { get { return StartLine == 0xfeefee && StartLine == EndLine; } } + + internal void SetHidden() + { + StartLine = EndLine = 0xfeefee; + } } } diff --git a/ILSpy/Languages/CSharpILMixedLanguage.cs b/ILSpy/Languages/CSharpILMixedLanguage.cs index 08e0fb58a..628e88933 100644 --- a/ILSpy/Languages/CSharpILMixedLanguage.cs +++ b/ILSpy/Languages/CSharpILMixedLanguage.cs @@ -82,9 +82,10 @@ namespace ICSharpCode.ILSpy int index = sequencePoints.BinarySearch(instruction.Offset, seq => seq.Offset); if (index >= 0) { var info = sequencePoints[index]; + var highlightingOutput = output as ISmartTextOutput; if (!info.IsHidden) { for (int line = info.StartLine; line <= info.EndLine; line++) { - if (output is ISmartTextOutput highlightingOutput) { + if (highlightingOutput != null) { string text = codeLines[line - 1]; int startColumn = 1; int endColumn = text.Length + 1; @@ -97,25 +98,28 @@ namespace ICSharpCode.ILSpy WriteCommentLine(output, codeLines[line - 1]); } } else { - WriteCommentLine(output, "no code"); + output.Write("// "); + highlightingOutput?.BeginSpan(gray); + output.WriteLine("(hidden sequence point)"); + highlightingOutput?.EndSpan(); } } base.WriteInstruction(output, instruction); } HighlightingColor gray = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Colors.DarkGray) }; - HighlightingColor black = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Colors.Black) }; void WriteHighlightedCommentLine(ISmartTextOutput output, string text, int startColumn, int endColumn, bool isSingleLine) { + output.Write("// "); output.BeginSpan(gray); if (isSingleLine) - output.Write("// " + text.Substring(0, startColumn).TrimStart()); + output.Write(text.Substring(0, startColumn).TrimStart()); else - output.Write("// " + text.Substring(0, startColumn)); - output.BeginSpan(black); - output.Write(text.Substring(startColumn, endColumn - startColumn)); + output.Write(text.Substring(0, startColumn)); output.EndSpan(); + output.Write(text.Substring(startColumn, endColumn - startColumn)); + output.BeginSpan(gray); output.Write(text.Substring(endColumn)); output.EndSpan(); output.WriteLine(); From 3aca47d1f55a259782175de49b7cf1c3aa396634 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 14 Oct 2017 15:59:35 +0200 Subject: [PATCH 130/190] Allow decompiling whole assembly in IL + C# mode. --- .../CSharp/SequencePointBuilder.cs | 25 +++++-- .../Transforms/IntroduceExtensionMethods.cs | 15 ++++- .../Disassembler/MethodBodyDisassembler.cs | 2 +- ILSpy/Languages/CSharpILMixedLanguage.cs | 65 ++++++++++--------- ILSpy/Languages/ILLanguage.cs | 30 +++++---- 5 files changed, 82 insertions(+), 55 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs index 716710e01..463ff1e1c 100644 --- a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs @@ -63,7 +63,7 @@ namespace ICSharpCode.Decompiler.CSharp readonly Stack outerStates = new Stack(); // Collects information for the current sequence point. - StatePerSequencePoint current = new StatePerSequencePoint(); + StatePerSequencePoint current; void VisitAsSequencePoint(AstNode node) { @@ -165,7 +165,7 @@ namespace ICSharpCode.Decompiler.CSharp return; } // Add the IL range associated with this instruction to the current sequence point. - if (!inst.ILRange.IsEmpty) { + if (!inst.ILRange.IsEmpty && current.Intervals != null) { current.Intervals.Add(inst.ILRange); current.Function = inst.Ancestors.OfType().FirstOrDefault(); } @@ -189,13 +189,24 @@ namespace ICSharpCode.Decompiler.CSharp list.Add(sequencePoint); } foreach (var (function, list) in dict.ToList()) { - // For each function, sort sequence points - // and insert hidden sequence points in the gaps. + // For each function, sort sequence points and fix overlaps+gaps var newList = new List(); int pos = 0; - foreach (var sequencePoint in list.OrderBy(sp => sp.Offset)) { - Debug.Assert(sequencePoint.Offset >= pos); - if (sequencePoint.Offset > pos) { + foreach (var sequencePoint in list.OrderBy(sp => sp.Offset).ThenBy(sp => sp.EndOffset)) { + if (sequencePoint.Offset < pos) { + // overlapping sequence point? + // delete previous sequence points that are after sequencePoint.Offset + while (newList.Count > 0 && newList.Last().EndOffset > pos) { + var last = newList.Last(); + if (last.Offset >= sequencePoint.Offset) { + newList.RemoveAt(newList.Count - 1); + } else { + last.EndOffset = sequencePoint.Offset; + newList[newList.Count - 1] = last; + } + } + } else if (sequencePoint.Offset > pos) { + // insert hidden sequence point in the gap. var hidden = new SequencePoint(); hidden.Offset = pos; hidden.EndOffset = sequencePoint.Offset; diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs index 1ff8f83e3..53596faa9 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs @@ -43,15 +43,24 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms { this.context = context; this.usingScope = this.rootUsingScope = rootNode.Annotation(); + currentMember = context.DecompiledMember; + SetContext(); rootNode.AcceptVisitor(this); } void SetContext() { this.usingScope = rootUsingScope; - foreach (var name in currentMember.Namespace.Split('.')) - usingScope = new UsingScope(usingScope, name); - resolveContext = new CSharpTypeResolveContext(currentMember.ParentAssembly, usingScope.Resolve(context.TypeSystem.Compilation), currentMember.DeclaringTypeDefinition, currentMember); + string ns = currentMember?.Namespace ?? context.DecompiledTypeDefinition?.Namespace; + if (ns != null) { + foreach (var name in ns.Split('.')) + usingScope = new UsingScope(usingScope, name); + } + resolveContext = new CSharpTypeResolveContext( + context.DecompiledAssembly, + usingScope.Resolve(context.TypeSystem.Compilation), + currentMember?.DeclaringTypeDefinition ?? context.DecompiledTypeDefinition, + currentMember); resolver = new CSharpResolver(resolveContext); } diff --git a/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs b/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs index ec65a8371..c5860c7cb 100644 --- a/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs +++ b/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs @@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.Disassembler this.cancellationToken = cancellationToken; } - public void Disassemble(MethodBody body) + public virtual void Disassemble(MethodBody body) { // start writing IL code MethodDefinition method = body.Method; diff --git a/ILSpy/Languages/CSharpILMixedLanguage.cs b/ILSpy/Languages/CSharpILMixedLanguage.cs index 628e88933..73340f695 100644 --- a/ILSpy/Languages/CSharpILMixedLanguage.cs +++ b/ILSpy/Languages/CSharpILMixedLanguage.cs @@ -16,68 +16,69 @@ using ICSharpCode.Decompiler.IL; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.Util; using Mono.Cecil; +using Mono.Cecil.Cil; namespace ICSharpCode.ILSpy { [Export(typeof(Language))] - class CSharpILMixedLanguage : Language + class CSharpILMixedLanguage : ILLanguage { - private readonly bool detectControlStructure = true; - public override string Name => "IL with C#"; - public override string FileExtension => ".il"; + protected override ReflectionDisassembler CreateDisassembler(ITextOutput output, DecompilationOptions options) + { + return new ReflectionDisassembler(output, + new MixedMethodBodyDisassembler(output, detectControlStructure, options), + options.CancellationToken); + } - CSharpDecompiler CreateDecompiler(ModuleDefinition module, DecompilationOptions options) + static CSharpDecompiler CreateDecompiler(ModuleDefinition module, DecompilationOptions options) { CSharpDecompiler decompiler = new CSharpDecompiler(module, options.DecompilerSettings); decompiler.CancellationToken = options.CancellationToken; return decompiler; } - void WriteCode(TextWriter output, DecompilerSettings settings, SyntaxTree syntaxTree, IDecompilerTypeSystem typeSystem) + static void WriteCode(TextWriter output, DecompilerSettings settings, SyntaxTree syntaxTree, IDecompilerTypeSystem typeSystem) { syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); TokenWriter tokenWriter = new TextWriterTokenWriter(output); tokenWriter = TokenWriter.WrapInWriterThatSetsLocationsInAST(tokenWriter); syntaxTree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, settings.CSharpFormattingOptions)); } - - public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options) - { - //AddReferenceWarningMessage(method.Module.Assembly, output); - var csharpOutput = new StringWriter(); - CSharpDecompiler decompiler = CreateDecompiler(method.Module, options); - var st = decompiler.Decompile(method); - WriteCode(csharpOutput, options.DecompilerSettings, st, decompiler.TypeSystem); - var sequencePoints = (IList)decompiler.CreateSequencePoints(st).FirstOrDefault(kvp => kvp.Key.CecilMethod == method).Value ?? EmptyList.Instance; - var codeLines = csharpOutput.ToString().Split(new[] { Environment.NewLine }, StringSplitOptions.None); - WriteCommentLine(output, TypeToString(method.DeclaringType, includeNamespace: true)); - var methodDisassembler = new MixedMethodBodyDisassembler(output, codeLines, sequencePoints, detectControlStructure, options.CancellationToken); - var dis = new ReflectionDisassembler(output, methodDisassembler, options.CancellationToken); - dis.DisassembleMethod(method); - } - + class MixedMethodBodyDisassembler : MethodBodyDisassembler { + readonly DecompilationOptions options; // list sorted by IL offset - IList sequencePoints; + IList sequencePoints; // lines of raw c# source code string[] codeLines; - public MixedMethodBodyDisassembler(ITextOutput output, string[] codeLines, IList sequencePoints, bool detectControlStructure, CancellationToken cancellationToken) - : base(output, detectControlStructure, cancellationToken) + public MixedMethodBodyDisassembler(ITextOutput output, bool detectControlStructure, DecompilationOptions options) + : base(output, detectControlStructure, options.CancellationToken) { - if (codeLines == null) - throw new ArgumentNullException(nameof(codeLines)); - if (sequencePoints == null) - throw new ArgumentNullException(nameof(sequencePoints)); + this.options = options; + } - this.codeLines = codeLines; - this.sequencePoints = sequencePoints; + public override void Disassemble(MethodBody body) + { + var method = body.Method; + try { + var csharpOutput = new StringWriter(); + CSharpDecompiler decompiler = CreateDecompiler(method.Module, options); + var st = decompiler.Decompile(method); + WriteCode(csharpOutput, options.DecompilerSettings, st, decompiler.TypeSystem); + this.sequencePoints = decompiler.CreateSequencePoints(st).FirstOrDefault(kvp => kvp.Key.CecilMethod == method).Value ?? (IList)EmptyList.Instance; + this.codeLines = csharpOutput.ToString().Split(new[] { Environment.NewLine }, StringSplitOptions.None); + base.Disassemble(body); + } finally { + this.sequencePoints = null; + this.codeLines = null; + } } - protected override void WriteInstruction(ITextOutput output, Mono.Cecil.Cil.Instruction instruction) + protected override void WriteInstruction(ITextOutput output, Instruction instruction) { int index = sequencePoints.BinarySearch(instruction.Offset, seq => seq.Offset); if (index >= 0) { diff --git a/ILSpy/Languages/ILLanguage.cs b/ILSpy/Languages/ILLanguage.cs index 817586d95..71dec3ee7 100644 --- a/ILSpy/Languages/ILLanguage.cs +++ b/ILSpy/Languages/ILLanguage.cs @@ -34,7 +34,7 @@ namespace ICSharpCode.ILSpy [Export(typeof(Language))] public class ILLanguage : Language { - private readonly bool detectControlStructure = true; + protected bool detectControlStructure = true; public override string Name { get { return "IL"; } @@ -44,21 +44,26 @@ namespace ICSharpCode.ILSpy get { return ".il"; } } + protected virtual ReflectionDisassembler CreateDisassembler(ITextOutput output, DecompilationOptions options) + { + return new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken); + } + public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options) { - var dis = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken); + var dis = CreateDisassembler(output, options); dis.DisassembleMethod(method); } public override void DecompileField(FieldDefinition field, ITextOutput output, DecompilationOptions options) { - var dis = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken); + var dis = CreateDisassembler(output, options); dis.DisassembleField(field); } public override void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilationOptions options) { - ReflectionDisassembler rd = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken); + ReflectionDisassembler rd = CreateDisassembler(output, options); rd.DisassembleProperty(property); if (property.GetMethod != null) { output.WriteLine(); @@ -76,7 +81,7 @@ namespace ICSharpCode.ILSpy public override void DecompileEvent(EventDefinition ev, ITextOutput output, DecompilationOptions options) { - ReflectionDisassembler rd = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken); + ReflectionDisassembler rd = CreateDisassembler(output, options); rd.DisassembleEvent(ev); if (ev.AddMethod != null) { output.WriteLine(); @@ -94,13 +99,14 @@ namespace ICSharpCode.ILSpy public override void DecompileType(TypeDefinition type, ITextOutput output, DecompilationOptions options) { - var dis = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken); + var dis = CreateDisassembler(output, options); dis.DisassembleType(type); } public override void DecompileNamespace(string nameSpace, IEnumerable types, ITextOutput output, DecompilationOptions options) { - new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken).DisassembleNamespace(nameSpace, types); + var dis = CreateDisassembler(output, options); + dis.DisassembleNamespace(nameSpace, types); } public override void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options) @@ -108,17 +114,17 @@ namespace ICSharpCode.ILSpy output.WriteLine("// " + assembly.FileName); output.WriteLine(); - ReflectionDisassembler rd = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken); + var dis = CreateDisassembler(output, options); if (options.FullDecompilation) - rd.WriteAssemblyReferences(assembly.ModuleDefinition); + dis.WriteAssemblyReferences(assembly.ModuleDefinition); if (assembly.AssemblyDefinition != null) - rd.WriteAssemblyHeader(assembly.AssemblyDefinition); + dis.WriteAssemblyHeader(assembly.AssemblyDefinition); output.WriteLine(); - rd.WriteModuleHeader(assembly.ModuleDefinition); + dis.WriteModuleHeader(assembly.ModuleDefinition); if (options.FullDecompilation) { output.WriteLine(); output.WriteLine(); - rd.WriteModuleContents(assembly.ModuleDefinition); + dis.WriteModuleContents(assembly.ModuleDefinition); } } From 312277119c5c5f9a01e8ab378dcd1f2eb24ac6a1 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 15:07:36 +0200 Subject: [PATCH 131/190] Move ILAstWritingOptions to separate file --- .../ICSharpCode.Decompiler.csproj | 1 + .../IL/ILAstWritingOptions.cs | 66 +++++++++++++++++++ .../IL/Instructions/ILInstruction.cs | 13 ---- 3 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 ICSharpCode.Decompiler/IL/ILAstWritingOptions.cs diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 93e3c5389..07d6c2668 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -273,6 +273,7 @@ + diff --git a/ICSharpCode.Decompiler/IL/ILAstWritingOptions.cs b/ICSharpCode.Decompiler/IL/ILAstWritingOptions.cs new file mode 100644 index 000000000..42b8ddf66 --- /dev/null +++ b/ICSharpCode.Decompiler/IL/ILAstWritingOptions.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Text; + +namespace ICSharpCode.Decompiler.IL +{ + public class ILAstWritingOptions : INotifyPropertyChanged + { + private bool useLogicOperationSugar; + private bool useFieldSugar; + private bool showILRanges; + + /// + /// Sugar for logic.not/and/or. + /// + public bool UseLogicOperationSugar { + get { return useLogicOperationSugar; } + set { + if (useLogicOperationSugar != value) { + useLogicOperationSugar = value; + OnPropertyChanged(); + } + } + } + + /// + /// Sugar for ldfld/stfld. + /// + public bool UseFieldSugar { + get { return useFieldSugar; } + set { + if (useFieldSugar != value) { + useFieldSugar = value; + OnPropertyChanged(); + } + } + } + + /// + /// Show IL ranges in ILAst output. + /// + public bool ShowILRanges { + get { return showILRanges; } + set { + if (showILRanges != value) { + showILRanges = value; + OnPropertyChanged(); + } + } + } + + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); + } + + protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) + { + PropertyChanged?.Invoke(this, e); + } + + public event PropertyChangedEventHandler PropertyChanged; + } +} diff --git a/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs index b4042364e..d0bce881a 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs @@ -745,17 +745,4 @@ namespace ICSharpCode.Decompiler.IL /// StackType UnderlyingResultType { get; } } - - public class ILAstWritingOptions - { - /// - /// Sugar for logic.not/and/or. - /// - public bool UseLogicOperationSugar { get; set; } - - /// - /// Sugar for ldfld/stfld. - /// - public bool UseFieldSugar { get; set; } - } } From 10cf712135bc0dd41de9577dd9c0ed63b85583ec Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 15:08:52 +0200 Subject: [PATCH 132/190] Move ILAst writing options to DebugSteps pane and implement auto refresh. --- ILSpy/DebugSteps.xaml | 9 ++++- ILSpy/DebugSteps.xaml.cs | 28 +++++++++++++- ILSpy/Languages/ILAstLanguage.cs | 63 +------------------------------- 3 files changed, 34 insertions(+), 66 deletions(-) diff --git a/ILSpy/DebugSteps.xaml b/ILSpy/DebugSteps.xaml index a96d1463e..e343e5070 100644 --- a/ILSpy/DebugSteps.xaml +++ b/ILSpy/DebugSteps.xaml @@ -6,7 +6,12 @@ xmlns:local="clr-namespace:ICSharpCode.ILSpy" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> - + + + + + + @@ -21,5 +26,5 @@ - + diff --git a/ILSpy/DebugSteps.xaml.cs b/ILSpy/DebugSteps.xaml.cs index f2c44b474..f3c3b7a7f 100644 --- a/ILSpy/DebugSteps.xaml.cs +++ b/ILSpy/DebugSteps.xaml.cs @@ -2,6 +2,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using ICSharpCode.Decompiler.IL; using ICSharpCode.Decompiler.IL.Transforms; namespace ICSharpCode.ILSpy @@ -12,6 +13,13 @@ namespace ICSharpCode.ILSpy /// public partial class DebugSteps : UserControl, IPane { + static readonly ILAstWritingOptions writingOptions = new ILAstWritingOptions { + UseFieldSugar = true, + UseLogicOperationSugar = true + }; + + public static ILAstWritingOptions Options => writingOptions; + #if DEBUG ILAstLanguage language; #endif @@ -23,6 +31,7 @@ namespace ICSharpCode.ILSpy #if DEBUG MainWindow.Instance.SessionSettings.FilterSettings.PropertyChanged += FilterSettings_PropertyChanged; MainWindow.Instance.SelectionChanged += SelectionChanged; + writingOptions.PropertyChanged += WritingOptions_PropertyChanged; if (MainWindow.Instance.CurrentLanguage is ILAstLanguage l) { l.StepperUpdated += ILAstStepperUpdated; @@ -32,9 +41,17 @@ namespace ICSharpCode.ILSpy #endif } + private void WritingOptions_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + DecompileAsync(lastSelectedStep); + } + private void SelectionChanged(object sender, SelectionChangedEventArgs e) { - Dispatcher.Invoke(() => tree.ItemsSource = null); + Dispatcher.Invoke(() => { + tree.ItemsSource = null; + lastSelectedStep = int.MaxValue; + }); } private void FilterSettings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) @@ -57,7 +74,10 @@ namespace ICSharpCode.ILSpy { #if DEBUG if (language == null) return; - Dispatcher.Invoke(() => tree.ItemsSource = language.Stepper.Steps); + Dispatcher.Invoke(() => { + tree.ItemsSource = language.Stepper.Steps; + lastSelectedStep = int.MaxValue; + }); #endif } @@ -71,6 +91,7 @@ namespace ICSharpCode.ILSpy #if DEBUG MainWindow.Instance.SessionSettings.FilterSettings.PropertyChanged -= FilterSettings_PropertyChanged; MainWindow.Instance.SelectionChanged -= SelectionChanged; + writingOptions.PropertyChanged -= WritingOptions_PropertyChanged; if (language != null) { language.StepperUpdated -= ILAstStepperUpdated; } @@ -98,8 +119,11 @@ namespace ICSharpCode.ILSpy DecompileAsync(n.BeginStep, true); } + int lastSelectedStep = int.MaxValue; + void DecompileAsync(int step, bool isDebug = false) { + lastSelectedStep = step; var window = MainWindow.Instance; var state = window.TextView.GetState(); window.TextView.DecompileAsync(window.CurrentLanguage, window.SelectedNodes, diff --git a/ILSpy/Languages/ILAstLanguage.cs b/ILSpy/Languages/ILAstLanguage.cs index a812da2b5..416455600 100644 --- a/ILSpy/Languages/ILAstLanguage.cs +++ b/ILSpy/Languages/ILAstLanguage.cs @@ -53,47 +53,6 @@ namespace ICSharpCode.ILSpy } public override string Name { get { return name; } } - /* - public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options) - { - if (!method.HasBody) { - return; - } - - ILAstBuilder astBuilder = new ILAstBuilder(); - ILBlock ilMethod = new ILBlock(); - DecompilerContext context = new DecompilerContext(method.Module) { CurrentType = method.DeclaringType, CurrentMethod = method }; - ilMethod.Body = astBuilder.Build(method, inlineVariables, context); - - if (abortBeforeStep != null) { - new ILAstOptimizer().Optimize(context, ilMethod, abortBeforeStep.Value); - } - - if (context.CurrentMethodIsAsync) - output.WriteLine("async/await"); - - var allVariables = ilMethod.GetSelfAndChildrenRecursive().Select(e => e.Operand as ILVariable) - .Where(v => v != null && !v.IsParameter).Distinct(); - foreach (ILVariable v in allVariables) { - output.WriteDefinition(v.Name, v); - if (v.Type != null) { - output.Write(" : "); - if (v.IsPinned) - output.Write("pinned "); - v.Type.WriteTo(output, ILNameSyntax.ShortTypeName); - } - if (v.IsGenerated) { - output.Write(" [generated]"); - } - output.WriteLine(); - } - output.WriteLine(); - - foreach (ILNode node in ilMethod.Body) { - node.WriteTo(output); - output.WriteLine(); - } - }*/ internal static IEnumerable GetDebugLanguages() { @@ -141,10 +100,6 @@ namespace ICSharpCode.ILSpy class BlockIL : ILAstLanguage { readonly IReadOnlyList transforms; - readonly ILAstWritingOptions writingOptions = new ILAstWritingOptions { - UseFieldSugar = true, - UseLogicOperationSugar = true - }; public BlockIL(IReadOnlyList transforms) : base("ILAst") { @@ -180,27 +135,11 @@ namespace ICSharpCode.ILSpy OnStepperUpdated(new EventArgs()); } } - (output as ISmartTextOutput)?.AddUIElement(OptionsCheckBox(nameof(writingOptions.UseFieldSugar))); - output.WriteLine(); - (output as ISmartTextOutput)?.AddUIElement(OptionsCheckBox(nameof(writingOptions.UseLogicOperationSugar))); - output.WriteLine(); (output as ISmartTextOutput)?.AddButton(Images.ViewCode, "Show Steps", delegate { DebugSteps.Show(); }); output.WriteLine(); - il.WriteTo(output, writingOptions); - } - - Func OptionsCheckBox(string propertyName) - { - return () => { - var checkBox = new System.Windows.Controls.CheckBox(); - checkBox.Content = propertyName; - checkBox.Cursor = System.Windows.Input.Cursors.Arrow; - checkBox.SetBinding(System.Windows.Controls.CheckBox.IsCheckedProperty, - new System.Windows.Data.Binding(propertyName) { Source = writingOptions }); - return checkBox; - }; + il.WriteTo(output, DebugSteps.Options); } } } From 5fec6bd7f7925816fe3e58cb7d1191269fa7734f Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 15:59:22 +0200 Subject: [PATCH 133/190] Implement Interval.WriteTo extension method on ILAst --- .../IL/InstructionOutputExtensions.cs | 11 ++++++ ICSharpCode.Decompiler/IL/Instructions.cs | 37 +++++++++++++++++++ ICSharpCode.Decompiler/IL/Instructions.tt | 1 + .../Instructions/BinaryNumericInstruction.cs | 1 + .../IL/Instructions/Branch.cs | 1 + .../IL/Instructions/CallIndirect.cs | 1 + .../IL/Instructions/CallInstruction.cs | 1 + .../IL/Instructions/Comp.cs | 1 + .../CompoundAssignmentInstruction.cs | 1 + .../IL/Instructions/Conv.cs | 1 + .../IL/Instructions/IfInstruction.cs | 1 + .../IL/Instructions/LdLen.cs | 1 + .../IL/Instructions/Leave.cs | 1 + .../IL/Instructions/LockInstruction.cs | 1 + .../IL/Instructions/MemoryInstructions.cs | 4 ++ .../Instructions/NullCoalescingInstruction.cs | 1 + .../IL/Instructions/SimpleInstruction.cs | 4 ++ .../IL/Instructions/StringToInt.cs | 1 + .../IL/Instructions/SwitchInstruction.cs | 2 + .../IL/Instructions/TryInstruction.cs | 4 ++ .../IL/Instructions/UnaryInstruction.cs | 1 + .../IL/Instructions/UsingInstruction.cs | 1 + 22 files changed, 78 insertions(+) diff --git a/ICSharpCode.Decompiler/IL/InstructionOutputExtensions.cs b/ICSharpCode.Decompiler/IL/InstructionOutputExtensions.cs index 1bc8681ca..d5a79cb1a 100644 --- a/ICSharpCode.Decompiler/IL/InstructionOutputExtensions.cs +++ b/ICSharpCode.Decompiler/IL/InstructionOutputExtensions.cs @@ -18,6 +18,7 @@ using ICSharpCode.Decompiler.Disassembler; using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler.IL { @@ -50,5 +51,15 @@ namespace ICSharpCode.Decompiler.IL else output.WriteReference(symbol.Name, symbol); } + + public static void WriteTo(this Interval interval, ITextOutput output, ILAstWritingOptions options) + { + if (!options.ShowILRanges) + return; + if (interval.IsEmpty) + output.Write("[empty] "); + else + output.Write($"[{interval.Start}..{interval.InclusiveEnd}] "); + } } } diff --git a/ICSharpCode.Decompiler/IL/Instructions.cs b/ICSharpCode.Decompiler/IL/Instructions.cs index 2afb023df..cf68e4446 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.cs +++ b/ICSharpCode.Decompiler/IL/Instructions.cs @@ -297,6 +297,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write('('); this.argument.WriteTo(output, options); @@ -389,6 +390,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write('('); this.left.WriteTo(output, options); @@ -816,6 +818,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); variable.WriteTo(output); @@ -2113,6 +2116,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); variable.WriteTo(output); @@ -2187,6 +2191,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); variable.WriteTo(output); @@ -2318,6 +2323,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); variable.WriteTo(output); @@ -2412,6 +2418,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write('('); this.value.WriteTo(output, options); @@ -2505,6 +2512,7 @@ namespace ICSharpCode.Decompiler.IL public override StackType ResultType { get { return StackType.O; } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); Disassembler.DisassemblerHelpers.WriteOperand(output, Value); @@ -2541,6 +2549,7 @@ namespace ICSharpCode.Decompiler.IL public override StackType ResultType { get { return StackType.I4; } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); Disassembler.DisassemblerHelpers.WriteOperand(output, Value); @@ -2577,6 +2586,7 @@ namespace ICSharpCode.Decompiler.IL public override StackType ResultType { get { return StackType.I8; } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); Disassembler.DisassemblerHelpers.WriteOperand(output, Value); @@ -2613,6 +2623,7 @@ namespace ICSharpCode.Decompiler.IL public override StackType ResultType { get { return StackType.F; } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); Disassembler.DisassemblerHelpers.WriteOperand(output, Value); @@ -2649,6 +2660,7 @@ namespace ICSharpCode.Decompiler.IL public override StackType ResultType { get { return StackType.O; } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); Disassembler.DisassemblerHelpers.WriteOperand(output, Value); @@ -2715,6 +2727,7 @@ namespace ICSharpCode.Decompiler.IL public override StackType ResultType { get { return StackType.I; } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); method.WriteTo(output); @@ -2762,6 +2775,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); method.WriteTo(output); @@ -2803,6 +2817,7 @@ namespace ICSharpCode.Decompiler.IL public override StackType ResultType { get { return StackType.O; } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); type.WriteTo(output); @@ -2841,6 +2856,7 @@ namespace ICSharpCode.Decompiler.IL public override StackType ResultType { get { return StackType.O; } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); member.WriteTo(output); @@ -3009,6 +3025,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); if (IsVolatile) output.Write("volatile."); if (UnalignedPrefix > 0) @@ -3149,6 +3166,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); if (IsVolatile) output.Write("volatile."); if (UnalignedPrefix > 0) @@ -3254,6 +3272,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); field.WriteTo(output); @@ -3295,6 +3314,7 @@ namespace ICSharpCode.Decompiler.IL public IField Field { get { return field; } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); field.WriteTo(output); @@ -3342,6 +3362,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); type.WriteTo(output); @@ -3383,6 +3404,7 @@ namespace ICSharpCode.Decompiler.IL public override StackType ResultType { get { return StackType.O; } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); type.WriteTo(output); @@ -3485,6 +3507,7 @@ namespace ICSharpCode.Decompiler.IL } void OriginalWriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); if (IsVolatile) output.Write("volatile."); if (UnalignedPrefix > 0) @@ -3609,6 +3632,7 @@ namespace ICSharpCode.Decompiler.IL } void OriginalWriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); if (IsVolatile) output.Write("volatile."); if (UnalignedPrefix > 0) @@ -3665,6 +3689,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); type.WriteTo(output); @@ -3715,6 +3740,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); type.WriteTo(output); @@ -3765,6 +3791,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); type.WriteTo(output); @@ -3875,6 +3902,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); type.WriteTo(output); @@ -3920,6 +3948,7 @@ namespace ICSharpCode.Decompiler.IL public override StackType ResultType { get { return type.GetStackType(); } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); type.WriteTo(output); @@ -4032,6 +4061,7 @@ namespace ICSharpCode.Decompiler.IL public override StackType ResultType { get { return StackType.I4; } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); type.WriteTo(output); @@ -4217,6 +4247,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); if (IsReadOnly) output.Write("readonly."); output.Write(OpCode); @@ -4318,6 +4349,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write('('); this.array.WriteTo(output, options); @@ -4438,6 +4470,7 @@ namespace ICSharpCode.Decompiler.IL public override StackType ResultType { get { return StackType.O; } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); type.WriteTo(output); @@ -4516,6 +4549,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); type.WriteTo(output); @@ -4610,6 +4644,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write('('); this.value.WriteTo(output, options); @@ -4702,6 +4737,7 @@ namespace ICSharpCode.Decompiler.IL } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write('('); this.value.WriteTo(output, options); @@ -4763,6 +4799,7 @@ namespace ICSharpCode.Decompiler.IL.Patterns } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write('('); output.Write(')'); diff --git a/ICSharpCode.Decompiler/IL/Instructions.tt b/ICSharpCode.Decompiler/IL/Instructions.tt index 598763260..59c19a742 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.tt +++ b/ICSharpCode.Decompiler/IL/Instructions.tt @@ -499,6 +499,7 @@ namespace ICSharpCode.Decompiler.IL public IEnumerable WriteToBody { get { + yield return "ILRange.WriteTo(output, options);"; foreach (string line in WriteOpCodePrefix) yield return line; yield return "output.Write(OpCode);"; diff --git a/ICSharpCode.Decompiler/IL/Instructions/BinaryNumericInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/BinaryNumericInstruction.cs index a1a037443..e409973ab 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/BinaryNumericInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/BinaryNumericInstruction.cs @@ -178,6 +178,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write("." + GetOperatorName(Operator)); if (CheckForOverflow) { diff --git a/ICSharpCode.Decompiler/IL/Instructions/Branch.cs b/ICSharpCode.Decompiler/IL/Instructions/Branch.cs index 7085ab6a1..6248f75f7 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/Branch.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/Branch.cs @@ -113,6 +113,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); output.WriteReference(TargetLabel, (object)targetBlock ?? TargetILOffset, isLocal: true); diff --git a/ICSharpCode.Decompiler/IL/Instructions/CallIndirect.cs b/ICSharpCode.Decompiler/IL/Instructions/CallIndirect.cs index 7b74939a2..a2380d5cf 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/CallIndirect.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/CallIndirect.cs @@ -91,6 +91,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write("call.indirect "); ReturnType.WriteTo(output); output.Write('('); diff --git a/ICSharpCode.Decompiler/IL/Instructions/CallInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/CallInstruction.cs index f846cb754..915ba74bc 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/CallInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/CallInstruction.cs @@ -76,6 +76,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); if (ConstrainedTo != null) { output.Write("constrained["); ConstrainedTo.WriteTo(output, ILNameSyntax.ShortTypeName); diff --git a/ICSharpCode.Decompiler/IL/Instructions/Comp.cs b/ICSharpCode.Decompiler/IL/Instructions/Comp.cs index 371cc4723..b4de5e4c2 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/Comp.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/Comp.cs @@ -175,6 +175,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); if (options.UseLogicOperationSugar && MatchLogicNot(out var arg)) { output.Write("logic.not("); arg.WriteTo(output, options); diff --git a/ICSharpCode.Decompiler/IL/Instructions/CompoundAssignmentInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/CompoundAssignmentInstruction.cs index 7d372c5cf..2b7f34e40 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/CompoundAssignmentInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/CompoundAssignmentInstruction.cs @@ -154,6 +154,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write("." + GetOperatorName(Operator)); if (CompoundAssignmentType == CompoundAssignmentType.EvaluatesToNewValue) diff --git a/ICSharpCode.Decompiler/IL/Instructions/Conv.cs b/ICSharpCode.Decompiler/IL/Instructions/Conv.cs index 8ba33dec9..235170a07 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/Conv.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/Conv.cs @@ -260,6 +260,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); if (CheckForOverflow) { output.Write(".ovf"); diff --git a/ICSharpCode.Decompiler/IL/Instructions/IfInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/IfInstruction.cs index 09ae5a87c..59845c679 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/IfInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/IfInstruction.cs @@ -78,6 +78,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); if (options.UseLogicOperationSugar) { if (MatchLogicAnd(out var lhs, out var rhs)) { output.Write("logic.and("); diff --git a/ICSharpCode.Decompiler/IL/Instructions/LdLen.cs b/ICSharpCode.Decompiler/IL/Instructions/LdLen.cs index b654624b0..82f65eb32 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/LdLen.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/LdLen.cs @@ -40,6 +40,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write('.'); output.Write(resultType); diff --git a/ICSharpCode.Decompiler/IL/Instructions/Leave.cs b/ICSharpCode.Decompiler/IL/Instructions/Leave.cs index 7bdabcc26..38e60cbe1 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/Leave.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/Leave.cs @@ -111,6 +111,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); if (targetContainer != null) { output.Write(' '); diff --git a/ICSharpCode.Decompiler/IL/Instructions/LockInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/LockInstruction.cs index 36cd8380e..b38c399bc 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/LockInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/LockInstruction.cs @@ -28,6 +28,7 @@ namespace ICSharpCode.Decompiler.IL { public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write("lock ("); OnExpression.WriteTo(output, options); output.WriteLine(") {"); diff --git a/ICSharpCode.Decompiler/IL/Instructions/MemoryInstructions.cs b/ICSharpCode.Decompiler/IL/Instructions/MemoryInstructions.cs index bc8236d05..533973dc0 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/MemoryInstructions.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/MemoryInstructions.cs @@ -41,6 +41,7 @@ namespace ICSharpCode.Decompiler.IL { if (options.UseFieldSugar) { if (this.MatchLdFld(out var target, out var field)) { + ILRange.WriteTo(output, options); output.Write("ldfld "); Disassembler.DisassemblerHelpers.WriteOperand(output, field); output.Write('('); @@ -48,6 +49,7 @@ namespace ICSharpCode.Decompiler.IL output.Write(')'); return; } else if (this.MatchLdsFld(out field)) { + ILRange.WriteTo(output, options); output.Write("ldsfld "); Disassembler.DisassemblerHelpers.WriteOperand(output, field); return; @@ -63,6 +65,7 @@ namespace ICSharpCode.Decompiler.IL { if (options.UseFieldSugar) { if (this.MatchStFld(out var target, out var field, out var value)) { + ILRange.WriteTo(output, options); output.Write("stfld "); Disassembler.DisassemblerHelpers.WriteOperand(output, field); output.Write('('); @@ -72,6 +75,7 @@ namespace ICSharpCode.Decompiler.IL output.Write(')'); return; } else if (this.MatchStsFld(out field, out value)) { + ILRange.WriteTo(output, options); output.Write("stsfld "); Disassembler.DisassemblerHelpers.WriteOperand(output, field); output.Write('('); diff --git a/ICSharpCode.Decompiler/IL/Instructions/NullCoalescingInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/NullCoalescingInstruction.cs index fd4385d1d..04606493a 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/NullCoalescingInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/NullCoalescingInstruction.cs @@ -91,6 +91,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); output.Write("("); valueInst.WriteTo(output, options); diff --git a/ICSharpCode.Decompiler/IL/Instructions/SimpleInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/SimpleInstruction.cs index 18f5b6f6f..82657c6bb 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/SimpleInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/SimpleInstruction.cs @@ -26,6 +26,7 @@ namespace ICSharpCode.Decompiler.IL { public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); // the non-custom WriteTo would add useless parentheses } @@ -37,6 +38,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); if (!string.IsNullOrEmpty(Comment)) { output.Write(" // " + Comment); @@ -60,6 +62,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); if (!string.IsNullOrEmpty(Message)) { output.Write("(\""); @@ -86,6 +89,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); if (!string.IsNullOrEmpty(Message)) { output.Write("(\""); diff --git a/ICSharpCode.Decompiler/IL/Instructions/StringToInt.cs b/ICSharpCode.Decompiler/IL/Instructions/StringToInt.cs index f804a3928..9ac94e591 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/StringToInt.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/StringToInt.cs @@ -32,6 +32,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write("string.to.int ("); Argument.WriteTo(output, options); output.Write(", { "); diff --git a/ICSharpCode.Decompiler/IL/Instructions/SwitchInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/SwitchInstruction.cs index ae828983f..7cba520d6 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/SwitchInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/SwitchInstruction.cs @@ -76,6 +76,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write("switch"); if (IsLifted) output.Write(".lifted"); @@ -180,6 +181,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.WriteDefinition("case", this, isLocal: true); output.Write(' '); if (HasNullLabel) { diff --git a/ICSharpCode.Decompiler/IL/Instructions/TryInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/TryInstruction.cs index 033d1cba0..b53611c42 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/TryInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/TryInstruction.cs @@ -67,6 +67,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(".try "); TryBlock.WriteTo(output, options); foreach (var handler in Handlers) { @@ -161,6 +162,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write("catch "); if (variable != null) { output.WriteDefinition(variable.Name, variable); @@ -202,6 +204,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(".try "); TryBlock.WriteTo(output, options); output.Write(" finally "); @@ -297,6 +300,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(".try "); TryBlock.WriteTo(output, options); output.Write(" fault "); diff --git a/ICSharpCode.Decompiler/IL/Instructions/UnaryInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/UnaryInstruction.cs index 52d489a0c..0773fc888 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/UnaryInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/UnaryInstruction.cs @@ -51,6 +51,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); if (IsLifted) { output.Write(".lifted"); diff --git a/ICSharpCode.Decompiler/IL/Instructions/UsingInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/UsingInstruction.cs index 795be5914..2a9e79ce3 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/UsingInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/UsingInstruction.cs @@ -38,6 +38,7 @@ namespace ICSharpCode.Decompiler.IL { public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write("using ("); Variable.WriteTo(output); output.Write(" = "); From 81e6f0c9bb7e2e518016bd5e60e05c7f9880f723 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 16:13:51 +0200 Subject: [PATCH 134/190] Improve ILRange output in ILAst --- ICSharpCode.Decompiler/IL/InstructionOutputExtensions.cs | 2 +- ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/IL/InstructionOutputExtensions.cs b/ICSharpCode.Decompiler/IL/InstructionOutputExtensions.cs index d5a79cb1a..33b5cbc88 100644 --- a/ICSharpCode.Decompiler/IL/InstructionOutputExtensions.cs +++ b/ICSharpCode.Decompiler/IL/InstructionOutputExtensions.cs @@ -59,7 +59,7 @@ namespace ICSharpCode.Decompiler.IL if (interval.IsEmpty) output.Write("[empty] "); else - output.Write($"[{interval.Start}..{interval.InclusiveEnd}] "); + output.Write($"[{interval.Start:x4}..{interval.InclusiveEnd:x4}] "); } } } diff --git a/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs b/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs index 7fd03b666..523f6218e 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs @@ -85,6 +85,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write(OpCode); if (Method != null) { output.Write(' '); From d68b9a98939927b1c25e134733bd5aacc2a4c7ea Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 14 Oct 2017 16:34:04 +0200 Subject: [PATCH 135/190] Fix missing InvalidateFlags() call. --- .../IL/Instructions/BlockContainer.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs index b70056841..2c6733598 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs @@ -40,11 +40,19 @@ namespace ICSharpCode.Decompiler.IL public readonly InstructionCollection Blocks; public StackType ExpectedResultType { get; set; } - + + int leaveCount; + /// /// Gets the number of 'leave' instructions that target this BlockContainer. /// - public int LeaveCount { get; internal set; } + public int LeaveCount { + get => leaveCount; + internal set { + leaveCount = value; + InvalidateFlags(); + } + } Block entryPoint; From c2a7c806f0e39e78191c4ca13df4df1724b16a1d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 16:51:27 +0200 Subject: [PATCH 136/190] Add missing annotations after TranslateFunction --- ICSharpCode.Decompiler/CSharp/CallBuilder.cs | 3 ++- ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index 23f0add1a..519eb2ae2 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -323,7 +323,8 @@ namespace ICSharpCode.Decompiler.CSharp break; case OpCode.ILFunction: method = ((ILFunction)func).Method; - return expressionBuilder.TranslateFunction(inst.Method.DeclaringType, (ILFunction)func); + return expressionBuilder.TranslateFunction(inst.Method.DeclaringType, (ILFunction)func) + .WithILInstruction(inst); default: throw new ArgumentException($"Unknown instruction type: {func.OpCode}"); } diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 25ed0ddb3..f2f252d4b 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -1026,7 +1026,7 @@ namespace ICSharpCode.Decompiler.CSharp return new CallBuilder(this, typeSystem, settings).Build(inst); } - internal TranslatedExpression TranslateFunction(IType delegateType, ILFunction function) + internal ExpressionWithResolveResult TranslateFunction(IType delegateType, ILFunction function) { var method = function.Method.MemberDefinition as IMethod; Debug.Assert(method != null); @@ -1098,7 +1098,7 @@ namespace ICSharpCode.Decompiler.CSharp TranslatedExpression translatedLambda = replacement.WithILInstruction(function).WithRR(rr); return new CastExpression(ConvertType(delegateType), translatedLambda) - .WithoutILInstruction().WithRR(new ConversionResolveResult(delegateType, rr, LambdaConversion.Instance)); + .WithRR(new ConversionResolveResult(delegateType, rr, LambdaConversion.Instance)); } IType InferReturnType(BlockStatement body) From f21d48317c61e7bde0ca05de531729d11318933f Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 14 Oct 2017 17:19:13 +0200 Subject: [PATCH 137/190] ILAst: show if block container is a loop container. --- ICSharpCode.Decompiler/IL/Instructions/Block.cs | 2 +- ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/IL/Instructions/Block.cs b/ICSharpCode.Decompiler/IL/Instructions/Block.cs index 0c5f9b7cc..d06f54fb0 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/Block.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/Block.cs @@ -135,7 +135,7 @@ namespace ICSharpCode.Decompiler.IL output.Write(" (incoming: {0})", IncomingEdgeCount); output.Write(' '); output.MarkFoldStart("{...}"); - output.WriteLine(" {"); + output.WriteLine("{"); output.Indent(); foreach (var inst in Instructions) { inst.WriteTo(output, options); diff --git a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs index 2c6733598..6288f9e69 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs @@ -117,6 +117,12 @@ namespace ICSharpCode.Decompiler.IL { output.WriteDefinition("BlockContainer", this); output.Write(' '); + if (entryPoint.IncomingEdgeCount > 1) { + output.Write("(loop) "); + } + if (entryPoint.Instructions.Count == 1 && entryPoint.Instructions[0] is SwitchInstruction) { + output.Write("(switch) "); + } output.MarkFoldStart("{...}"); output.WriteLine("{"); output.Indent(); From 84592fcc6fe31d1b9f5456ade3c2e91f8afa5373 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 17:20:26 +0200 Subject: [PATCH 138/190] Prevent SequencePointBuilder from combining sequence points of lambda expressions. --- ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs | 8 +++++++- ILSpy/Languages/CSharpILMixedLanguage.cs | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs index 463ff1e1c..2519cdd30 100644 --- a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs @@ -120,6 +120,12 @@ namespace ICSharpCode.Decompiler.CSharp } } + public override void VisitLambdaExpression(LambdaExpression lambdaExpression) + { + AddToSequencePoint(lambdaExpression); + VisitAsSequencePoint(lambdaExpression.Body); + } + /// /// Start a new C# statement = new sequence point. /// @@ -160,7 +166,7 @@ namespace ICSharpCode.Decompiler.CSharp void AddToSequencePoint(ILInstruction inst) { - if (!mappedInstructions.Add(inst)) { + if (!mappedInstructions.Add(inst) || inst is ILFunction) { // inst was already used by a nested sequence point within this sequence point return; } diff --git a/ILSpy/Languages/CSharpILMixedLanguage.cs b/ILSpy/Languages/CSharpILMixedLanguage.cs index 73340f695..da1297021 100644 --- a/ILSpy/Languages/CSharpILMixedLanguage.cs +++ b/ILSpy/Languages/CSharpILMixedLanguage.cs @@ -69,7 +69,8 @@ namespace ICSharpCode.ILSpy CSharpDecompiler decompiler = CreateDecompiler(method.Module, options); var st = decompiler.Decompile(method); WriteCode(csharpOutput, options.DecompilerSettings, st, decompiler.TypeSystem); - this.sequencePoints = decompiler.CreateSequencePoints(st).FirstOrDefault(kvp => kvp.Key.CecilMethod == method).Value ?? (IList)EmptyList.Instance; + var mapping = decompiler.CreateSequencePoints(st).FirstOrDefault(kvp => kvp.Key.CecilMethod == method); + this.sequencePoints = mapping.Value ?? (IList)EmptyList.Instance; this.codeLines = csharpOutput.ToString().Split(new[] { Environment.NewLine }, StringSplitOptions.None); base.Disassemble(body); } finally { From b7d4636f801c2094274cc2dd403de7e899a169f1 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 14 Oct 2017 17:37:33 +0200 Subject: [PATCH 139/190] Implement ILInstruction.AddILRange() --- .../IL/Instructions/ILInstruction.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs index d0bce881a..433bf39d8 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs @@ -208,10 +208,26 @@ namespace ICSharpCode.Decompiler.IL /// public Interval ILRange; - public void AddILRange(Interval ilRange) + public void AddILRange(Interval newRange) { - // TODO: try to combine the two ranges - this.ILRange = ilRange; + if (newRange.IsEmpty) { + return; + } + if (this.ILRange.IsEmpty) { + this.ILRange = newRange; + return; + } + if (newRange.Start <= this.ILRange.Start) { + if (newRange.End < this.ILRange.Start) { + this.ILRange = newRange; // use the earlier range + } else { + // join overlapping ranges + this.ILRange = new Interval(newRange.Start, Math.Max(newRange.End, this.ILRange.End)); + } + } else if (newRange.Start <= this.ILRange.End) { + // join overlapping ranges + this.ILRange = new Interval(this.ILRange.Start, Math.Max(newRange.End, this.ILRange.End)); + } } /// From 5e50294c8266a124eee25eab7d4302292f1368ef Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 17:46:41 +0200 Subject: [PATCH 140/190] Fix ILRange of ILFunction in DelegateConstruction --- ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs index 42de10379..62bf0ac17 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs @@ -43,7 +43,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms foreach (var call in block.Instructions[i].Descendants.OfType()) { ILFunction f = TransformDelegateConstruction(call, out ILInstruction target); if (f != null) { - call.Arguments[0].ReplaceWith(new Nop()); + f.AddILRange(call.Arguments[0].ILRange); + f.AddILRange(call.Arguments[1].ILRange); + call.Arguments[0].ReplaceWith(new LdNull()); call.Arguments[1].ReplaceWith(f); if (target is IInstructionWithVariableOperand && !target.MatchLdThis()) targetsToReplace.Add((IInstructionWithVariableOperand)target); From f890900d4d3aff1da2a65293778a9f40e805ab4b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 17:47:43 +0200 Subject: [PATCH 141/190] Fix AddToSequencePoint for ILFunction --- ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs index 2519cdd30..e86825bc5 100644 --- a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs @@ -166,15 +166,20 @@ namespace ICSharpCode.Decompiler.CSharp void AddToSequencePoint(ILInstruction inst) { - if (!mappedInstructions.Add(inst) || inst is ILFunction) { + if (!mappedInstructions.Add(inst)) { // inst was already used by a nested sequence point within this sequence point return; } // Add the IL range associated with this instruction to the current sequence point. if (!inst.ILRange.IsEmpty && current.Intervals != null) { current.Intervals.Add(inst.ILRange); - current.Function = inst.Ancestors.OfType().FirstOrDefault(); + current.Function = inst.Parent.Ancestors.OfType().FirstOrDefault(); } + + // Do not add instructions of lambdas/delegates. + if (inst is ILFunction) + return; + // Also add the child IL instructions, unless they were already processed by // another C# expression. foreach (var child in inst.Children) { From d2b66515074b039be4ef38bb62ddfa675a96101f Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 14 Oct 2017 18:58:41 +0200 Subject: [PATCH 142/190] ILAst: show unused IL ranges --- .../CSharp/SequencePointBuilder.cs | 20 ++++++++++-- .../IL/ILAstWritingOptions.cs | 21 +++++++++++-- .../IL/Instructions/Block.cs | 1 + .../IL/Instructions/BlockContainer.cs | 1 + .../IL/Instructions/ILFunction.cs | 31 ++++++++++++++++++- 5 files changed, 68 insertions(+), 6 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs index e86825bc5..a4528113f 100644 --- a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs @@ -171,9 +171,11 @@ namespace ICSharpCode.Decompiler.CSharp return; } // Add the IL range associated with this instruction to the current sequence point. - if (!inst.ILRange.IsEmpty && current.Intervals != null) { + if (HasUsableILRange(inst) && current.Intervals != null) { current.Intervals.Add(inst.ILRange); - current.Function = inst.Parent.Ancestors.OfType().FirstOrDefault(); + var function = inst.Parent.Ancestors.OfType().FirstOrDefault(); + Debug.Assert(current.Function == null || current.Function == function); + current.Function = function; } // Do not add instructions of lambdas/delegates. @@ -187,6 +189,13 @@ namespace ICSharpCode.Decompiler.CSharp } } + internal static bool HasUsableILRange(ILInstruction inst) + { + if (inst.ILRange.IsEmpty) + return false; + return !(inst is BlockContainer || inst is Block); + } + /// /// Called after the visitor is done to return the results. /// @@ -227,6 +236,13 @@ namespace ICSharpCode.Decompiler.CSharp newList.Add(sequencePoint); pos = sequencePoint.EndOffset; } + if (pos < function.CecilMethod.Body.CodeSize) { + var hidden = new SequencePoint(); + hidden.Offset = pos; + hidden.EndOffset = function.CecilMethod.Body.CodeSize; + hidden.SetHidden(); + newList.Add(hidden); + } dict[function] = newList; } return dict; diff --git a/ICSharpCode.Decompiler/IL/ILAstWritingOptions.cs b/ICSharpCode.Decompiler/IL/ILAstWritingOptions.cs index 42b8ddf66..3b6098d1c 100644 --- a/ICSharpCode.Decompiler/IL/ILAstWritingOptions.cs +++ b/ICSharpCode.Decompiler/IL/ILAstWritingOptions.cs @@ -1,8 +1,23 @@ -using System; -using System.Collections.Generic; +// Copyright (c) 2017 Daniel Grunwald +// +// 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.ComponentModel; using System.Runtime.CompilerServices; -using System.Text; namespace ICSharpCode.Decompiler.IL { diff --git a/ICSharpCode.Decompiler/IL/Instructions/Block.cs b/ICSharpCode.Decompiler/IL/Instructions/Block.cs index 0c5f9b7cc..8548717bc 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/Block.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/Block.cs @@ -129,6 +129,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.Write("Block "); output.WriteDefinition(Label, this); if (Parent is BlockContainer) diff --git a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs index b70056841..099f553a4 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs @@ -107,6 +107,7 @@ namespace ICSharpCode.Decompiler.IL public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { + ILRange.WriteTo(output, options); output.WriteDefinition("BlockContainer", this); output.Write(' '); output.MarkFoldStart("{...}"); diff --git a/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs b/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs index 523f6218e..4424ba4f5 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs @@ -114,12 +114,41 @@ namespace ICSharpCode.Decompiler.IL } body.WriteTo(output, options); - output.WriteLine(); + + if (options.ShowILRanges) { + var unusedILRanges = FindUnusedILRanges(); + if (!unusedILRanges.IsEmpty) { + output.Write("// Unused IL Ranges: "); + output.Write(string.Join(", ", unusedILRanges.Intervals.Select( + range => $"[{range.Start:x4}..{range.InclusiveEnd:x4}]"))); + output.WriteLine(); + } + } + output.Unindent(); output.WriteLine("}"); } + LongSet FindUnusedILRanges() + { + var usedILRanges = new List(); + MarkUsedILRanges(body); + return new LongSet(new LongInterval(0, CecilMethod.Body.CodeSize)).ExceptWith(new LongSet(usedILRanges)); + + void MarkUsedILRanges(ILInstruction inst) + { + if (CSharp.SequencePointBuilder.HasUsableILRange(inst)) { + usedILRanges.Add(new LongInterval(inst.ILRange.Start, inst.ILRange.End)); + } + if (!(inst is ILFunction)) { + foreach (var child in inst.Children) { + MarkUsedILRanges(child); + } + } + } + } + protected override InstructionFlags ComputeFlags() { // Creating a lambda may throw OutOfMemoryException From 462d0da7b6449b5a22d99d59820b6120684623e2 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 14 Oct 2017 19:31:10 +0200 Subject: [PATCH 143/190] Add feature to the MethodBodyDisassembler that shows sequence points from PDB in disassembled IL. --- .../Helpers/Tester.cs | 3 +- .../Disassembler/MethodBodyDisassembler.cs | 42 +++++++++++++++---- .../Disassembler/ReflectionDisassembler.cs | 14 ++++++- ICSharpCode.Decompiler/IL/ILReader.cs | 3 +- ILSpy/Languages/CSharpILMixedLanguage.cs | 11 +++-- ILSpy/Languages/ILAstLanguage.cs | 2 +- ILSpy/Languages/ILLanguage.cs | 5 ++- 7 files changed, 63 insertions(+), 17 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs index 3fa97ed6f..05de0357e 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs @@ -111,7 +111,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers using (var writer = new StreamWriter(outputFile)) { module.Name = Path.GetFileNameWithoutExtension(outputFile); var output = new PlainTextOutput(writer); - ReflectionDisassembler rd = new ReflectionDisassembler(output, false, CancellationToken.None); + ReflectionDisassembler rd = new ReflectionDisassembler(output, CancellationToken.None); + rd.DetectControlStructure = false; rd.WriteAssemblyReferences(module); if (module.Assembly != null) rd.WriteAssemblyHeader(module.Assembly); diff --git a/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs b/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs index c5860c7cb..24a1fb3b8 100644 --- a/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs +++ b/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.Threading; using Mono.Cecil; using Mono.Cecil.Cil; +using Mono.Collections.Generic; namespace ICSharpCode.Decompiler.Disassembler { @@ -30,15 +31,24 @@ namespace ICSharpCode.Decompiler.Disassembler public class MethodBodyDisassembler { readonly ITextOutput output; - readonly bool detectControlStructure; readonly CancellationToken cancellationToken; - public MethodBodyDisassembler(ITextOutput output, bool detectControlStructure, CancellationToken cancellationToken) + /// + /// Show .try/finally as blocks in IL code; indent loops. + /// + public bool DetectControlStructure { get; set; } = true; + + /// + /// Show sequence points if debug information is loaded in Cecil. + /// + public bool ShowSequencePoints { get; set; } + + Collection sequencePoints; + int nextSequencePointIndex; + + public MethodBodyDisassembler(ITextOutput output, CancellationToken cancellationToken) { - if (output == null) - throw new ArgumentNullException(nameof(output)); - this.output = output; - this.detectControlStructure = detectControlStructure; + this.output = output ?? throw new ArgumentNullException(nameof(output)); this.cancellationToken = cancellationToken; } @@ -55,7 +65,9 @@ namespace ICSharpCode.Decompiler.Disassembler DisassembleLocalsBlock(body); output.WriteLine(); - if (detectControlStructure && body.Instructions.Count > 0) { + sequencePoints = method.DebugInformation?.SequencePoints; + nextSequencePointIndex = 0; + if (DetectControlStructure && body.Instructions.Count > 0) { Instruction inst = body.Instructions[0]; HashSet branchTargets = GetBranchTargets(body.Instructions); WriteStructureBody(new ILStructure(body), branchTargets, ref inst, method.Body.CodeSize); @@ -66,6 +78,7 @@ namespace ICSharpCode.Decompiler.Disassembler } WriteExceptionHandlers(body); } + sequencePoints = null; } private void DisassembleLocalsBlock(MethodBody body) @@ -215,6 +228,21 @@ namespace ICSharpCode.Decompiler.Disassembler protected virtual void WriteInstruction(ITextOutput output, Instruction instruction) { + if (ShowSequencePoints && nextSequencePointIndex < sequencePoints?.Count) { + SequencePoint sp = sequencePoints[nextSequencePointIndex]; + if (sp.Offset <= instruction.Offset) { + output.Write("// sequence point: "); + if (sp.Offset != instruction.Offset) { + output.Write("!! at " + DisassemblerHelpers.OffsetToString(sp.Offset) + " !!"); + } + if (sp.IsHidden) { + output.WriteLine("hidden"); + } else { + output.WriteLine($"(line {sp.StartLine}, col {sp.StartColumn}) to (line {sp.EndLine}, col {sp.EndColumn}) in {sp.Document?.Url}"); + } + nextSequencePointIndex++; + } + } instruction.WriteTo(output); } } diff --git a/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs b/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs index 6137fc0d5..851c47842 100644 --- a/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs +++ b/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs @@ -35,8 +35,18 @@ namespace ICSharpCode.Decompiler.Disassembler MethodBodyDisassembler methodBodyDisassembler; MemberReference currentMember; - public ReflectionDisassembler(ITextOutput output, bool detectControlStructure, CancellationToken cancellationToken) - : this(output, new MethodBodyDisassembler(output, detectControlStructure, cancellationToken), cancellationToken) + public bool DetectControlStructure { + get => methodBodyDisassembler.DetectControlStructure; + set => methodBodyDisassembler.DetectControlStructure = value; + } + + public bool ShowSequencePoints { + get => methodBodyDisassembler.ShowSequencePoints; + set => methodBodyDisassembler.ShowSequencePoints = value; + } + + public ReflectionDisassembler(ITextOutput output, CancellationToken cancellationToken) + : this(output, new MethodBodyDisassembler(output, cancellationToken), cancellationToken) { } diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index 866fe7afd..91689aef7 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -304,7 +304,8 @@ namespace ICSharpCode.Decompiler.IL inst.WriteTo(output, new ILAstWritingOptions()); output.WriteLine(); } - new Disassembler.MethodBodyDisassembler(output, false, cancellationToken).WriteExceptionHandlers(body); + new Disassembler.MethodBodyDisassembler(output, cancellationToken) { DetectControlStructure = false } + .WriteExceptionHandlers(body); } /// diff --git a/ILSpy/Languages/CSharpILMixedLanguage.cs b/ILSpy/Languages/CSharpILMixedLanguage.cs index da1297021..1e027fae8 100644 --- a/ILSpy/Languages/CSharpILMixedLanguage.cs +++ b/ILSpy/Languages/CSharpILMixedLanguage.cs @@ -28,7 +28,10 @@ namespace ICSharpCode.ILSpy protected override ReflectionDisassembler CreateDisassembler(ITextOutput output, DecompilationOptions options) { return new ReflectionDisassembler(output, - new MixedMethodBodyDisassembler(output, detectControlStructure, options), + new MixedMethodBodyDisassembler(output, options) { + DetectControlStructure = detectControlStructure, + ShowSequencePoints = true + }, options.CancellationToken); } @@ -55,8 +58,8 @@ namespace ICSharpCode.ILSpy // lines of raw c# source code string[] codeLines; - public MixedMethodBodyDisassembler(ITextOutput output, bool detectControlStructure, DecompilationOptions options) - : base(output, detectControlStructure, options.CancellationToken) + public MixedMethodBodyDisassembler(ITextOutput output, DecompilationOptions options) + : base(output, options.CancellationToken) { this.options = options; } @@ -102,7 +105,7 @@ namespace ICSharpCode.ILSpy } else { output.Write("// "); highlightingOutput?.BeginSpan(gray); - output.WriteLine("(hidden sequence point)"); + output.WriteLine("(no C# code)"); highlightingOutput?.EndSpan(); } } diff --git a/ILSpy/Languages/ILAstLanguage.cs b/ILSpy/Languages/ILAstLanguage.cs index 416455600..88a6601e6 100644 --- a/ILSpy/Languages/ILAstLanguage.cs +++ b/ILSpy/Languages/ILAstLanguage.cs @@ -77,7 +77,7 @@ namespace ICSharpCode.ILSpy public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options) { base.DecompileMethod(method, output, options); - new ReflectionDisassembler(output, false, options.CancellationToken).DisassembleMethodHeader(method); + new ReflectionDisassembler(output, options.CancellationToken).DisassembleMethodHeader(method); output.WriteLine(); output.WriteLine(); } diff --git a/ILSpy/Languages/ILLanguage.cs b/ILSpy/Languages/ILLanguage.cs index 71dec3ee7..24aeedfba 100644 --- a/ILSpy/Languages/ILLanguage.cs +++ b/ILSpy/Languages/ILLanguage.cs @@ -46,7 +46,10 @@ namespace ICSharpCode.ILSpy protected virtual ReflectionDisassembler CreateDisassembler(ITextOutput output, DecompilationOptions options) { - return new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken); + return new ReflectionDisassembler(output, options.CancellationToken) { + DetectControlStructure = detectControlStructure, + ShowSequencePoints = true + }; } public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options) From 79d3ff10a32581bb30a1325bfbff70be0002b247 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 20:00:21 +0200 Subject: [PATCH 144/190] Add setting ShowDebugInfo --- ICSharpCode.Decompiler/DecompilerSettings.cs | 17 +++++++++++++++-- ILSpy/Languages/CSharpILMixedLanguage.cs | 2 +- ILSpy/Languages/ILLanguage.cs | 2 +- ILSpy/Options/DecompilerSettingsPanel.xaml | 1 + ILSpy/Options/DecompilerSettingsPanel.xaml.cs | 2 ++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler/DecompilerSettings.cs b/ICSharpCode.Decompiler/DecompilerSettings.cs index 50f744e6d..6d6e16d21 100644 --- a/ICSharpCode.Decompiler/DecompilerSettings.cs +++ b/ICSharpCode.Decompiler/DecompilerSettings.cs @@ -360,8 +360,21 @@ namespace ICSharpCode.Decompiler } } } + + bool showDebugInfo; + + public bool ShowDebugInfo { + get { return showDebugInfo; } + set { + if (showDebugInfo != value) { + showDebugInfo = value; + OnPropertyChanged(); + } + } + } + #endregion - + CSharpFormattingOptions csharpFormattingOptions; public CSharpFormattingOptions CSharpFormattingOptions { @@ -382,7 +395,7 @@ namespace ICSharpCode.Decompiler } } } - + public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) diff --git a/ILSpy/Languages/CSharpILMixedLanguage.cs b/ILSpy/Languages/CSharpILMixedLanguage.cs index 1e027fae8..39d659093 100644 --- a/ILSpy/Languages/CSharpILMixedLanguage.cs +++ b/ILSpy/Languages/CSharpILMixedLanguage.cs @@ -30,7 +30,7 @@ namespace ICSharpCode.ILSpy return new ReflectionDisassembler(output, new MixedMethodBodyDisassembler(output, options) { DetectControlStructure = detectControlStructure, - ShowSequencePoints = true + ShowSequencePoints = options.DecompilerSettings.ShowDebugInfo }, options.CancellationToken); } diff --git a/ILSpy/Languages/ILLanguage.cs b/ILSpy/Languages/ILLanguage.cs index 24aeedfba..9e618150a 100644 --- a/ILSpy/Languages/ILLanguage.cs +++ b/ILSpy/Languages/ILLanguage.cs @@ -48,7 +48,7 @@ namespace ICSharpCode.ILSpy { return new ReflectionDisassembler(output, options.CancellationToken) { DetectControlStructure = detectControlStructure, - ShowSequencePoints = true + ShowSequencePoints = options.DecompilerSettings.ShowDebugInfo }; } diff --git a/ILSpy/Options/DecompilerSettingsPanel.xaml b/ILSpy/Options/DecompilerSettingsPanel.xaml index ecad2b28b..e43c553d3 100644 --- a/ILSpy/Options/DecompilerSettingsPanel.xaml +++ b/ILSpy/Options/DecompilerSettingsPanel.xaml @@ -11,6 +11,7 @@ Decompile expression trees Decompile automatic properties Use variable names from debug symbols, if available + Show info from debug symbols, if available Show XML documentation in decompiled code Enable folding on all blocks in braces diff --git a/ILSpy/Options/DecompilerSettingsPanel.xaml.cs b/ILSpy/Options/DecompilerSettingsPanel.xaml.cs index b013aa708..8541be53d 100644 --- a/ILSpy/Options/DecompilerSettingsPanel.xaml.cs +++ b/ILSpy/Options/DecompilerSettingsPanel.xaml.cs @@ -58,6 +58,7 @@ namespace ICSharpCode.ILSpy.Options s.QueryExpressions = (bool?)e.Attribute("queryExpressions") ?? s.QueryExpressions; s.ExpressionTrees = (bool?)e.Attribute("expressionTrees") ?? s.ExpressionTrees; s.UseDebugSymbols = (bool?)e.Attribute("useDebugSymbols") ?? s.UseDebugSymbols; + s.ShowDebugInfo = (bool?)e.Attribute("showDebugInfo") ?? s.ShowDebugInfo; s.ShowXmlDocumentation = (bool?)e.Attribute("xmlDoc") ?? s.ShowXmlDocumentation; s.FoldBraces = (bool?)e.Attribute("foldBraces") ?? s.FoldBraces; return s; @@ -75,6 +76,7 @@ namespace ICSharpCode.ILSpy.Options section.SetAttributeValue("queryExpressions", s.QueryExpressions); section.SetAttributeValue("expressionTrees", s.ExpressionTrees); section.SetAttributeValue("useDebugSymbols", s.UseDebugSymbols); + section.SetAttributeValue("showDebugInfo", s.ShowDebugInfo); section.SetAttributeValue("xmlDoc", s.ShowXmlDocumentation); section.SetAttributeValue("foldBraces", s.FoldBraces); From 2169d44c81a39c518d68fd8d1224f1fa4d22a5b8 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 20:00:44 +0200 Subject: [PATCH 145/190] Implement sequence points for using statement. --- ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs | 9 +++++++++ ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs index a4528113f..3486542ee 100644 --- a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs @@ -126,6 +126,15 @@ namespace ICSharpCode.Decompiler.CSharp VisitAsSequencePoint(lambdaExpression.Body); } + public override void VisitUsingStatement(UsingStatement usingStatement) + { + StartSequencePoint(usingStatement); + usingStatement.ResourceAcquisition.AcceptVisitor(this); + VisitAsSequencePoint(usingStatement.EmbeddedStatement); + AddToSequencePoint(usingStatement); + EndSequencePoint(usingStatement.StartLocation, usingStatement.RParToken.EndLocation); + } + /// /// Start a new C# statement = new sequence point. /// diff --git a/ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs index 1c64d2983..3d6cd1639 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs @@ -87,7 +87,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms context.Step("UsingTransform", tryFinally); storeInst.Variable.Kind = VariableKind.UsingLocal; block.Instructions.RemoveAt(i); - block.Instructions[i - 1] = new UsingInstruction(storeInst.Variable, storeInst.Value, tryFinally.TryBlock); + block.Instructions[i - 1] = new UsingInstruction(storeInst.Variable, storeInst.Value, tryFinally.TryBlock) { ILRange = storeInst.ILRange }; return true; } From c202b9145bbf2d348594ff570733ae4c5666f400 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 14 Oct 2017 22:31:56 +0200 Subject: [PATCH 146/190] Only follow hyperlinks on MouseUp if the mouse wasn't moved since MouseDown. This allows selecting text inside hyperlinks. Closes #704 --- ILSpy/ILSpy.csproj | 2 +- ILSpy/TextView/DecompilerTextView.cs | 35 ++++++++++++++++++--- ILSpy/TextView/ReferenceElementGenerator.cs | 10 ------ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index f61c643c4..1f3fc6f81 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -50,7 +50,7 @@ - + diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index ad52a7046..b8fea2606 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -106,7 +106,8 @@ namespace ICSharpCode.ILSpy.TextView textEditor.Options.RequireControlModifierForHyperlinkClick = false; textEditor.TextArea.TextView.MouseHover += TextViewMouseHover; textEditor.TextArea.TextView.MouseHoverStopped += TextViewMouseHoverStopped; - textEditor.TextArea.TextView.MouseDown += TextViewMouseDown; + textEditor.TextArea.PreviewMouseDown += TextAreaMouseDown; + textEditor.TextArea.PreviewMouseUp += TextAreaMouseUp; textEditor.SetBinding(Control.FontFamilyProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFont") }); textEditor.SetBinding(Control.FontSizeProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFontSize") }); textEditor.SetBinding(TextEditor.WordWrapProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("EnableWordWrap") }); @@ -602,12 +603,36 @@ namespace ICSharpCode.ILSpy.TextView MainWindow.Instance.JumpToReference(reference); } - void TextViewMouseDown(object sender, MouseButtonEventArgs e) + Point? mouseDownPos; + + void TextAreaMouseDown(object sender, MouseButtonEventArgs e) { - if (GetReferenceSegmentAtMousePosition() == null) - ClearLocalReferenceMarks(); + mouseDownPos = e.GetPosition(this); } - + + void TextAreaMouseUp(object sender, MouseButtonEventArgs e) + { + if (mouseDownPos == null) + return; + Vector dragDistance = e.GetPosition(this) - mouseDownPos.Value; + if (Math.Abs(dragDistance.X) < SystemParameters.MinimumHorizontalDragDistance + && Math.Abs(dragDistance.Y) < SystemParameters.MinimumVerticalDragDistance + && e.ChangedButton == MouseButton.Left) + { + // click without moving mouse + var referenceSegment = GetReferenceSegmentAtMousePosition(); + if (referenceSegment == null) { + ClearLocalReferenceMarks(); + } else { + JumpToReference(referenceSegment); + textEditor.TextArea.ClearSelection(); + } + // cancel mouse selection to avoid AvalonEdit selecting between the new + // cursor position and the mouse position. + textEditor.TextArea.MouseSelectionMode = MouseSelectionMode.None; + } + } + void ClearLocalReferenceMarks() { foreach (var mark in localReferenceMarks) { diff --git a/ILSpy/TextView/ReferenceElementGenerator.cs b/ILSpy/TextView/ReferenceElementGenerator.cs index 3e4e88ca0..262f7d598 100644 --- a/ILSpy/TextView/ReferenceElementGenerator.cs +++ b/ILSpy/TextView/ReferenceElementGenerator.cs @@ -105,16 +105,6 @@ namespace ICSharpCode.ILSpy.TextView e.Cursor = referenceSegment.IsLocal ? Cursors.Arrow : Cursors.Hand; } - /// - protected override void OnMouseDown(MouseButtonEventArgs e) - { - if (e.ChangedButton == MouseButton.Left && !e.Handled) { - parent.JumpToReference(referenceSegment); - if(!referenceSegment.IsLocal) - e.Handled = true; - } - } - /// protected override VisualLineText CreateInstance(int length) { From 4ca4d97011b289ebfe84e628548c087bb2e17905 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 14 Oct 2017 22:47:59 +0200 Subject: [PATCH 147/190] Improve SequencePointBuilder --- ICSharpCode.Decompiler/CSharp/Annotations.cs | 14 ++++++++ .../CSharp/NRefactoryExtensions.cs | 14 ++++++-- .../InsertMissingTokensDecorator.cs | 5 ++- .../CSharp/SequencePointBuilder.cs | 32 +++++++++++++++++++ .../CSharp/StatementBuilder.cs | 1 + .../ReplaceMethodCallsWithOperators.cs | 4 ++- .../ControlFlow/ControlFlowSimplification.cs | 20 +++++++++--- ICSharpCode.Decompiler/IL/ILReader.cs | 2 +- .../IL/Instructions/SimpleInstruction.cs | 11 +++++++ .../IL/Transforms/CopyPropagation.cs | 3 ++ .../IL/Transforms/LockTransform.cs | 6 ++-- 11 files changed, 100 insertions(+), 12 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/Annotations.cs b/ICSharpCode.Decompiler/CSharp/Annotations.cs index dde037429..40d1b5f93 100644 --- a/ICSharpCode.Decompiler/CSharp/Annotations.cs +++ b/ICSharpCode.Decompiler/CSharp/Annotations.cs @@ -164,4 +164,18 @@ namespace ICSharpCode.Decompiler.CSharp this.Variable = v; } } + + public class ForeachAnnotation + { + public readonly ILInstruction GetEnumeratorCall; + public readonly ILInstruction MoveNextCall; + public readonly ILInstruction GetCurrentCall; + + public ForeachAnnotation(ILInstruction getEnumeratorCall, ILInstruction moveNextCall, ILInstruction getCurrentCall) + { + GetEnumeratorCall = getEnumeratorCall; + MoveNextCall = moveNextCall; + GetCurrentCall = getCurrentCall; + } + } } diff --git a/ICSharpCode.Decompiler/CSharp/NRefactoryExtensions.cs b/ICSharpCode.Decompiler/CSharp/NRefactoryExtensions.cs index af2cce2b5..a1f3bb3d2 100644 --- a/ICSharpCode.Decompiler/CSharp/NRefactoryExtensions.cs +++ b/ICSharpCode.Decompiler/CSharp/NRefactoryExtensions.cs @@ -17,8 +17,10 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Linq; using ICSharpCode.Decompiler.CSharp.Syntax; using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; +using ICSharpCode.Decompiler.IL; namespace ICSharpCode.Decompiler.CSharp { @@ -31,7 +33,7 @@ namespace ICSharpCode.Decompiler.CSharp node.AddAnnotation(annotation); return node; } - + public static T CopyAnnotationsFrom(this T node, AstNode other) where T : AstNode { foreach (object annotation in other.Annotations) { @@ -39,7 +41,15 @@ namespace ICSharpCode.Decompiler.CSharp } return node; } - + + public static T CopyInstructionsFrom(this T node, AstNode other) where T : AstNode + { + foreach (object annotation in other.Annotations.OfType()) { + node.AddAnnotation(annotation); + } + return node; + } + public static T Detach(this T node) where T : AstNode { node.Remove(); diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs index 1e20d061a..8748eff1b 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs @@ -88,7 +88,10 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor if (node != null) node.Location = start; } - if (t != null) currentList.Add(t); + if (t != null) { + currentList.Add(t); + t.Role = role; + } base.WriteKeyword(role, keyword); } diff --git a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs index 3486542ee..24aa6e164 100644 --- a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs @@ -135,6 +135,36 @@ namespace ICSharpCode.Decompiler.CSharp EndSequencePoint(usingStatement.StartLocation, usingStatement.RParToken.EndLocation); } + public override void VisitForeachStatement(ForeachStatement foreachStatement) + { + var foreachInfo = foreachStatement.Annotation(); + if (foreachInfo == null) { + base.VisitForeachStatement(foreachStatement); + return; + } + // TODO : Add a sequence point on foreach token (mapped to nop before using instruction). + StartSequencePoint(foreachStatement); + foreachStatement.InExpression.AcceptVisitor(this); + AddToSequencePoint(foreachInfo.GetEnumeratorCall); + EndSequencePoint(foreachStatement.InExpression.StartLocation, foreachStatement.InExpression.EndLocation); + StartSequencePoint(foreachStatement); + AddToSequencePoint(foreachInfo.MoveNextCall); + EndSequencePoint(foreachStatement.InToken.StartLocation, foreachStatement.InToken.EndLocation); + StartSequencePoint(foreachStatement); + AddToSequencePoint(foreachInfo.GetCurrentCall); + EndSequencePoint(foreachStatement.VariableType.StartLocation, foreachStatement.VariableNameToken.EndLocation); + VisitAsSequencePoint(foreachStatement.EmbeddedStatement); + } + + public override void VisitLockStatement(LockStatement lockStatement) + { + StartSequencePoint(lockStatement); + lockStatement.Expression.AcceptVisitor(this); + VisitAsSequencePoint(lockStatement.EmbeddedStatement); + AddToSequencePoint(lockStatement); + EndSequencePoint(lockStatement.StartLocation, lockStatement.RParToken.EndLocation); + } + /// /// Start a new C# statement = new sequence point. /// @@ -146,6 +176,8 @@ namespace ICSharpCode.Decompiler.CSharp void EndSequencePoint(TextLocation startLocation, TextLocation endLocation) { + Debug.Assert(!startLocation.IsEmpty, "missing startLocation"); + Debug.Assert(!endLocation.IsEmpty, "missing endLocation"); if (current.Intervals.Count > 0 && current.Function != null) { // use LongSet to deduplicate and merge the intervals var longSet = new LongSet(current.Intervals.Select(i => new LongInterval(i.Start, i.End))); diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 909339d6d..f6cc29304 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -506,6 +506,7 @@ namespace ICSharpCode.Decompiler.CSharp }; // Add the variable annotation for highlighting (TokenTextWriter expects it directly on the ForeachStatement). foreachStmt.AddAnnotation(new ILVariableResolveResult(foreachVariable, foreachVariable.Type)); + foreachStmt.AddAnnotation(new ForeachAnnotation(inst.ResourceExpression, loop.Conditions.Single(), singleGetter)); // If there was an optional return statement, return it as well. if (optionalReturnAfterLoop != null) { return new BlockStatement { diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs b/ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs index 96e9a9516..fa7001f30 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs @@ -69,7 +69,9 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms case "System.Type.GetTypeFromHandle": if (arguments.Length == 1) { if (typeHandleOnTypeOfPattern.IsMatch(arguments[0])) { - invocationExpression.ReplaceWith(((MemberReferenceExpression)arguments[0]).Target); + Expression target = ((MemberReferenceExpression)arguments[0]).Target; + target.CopyInstructionsFrom(invocationExpression); + invocationExpression.ReplaceWith(target); return; } } diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs b/ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs index a896ca11a..6e336377e 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs @@ -44,9 +44,8 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow foreach (var block in function.Descendants.OfType()) { context.CancellationToken.ThrowIfCancellationRequested(); - // Remove 'nop' instructions - block.Instructions.RemoveAll(inst => inst.OpCode == OpCode.Nop); - + RemoveNopInstructions(block); + InlineVariableInReturnBlock(block, context); // 1st pass SimplifySwitchInstruction before SimplifyBranchChains() // starts duplicating return instructions. @@ -55,7 +54,20 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow SimplifyBranchChains(function, context); CleanUpEmptyBlocks(function, context); } - + + private static void RemoveNopInstructions(Block block) + { + // Move ILRanges of special nop instructions to the previous non-nop instruction. + for (int i = block.Instructions.Count - 1; i > 0; i--) { + if (block.Instructions[i] is Nop nop && nop.Kind == NopKind.Pop) { + block.Instructions[i - 1].AddILRange(nop.ILRange); + } + } + + // Remove 'nop' instructions + block.Instructions.RemoveAll(inst => inst.OpCode == OpCode.Nop); + } + void InlineVariableInReturnBlock(Block block, ILTransformContext context) { // In debug mode, the C#-compiler generates 'return blocks' that diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index 91689aef7..4ddfb54fb 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -650,7 +650,7 @@ namespace ICSharpCode.Decompiler.IL return BinaryNumeric(BinaryNumericOperator.BitOr); case Cil.Code.Pop: Pop(); - return new Nop(); + return new Nop() { Kind = NopKind.Pop }; case Cil.Code.Rem: return BinaryNumeric(BinaryNumericOperator.Rem, false, Sign.Signed); case Cil.Code.Rem_Un: diff --git a/ICSharpCode.Decompiler/IL/Instructions/SimpleInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/SimpleInstruction.cs index 82657c6bb..bb3432835 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/SimpleInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/SimpleInstruction.cs @@ -31,15 +31,26 @@ namespace ICSharpCode.Decompiler.IL // the non-custom WriteTo would add useless parentheses } } + + public enum NopKind + { + Normal, + Pop + } partial class Nop { public string Comment; + public NopKind Kind; + public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write(OpCode); + if (Kind != NopKind.Normal) { + output.Write("." + Kind.ToString().ToLowerInvariant()); + } if (!string.IsNullOrEmpty(Comment)) { output.Write(" // " + Comment); } diff --git a/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs b/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs index ea1e61834..91a79c6c4 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs @@ -51,9 +51,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms // dead store to stack if (copiedExpr.Flags == InstructionFlags.None) { // no-op -> delete + context.Step("remove dead store to stack: no-op -> delete", block.Instructions[i - 1]); block.Instructions.RemoveAt(i--); } else { // evaluate the value for its side-effects + context.Step("remove dead store to stack: evaluate the value for its side-effects", block.Instructions[i]); + copiedExpr.AddILRange(block.Instructions[i].ILRange); block.Instructions[i] = copiedExpr; } } else if (v.IsSingleDefinition && CanPerformCopyPropagation(v, copiedExpr)) { diff --git a/ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs index e09c0a2b8..cc497af74 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs @@ -83,7 +83,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms context.Step("LockTransformV2", block); block.Instructions.RemoveAt(i - 1); block.Instructions.RemoveAt(i - 2); - body.ReplaceWith(new LockInstruction(objectStore.Value, body.TryBlock)); + body.ReplaceWith(new LockInstruction(objectStore.Value, body.TryBlock) { ILRange = objectStore.ILRange }); return true; } @@ -127,7 +127,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms context.Step("LockTransformV4", block); block.Instructions.RemoveAt(i - 1); tryContainer.EntryPoint.Instructions.RemoveAt(0); - body.ReplaceWith(new LockInstruction(objectStore.Value, body.TryBlock)); + body.ReplaceWith(new LockInstruction(objectStore.Value, body.TryBlock) { ILRange = objectStore.ILRange }); return true; } @@ -173,7 +173,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms block.Instructions.RemoveAt(i - 1); block.Instructions.RemoveAt(i - 2); tryContainer.EntryPoint.Instructions.RemoveAt(0); - body.ReplaceWith(new LockInstruction(objectStore.Value, body.TryBlock)); + body.ReplaceWith(new LockInstruction(objectStore.Value, body.TryBlock) { ILRange = objectStore.ILRange }); return true; } From 5b4db073ef4d8324ff5c353c6a4b954d1bb6187d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 15 Oct 2017 09:27:24 +0200 Subject: [PATCH 148/190] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e86b98a8..e825513df 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ILSpy is the open-source .NET assembly browser and decompiler. -Download: [latest release](https://github.com/icsharpcode/ILSpy/releases) | [latest CI build](https://ci.appveyor.com/api/projects/icsharpcode/ilspy/artifacts/ILSpy_binaries.zip?branch=master&job=Configuration%3A+Release) +Download: [latest release](https://github.com/icsharpcode/ILSpy/releases) | [latest CI build (master)](https://ci.appveyor.com/api/projects/icsharpcode/ilspy/artifacts/ILSpy_binaries.zip?branch=master&job=Configuration%3A+Release) Note: Only the CI builds support .NET Standard/Core assemblies. However, those builds are not yet at feature parity with the released bits, see [C# language support status](https://github.com/icsharpcode/ILSpy/issues/829) for details. From f03de7abb84fa64a95d71d66c42ab0835785360e Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 15 Oct 2017 09:40:42 +0200 Subject: [PATCH 149/190] Fix #916: consistently use AvalonEdit 5.0.4 --- ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj b/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj index 715adb513..dcaf09535 100644 --- a/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj +++ b/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj @@ -36,7 +36,7 @@ - + From a0ed79156775ef2715342694d1d8e339630f5115 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 15 Oct 2017 10:17:55 +0200 Subject: [PATCH 150/190] SequencePointBuilder: add support for if-statement, while-statement and do-while-statement --- .../CSharp/SequencePointBuilder.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs index 24aa6e164..3e3e66e2e 100644 --- a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs @@ -67,6 +67,7 @@ namespace ICSharpCode.Decompiler.CSharp void VisitAsSequencePoint(AstNode node) { + if (node.IsNull) return; StartSequencePoint(node); node.AcceptVisitor(this); EndSequencePoint(node.StartLocation, node.EndLocation); @@ -165,6 +166,34 @@ namespace ICSharpCode.Decompiler.CSharp EndSequencePoint(lockStatement.StartLocation, lockStatement.RParToken.EndLocation); } + public override void VisitIfElseStatement(IfElseStatement ifElseStatement) + { + StartSequencePoint(ifElseStatement); + ifElseStatement.Condition.AcceptVisitor(this); + VisitAsSequencePoint(ifElseStatement.TrueStatement); + VisitAsSequencePoint(ifElseStatement.FalseStatement); + AddToSequencePoint(ifElseStatement); + EndSequencePoint(ifElseStatement.StartLocation, ifElseStatement.RParToken.EndLocation); + } + + public override void VisitWhileStatement(WhileStatement whileStatement) + { + StartSequencePoint(whileStatement); + whileStatement.Condition.AcceptVisitor(this); + VisitAsSequencePoint(whileStatement.EmbeddedStatement); + AddToSequencePoint(whileStatement); + EndSequencePoint(whileStatement.StartLocation, whileStatement.RParToken.EndLocation); + } + + public override void VisitDoWhileStatement(DoWhileStatement doWhileStatement) + { + StartSequencePoint(doWhileStatement); + VisitAsSequencePoint(doWhileStatement.EmbeddedStatement); + doWhileStatement.Condition.AcceptVisitor(this); + AddToSequencePoint(doWhileStatement); + EndSequencePoint(doWhileStatement.WhileToken.StartLocation, doWhileStatement.RParToken.EndLocation); + } + /// /// Start a new C# statement = new sequence point. /// From 451104381576a349602cca77509d1016a0243041 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 15 Oct 2017 10:36:09 +0200 Subject: [PATCH 151/190] SequencePointBuilder: add support for fixed-statement --- ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs index 3e3e66e2e..0daf76ab6 100644 --- a/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs @@ -194,6 +194,14 @@ namespace ICSharpCode.Decompiler.CSharp EndSequencePoint(doWhileStatement.WhileToken.StartLocation, doWhileStatement.RParToken.EndLocation); } + public override void VisitFixedStatement(FixedStatement fixedStatement) + { + foreach (var v in fixedStatement.Variables) { + VisitAsSequencePoint(v); + } + VisitAsSequencePoint(fixedStatement.EmbeddedStatement); + } + /// /// Start a new C# statement = new sequence point. /// From e34480527d6ec873afa4e558b1b8ddb1a14551ac Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 15 Oct 2017 11:08:34 +0200 Subject: [PATCH 152/190] Fix line tracking when printing single-line comments. --- .../CSharp/OutputVisitor/TextWriterOutputFormatter.cs | 6 ++++-- ILSpy/Languages/CSharpILMixedLanguage.cs | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterOutputFormatter.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterOutputFormatter.cs index 8d93ada89..a0f37ff74 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterOutputFormatter.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterOutputFormatter.cs @@ -128,7 +128,8 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor case CommentType.SingleLine: textWriter.Write("//"); textWriter.WriteLine(content); - column += 2 + content.Length; + column = 1; + line++; needsIndent = true; isAtStartOfLine = true; break; @@ -144,7 +145,8 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor case CommentType.Documentation: textWriter.Write("///"); textWriter.WriteLine(content); - column += 3 + content.Length; + column = 1; + line++; needsIndent = true; isAtStartOfLine = true; break; diff --git a/ILSpy/Languages/CSharpILMixedLanguage.cs b/ILSpy/Languages/CSharpILMixedLanguage.cs index 39d659093..073fd61bb 100644 --- a/ILSpy/Languages/CSharpILMixedLanguage.cs +++ b/ILSpy/Languages/CSharpILMixedLanguage.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.Composition; +using System.Diagnostics; using System.IO; using System.Linq; using System.Threading; @@ -116,6 +117,14 @@ namespace ICSharpCode.ILSpy void WriteHighlightedCommentLine(ISmartTextOutput output, string text, int startColumn, int endColumn, bool isSingleLine) { + if (startColumn > text.Length) { + Debug.Fail("startColumn is invalid"); + startColumn = text.Length; + } + if (endColumn > text.Length) { + Debug.Fail("endColumn is invalid"); + endColumn = text.Length; + } output.Write("// "); output.BeginSpan(gray); if (isSingleLine) From 086325afdf637701bdcfcc3dcbfb99389e07d118 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 15 Oct 2017 14:57:38 +0200 Subject: [PATCH 153/190] Fix #917: InvalidCastException: Cast from Int64 to Boolean not supported. --- .../TestCases/Pretty/Switch.cs | 35 ++++++++ .../TestCases/Pretty/Switch.il | 83 +++++++++++++++---- .../TestCases/Pretty/Switch.opt.il | 75 +++++++++++++---- .../TestCases/Pretty/Switch.opt.roslyn.il | 51 +++++++++++- .../TestCases/Pretty/Switch.roslyn.il | 64 +++++++++++++- .../CSharp/StatementBuilder.cs | 6 +- 6 files changed, 273 insertions(+), 41 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index 1f6ec6f17..4f19a857f 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -39,6 +39,41 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } + public enum State + { + False = 0, + True = 1, + Null = 2 + } + + public static State SwitchOverNullableBool(bool? value) + { + switch (value) { + case false: + return State.False; + case true: + return State.True; + case null: + return State.Null; + default: + throw new InvalidOperationException(); + } + } + + //public static bool? SwitchOverNullableEnum(State? state) + //{ + // switch (state) { + // case State.False: + // return false; + // case State.True: + // return true; + // case State.Null: + // return null; + // default: + // throw new InvalidOperationException(); + // } + //} + public static string SparseIntegerSwitch(int i) { Console.WriteLine("SparseIntegerSwitch: " + i); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il index 40a21bc93..581dfad62 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly '4doqvnxq' +.assembly mhfw1ujx { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module '4doqvnxq.dll' -// MVID: {5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF} +.module mhfw1ujx.dll +// MVID: {2E35825E-3352-4C5E-B230-3B3F7055B304} .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: 0x03320000 +// Image base: 0x005A0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -93,6 +93,55 @@ } // end of property SetProperty::Set } // end of class SetProperty + .class auto ansi sealed nested public State + extends [mscorlib]System.Enum + { + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State False = int32(0x00000000) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State True = int32(0x00000001) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State Null = int32(0x00000002) + } // end of class State + + .method public hidebysig static valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State + SwitchOverNullableBool(valuetype [mscorlib]System.Nullable`1 'value') cil managed + { + // Code size 53 (0x35) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State V_0, + bool V_1) + IL_0000: nop + IL_0001: ldarga.s 'value' + IL_0003: dup + IL_0004: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0009: stloc.1 + IL_000a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000f: brfalse.s IL_0029 + + IL_0011: ldloc.1 + IL_0012: switch ( + IL_0021, + IL_0025) + IL_001f: br.s IL_002d + + IL_0021: ldc.i4.0 + IL_0022: stloc.0 + IL_0023: br.s IL_0033 + + IL_0025: ldc.i4.1 + IL_0026: stloc.0 + IL_0027: br.s IL_0033 + + IL_0029: ldc.i4.2 + IL_002a: stloc.0 + IL_002b: br.s IL_0033 + + IL_002d: newobj instance void [mscorlib]System.InvalidOperationException::.ctor() + IL_0032: throw + + IL_0033: ldloc.0 + IL_0034: ret + } // end of method Switch::SwitchOverNullableBool + .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { @@ -785,7 +834,7 @@ IL_0015: brfalse IL_00e9 IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000b-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000c-1' IL_0021: brtrue.s IL_0084 IL_0023: ldc.i4.7 @@ -826,9 +875,9 @@ IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007d: volatile. - IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000b-1' + IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000c-1' IL_0084: volatile. - IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000b-1' + IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000c-1' IL_008b: ldloc.1 IL_008c: ldloca.s V_2 IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -900,7 +949,7 @@ IL_0013: brfalse IL_0158 IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000c-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000d-1' IL_001f: brtrue IL_00b8 IL_0024: ldc.i4.s 11 @@ -961,9 +1010,9 @@ IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00b1: volatile. - IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000c-1' + IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000d-1' IL_00b8: volatile. - IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000c-1' + IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000d-1' IL_00bf: ldloc.1 IL_00c0: ldloca.s V_2 IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1248,7 +1297,7 @@ IL_0030: brfalse IL_0121 IL_0035: volatile. - IL_0037: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x6000011-1' + IL_0037: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x6000012-1' IL_003c: brtrue.s IL_0093 IL_003e: ldc.i4.6 @@ -1284,9 +1333,9 @@ IL_0087: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_008c: volatile. - IL_008e: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x6000011-1' + IL_008e: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x6000012-1' IL_0093: volatile. - IL_0095: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x6000011-1' + IL_0095: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x6000012-1' IL_009a: ldloc.s V_5 IL_009c: ldloca.s V_6 IL_009e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1513,14 +1562,14 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}' +.class private auto ansi '{2E35825E-3352-4C5E-B230-3B3F7055B304}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000b-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000c-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000011-1' -} // end of class '{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000d-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000012-1' +} // end of class '{2E35825E-3352-4C5E-B230-3B3F7055B304}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il index 44acd173c..0dbe1fff9 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly jfao3dmb +.assembly okac2jza { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module jfao3dmb.dll -// MVID: {96F356C7-71A4-48B4-BE55-B48554E94654} +.module okac2jza.dll +// MVID: {7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F} .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: 0x01900000 +// Image base: 0x01A40000 // =============== CLASS MEMBERS DECLARATION =================== @@ -85,6 +85,47 @@ } // end of property SetProperty::Set } // end of class SetProperty + .class auto ansi sealed nested public State + extends [mscorlib]System.Enum + { + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State False = int32(0x00000000) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State True = int32(0x00000001) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State Null = int32(0x00000002) + } // end of class State + + .method public hidebysig static valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State + SwitchOverNullableBool(valuetype [mscorlib]System.Nullable`1 'value') cil managed + { + // Code size 44 (0x2c) + .maxstack 2 + .locals init (bool V_0) + IL_0000: ldarga.s 'value' + IL_0002: dup + IL_0003: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0008: stloc.0 + IL_0009: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000e: brfalse.s IL_0024 + + IL_0010: ldloc.0 + IL_0011: switch ( + IL_0020, + IL_0022) + IL_001e: br.s IL_0026 + + IL_0020: ldc.i4.0 + IL_0021: ret + + IL_0022: ldc.i4.1 + IL_0023: ret + + IL_0024: ldc.i4.2 + IL_0025: ret + + IL_0026: newobj instance void [mscorlib]System.InvalidOperationException::.ctor() + IL_002b: throw + } // end of method Switch::SwitchOverNullableBool + .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { @@ -670,7 +711,7 @@ IL_0013: brfalse IL_00db IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000b-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000c-1' IL_001f: brtrue.s IL_0082 IL_0021: ldc.i4.7 @@ -711,9 +752,9 @@ IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007b: volatile. - IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000b-1' + IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000c-1' IL_0082: volatile. - IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000b-1' + IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000c-1' IL_0089: ldloc.0 IL_008a: ldloca.s V_1 IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -771,7 +812,7 @@ IL_0011: brfalse IL_013d IL_0016: volatile. - IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000c-1' + IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000d-1' IL_001d: brtrue IL_00b6 IL_0022: ldc.i4.s 11 @@ -832,9 +873,9 @@ IL_00aa: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00af: volatile. - IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000c-1' + IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000d-1' IL_00b6: volatile. - IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000c-1' + IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000d-1' IL_00bd: ldloc.0 IL_00be: ldloca.s V_1 IL_00c0: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1058,7 +1099,7 @@ IL_002d: brfalse IL_0115 IL_0032: volatile. - IL_0034: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x6000011-1' + IL_0034: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x6000012-1' IL_0039: brtrue.s IL_0090 IL_003b: ldc.i4.6 @@ -1094,9 +1135,9 @@ IL_0084: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_0089: volatile. - IL_008b: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x6000011-1' + IL_008b: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x6000012-1' IL_0090: volatile. - IL_0092: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x6000011-1' + IL_0092: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x6000012-1' IL_0097: ldloc.s V_5 IL_0099: ldloca.s V_6 IL_009b: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1290,14 +1331,14 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{96F356C7-71A4-48B4-BE55-B48554E94654}' +.class private auto ansi '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000b-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000c-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000011-1' -} // end of class '{96F356C7-71A4-48B4-BE55-B48554E94654}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000d-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000012-1' +} // end of class '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il index 3c4b7ec5b..359906595 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {4366DF41-DCD0-42E1-B99D-7B67787ECEA9} +// MVID: {6F3B5958-B8BE-48C6-82B8-5D3026DEACD1} .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: 0x00690000 +// Image base: 0x03160000 // =============== CLASS MEMBERS DECLARATION =================== @@ -89,6 +89,53 @@ } // end of property SetProperty::Set } // end of class SetProperty + .class auto ansi sealed nested public State + extends [mscorlib]System.Enum + { + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State False = int32(0x00000000) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State True = int32(0x00000001) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State Null = int32(0x00000002) + } // end of class State + + .method public hidebysig static valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State + SwitchOverNullableBool(valuetype [mscorlib]System.Nullable`1 'value') cil managed + { + // Code size 40 (0x28) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + bool V_1) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brfalse.s IL_0020 + + IL_000b: ldloca.s V_0 + IL_000d: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0012: stloc.1 + IL_0013: ldloc.1 + IL_0014: brfalse.s IL_001c + + IL_0016: ldloc.1 + IL_0017: ldc.i4.1 + IL_0018: beq.s IL_001e + + IL_001a: br.s IL_0022 + + IL_001c: ldc.i4.0 + IL_001d: ret + + IL_001e: ldc.i4.1 + IL_001f: ret + + IL_0020: ldc.i4.2 + IL_0021: ret + + IL_0022: newobj instance void [mscorlib]System.InvalidOperationException::.ctor() + IL_0027: throw + } // end of method Switch::SwitchOverNullableBool + .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il index 47d88ae31..7cce7b604 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {0EBEAA6B-55A7-4255-9CA2-CE888E0F54BA} +// MVID: {7ADDBD28-42D6-469D-B92D-065C803347D0} .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: 0x00690000 +// Image base: 0x00C40000 // =============== CLASS MEMBERS DECLARATION =================== @@ -92,6 +92,66 @@ } // end of property SetProperty::Set } // end of class SetProperty + .class auto ansi sealed nested public State + extends [mscorlib]System.Enum + { + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State False = int32(0x00000000) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State True = int32(0x00000001) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State Null = int32(0x00000002) + } // end of class State + + .method public hidebysig static valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State + SwitchOverNullableBool(valuetype [mscorlib]System.Nullable`1 'value') cil managed + { + // Code size 53 (0x35) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + bool V_2, + valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State V_3) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: stloc.0 + IL_0005: ldloca.s V_0 + IL_0007: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000c: brfalse.s IL_0029 + + IL_000e: ldloca.s V_0 + IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0015: stloc.2 + IL_0016: ldloc.2 + IL_0017: brfalse.s IL_0021 + + IL_0019: br.s IL_001b + + IL_001b: ldloc.2 + IL_001c: ldc.i4.1 + IL_001d: beq.s IL_0025 + + IL_001f: br.s IL_002d + + IL_0021: ldc.i4.0 + IL_0022: stloc.3 + IL_0023: br.s IL_0033 + + IL_0025: ldc.i4.1 + IL_0026: stloc.3 + IL_0027: br.s IL_0033 + + IL_0029: ldc.i4.2 + IL_002a: stloc.3 + IL_002b: br.s IL_0033 + + IL_002d: newobj instance void [mscorlib]System.InvalidOperationException::.ctor() + IL_0032: throw + + IL_0033: ldloc.3 + IL_0034: ret + } // end of method Switch::SwitchOverNullableBool + .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 909339d6d..f2c9f5c92 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -86,6 +86,9 @@ namespace ICSharpCode.Decompiler.CSharp ConstantResolveResult CreateTypedCaseLabel(long i, IType type, string[] map = null) { object value; + // unpack nullable type, if necessary: + // we need to do this in all cases, because there are nullable bools and enum types as well. + type = NullableType.GetUnderlyingType(type); if (type.IsKnownType(KnownTypeCode.Boolean)) { value = i != 0; } else if (type.IsKnownType(KnownTypeCode.String) && map != null) { @@ -93,9 +96,6 @@ namespace ICSharpCode.Decompiler.CSharp } else if (type.Kind == TypeKind.Enum) { var enumType = type.GetDefinition().EnumUnderlyingType; value = CSharpPrimitiveCast.Cast(ReflectionHelper.GetTypeCode(enumType), i, false); - } else if (type.IsKnownType(KnownTypeCode.NullableOfT)) { - var nullableType = NullableType.GetUnderlyingType(type); - value = CSharpPrimitiveCast.Cast(ReflectionHelper.GetTypeCode(nullableType), i, false); } else { value = CSharpPrimitiveCast.Cast(ReflectionHelper.GetTypeCode(type), i, false); } From 14b6c599c168e3a17c11612717caa9166b5355c2 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 15 Oct 2017 15:47:24 +0200 Subject: [PATCH 154/190] Fix object initializers directly accessing struct members + add initializer pretty tests. --- .../ICSharpCode.Decompiler.Tests.csproj | 1 + .../PrettyTestRunner.cs | 6 + .../TestCases/Pretty/InitializerTests.cs | 92 +++++++ .../TestCases/Pretty/InitializerTests.il | 245 +++++++++++++++++ .../TestCases/Pretty/InitializerTests.opt.il | 207 +++++++++++++++ .../Pretty/InitializerTests.opt.roslyn.il | 195 ++++++++++++++ .../Pretty/InitializerTests.roslyn.il | 247 ++++++++++++++++++ ...ransformCollectionAndObjectInitializers.cs | 16 +- 8 files changed, 1004 insertions(+), 5 deletions(-) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index 490bc4c50..1affff8f5 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -66,6 +66,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index f5eee0fb8..dd00235d2 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -188,6 +188,12 @@ namespace ICSharpCode.Decompiler.Tests Run(cscOptions: cscOptions, asmOptions: AssemblerOptions.UseOwnDisassembler); } + [Test] + public void InitializerTests([ValueSource("defaultOptions")] CompilerOptions cscOptions) + { + Run(cscOptions: cscOptions); + } + [Test] public void FixProxyCalls([Values(CompilerOptions.None, CompilerOptions.Optimize, CompilerOptions.UseRoslyn)] CompilerOptions cscOptions) { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs new file mode 100644 index 000000000..352e68a17 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs @@ -0,0 +1,92 @@ +// 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.Collections.Generic; + +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty +{ + public class InitializerTests + { + public class C + { + public int Z; + public S Y; + public List L; + } + + public struct S + { + public int A; + public int B; + + public S(int a) + { + this.A = a; + this.B = 0; + } + } + + public static C TestCall(int a, C c) + { + return c; + } + + public C Test() + { + C c = new C(); + c.L = new List(); + c.L.Add(new S(1)); + return c; + } + + public C Test2() + { + C c = new C(); + c.Z = 1; + c.Z = 2; + return c; + } + + public C Test3() + { + C c = new C(); + c.Y = new S(1); + c.Y.A = 2; + return c; + } + + public C Test3b() + { + return InitializerTests.TestCall(0, new C { + Z = 1, + Y = { + A = 2 + } + }); + } + + public C Test4() + { + C c = new C(); + c.Y.A = 1; + c.Y.B = 3; + c.Z = 2; + return c; + } + } +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il new file mode 100644 index 000000000..88dc47267 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il @@ -0,0 +1,245 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly '0zopdghu' +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module '0zopdghu.dll' +// MVID: {56C873AC-FD1E-4808-A65A-845BA0A3C2B7} +.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: 0x032A0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests + extends [mscorlib]System.Object +{ + .class auto ansi nested public beforefieldinit C + extends [mscorlib]System.Object + { + .field public int32 Z + .field public valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S Y + .field public class [mscorlib]System.Collections.Generic.List`1 L + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method C::.ctor + + } // end of class C + + .class sequential ansi sealed nested public beforefieldinit S + extends [mscorlib]System.ValueType + { + .field public int32 A + .field public int32 B + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 a) cil managed + { + // Code size 16 (0x10) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_0008: ldarg.0 + IL_0009: ldc.i4.0 + IL_000a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B + IL_000f: ret + } // end of method S::.ctor + + } // end of class S + + .method public hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + TestCall(int32 a, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C c) cil managed + { + // Code size 7 (0x7) + .maxstack 1 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: stloc.0 + IL_0003: br.s IL_0005 + + IL_0005: ldloc.0 + IL_0006: ret + } // end of method InitializerTests::TestCall + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test() cil managed + { + // Code size 42 (0x2a) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_1) + IL_0000: nop + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000d: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::L + IL_0012: ldloc.0 + IL_0013: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::L + IL_0018: ldc.i4.1 + IL_0019: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::.ctor(int32) + IL_001e: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0023: nop + IL_0024: ldloc.0 + IL_0025: stloc.1 + IL_0026: br.s IL_0028 + + IL_0028: ldloc.1 + IL_0029: ret + } // end of method InitializerTests::Test + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test2() cil managed + { + // Code size 27 (0x1b) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_1) + IL_0000: nop + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldc.i4.1 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_000e: ldloc.0 + IL_000f: ldc.i4.2 + IL_0010: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0015: ldloc.0 + IL_0016: stloc.1 + IL_0017: br.s IL_0019 + + IL_0019: ldloc.1 + IL_001a: ret + } // end of method InitializerTests::Test2 + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test3() cil managed + { + // Code size 37 (0x25) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_1) + IL_0000: nop + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldc.i4.1 + IL_0009: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::.ctor(int32) + IL_000e: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0013: ldloc.0 + IL_0014: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0019: ldc.i4.2 + IL_001a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_001f: ldloc.0 + IL_0020: stloc.1 + IL_0021: br.s IL_0023 + + IL_0023: ldloc.1 + IL_0024: ret + } // end of method InitializerTests::Test3 + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test3b() cil managed + { + // Code size 38 (0x26) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_1) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldc.i4.1 + IL_000a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_000f: ldloc.0 + IL_0010: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0015: ldc.i4.2 + IL_0016: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_001b: ldloc.0 + IL_001c: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::TestCall(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C) + IL_0021: stloc.1 + IL_0022: br.s IL_0024 + + IL_0024: ldloc.1 + IL_0025: ret + } // end of method InitializerTests::Test3b + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test4() cil managed + { + // Code size 44 (0x2c) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_1) + IL_0000: nop + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_000d: ldc.i4.1 + IL_000e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_0013: ldloc.0 + IL_0014: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0019: ldc.i4.3 + IL_001a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B + IL_001f: ldloc.0 + IL_0020: ldc.i4.2 + IL_0021: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0026: ldloc.0 + IL_0027: stloc.1 + IL_0028: br.s IL_002a + + IL_002a: ldloc.1 + IL_002b: ret + } // end of method InitializerTests::Test4 + + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method InitializerTests::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\InitializerTests.res" wurde erstellt. diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il new file mode 100644 index 000000000..9045f3b19 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il @@ -0,0 +1,207 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly xvcsxiw0 +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module xvcsxiw0.dll +// MVID: {ADB73224-52C3-4DFE-AB87-E9CEDD4FB2C3} +.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: 0x00D20000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests + extends [mscorlib]System.Object +{ + .class auto ansi nested public beforefieldinit C + extends [mscorlib]System.Object + { + .field public int32 Z + .field public valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S Y + .field public class [mscorlib]System.Collections.Generic.List`1 L + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method C::.ctor + + } // end of class C + + .class sequential ansi sealed nested public beforefieldinit S + extends [mscorlib]System.ValueType + { + .field public int32 A + .field public int32 B + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 a) cil managed + { + // Code size 15 (0xf) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_0007: ldarg.0 + IL_0008: ldc.i4.0 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B + IL_000e: ret + } // end of method S::.ctor + + } // end of class S + + .method public hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + TestCall(int32 a, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C c) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } // end of method InitializerTests::TestCall + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test() cil managed + { + // Code size 36 (0x24) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000c: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::L + IL_0011: ldloc.0 + IL_0012: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::L + IL_0017: ldc.i4.1 + IL_0018: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::.ctor(int32) + IL_001d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0022: ldloc.0 + IL_0023: ret + } // end of method InitializerTests::Test + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test2() cil managed + { + // Code size 22 (0x16) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldc.i4.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_000d: ldloc.0 + IL_000e: ldc.i4.2 + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0014: ldloc.0 + IL_0015: ret + } // end of method InitializerTests::Test2 + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test3() cil managed + { + // Code size 32 (0x20) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldc.i4.1 + IL_0008: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::.ctor(int32) + IL_000d: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0012: ldloc.0 + IL_0013: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0018: ldc.i4.2 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_001e: ldloc.0 + IL_001f: ret + } // end of method InitializerTests::Test3 + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test3b() cil managed + { + // Code size 33 (0x21) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0) + IL_0000: ldc.i4.0 + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldc.i4.1 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_000e: ldloc.0 + IL_000f: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0014: ldc.i4.2 + IL_0015: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_001a: ldloc.0 + IL_001b: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::TestCall(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C) + IL_0020: ret + } // end of method InitializerTests::Test3b + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test4() cil managed + { + // Code size 39 (0x27) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_000c: ldc.i4.1 + IL_000d: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_0012: ldloc.0 + IL_0013: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0018: ldc.i4.3 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B + IL_001e: ldloc.0 + IL_001f: ldc.i4.2 + IL_0020: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0025: ldloc.0 + IL_0026: ret + } // end of method InitializerTests::Test4 + + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method InitializerTests::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\InitializerTests.opt.res" wurde erstellt. diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il new file mode 100644 index 000000000..b4dca5b95 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il @@ -0,0 +1,195 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly InitializerTests +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module InitializerTests.dll +// MVID: {73C118AC-648F-43DB-A2FB-1B159DF870BA} +.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: 0x03230000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests + extends [mscorlib]System.Object +{ + .class auto ansi nested public beforefieldinit C + extends [mscorlib]System.Object + { + .field public int32 Z + .field public valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S Y + .field public class [mscorlib]System.Collections.Generic.List`1 L + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method C::.ctor + + } // end of class C + + .class sequential ansi sealed nested public beforefieldinit S + extends [mscorlib]System.ValueType + { + .field public int32 A + .field public int32 B + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 a) cil managed + { + // Code size 15 (0xf) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_0007: ldarg.0 + IL_0008: ldc.i4.0 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B + IL_000e: ret + } // end of method S::.ctor + + } // end of class S + + .method public hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + TestCall(int32 a, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C c) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } // end of method InitializerTests::TestCall + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test() cil managed + { + // Code size 34 (0x22) + .maxstack 8 + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0005: dup + IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000b: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::L + IL_0010: dup + IL_0011: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::L + IL_0016: ldc.i4.1 + IL_0017: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::.ctor(int32) + IL_001c: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0021: ret + } // end of method InitializerTests::Test + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test2() cil managed + { + // Code size 20 (0x14) + .maxstack 8 + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0005: dup + IL_0006: ldc.i4.1 + IL_0007: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_000c: dup + IL_000d: ldc.i4.2 + IL_000e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0013: ret + } // end of method InitializerTests::Test2 + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test3() cil managed + { + // Code size 30 (0x1e) + .maxstack 8 + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0005: dup + IL_0006: ldc.i4.1 + IL_0007: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::.ctor(int32) + IL_000c: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0011: dup + IL_0012: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0017: ldc.i4.2 + IL_0018: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_001d: ret + } // end of method InitializerTests::Test3 + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test3b() cil managed + { + // Code size 31 (0x1f) + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0006: dup + IL_0007: ldc.i4.1 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_000d: dup + IL_000e: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0013: ldc.i4.2 + IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_0019: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::TestCall(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C) + IL_001e: ret + } // end of method InitializerTests::Test3b + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test4() cil managed + { + // Code size 37 (0x25) + .maxstack 8 + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0005: dup + IL_0006: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_000b: ldc.i4.1 + IL_000c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_0011: dup + IL_0012: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0017: ldc.i4.3 + IL_0018: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B + IL_001d: dup + IL_001e: ldc.i4.2 + IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0024: ret + } // end of method InitializerTests::Test4 + + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method InitializerTests::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il new file mode 100644 index 000000000..dab3fefa3 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il @@ -0,0 +1,247 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly InitializerTests +{ + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module InitializerTests.dll +// MVID: {53F415C2-DC80-4EFA-8787-82F129B1AC28} +.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: 0x002F0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests + extends [mscorlib]System.Object +{ + .class auto ansi nested public beforefieldinit C + extends [mscorlib]System.Object + { + .field public int32 Z + .field public valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S Y + .field public class [mscorlib]System.Collections.Generic.List`1 L + .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 C::.ctor + + } // end of class C + + .class sequential ansi sealed nested public beforefieldinit S + extends [mscorlib]System.ValueType + { + .field public int32 A + .field public int32 B + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 a) cil managed + { + // Code size 16 (0x10) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_0008: ldarg.0 + IL_0009: ldc.i4.0 + IL_000a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B + IL_000f: ret + } // end of method S::.ctor + + } // end of class S + + .method public hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + TestCall(int32 a, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C c) cil managed + { + // Code size 7 (0x7) + .maxstack 1 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: stloc.0 + IL_0003: br.s IL_0005 + + IL_0005: ldloc.0 + IL_0006: ret + } // end of method InitializerTests::TestCall + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test() cil managed + { + // Code size 42 (0x2a) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_1) + IL_0000: nop + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000d: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::L + IL_0012: ldloc.0 + IL_0013: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::L + IL_0018: ldc.i4.1 + IL_0019: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::.ctor(int32) + IL_001e: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0023: nop + IL_0024: ldloc.0 + IL_0025: stloc.1 + IL_0026: br.s IL_0028 + + IL_0028: ldloc.1 + IL_0029: ret + } // end of method InitializerTests::Test + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test2() cil managed + { + // Code size 27 (0x1b) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_1) + IL_0000: nop + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldc.i4.1 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_000e: ldloc.0 + IL_000f: ldc.i4.2 + IL_0010: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0015: ldloc.0 + IL_0016: stloc.1 + IL_0017: br.s IL_0019 + + IL_0019: ldloc.1 + IL_001a: ret + } // end of method InitializerTests::Test2 + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test3() cil managed + { + // Code size 37 (0x25) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_1) + IL_0000: nop + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldc.i4.1 + IL_0009: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::.ctor(int32) + IL_000e: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0013: ldloc.0 + IL_0014: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0019: ldc.i4.2 + IL_001a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_001f: ldloc.0 + IL_0020: stloc.1 + IL_0021: br.s IL_0023 + + IL_0023: ldloc.1 + IL_0024: ret + } // end of method InitializerTests::Test3 + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test3b() cil managed + { + // Code size 36 (0x24) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0007: dup + IL_0008: ldc.i4.1 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_000e: dup + IL_000f: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0014: ldc.i4.2 + IL_0015: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_001a: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::TestCall(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C) + IL_001f: stloc.0 + IL_0020: br.s IL_0022 + + IL_0022: ldloc.0 + IL_0023: ret + } // end of method InitializerTests::Test3b + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test4() cil managed + { + // Code size 44 (0x2c) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_1) + IL_0000: nop + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_000d: ldc.i4.1 + IL_000e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A + IL_0013: ldloc.0 + IL_0014: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0019: ldc.i4.3 + IL_001a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B + IL_001f: ldloc.0 + IL_0020: ldc.i4.2 + IL_0021: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0026: ldloc.0 + IL_0027: stloc.1 + IL_0028: br.s IL_002a + + IL_002a: ldloc.1 + IL_002b: ret + } // end of method InitializerTests::Test4 + + .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 InitializerTests::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs index bc699eaed..1e66d3b1e 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs @@ -224,17 +224,18 @@ namespace ICSharpCode.Decompiler.IL.Transforms } } break; - case LdObj ldobj: + case LdObj ldobj: { if (ldobj.Target is LdFlda ldflda) { path.Insert(0, new AccessPathElement(ldflda.Field)); instruction = ldflda.Target; break; } goto default; - case StObj stobj: - if (stobj.Target is LdFlda ldflda2) { - path.Insert(0, new AccessPathElement(ldflda2.Field)); - instruction = ldflda2.Target; + } + case StObj stobj: { + if (stobj.Target is LdFlda ldflda) { + path.Insert(0, new AccessPathElement(ldflda.Field)); + instruction = ldflda.Target; if (values == null) { values = new List(new[] { stobj.Value }); kind = AccessPathKind.Setter; @@ -242,6 +243,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms break; } goto default; + } case LdLoc ldloc: target = ldloc.Variable; instruction = null; @@ -250,6 +252,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms target = ldloca.Variable; instruction = null; break; + case LdFlda ldflda: + path.Insert(0, new AccessPathElement(ldflda.Field)); + instruction = ldflda.Target; + break; default: kind = AccessPathKind.Invalid; instruction = null; From 9e3fbe68f30e248096d7fcb4facf8db6cf92583b Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 15 Oct 2017 15:14:40 +0200 Subject: [PATCH 155/190] #907: Avoid unnecessary casts in delegate comparisons. --- .../TestCases/Pretty/TypeAnalysisTests.cs | 15 +++++ .../TestCases/Pretty/TypeAnalysisTests.il | 64 +++++++++++++++++-- .../TestCases/Pretty/TypeAnalysisTests.opt.il | 46 +++++++++++-- .../Pretty/TypeAnalysisTests.opt.roslyn.il | 42 +++++++++++- .../Pretty/TypeAnalysisTests.roslyn.il | 60 ++++++++++++++++- ICSharpCode.Decompiler/CSharp/CallBuilder.cs | 30 +++++++-- .../CSharp/ExpressionBuilder.cs | 13 ++++ 7 files changed, 249 insertions(+), 21 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs index 853b19653..72db78dfb 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs @@ -199,5 +199,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { return Math.Abs(a - b); } + + public bool CompareDelegatesByValue(Action a, Action b) + { + return a == b; + } + + public bool CompareDelegatesByReference(Action a, Action b) + { + return (object)a == b; + } + + public bool CompareDelegateWithNull(Action a) + { + return a == null; + } } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.il index acd241b96..0eab76d08 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.il @@ -1,5 +1,5 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.18020 +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly q5z5ui4l +.assembly ph2u0axx { .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 q5z5ui4l.dll -// MVID: {E0E1769A-5636-428C-B7CE-29408F5D108F} +.module ph2u0axx.dll +// MVID: {8F821F70-8053-4F18-BDF7-88A43880B754} .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: 0x024D0000 +// Image base: 0x00D70000 // =============== CLASS MEMBERS DECLARATION =================== @@ -681,6 +681,60 @@ IL_000d: ret } // end of method TypeAnalysisTests::EnumDiff + .method public hidebysig instance bool + CompareDelegatesByValue(class [mscorlib]System.Action a, + class [mscorlib]System.Action b) cil managed + { + // Code size 13 (0xd) + .maxstack 2 + .locals init (bool V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call bool [mscorlib]System.Delegate::op_Equality(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0008: stloc.0 + IL_0009: br.s IL_000b + + IL_000b: ldloc.0 + IL_000c: ret + } // end of method TypeAnalysisTests::CompareDelegatesByValue + + .method public hidebysig instance bool + CompareDelegatesByReference(class [mscorlib]System.Action a, + class [mscorlib]System.Action b) cil managed + { + // Code size 10 (0xa) + .maxstack 2 + .locals init (bool V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: ceq + IL_0005: stloc.0 + IL_0006: br.s IL_0008 + + IL_0008: ldloc.0 + IL_0009: ret + } // end of method TypeAnalysisTests::CompareDelegatesByReference + + .method public hidebysig instance bool + CompareDelegateWithNull(class [mscorlib]System.Action a) cil managed + { + // Code size 10 (0xa) + .maxstack 2 + .locals init (bool V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldnull + IL_0003: ceq + IL_0005: stloc.0 + IL_0006: br.s IL_0008 + + IL_0008: ldloc.0 + IL_0009: ret + } // end of method TypeAnalysisTests::CompareDelegateWithNull + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.il index 25071943f..c5c37d26a 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.il @@ -1,5 +1,5 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.18020 +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly '5lntuoy2' +.assembly frnxitb5 { .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 '5lntuoy2.dll' -// MVID: {85A70DA1-7D32-4ED1-89B1-4720D974D969} +.module frnxitb5.dll +// MVID: {DC6B1392-D29F-44A5-97D6-0C026DCD3A00} .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: 0x05730000 +// Image base: 0x00D50000 // =============== CLASS MEMBERS DECLARATION =================== @@ -474,6 +474,42 @@ IL_0008: ret } // end of method TypeAnalysisTests::EnumDiff + .method public hidebysig instance bool + CompareDelegatesByValue(class [mscorlib]System.Action a, + class [mscorlib]System.Action b) cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: call bool [mscorlib]System.Delegate::op_Equality(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0007: ret + } // end of method TypeAnalysisTests::CompareDelegatesByValue + + .method public hidebysig instance bool + CompareDelegatesByReference(class [mscorlib]System.Action a, + class [mscorlib]System.Action b) cil managed + { + // Code size 5 (0x5) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: ceq + IL_0004: ret + } // end of method TypeAnalysisTests::CompareDelegatesByReference + + .method public hidebysig instance bool + CompareDelegateWithNull(class [mscorlib]System.Action a) cil managed + { + // Code size 5 (0x5) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldnull + IL_0002: ceq + IL_0004: ret + } // end of method TypeAnalysisTests::CompareDelegateWithNull + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.roslyn.il index 2644fb9ba..0a09fe8f2 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.roslyn.il @@ -1,5 +1,5 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.18020 +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module TypeAnalysisTests.dll -// MVID: {60E6985E-8E86-4693-9F02-AD3FF7341588} +// MVID: {B6659F2C-8CAA-447B-9D1D-D59D8C40C6D7} .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: 0x02440000 +// Image base: 0x003E0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -476,6 +476,42 @@ IL_0008: ret } // end of method TypeAnalysisTests::EnumDiff + .method public hidebysig instance bool + CompareDelegatesByValue(class [mscorlib]System.Action a, + class [mscorlib]System.Action b) cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: call bool [mscorlib]System.Delegate::op_Equality(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0007: ret + } // end of method TypeAnalysisTests::CompareDelegatesByValue + + .method public hidebysig instance bool + CompareDelegatesByReference(class [mscorlib]System.Action a, + class [mscorlib]System.Action b) cil managed + { + // Code size 5 (0x5) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: ceq + IL_0004: ret + } // end of method TypeAnalysisTests::CompareDelegatesByReference + + .method public hidebysig instance bool + CompareDelegateWithNull(class [mscorlib]System.Action a) cil managed + { + // Code size 5 (0x5) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldnull + IL_0002: ceq + IL_0004: ret + } // end of method TypeAnalysisTests::CompareDelegateWithNull + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.roslyn.il index e18c1015f..f12c3a17a 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.roslyn.il @@ -1,5 +1,5 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.18020 +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module TypeAnalysisTests.dll -// MVID: {389E1347-98C0-49C1-B484-EDF5FFA1CD16} +// MVID: {E25A3961-A07D-4220-AB6C-FE5B1624514C} .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: 0x027F0000 +// Image base: 0x00D80000 // =============== CLASS MEMBERS DECLARATION =================== @@ -680,6 +680,60 @@ IL_000d: ret } // end of method TypeAnalysisTests::EnumDiff + .method public hidebysig instance bool + CompareDelegatesByValue(class [mscorlib]System.Action a, + class [mscorlib]System.Action b) cil managed + { + // Code size 13 (0xd) + .maxstack 2 + .locals init (bool V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call bool [mscorlib]System.Delegate::op_Equality(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0008: stloc.0 + IL_0009: br.s IL_000b + + IL_000b: ldloc.0 + IL_000c: ret + } // end of method TypeAnalysisTests::CompareDelegatesByValue + + .method public hidebysig instance bool + CompareDelegatesByReference(class [mscorlib]System.Action a, + class [mscorlib]System.Action b) cil managed + { + // Code size 10 (0xa) + .maxstack 2 + .locals init (bool V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: ceq + IL_0005: stloc.0 + IL_0006: br.s IL_0008 + + IL_0008: ldloc.0 + IL_0009: ret + } // end of method TypeAnalysisTests::CompareDelegatesByReference + + .method public hidebysig instance bool + CompareDelegateWithNull(class [mscorlib]System.Action a) cil managed + { + // Code size 10 (0xa) + .maxstack 2 + .locals init (bool V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldnull + IL_0003: ceq + IL_0005: stloc.0 + IL_0006: br.s IL_0008 + + IL_0008: ldloc.0 + IL_0009: ret + } // end of method TypeAnalysisTests::CompareDelegateWithNull + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index 23f0add1a..277fa38d6 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -22,16 +22,11 @@ using System.Diagnostics; using System.Linq; using ICSharpCode.Decompiler.CSharp.Resolver; using ICSharpCode.Decompiler.CSharp.Syntax; -using ICSharpCode.Decompiler.CSharp.Transforms; -using ICSharpCode.Decompiler.CSharp.TypeSystem; using ICSharpCode.Decompiler.IL; using ICSharpCode.Decompiler.Semantics; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem.Implementation; using ICSharpCode.Decompiler.Util; -using ExpressionType = System.Linq.Expressions.ExpressionType; -using PrimitiveType = ICSharpCode.Decompiler.CSharp.Syntax.PrimitiveType; -using System.Threading; namespace ICSharpCode.Decompiler.CSharp { @@ -163,6 +158,9 @@ namespace ICSharpCode.Decompiler.CSharp return HandleAccessorCall(inst, target, method, arguments.ToList()); } else if (method.Name == "Invoke" && method.DeclaringType.Kind == TypeKind.Delegate) { return new InvocationExpression(target, arguments.Select(arg => arg.Expression)).WithILInstruction(inst).WithRR(rr); + } else if (IsDelegateEqualityComparison(method, arguments)) { + return HandleDelegateEqualityComparison(method, arguments) + .WithILInstruction(inst).WithRR(rr); } else { bool requireTypeArguments = false; bool targetCasted = false; @@ -215,6 +213,28 @@ namespace ICSharpCode.Decompiler.CSharp } } + private bool IsDelegateEqualityComparison(IMethod method, IList arguments) + { + // Comparison on a delegate type is a C# builtin operator + // that compiles down to a Delegate.op_Equality call. + // We handle this as a special case to avoid inserting a cast to System.Delegate. + return method.IsOperator + && method.DeclaringType.IsKnownType(KnownTypeCode.Delegate) + && (method.Name == "op_Equality" || method.Name == "op_Inequality") + && arguments.Count == 2 + && arguments[0].Type.Kind == TypeKind.Delegate + && arguments[1].Type.Equals(arguments[0].Type); + } + + private Expression HandleDelegateEqualityComparison(IMethod method, IList arguments) + { + return new BinaryOperatorExpression( + arguments[0], + method.Name == "op_Equality" ? BinaryOperatorType.Equality : BinaryOperatorType.InEquality, + arguments[1] + ); + } + OverloadResolutionErrors IsUnambiguousCall(ILInstruction inst, TranslatedExpression target, IMethod method, IType[] typeArguments, IList arguments) { var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly); diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 25ed0ddb3..d0325ac93 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -492,6 +492,19 @@ namespace ICSharpCode.Decompiler.CSharp left = AdjustConstantExpressionToType(left, right.Type); right = AdjustConstantExpressionToType(right, left.Type); + if (left.Type.Kind == TypeKind.Delegate && right.Type.Kind == TypeKind.Null + || left.Type.Kind == TypeKind.Null && right.Type.Kind == TypeKind.Delegate) + { + // When comparing a delegate with null, the C# compiler generates a reference comparison. + negateOutput = false; + return new BinaryOperatorExpression(left.Expression, inst.Kind.ToBinaryOperatorType(), right.Expression) + .WithILInstruction(inst) + .WithRR(new OperatorResolveResult( + compilation.FindType(KnownTypeCode.Boolean), + inst.Kind == ComparisonKind.Equality ? ExpressionType.Equal : ExpressionType.NotEqual, + left.ResolveResult, right.ResolveResult)); + } + var rr = resolver.ResolveBinaryOperator(inst.Kind.ToBinaryOperatorType(), left.ResolveResult, right.ResolveResult) as OperatorResolveResult; if (rr == null || rr.IsError || rr.UserDefinedOperatorMethod != null From 381bd425999e1800fe21702f3afb710430c7c95b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 16 Oct 2017 18:55:58 +0200 Subject: [PATCH 156/190] Fix bug mentioned in #909 --- .../TestCases/Pretty/InitializerTests.cs | 13 +++- .../TestCases/Pretty/InitializerTests.il | 56 ++++++++++++++---- .../TestCases/Pretty/InitializerTests.opt.il | 49 +++++++++++---- .../Pretty/InitializerTests.opt.roslyn.il | 39 ++++++++---- .../Pretty/InitializerTests.roslyn.il | 46 +++++++++++---- .../CSharp/ExpressionBuilder.cs | 9 ++- ...ransformCollectionAndObjectInitializers.cs | 59 ++++++++++++++++--- .../Util/CollectionExtensions.cs | 7 +++ 8 files changed, 218 insertions(+), 60 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs index 352e68a17..6309f08b0 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs @@ -46,7 +46,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty return c; } - public C Test() + public C Test1() { C c = new C(); c.L = new List(); @@ -54,6 +54,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty return c; } + public C Test1Alternative() + { + return InitializerTests.TestCall(1, new C { + L = new List { + new S(1) + } + }); + } + public C Test2() { C c = new C(); @@ -84,8 +93,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { C c = new C(); c.Y.A = 1; - c.Y.B = 3; c.Z = 2; + c.Y.B = 3; return c; } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il index 88dc47267..29834fb53 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly '0zopdghu' +.assembly '0meyjl4r' { .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 '0zopdghu.dll' -// MVID: {56C873AC-FD1E-4808-A65A-845BA0A3C2B7} +.module '0meyjl4r.dll' +// MVID: {DBAD72F7-978F-407F-9C77-44D3E99CD8AD} .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: 0x032A0000 +// Image base: 0x02FE0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -93,7 +93,7 @@ } // end of method InitializerTests::TestCall .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C - Test() cil managed + Test1() cil managed { // Code size 42 (0x2a) .maxstack 2 @@ -117,7 +117,39 @@ IL_0028: ldloc.1 IL_0029: ret - } // end of method InitializerTests::Test + } // end of method InitializerTests::Test1 + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test1Alternative() cil managed + { + // Code size 45 (0x2d) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0, + class [mscorlib]System.Collections.Generic.List`1 V_1, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_2) + IL_0000: nop + IL_0001: ldc.i4.1 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000e: stloc.1 + IL_000f: ldloc.1 + IL_0010: ldc.i4.1 + IL_0011: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::.ctor(int32) + IL_0016: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001b: nop + IL_001c: ldloc.1 + IL_001d: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::L + IL_0022: ldloc.0 + IL_0023: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::TestCall(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C) + IL_0028: stloc.2 + IL_0029: br.s IL_002b + + IL_002b: ldloc.2 + IL_002c: ret + } // end of method InitializerTests::Test1Alternative .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C Test2() cil managed @@ -212,12 +244,12 @@ IL_000d: ldc.i4.1 IL_000e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A IL_0013: ldloc.0 - IL_0014: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y - IL_0019: ldc.i4.3 - IL_001a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B - IL_001f: ldloc.0 - IL_0020: ldc.i4.2 - IL_0021: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0014: ldc.i4.2 + IL_0015: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_001a: ldloc.0 + IL_001b: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0020: ldc.i4.3 + IL_0021: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B IL_0026: ldloc.0 IL_0027: stloc.1 IL_0028: br.s IL_002a diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il index 9045f3b19..8de6548d9 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly xvcsxiw0 +.assembly u2solxiw { .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 xvcsxiw0.dll -// MVID: {ADB73224-52C3-4DFE-AB87-E9CEDD4FB2C3} +.module u2solxiw.dll +// MVID: {D1507E89-2CB3-46B1-AEC7-B176088BA3F9} .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: 0x00D20000 +// Image base: 0x028E0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -86,7 +86,7 @@ } // end of method InitializerTests::TestCall .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C - Test() cil managed + Test1() cil managed { // Code size 36 (0x24) .maxstack 2 @@ -103,7 +103,32 @@ IL_001d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) IL_0022: ldloc.0 IL_0023: ret - } // end of method InitializerTests::Test + } // end of method InitializerTests::Test1 + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test1Alternative() cil managed + { + // Code size 39 (0x27) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0, + class [mscorlib]System.Collections.Generic.List`1 V_1) + IL_0000: ldc.i4.1 + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000d: stloc.1 + IL_000e: ldloc.1 + IL_000f: ldc.i4.1 + IL_0010: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::.ctor(int32) + IL_0015: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001a: ldloc.1 + IL_001b: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::L + IL_0020: ldloc.0 + IL_0021: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::TestCall(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C) + IL_0026: ret + } // end of method InitializerTests::Test1Alternative .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C Test2() cil managed @@ -178,12 +203,12 @@ IL_000c: ldc.i4.1 IL_000d: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A IL_0012: ldloc.0 - IL_0013: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y - IL_0018: ldc.i4.3 - IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B - IL_001e: ldloc.0 - IL_001f: ldc.i4.2 - IL_0020: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0013: ldc.i4.2 + IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0019: ldloc.0 + IL_001a: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_001f: ldc.i4.3 + IL_0020: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B IL_0025: ldloc.0 IL_0026: ret } // end of method InitializerTests::Test4 diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il index b4dca5b95..8b03bca83 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module InitializerTests.dll -// MVID: {73C118AC-648F-43DB-A2FB-1B159DF870BA} +// MVID: {F2C6C41E-98CC-4261-BF7B-1991B54DA121} .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: 0x03230000 +// Image base: 0x029A0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -90,7 +90,7 @@ } // end of method InitializerTests::TestCall .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C - Test() cil managed + Test1() cil managed { // Code size 34 (0x22) .maxstack 8 @@ -104,7 +104,26 @@ IL_0017: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::.ctor(int32) IL_001c: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) IL_0021: ret - } // end of method InitializerTests::Test + } // end of method InitializerTests::Test1 + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test1Alternative() cil managed + { + // Code size 35 (0x23) + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0006: dup + IL_0007: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000c: dup + IL_000d: ldc.i4.1 + IL_000e: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::.ctor(int32) + IL_0013: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0018: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::L + IL_001d: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::TestCall(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C) + IL_0022: ret + } // end of method InitializerTests::Test1Alternative .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C Test2() cil managed @@ -168,12 +187,12 @@ IL_000b: ldc.i4.1 IL_000c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A IL_0011: dup - IL_0012: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y - IL_0017: ldc.i4.3 - IL_0018: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B - IL_001d: dup - IL_001e: ldc.i4.2 - IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0012: ldc.i4.2 + IL_0013: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0018: dup + IL_0019: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_001e: ldc.i4.3 + IL_001f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B IL_0024: ret } // end of method InitializerTests::Test4 diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il index dab3fefa3..383822da9 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module InitializerTests.dll -// MVID: {53F415C2-DC80-4EFA-8787-82F129B1AC28} +// MVID: {7000C1D7-C4EC-4376-B053-4BE74428CE7A} .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: 0x002F0000 +// Image base: 0x00C90000 // =============== CLASS MEMBERS DECLARATION =================== @@ -98,7 +98,7 @@ } // end of method InitializerTests::TestCall .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C - Test() cil managed + Test1() cil managed { // Code size 42 (0x2a) .maxstack 2 @@ -122,7 +122,33 @@ IL_0028: ldloc.1 IL_0029: ret - } // end of method InitializerTests::Test + } // end of method InitializerTests::Test1 + + .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C + Test1Alternative() cil managed + { + // Code size 41 (0x29) + .maxstack 6 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C V_0) + IL_0000: nop + IL_0001: ldc.i4.1 + IL_0002: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::.ctor() + IL_0007: dup + IL_0008: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000d: dup + IL_000e: ldc.i4.1 + IL_000f: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::.ctor(int32) + IL_0014: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0019: nop + IL_001a: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::L + IL_001f: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::TestCall(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C) + IL_0024: stloc.0 + IL_0025: br.s IL_0027 + + IL_0027: ldloc.0 + IL_0028: ret + } // end of method InitializerTests::Test1Alternative .method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C Test2() cil managed @@ -214,12 +240,12 @@ IL_000d: ldc.i4.1 IL_000e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::A IL_0013: ldloc.0 - IL_0014: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y - IL_0019: ldc.i4.3 - IL_001a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B - IL_001f: ldloc.0 - IL_0020: ldc.i4.2 - IL_0021: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_0014: ldc.i4.2 + IL_0015: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Z + IL_001a: ldloc.0 + IL_001b: ldflda valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C::Y + IL_0020: ldc.i4.3 + IL_0021: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/S::B IL_0026: ldloc.0 IL_0027: stloc.1 IL_0028: br.s IL_002a diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 25ed0ddb3..7aec147d5 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -1427,11 +1427,10 @@ namespace ICSharpCode.Decompiler.CSharp if (currentPath == null) { currentPath = info.Path; } else { - int firstDifferenceIndex = Math.Min(currentPath.Count, info.Path.Count); - int index = 0; - while (index < firstDifferenceIndex && info.Path[index] == currentPath[index]) - index++; - firstDifferenceIndex = index; + int minLen = Math.Min(currentPath.Count, info.Path.Count); + int firstDifferenceIndex = 0; + while (firstDifferenceIndex < minLen && info.Path[firstDifferenceIndex] == currentPath[firstDifferenceIndex]) + firstDifferenceIndex++; while (elementsStack.Count - 1 > firstDifferenceIndex) { var methodElement = currentPath[elementsStack.Count - 1]; var pathElement = currentPath[elementsStack.Count - 2]; diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs index 1e66d3b1e..e01b58a84 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Linq; using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler.IL.Transforms { @@ -83,13 +84,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms } int initializerItemsCount = 0; var blockType = initializerBlock?.Type ?? BlockType.CollectionInitializer; - var possibleIndexVariables = new Dictionary(); + possibleIndexVariables = new Dictionary(); + currentPath = new List(); + isCollection = false; + pathStack = new Stack>(); + pathStack.Push(new HashSet()); // Detect initializer type by scanning the following statements // each must be a callvirt with ldloc v as first argument // if the method is a setter we're dealing with an object initializer // if the method is named Add and has at least 2 arguments we're dealing with a collection/dictionary initializer while (pos + initializerItemsCount + 1 < body.Instructions.Count - && IsPartOfInitializer(body.Instructions, pos + initializerItemsCount + 1, v, instType, ref blockType, possibleIndexVariables)) { + && IsPartOfInitializer(body.Instructions, pos + initializerItemsCount + 1, v, instType, ref blockType)) { initializerItemsCount++; } var index = possibleIndexVariables.Where(info => info.Value.Index > -1).Min(info => (int?)info.Value.Index); @@ -139,7 +144,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; } - bool IsPartOfInitializer(InstructionCollection instructions, int pos, ILVariable target, IType rootType, ref BlockType blockType, Dictionary possibleIndexVariables) + Dictionary possibleIndexVariables; + List currentPath; + bool isCollection; + Stack> pathStack; + + bool IsPartOfInitializer(InstructionCollection instructions, int pos, ILVariable target, IType rootType, ref BlockType blockType) { if (instructions[pos] is StLoc stloc && stloc.Variable.Kind == VariableKind.Local && stloc.Variable.IsSingleDefinition) { if (stloc.Value.Descendants.OfType().Any(ld => ld.Variable == target && (ld is LdLoc || ld is LdLoca))) @@ -147,12 +157,40 @@ namespace ICSharpCode.Decompiler.IL.Transforms possibleIndexVariables.Add(stloc.Variable, (stloc.ChildIndex, stloc.Value)); return true; } - (var kind, var path, var values, var targetVariable) = AccessPathElement.GetAccessPath(instructions[pos], rootType, possibleIndexVariables); + (var kind, var newPath, var values, var targetVariable) = AccessPathElement.GetAccessPath(instructions[pos], rootType, possibleIndexVariables); + if (kind == AccessPathKind.Invalid || target != targetVariable) + return false; + // Treat last element separately: + // Can either be an Add method call or property setter. + var lastElement = newPath.Last(); + newPath.RemoveLast(); + // Compare new path with current path: + int minLen = Math.Min(currentPath.Count, newPath.Count); + int firstDifferenceIndex = 0; + while (firstDifferenceIndex < minLen && newPath[firstDifferenceIndex] == currentPath[firstDifferenceIndex]) + firstDifferenceIndex++; + while (currentPath.Count > firstDifferenceIndex) { + isCollection = false; + currentPath.RemoveAt(currentPath.Count - 1); + pathStack.Pop(); + } + while (currentPath.Count < newPath.Count) { + AccessPathElement newElement = newPath[currentPath.Count]; + currentPath.Add(newElement); + if (isCollection || !pathStack.Peek().Add(newElement)) + return false; + pathStack.Push(new HashSet()); + } switch (kind) { case AccessPathKind.Adder: - return target == targetVariable; + isCollection = true; + if (pathStack.Peek().Count != 0) + return false; + return true; case AccessPathKind.Setter: - if (values.Count == 1 && target == targetVariable) { + if (isCollection || !pathStack.Peek().Add(lastElement)) + return false; + if (values.Count == 1) { blockType = BlockType.ObjectInitializer; return true; } @@ -319,7 +357,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms public bool Equals(AccessPathElement other) { - return other.Member.Equals(this.Member) && (other.Indices == this.Indices || other.Indices.SequenceEqual(this.Indices, ILInstructionMatchComparer.Instance)); + return other.Member.Equals(this.Member) + && (other.Indices == this.Indices || other.Indices.SequenceEqual(this.Indices, ILInstructionMatchComparer.Instance)); } public static bool operator ==(AccessPathElement lhs, AccessPathElement rhs) @@ -343,12 +382,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; if (x == null || y == null) return false; - return x.Match(y).Success; + return SemanticHelper.IsPure(x.Flags) + && SemanticHelper.IsPure(y.Flags) + && x.Match(y).Success; } public int GetHashCode(ILInstruction obj) { - return obj.GetHashCode(); + throw new NotSupportedException(); } } } diff --git a/ICSharpCode.Decompiler/Util/CollectionExtensions.cs b/ICSharpCode.Decompiler/Util/CollectionExtensions.cs index d6f67cae8..df1785c7e 100644 --- a/ICSharpCode.Decompiler/Util/CollectionExtensions.cs +++ b/ICSharpCode.Decompiler/Util/CollectionExtensions.cs @@ -190,5 +190,12 @@ namespace ICSharpCode.Decompiler.Util return maxElement; } } + + public static void RemoveLast(this IList list) + { + if (list == null) + throw new ArgumentNullException(nameof(list)); + list.RemoveAt(list.Count - 1); + } } } From 0b6987f1959606d8f90e561ff7812e1086c89b2f Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 16 Oct 2017 22:42:15 +0200 Subject: [PATCH 157/190] Fix pretty unit tests. --- .../TestCases/Pretty/InitializerTests.il | 8 +++---- .../TestCases/Pretty/InitializerTests.opt.il | 8 +++---- .../Pretty/InitializerTests.opt.roslyn.il | 2 +- .../Pretty/InitializerTests.roslyn.il | 2 +- .../IL/Transforms/AssignVariableNames.cs | 24 +++++++++++++++++++ ...ransformCollectionAndObjectInitializers.cs | 13 ++++++++++ 6 files changed, 47 insertions(+), 10 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il index 29834fb53..d6a62db22 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly '0meyjl4r' +.assembly umgm00go { .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 '0meyjl4r.dll' -// MVID: {DBAD72F7-978F-407F-9C77-44D3E99CD8AD} +.module umgm00go.dll +// MVID: {8C42504A-ACC6-453C-81BA-626AB6649E25} .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: 0x02FE0000 +// Image base: 0x02AE0000 // =============== CLASS MEMBERS DECLARATION =================== diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il index 8de6548d9..ac94bb18e 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly u2solxiw +.assembly ecxzpbak { .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 u2solxiw.dll -// MVID: {D1507E89-2CB3-46B1-AEC7-B176088BA3F9} +.module ecxzpbak.dll +// MVID: {F67EEE6A-7EFF-4261-9FC7-3F2C4A0972E9} .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: 0x028E0000 +// Image base: 0x02430000 // =============== CLASS MEMBERS DECLARATION =================== diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il index 8b03bca83..13eb53fdd 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il @@ -32,7 +32,7 @@ .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x029A0000 +// Image base: 0x00700000 // =============== CLASS MEMBERS DECLARATION =================== diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il index 383822da9..5db37abe9 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il @@ -32,7 +32,7 @@ .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x00C90000 +// Image base: 0x005E0000 // =============== CLASS MEMBERS DECLARATION =================== diff --git a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs index 520a2d18e..a8db2d911 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs @@ -196,6 +196,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms proposedName = proposedNameForLoads[0]; } } + if (string.IsNullOrEmpty(proposedName)) { + var proposedNameForStoresFromNewObj = variable.StoreInstructions.OfType() + .Select(expr => GetNameByType(GuessType(expr.Value, context))) + .Except(currentFieldNames).ToList(); + if (proposedNameForStoresFromNewObj.Count == 1) { + proposedName = proposedNameForStoresFromNewObj[0]; + } + } if (string.IsNullOrEmpty(proposedName)) { proposedName = GetNameByType(variable.Type); } @@ -349,6 +357,22 @@ namespace ICSharpCode.Decompiler.IL.Transforms return char.ToLower(name[0]) + name.Substring(1); } + internal static IType GuessType(ILInstruction inst, ILTransformContext context) + { + switch (inst) { + case NewObj newObj: + return newObj.Method.DeclaringType; + case Call call: + return call.Method.ReturnType; + case CallVirt callVirt: + return callVirt.Method.ReturnType; + case CallIndirect calli: + return calli.ReturnType; + default: + return context.TypeSystem.Compilation.FindType(inst.ResultType.ToKnownTypeCode()); + } + } + internal static string GenerateForeachVariableName(ILFunction function, ILInstruction valueContext, ILVariable existingVariable = null) { if (function == null) diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs index e01b58a84..d927bb61f 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs @@ -97,6 +97,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms && IsPartOfInitializer(body.Instructions, pos + initializerItemsCount + 1, v, instType, ref blockType)) { initializerItemsCount++; } + if (IsMethodCallOnVariable(body.Instructions[pos + initializerItemsCount + 1], v)) + return false; var index = possibleIndexVariables.Where(info => info.Value.Index > -1).Min(info => (int?)info.Value.Index); if (index != null) { initializerItemsCount = index.Value - pos - 1; @@ -144,6 +146,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; } + bool IsMethodCallOnVariable(ILInstruction inst, ILVariable variable) + { + if (inst.MatchLdLocRef(variable)) + return true; + if (inst is CallInstruction call && call.Arguments.Count > 0 && !call.Method.IsStatic) + return IsMethodCallOnVariable(call.Arguments[0], variable); + if (inst.MatchLdFld(out var target, out _) || inst.MatchStFld(out target, out _, out _) || inst.MatchLdFlda(out target, out _)) + return IsMethodCallOnVariable(target, variable); + return false; + } + Dictionary possibleIndexVariables; List currentPath; bool isCollection; From 0ab805a6033fca5d4cc8d4bd8740062fc90656a5 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 17 Oct 2017 00:19:03 +0200 Subject: [PATCH 158/190] Add regression test for foreach variable naming. --- .../TestCases/Pretty/Loops.cs | 6 +++--- .../TestCases/Pretty/Loops.il | 16 ++++++++-------- .../TestCases/Pretty/Loops.opt.il | 16 ++++++++-------- .../TestCases/Pretty/Loops.opt.roslyn.il | 10 +++++----- .../TestCases/Pretty/Loops.roslyn.il | 10 +++++----- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs index 8bacd3048..f81976a52 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs @@ -260,10 +260,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { } - public void ForEach(IEnumerable enumerable) + public void ForEach(IEnumerable alternatives) { - foreach (string item in enumerable) { - item.ToLower(); + foreach (string alternative in alternatives) { + alternative.ToLower(); } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il index ad08c43b3..4d1ec82d2 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il @@ -1,6 +1,6 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 -// Copyright (c) Microsoft Corporation. All rights reserved. +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly y5enlto2 +.assembly y1gx1hfa { .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 y5enlto2.dll -// MVID: {7F6CCF81-BE23-4326-8F55-7E3BF0A8B7A2} +.module y1gx1hfa.dll +// MVID: {21EB73BD-6DA1-4305-9961-7F543EB0E1F3} .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: 0x009B0000 +// Image base: 0x02A00000 // =============== CLASS MEMBERS DECLARATION =================== @@ -635,7 +635,7 @@ } // end of method Loops::Operation .method public hidebysig instance void - ForEach(class [mscorlib]System.Collections.Generic.IEnumerable`1 enumerable) cil managed + ForEach(class [mscorlib]System.Collections.Generic.IEnumerable`1 alternatives) cil managed { // Code size 57 (0x39) .maxstack 2 @@ -1750,4 +1750,4 @@ // ============================================================= // *********** DISASSEMBLY COMPLETE *********************** -// WARNING: Created Win32 resource file ../../../TestCases/Pretty\Loops.res +// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\Loops.res" wurde erstellt. diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il index a1e2ed464..fbfe5756f 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il @@ -1,6 +1,6 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 -// Copyright (c) Microsoft Corporation. All rights reserved. +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly jiaqp12i +.assembly de0u0jkz { .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 jiaqp12i.dll -// MVID: {34208704-52B8-49EB-BC77-C3A95E1CBA19} +.module de0u0jkz.dll +// MVID: {F3F9EFD3-F9A8-4885-B2D2-AD75367C0339} .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: 0x02520000 +// Image base: 0x01A60000 // =============== CLASS MEMBERS DECLARATION =================== @@ -550,7 +550,7 @@ } // end of method Loops::Operation .method public hidebysig instance void - ForEach(class [mscorlib]System.Collections.Generic.IEnumerable`1 enumerable) cil managed + ForEach(class [mscorlib]System.Collections.Generic.IEnumerable`1 alternatives) cil managed { // Code size 44 (0x2c) .maxstack 1 @@ -1361,4 +1361,4 @@ // ============================================================= // *********** DISASSEMBLY COMPLETE *********************** -// WARNING: Created Win32 resource file ../../../TestCases/Pretty\Loops.opt.res +// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\Loops.opt.res" wurde erstellt. diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il index a3b169382..bdad1dc5d 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il @@ -1,6 +1,6 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 -// Copyright (c) Microsoft Corporation. All rights reserved. +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Loops.dll -// MVID: {8D392B4A-5D21-407A-B579-FCDFA93069CE} +// MVID: {13449EE0-18A5-44A4-B482-40B5C738DFBB} .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: 0x00DA0000 +// Image base: 0x00D70000 // =============== CLASS MEMBERS DECLARATION =================== @@ -554,7 +554,7 @@ } // end of method Loops::Operation .method public hidebysig instance void - ForEach(class [mscorlib]System.Collections.Generic.IEnumerable`1 enumerable) cil managed + ForEach(class [mscorlib]System.Collections.Generic.IEnumerable`1 alternatives) cil managed { // Code size 42 (0x2a) .maxstack 1 diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il index 864b1e5c5..5e5848cd3 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il @@ -1,6 +1,6 @@ -// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 -// Copyright (c) Microsoft Corporation. All rights reserved. +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Loops.dll -// MVID: {C6DBFA5B-CB31-4084-8E6F-7BA877923008} +// MVID: {747E198F-8825-4B5B-9C27-DF069E6F35AE} .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: 0x00A80000 +// Image base: 0x027A0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -639,7 +639,7 @@ } // end of method Loops::Operation .method public hidebysig instance void - ForEach(class [mscorlib]System.Collections.Generic.IEnumerable`1 enumerable) cil managed + ForEach(class [mscorlib]System.Collections.Generic.IEnumerable`1 alternatives) cil managed { // Code size 49 (0x31) .maxstack 1 From 11a9d901e21aa799d1cdabcfae2d4ccbff54ba8a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 17 Oct 2017 09:36:43 +0200 Subject: [PATCH 159/190] Fix foreach variable naming in case of parameter in-expression. Add more tests. --- .../TestCases/Pretty/Loops.cs | 9 +++ .../TestCases/Pretty/Loops.il | 62 +++++++++++++++-- .../TestCases/Pretty/Loops.opt.il | 49 +++++++++++-- .../TestCases/Pretty/Loops.opt.roslyn.il | 58 +++++++++++++--- .../TestCases/Pretty/Loops.roslyn.il | 68 ++++++++++++++++--- .../IL/Transforms/AssignVariableNames.cs | 5 ++ 6 files changed, 222 insertions(+), 29 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs index f81976a52..8345eaf1c 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs @@ -252,6 +252,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } + private IEnumerable alternatives; + private static void Operation(ref int item) { } @@ -260,6 +262,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { } + public void ForEachOnField() + { + foreach (string alternative in this.alternatives) { + alternative.ToLower(); + } + } + public void ForEach(IEnumerable alternatives) { foreach (string alternative in alternatives) { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il index 4d1ec82d2..030f6bd46 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly y1gx1hfa +.assembly ic2bztjj { .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 y1gx1hfa.dll -// MVID: {21EB73BD-6DA1-4305-9961-7F543EB0E1F3} +.module ic2bztjj.dll +// MVID: {821665CB-F67F-4600-8C6C-27617D873D36} .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: 0x02A00000 +// Image base: 0x01550000 // =============== CLASS MEMBERS DECLARATION =================== @@ -618,6 +618,7 @@ } // end of class '<>c__DisplayClass1' + .field private class [mscorlib]System.Collections.Generic.IEnumerable`1 alternatives .method private hidebysig static void Operation(int32& item) cil managed { // Code size 2 (0x2) @@ -634,6 +635,59 @@ IL_0001: ret } // end of method Loops::Operation + .method public hidebysig instance void + ForEachOnField() cil managed + { + // Code size 62 (0x3e) + .maxstack 2 + .locals init (string V_0, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1, + bool V_2) + IL_0000: nop + IL_0001: nop + IL_0002: ldarg.0 + IL_0003: ldfld class [mscorlib]System.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::alternatives + IL_0008: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_000d: stloc.1 + .try + { + IL_000e: br.s IL_0020 + + IL_0010: ldloc.1 + IL_0011: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0016: stloc.0 + IL_0017: nop + IL_0018: ldloc.0 + IL_0019: callvirt instance string [mscorlib]System.String::ToLower() + IL_001e: pop + IL_001f: nop + IL_0020: ldloc.1 + IL_0021: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() + IL_0026: stloc.2 + IL_0027: ldloc.2 + IL_0028: brtrue.s IL_0010 + + IL_002a: leave.s IL_003c + + } // end .try + finally + { + IL_002c: ldloc.1 + IL_002d: ldnull + IL_002e: ceq + IL_0030: stloc.2 + IL_0031: ldloc.2 + IL_0032: brtrue.s IL_003b + + IL_0034: ldloc.1 + IL_0035: callvirt instance void [mscorlib]System.IDisposable::Dispose() + IL_003a: nop + IL_003b: endfinally + } // end handler + IL_003c: nop + IL_003d: ret + } // end of method Loops::ForEachOnField + .method public hidebysig instance void ForEach(class [mscorlib]System.Collections.Generic.IEnumerable`1 alternatives) cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il index fbfe5756f..50a8785a7 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly de0u0jkz +.assembly fabjeeha { .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 de0u0jkz.dll -// MVID: {F3F9EFD3-F9A8-4885-B2D2-AD75367C0339} +.module fabjeeha.dll +// MVID: {4FB3AE1F-ECE0-4E7D-84DC-E693282CA0AF} .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: 0x01A60000 +// Image base: 0x00D90000 // =============== CLASS MEMBERS DECLARATION =================== @@ -535,6 +535,7 @@ } // end of class '<>c__DisplayClass1' + .field private class [mscorlib]System.Collections.Generic.IEnumerable`1 alternatives .method private hidebysig static void Operation(int32& item) cil managed { // Code size 1 (0x1) @@ -549,6 +550,46 @@ IL_0000: ret } // end of method Loops::Operation + .method public hidebysig instance void + ForEachOnField() cil managed + { + // Code size 49 (0x31) + .maxstack 1 + .locals init (string V_0, + class [mscorlib]System.Collections.Generic.IEnumerator`1 V_1) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::alternatives + IL_0006: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_000b: stloc.1 + .try + { + IL_000c: br.s IL_001c + + IL_000e: ldloc.1 + IL_000f: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0014: stloc.0 + IL_0015: ldloc.0 + IL_0016: callvirt instance string [mscorlib]System.String::ToLower() + IL_001b: pop + IL_001c: ldloc.1 + IL_001d: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() + IL_0022: brtrue.s IL_000e + + IL_0024: leave.s IL_0030 + + } // end .try + finally + { + IL_0026: ldloc.1 + IL_0027: brfalse.s IL_002f + + IL_0029: ldloc.1 + IL_002a: callvirt instance void [mscorlib]System.IDisposable::Dispose() + IL_002f: endfinally + } // end handler + IL_0030: ret + } // end of method Loops::ForEachOnField + .method public hidebysig instance void ForEach(class [mscorlib]System.Collections.Generic.IEnumerable`1 alternatives) cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il index bdad1dc5d..8fc3ae3c4 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Loops.dll -// MVID: {13449EE0-18A5-44A4-B482-40B5C738DFBB} +// MVID: {F03B196B-9B00-49BE-A335-2D460586E39A} .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: 0x00D70000 +// Image base: 0x02D60000 // =============== CLASS MEMBERS DECLARATION =================== @@ -510,7 +510,7 @@ } // end of property CustomStructEnumeratorWithIDisposable`1::Current } // end of class CustomStructEnumeratorWithIDisposable`1 - .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass23_0' + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass25_0' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) @@ -523,7 +523,7 @@ IL_0000: ldarg.0 IL_0001: call instance void [mscorlib]System.Object::.ctor() IL_0006: ret - } // end of method '<>c__DisplayClass23_0'::.ctor + } // end of method '<>c__DisplayClass25_0'::.ctor .method assembly hidebysig instance bool 'b__0'() cil managed @@ -531,14 +531,15 @@ // Code size 10 (0xa) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass23_0'::c + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass25_0'::c IL_0006: ldc.i4.5 IL_0007: ceq IL_0009: ret - } // end of method '<>c__DisplayClass23_0'::'b__0' + } // end of method '<>c__DisplayClass25_0'::'b__0' - } // end of class '<>c__DisplayClass23_0' + } // end of class '<>c__DisplayClass25_0' + .field private class [mscorlib]System.Collections.Generic.IEnumerable`1 alternatives .method private hidebysig static void Operation(int32& item) cil managed { // Code size 1 (0x1) @@ -553,6 +554,43 @@ IL_0000: ret } // end of method Loops::Operation + .method public hidebysig instance void + ForEachOnField() cil managed + { + // Code size 47 (0x2f) + .maxstack 1 + .locals init (class [mscorlib]System.Collections.Generic.IEnumerator`1 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::alternatives + IL_0006: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_000b: stloc.0 + .try + { + IL_000c: br.s IL_001a + + IL_000e: ldloc.0 + IL_000f: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0014: callvirt instance string [mscorlib]System.String::ToLower() + IL_0019: pop + IL_001a: ldloc.0 + IL_001b: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() + IL_0020: brtrue.s IL_000e + + IL_0022: leave.s IL_002e + + } // end .try + finally + { + IL_0024: ldloc.0 + IL_0025: brfalse.s IL_002d + + IL_0027: ldloc.0 + IL_0028: callvirt instance void [mscorlib]System.IDisposable::Dispose() + IL_002d: endfinally + } // end handler + IL_002e: ret + } // end of method Loops::ForEachOnField + .method public hidebysig instance void ForEach(class [mscorlib]System.Collections.Generic.IEnumerable`1 alternatives) cil managed { @@ -1063,11 +1101,11 @@ IL_0009: ldloca.s V_0 IL_000b: call instance !0 valuetype [mscorlib]System.Collections.Generic.List`1/Enumerator::get_Current() IL_0010: stloc.1 - IL_0011: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass23_0'::.ctor() + IL_0011: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass25_0'::.ctor() IL_0016: dup IL_0017: ldloc.1 - IL_0018: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass23_0'::c - IL_001d: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass23_0'::'b__0'() + IL_0018: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass25_0'::c + IL_001d: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass25_0'::'b__0'() IL_0023: newobj instance void class [mscorlib]System.Func`1::.ctor(object, native int) IL_0028: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Operation(class [mscorlib]System.Func`1) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il index 5e5848cd3..f10e2f5ff 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Loops.dll -// MVID: {747E198F-8825-4B5B-9C27-DF069E6F35AE} +// MVID: {F66BA703-8DC0-4A56-81BC-D288A1D83D30} .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: 0x027A0000 +// Image base: 0x02D60000 // =============== CLASS MEMBERS DECLARATION =================== @@ -592,7 +592,7 @@ } // end of property CustomStructEnumeratorWithIDisposable`1::Current } // end of class CustomStructEnumeratorWithIDisposable`1 - .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass23_0' + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass25_0' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) @@ -606,7 +606,7 @@ IL_0001: call instance void [mscorlib]System.Object::.ctor() IL_0006: nop IL_0007: ret - } // end of method '<>c__DisplayClass23_0'::.ctor + } // end of method '<>c__DisplayClass25_0'::.ctor .method assembly hidebysig instance bool 'b__0'() cil managed @@ -614,14 +614,15 @@ // Code size 10 (0xa) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass23_0'::c + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass25_0'::c IL_0006: ldc.i4.5 IL_0007: ceq IL_0009: ret - } // end of method '<>c__DisplayClass23_0'::'b__0' + } // end of method '<>c__DisplayClass25_0'::'b__0' - } // end of class '<>c__DisplayClass23_0' + } // end of class '<>c__DisplayClass25_0' + .field private class [mscorlib]System.Collections.Generic.IEnumerable`1 alternatives .method private hidebysig static void Operation(int32& item) cil managed { // Code size 2 (0x2) @@ -638,6 +639,51 @@ IL_0001: ret } // end of method Loops::Operation + .method public hidebysig instance void + ForEachOnField() cil managed + { + // Code size 54 (0x36) + .maxstack 1 + .locals init (class [mscorlib]System.Collections.Generic.IEnumerator`1 V_0, + string V_1) + IL_0000: nop + IL_0001: nop + IL_0002: ldarg.0 + IL_0003: ldfld class [mscorlib]System.Collections.Generic.IEnumerable`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::alternatives + IL_0008: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1 class [mscorlib]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_000d: stloc.0 + .try + { + IL_000e: br.s IL_0020 + + IL_0010: ldloc.0 + IL_0011: callvirt instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0016: stloc.1 + IL_0017: nop + IL_0018: ldloc.1 + IL_0019: callvirt instance string [mscorlib]System.String::ToLower() + IL_001e: pop + IL_001f: nop + IL_0020: ldloc.0 + IL_0021: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() + IL_0026: brtrue.s IL_0010 + + IL_0028: leave.s IL_0035 + + } // end .try + finally + { + IL_002a: ldloc.0 + IL_002b: brfalse.s IL_0034 + + IL_002d: ldloc.0 + IL_002e: callvirt instance void [mscorlib]System.IDisposable::Dispose() + IL_0033: nop + IL_0034: endfinally + } // end handler + IL_0035: ret + } // end of method Loops::ForEachOnField + .method public hidebysig instance void ForEach(class [mscorlib]System.Collections.Generic.IEnumerable`1 alternatives) cil managed { @@ -1259,7 +1305,7 @@ .maxstack 2 .locals init (valuetype [mscorlib]System.Collections.Generic.List`1/Enumerator V_0, int32 V_1, - class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass23_0' V_2) + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass25_0' V_2) IL_0000: nop IL_0001: nop IL_0002: ldarg.0 @@ -1272,14 +1318,14 @@ IL_000b: ldloca.s V_0 IL_000d: call instance !0 valuetype [mscorlib]System.Collections.Generic.List`1/Enumerator::get_Current() IL_0012: stloc.1 - IL_0013: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass23_0'::.ctor() + IL_0013: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass25_0'::.ctor() IL_0018: stloc.2 IL_0019: nop IL_001a: ldloc.2 IL_001b: ldloc.1 - IL_001c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass23_0'::c + IL_001c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass25_0'::c IL_0021: ldloc.2 - IL_0022: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass23_0'::'b__0'() + IL_0022: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops/'<>c__DisplayClass25_0'::'b__0'() IL_0028: newobj instance void class [mscorlib]System.Func`1::.ctor(object, native int) IL_002d: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Operation(class [mscorlib]System.Func`1) diff --git a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs index 520a2d18e..4b705d337 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs @@ -362,6 +362,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms AddExistingName(reservedVariableNames, f); string baseName = GetNameFromInstruction(valueContext); + if (string.IsNullOrEmpty(baseName)) { + if (valueContext is LdLoc ldloc && ldloc.Variable.Kind == VariableKind.Parameter) { + baseName = ldloc.Variable.Name; + } + } string proposedName = "item"; if (!string.IsNullOrEmpty(baseName)) { From a014684918c189ebb848af6faae7a96752d18667 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 17 Oct 2017 13:14:56 +0200 Subject: [PATCH 160/190] Fix regression in AssignVariableNames --- .../IL/Transforms/AssignVariableNames.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs index a8db2d911..eea8dedae 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs @@ -198,7 +198,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms } if (string.IsNullOrEmpty(proposedName)) { var proposedNameForStoresFromNewObj = variable.StoreInstructions.OfType() - .Select(expr => GetNameByType(GuessType(expr.Value, context))) + .Select(expr => GetNameByType(GuessType(variable.Type, expr.Value, context))) .Except(currentFieldNames).ToList(); if (proposedNameForStoresFromNewObj.Count == 1) { proposedName = proposedNameForStoresFromNewObj[0]; @@ -357,8 +357,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms return char.ToLower(name[0]) + name.Substring(1); } - internal static IType GuessType(ILInstruction inst, ILTransformContext context) + internal static IType GuessType(IType variableType, ILInstruction inst, ILTransformContext context) { + if (!variableType.IsKnownType(KnownTypeCode.Object)) + return variableType; + switch (inst) { case NewObj newObj: return newObj.Method.DeclaringType; From 60894a02a4887f3982bab9a5ef45fab9ffe45b85 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 17 Oct 2017 13:15:52 +0200 Subject: [PATCH 161/190] Fix missing ILStackWasEmpty-flag on call after conversion to newobj --- .../IL/Transforms/EarlyExpressionTransforms.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs b/ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs index e5b667734..bba216c13 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs @@ -104,6 +104,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms var newObj = new NewObj(inst.Method); newObj.ILRange = inst.ILRange; newObj.Arguments.AddRange(inst.Arguments.Skip(1)); + newObj.ILStackWasEmpty = inst.ILStackWasEmpty; var expr = new StObj(inst.Arguments[0], newObj, inst.Method.DeclaringType); inst.ReplaceWith(expr); return expr; From e1baac3a9c18a25d168148184ae3634dd112fe8d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 17 Oct 2017 13:16:47 +0200 Subject: [PATCH 162/190] Fix output of space before array initializer expression. --- .../CSharp/OutputVisitor/CSharpOutputVisitor.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs index 076ae703b..8eb432e8b 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs @@ -90,6 +90,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor Space(policy.SpaceBeforeBracketComma); // TODO: Comma policy has changed. writer.WriteToken(Roles.Comma, ","); + isAfterSpace = false; Space(!noSpaceAfterComma && policy.SpaceAfterBracketComma); // TODO: Comma policy has changed. } @@ -194,6 +195,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor #region Write tokens protected bool isAtStartOfLine = true; + protected bool isAfterSpace; /// /// Writes a keyword, and all specials up to @@ -207,18 +209,21 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor { writer.WriteKeyword(tokenRole, token); isAtStartOfLine = false; + isAfterSpace = false; } protected virtual void WriteIdentifier(Identifier identifier) { writer.WriteIdentifier(identifier); isAtStartOfLine = false; + isAfterSpace = false; } protected virtual void WriteIdentifier(string identifier) { AstType.Create(identifier).AcceptVisitor(this); isAtStartOfLine = false; + isAfterSpace = false; } protected virtual void WriteToken(TokenRole tokenRole) @@ -230,6 +235,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor { writer.WriteToken(tokenRole, token); isAtStartOfLine = false; + isAfterSpace = false; } protected virtual void LPar() @@ -260,8 +266,9 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor /// protected virtual void Space(bool addSpace = true) { - if (addSpace) { + if (addSpace && !isAfterSpace) { writer.Space(); + isAfterSpace = true; } } @@ -269,6 +276,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor { writer.NewLine(); isAtStartOfLine = true; + isAfterSpace = false; } protected virtual void OpenBrace(BraceStyle style) @@ -278,7 +286,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor case BraceStyle.EndOfLine: case BraceStyle.BannerStyle: if (!isAtStartOfLine) - writer.Space(); + Space(); writer.WriteToken(Roles.LBrace, "{"); break; case BraceStyle.EndOfLineWithoutSpace: @@ -937,6 +945,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor { StartNode(primitiveExpression); writer.WritePrimitiveValue(primitiveExpression.Value, primitiveExpression.UnsafeLiteralValue); + isAfterSpace = false; EndNode(primitiveExpression); } #endregion From 20d772ed65e4fab83e8d3b3e254e6f8f22542c21 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 17 Oct 2017 13:27:12 +0200 Subject: [PATCH 163/190] Add more tests --- .../TestCases/Pretty/InitializerTests.cs | 371 +++++- .../TestCases/Pretty/InitializerTests.il | 1125 +++++++++++++++- .../TestCases/Pretty/InitializerTests.opt.il | 947 +++++++++++++- .../Pretty/InitializerTests.opt.roslyn.il | 988 +++++++++++++- .../Pretty/InitializerTests.roslyn.il | 1143 ++++++++++++++++- 5 files changed, 4559 insertions(+), 15 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs index 6309f08b0..63439bcb7 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs @@ -17,11 +17,15 @@ // DEALINGS IN THE SOFTWARE. using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { public class InitializerTests { + #region Types and helpers public class C { public int Z; @@ -41,10 +45,102 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } + private enum MyEnum + { + a = 0, + b = 1 + } + + private enum MyEnum2 + { + c = 0, + d = 1 + } + + private class Data + { + public List FieldList = new List(); + public MyEnum a { + get; + set; + } + public MyEnum b { + get; + set; + } + public List PropertyList { + get; + set; + } + + public Data MoreData { + get; + set; + } + + public StructData NestedStruct { + get; + set; + } + + public Data this[int i] { + get { + return null; + } + set { + } + } + + public Data this[int i, string j] { + get { + return null; + } + set { + } + } + } + + private struct StructData + { + public int Field; + public int Property { + get; + set; + } + + public Data MoreData { + get; + set; + } + + public StructData(int initialValue) + { + this = default(StructData); + this.Field = initialValue; + this.Property = initialValue; + } + } + + // Helper methods used to ensure initializers used within expressions work correctly + private static void X(object a, object b) + { + } + + private static object Y() + { + return null; + } + + public static void TestCall(int a, Thread thread) + { + + } + public static C TestCall(int a, C c) { return c; } + #endregion public C Test1() { @@ -83,7 +179,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { return InitializerTests.TestCall(0, new C { Z = 1, - Y = { + Y = { A = 2 } }); @@ -97,5 +193,278 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty c.Y.B = 3; return c; } + + + public static void CollectionInitializerList() + { + InitializerTests.X(InitializerTests.Y(), new List { + 1, + 2, + 3 + }); + } + + public static object RecursiveCollectionInitializer() + { + List list = new List(); + list.Add(list); + return list; + } + + public static void CollectionInitializerDictionary() + { + InitializerTests.X(InitializerTests.Y(), new Dictionary { + { + "First", + 1 + }, + { + "Second", + 2 + }, + { + "Third", + 3 + } + }); + } + + public static void CollectionInitializerDictionaryWithEnumTypes() + { + InitializerTests.X(InitializerTests.Y(), new Dictionary { + { + MyEnum.a, + MyEnum2.c + }, + { + MyEnum.b, + MyEnum2.d + } + }); + } + + public static void NotACollectionInitializer() + { + List list = new List(); + list.Add(1); + list.Add(2); + list.Add(3); + InitializerTests.X(InitializerTests.Y(), list); + } + + public static void ObjectInitializer() + { + InitializerTests.X(InitializerTests.Y(), new Data { + a = MyEnum.a + }); + } + + public static void NotAnObjectInitializer() + { + Data data = new Data(); + data.a = MyEnum.a; + InitializerTests.X(InitializerTests.Y(), data); + } + + public static void ObjectInitializerAssignCollectionToField() + { + InitializerTests.X(InitializerTests.Y(), new Data { + a = MyEnum.a, + FieldList = new List { + MyEnum2.c, + MyEnum2.d + } + }); + } + + public static void ObjectInitializerAddToCollectionInField() + { + InitializerTests.X(InitializerTests.Y(), new Data { + a = MyEnum.a, + FieldList = { + MyEnum2.c, + MyEnum2.d + } + }); + } + + public static void ObjectInitializerAssignCollectionToProperty() + { + InitializerTests.X(InitializerTests.Y(), new Data { + a = MyEnum.a, + PropertyList = new List { + MyEnum2.c, + MyEnum2.d + } + }); + } + + public static void ObjectInitializerAddToCollectionInProperty() + { + InitializerTests.X(InitializerTests.Y(), new Data { + a = MyEnum.a, + PropertyList = { + MyEnum2.c, + MyEnum2.d + } + }); + } + + public static void ObjectInitializerWithInitializationOfNestedObjects() + { + InitializerTests.X(InitializerTests.Y(), new Data { + MoreData = { + a = MyEnum.a, + MoreData = { + a = MyEnum.b + } + } + }); + } + + private static int GetInt() + { + return 1; + } + + private static string GetString() + { + return "Test"; + } + +#if !LEGACY_CSC + public static void SimpleDictInitializer() + { + InitializerTests.X(InitializerTests.Y(), new Data { + MoreData = { + a = MyEnum.a, + [2] = (Data)null + } + }); + } + + public static void MixedObjectAndDictInitializer() + { + InitializerTests.X(InitializerTests.Y(), new Data { + MoreData = { + a = MyEnum.a, + [GetInt()] = { + a = MyEnum.b, + FieldList = { MyEnum2.c }, + [GetInt(), GetString()] = new Data(), + [2] = (Data)null + } + } + }); + } +#endif + + public static void ObjectInitializerWithInitializationOfDeeplyNestedObjects() + { + InitializerTests.X(InitializerTests.Y(), new Data { + a = MyEnum.b, + MoreData = { + a = MyEnum.a, + MoreData = { + MoreData = { + MoreData = { + MoreData = { + MoreData = { + MoreData = { + a = MyEnum.b + } + } + } + } + } + } + } + }); + } + + public static void CollectionInitializerInsideObjectInitializers() + { + InitializerTests.X(InitializerTests.Y(), new Data { + MoreData = new Data { + a = MyEnum.a, + b = MyEnum.b, + PropertyList = { + MyEnum2.c + } + } + }); + } + + public static void NotAStructInitializer_DefaultConstructor() + { + StructData structData = new StructData(); + structData.Field = 1; + structData.Property = 2; + InitializerTests.X(InitializerTests.Y(), structData); + } + + public static void StructInitializer_DefaultConstructor() + { + InitializerTests.X(InitializerTests.Y(), new StructData { + Field = 1, + Property = 2 + }); + } + + public static void NotAStructInitializer_ExplicitConstructor() + { + StructData structData = new StructData(0); + structData.Field = 1; + structData.Property = 2; + InitializerTests.X(InitializerTests.Y(), structData); + } + + public static void StructInitializer_ExplicitConstructor() + { + InitializerTests.X(InitializerTests.Y(), new StructData(0) { + Field = 1, + Property = 2 + }); + } + + public static void StructInitializerWithInitializationOfNestedObjects() + { + InitializerTests.X(InitializerTests.Y(), new StructData { + MoreData = { + a = MyEnum.a, + FieldList = { + MyEnum2.c, + MyEnum2.d + } + } + }); + } + + public static void StructInitializerWithinObjectInitializer() + { + InitializerTests.X(InitializerTests.Y(), new Data { + NestedStruct = new StructData(2) { + Field = 1, + Property = 2 + } + }); + } + + public static void Bug270_NestedInitialisers() + { + NumberFormatInfo[] source = null; + + InitializerTests.TestCall(0, new Thread(InitializerTests.Bug270_NestedInitialisers) { + Priority = ThreadPriority.BelowNormal, + CurrentCulture = new CultureInfo(0) { + DateTimeFormat = new DateTimeFormatInfo { + ShortDatePattern = "ddmmyy" + }, + NumberFormat = (from format in source + where format.CurrencySymbol == "$" + select format).First() + } + }); + } } } \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il index d6a62db22..3e9c08183 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il @@ -10,25 +10,30 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly umgm00go +.assembly extern System.Core +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly xws4p1nr { - .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .permissionset reqmin = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module umgm00go.dll -// MVID: {8C42504A-ACC6-453C-81BA-626AB6649E25} +.module xws4p1nr.dll +// MVID: {D353AAAB-C54F-4C62-88DC-E9FF995570BA} .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: 0x02AE0000 +// Image base: 0x002F0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -76,6 +81,430 @@ } // end of class S + .class auto ansi sealed nested private MyEnum + extends [mscorlib]System.Enum + { + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum a = int32(0x00000000) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum b = int32(0x00000001) + } // end of class MyEnum + + .class auto ansi sealed nested private MyEnum2 + extends [mscorlib]System.Enum + { + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum2 c = int32(0x00000000) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum2 d = int32(0x00000001) + } // end of class MyEnum2 + + .class auto ansi nested private beforefieldinit Data + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = ( 01 00 04 49 74 65 6D 00 00 ) // ...Item.. + .field public class [mscorlib]System.Collections.Generic.List`1 FieldList + .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private class [mscorlib]System.Collections.Generic.List`1 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig specialname + instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + get_a() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 11 (0xb) + .maxstack 1 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum V_0) + IL_0000: ldarg.0 + IL_0001: ldfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method Data::get_a + + .method public hidebysig specialname + instance void set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'value') 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: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_a + + .method public hidebysig specialname + instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + get_b() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 11 (0xb) + .maxstack 1 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum V_0) + IL_0000: ldarg.0 + IL_0001: ldfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method Data::get_b + + .method public hidebysig specialname + instance void set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'value') 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: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_b + + .method public hidebysig specialname + instance class [mscorlib]System.Collections.Generic.List`1 + get_PropertyList() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 11 (0xb) + .maxstack 1 + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method Data::get_PropertyList + + .method public hidebysig specialname + instance void set_PropertyList(class [mscorlib]System.Collections.Generic.List`1 'value') 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: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_PropertyList + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_MoreData() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 11 (0xb) + .maxstack 1 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method Data::get_MoreData + + .method public hidebysig specialname + instance void set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') 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: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_MoreData + + .method public hidebysig specialname + instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + get_NestedStruct() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 11 (0xb) + .maxstack 1 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: ldarg.0 + IL_0001: ldfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method Data::get_NestedStruct + + .method public hidebysig specialname + instance void set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData 'value') 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: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_NestedStruct + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_Item(int32 i) cil managed + { + // Code size 7 (0x7) + .maxstack 1 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: stloc.0 + IL_0003: br.s IL_0005 + + IL_0005: ldloc.0 + IL_0006: ret + } // end of method Data::get_Item + + .method public hidebysig specialname + instance void set_Item(int32 i, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Data::set_Item + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_Item(int32 i, + string j) cil managed + { + // Code size 7 (0x7) + .maxstack 1 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: stloc.0 + IL_0003: br.s IL_0005 + + IL_0005: ldloc.0 + IL_0006: ret + } // end of method Data::get_Item + + .method public hidebysig specialname + instance void set_Item(int32 i, + string j, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Data::set_Item + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 19 (0x13) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0006: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_000b: ldarg.0 + IL_000c: call instance void [mscorlib]System.Object::.ctor() + IL_0011: nop + IL_0012: ret + } // end of method Data::.ctor + + .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + a() + { + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_a() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + } // end of property Data::a + .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + b() + { + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_b() + } // end of property Data::b + .property instance class [mscorlib]System.Collections.Generic.List`1 + PropertyList() + { + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_PropertyList(class [mscorlib]System.Collections.Generic.List`1) + .get instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + } // end of property Data::PropertyList + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + MoreData() + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property Data::MoreData + .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + NestedStruct() + { + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_NestedStruct() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData) + } // end of property Data::NestedStruct + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + Item(int32) + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property Data::Item + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + Item(int32, + string) + { + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + string, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32, + string) + } // end of property Data::Item + } // end of class Data + + .class sequential ansi sealed nested private beforefieldinit StructData + extends [mscorlib]System.ValueType + { + .field public int32 Field + .field private int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig specialname + instance int32 get_Property() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 11 (0xb) + .maxstack 1 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method StructData::get_Property + + .method public hidebysig specialname + instance void set_Property(int32 'value') 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: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0007: ret + } // end of method StructData::set_Property + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_MoreData() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 11 (0xb) + .maxstack 1 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method StructData::get_MoreData + + .method public hidebysig specialname + instance void set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') 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: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0007: ret + } // end of method StructData::set_MoreData + + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 initialValue) cil managed + { + // Code size 24 (0x18) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_000f: ldarg.0 + IL_0010: ldarg.1 + IL_0011: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0016: nop + IL_0017: ret + } // end of method StructData::.ctor + + .property instance int32 Property() + { + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_Property() + } // end of property StructData::Property + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + MoreData() + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property StructData::MoreData + } // end of class StructData + + .field private static class [mscorlib]System.Func`2 'CS$<>9__CachedAnonymousMethodDelegate1a' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method private hidebysig static void X(object a, + object b) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method InitializerTests::X + + .method private hidebysig static object + Y() cil managed + { + // Code size 7 (0x7) + .maxstack 1 + .locals init (object V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: stloc.0 + IL_0003: br.s IL_0005 + + IL_0005: ldloc.0 + IL_0006: ret + } // end of method InitializerTests::Y + + .method public hidebysig static void TestCall(int32 a, + class [mscorlib]System.Threading.Thread thread) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method InitializerTests::TestCall + .method public hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C TestCall(int32 a, class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C c) cil managed @@ -258,6 +687,674 @@ IL_002b: ret } // end of method InitializerTests::Test4 + .method public hidebysig static void CollectionInitializerList() cil managed + { + // Code size 44 (0x2c) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000b: stloc.0 + IL_000c: ldloc.0 + IL_000d: ldc.i4.1 + IL_000e: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0013: nop + IL_0014: ldloc.0 + IL_0015: ldc.i4.2 + IL_0016: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001b: nop + IL_001c: ldloc.0 + IL_001d: ldc.i4.3 + IL_001e: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0023: nop + IL_0024: ldloc.0 + IL_0025: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002a: nop + IL_002b: ret + } // end of method InitializerTests::CollectionInitializerList + + .method public hidebysig static object + RecursiveCollectionInitializer() cil managed + { + // Code size 21 (0x15) + .maxstack 2 + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, + object V_1) + IL_0000: nop + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldloc.0 + IL_0009: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_000e: nop + IL_000f: ldloc.0 + IL_0010: stloc.1 + IL_0011: br.s IL_0013 + + IL_0013: ldloc.1 + IL_0014: ret + } // end of method InitializerTests::RecursiveCollectionInitializer + + .method public hidebysig static void CollectionInitializerDictionary() cil managed + { + // Code size 59 (0x3b) + .maxstack 4 + .locals init (class [mscorlib]System.Collections.Generic.Dictionary`2 V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor() + IL_000b: stloc.0 + IL_000c: ldloc.0 + IL_000d: ldstr "First" + IL_0012: ldc.i4.1 + IL_0013: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0018: nop + IL_0019: ldloc.0 + IL_001a: ldstr "Second" + IL_001f: ldc.i4.2 + IL_0020: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0025: nop + IL_0026: ldloc.0 + IL_0027: ldstr "Third" + IL_002c: ldc.i4.3 + IL_002d: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0032: nop + IL_0033: ldloc.0 + IL_0034: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0039: nop + IL_003a: ret + } // end of method InitializerTests::CollectionInitializerDictionary + + .method public hidebysig static void CollectionInitializerDictionaryWithEnumTypes() cil managed + { + // Code size 38 (0x26) + .maxstack 4 + .locals init (class [mscorlib]System.Collections.Generic.Dictionary`2 V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor() + IL_000b: stloc.0 + IL_000c: ldloc.0 + IL_000d: ldc.i4.0 + IL_000e: ldc.i4.0 + IL_000f: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0014: nop + IL_0015: ldloc.0 + IL_0016: ldc.i4.1 + IL_0017: ldc.i4.1 + IL_0018: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_001d: nop + IL_001e: ldloc.0 + IL_001f: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0024: nop + IL_0025: ret + } // end of method InitializerTests::CollectionInitializerDictionaryWithEnumTypes + + .method public hidebysig static void NotACollectionInitializer() cil managed + { + // Code size 44 (0x2c) + .maxstack 2 + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0) + IL_0000: nop + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldc.i4.1 + IL_0009: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_000e: nop + IL_000f: ldloc.0 + IL_0010: ldc.i4.2 + IL_0011: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0016: nop + IL_0017: ldloc.0 + IL_0018: ldc.i4.3 + IL_0019: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001e: nop + IL_001f: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0024: ldloc.0 + IL_0025: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002a: nop + IL_002b: ret + } // end of method InitializerTests::NotACollectionInitializer + + .method public hidebysig static void ObjectInitializer() cil managed + { + // Code size 28 (0x1c) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: stloc.0 + IL_000c: ldloc.0 + IL_000d: ldc.i4.0 + IL_000e: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0013: nop + IL_0014: ldloc.0 + IL_0015: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_001a: nop + IL_001b: ret + } // end of method InitializerTests::ObjectInitializer + + .method public hidebysig static void NotAnObjectInitializer() cil managed + { + // Code size 28 (0x1c) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: nop + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldc.i4.0 + IL_0009: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_000e: nop + IL_000f: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0014: ldloc.0 + IL_0015: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_001a: nop + IL_001b: ret + } // end of method InitializerTests::NotAnObjectInitializer + + .method public hidebysig static void ObjectInitializerAssignCollectionToField() cil managed + { + // Code size 57 (0x39) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0, + class [mscorlib]System.Collections.Generic.List`1 V_1) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: stloc.0 + IL_000c: ldloc.0 + IL_000d: ldc.i4.0 + IL_000e: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0013: nop + IL_0014: ldloc.0 + IL_0015: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_001a: stloc.1 + IL_001b: ldloc.1 + IL_001c: ldc.i4.0 + IL_001d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0022: nop + IL_0023: ldloc.1 + IL_0024: ldc.i4.1 + IL_0025: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002a: nop + IL_002b: ldloc.1 + IL_002c: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0031: ldloc.0 + IL_0032: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0037: nop + IL_0038: ret + } // end of method InitializerTests::ObjectInitializerAssignCollectionToField + + .method public hidebysig static void ObjectInitializerAddToCollectionInField() cil managed + { + // Code size 54 (0x36) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: stloc.0 + IL_000c: ldloc.0 + IL_000d: ldc.i4.0 + IL_000e: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0013: nop + IL_0014: ldloc.0 + IL_0015: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_001a: ldc.i4.0 + IL_001b: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0020: nop + IL_0021: ldloc.0 + IL_0022: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0027: ldc.i4.1 + IL_0028: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002d: nop + IL_002e: ldloc.0 + IL_002f: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0034: nop + IL_0035: ret + } // end of method InitializerTests::ObjectInitializerAddToCollectionInField + + .method public hidebysig static void ObjectInitializerAssignCollectionToProperty() cil managed + { + // Code size 58 (0x3a) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0, + class [mscorlib]System.Collections.Generic.List`1 V_1) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: stloc.0 + IL_000c: ldloc.0 + IL_000d: ldc.i4.0 + IL_000e: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0013: nop + IL_0014: ldloc.0 + IL_0015: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_001a: stloc.1 + IL_001b: ldloc.1 + IL_001c: ldc.i4.0 + IL_001d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0022: nop + IL_0023: ldloc.1 + IL_0024: ldc.i4.1 + IL_0025: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002a: nop + IL_002b: ldloc.1 + IL_002c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_PropertyList(class [mscorlib]System.Collections.Generic.List`1) + IL_0031: nop + IL_0032: ldloc.0 + IL_0033: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0038: nop + IL_0039: ret + } // end of method InitializerTests::ObjectInitializerAssignCollectionToProperty + + .method public hidebysig static void ObjectInitializerAddToCollectionInProperty() cil managed + { + // Code size 54 (0x36) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: stloc.0 + IL_000c: ldloc.0 + IL_000d: ldc.i4.0 + IL_000e: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0013: nop + IL_0014: ldloc.0 + IL_0015: callvirt instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + IL_001a: ldc.i4.0 + IL_001b: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0020: nop + IL_0021: ldloc.0 + IL_0022: callvirt instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + IL_0027: ldc.i4.1 + IL_0028: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002d: nop + IL_002e: ldloc.0 + IL_002f: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0034: nop + IL_0035: ret + } // end of method InitializerTests::ObjectInitializerAddToCollectionInProperty + + .method public hidebysig static void ObjectInitializerWithInitializationOfNestedObjects() cil managed + { + // Code size 51 (0x33) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: stloc.0 + IL_000c: ldloc.0 + IL_000d: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0012: ldc.i4.0 + IL_0013: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0018: nop + IL_0019: ldloc.0 + IL_001a: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_001f: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0024: ldc.i4.1 + IL_0025: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_002a: nop + IL_002b: ldloc.0 + IL_002c: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0031: nop + IL_0032: ret + } // end of method InitializerTests::ObjectInitializerWithInitializationOfNestedObjects + + .method private hidebysig static int32 + GetInt() cil managed + { + // Code size 7 (0x7) + .maxstack 1 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldc.i4.1 + IL_0002: stloc.0 + IL_0003: br.s IL_0005 + + IL_0005: ldloc.0 + IL_0006: ret + } // end of method InitializerTests::GetInt + + .method private hidebysig static string + GetString() cil managed + { + // Code size 11 (0xb) + .maxstack 1 + .locals init (string V_0) + IL_0000: nop + IL_0001: ldstr "Test" + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method InitializerTests::GetString + + .method public hidebysig static void ObjectInitializerWithInitializationOfDeeplyNestedObjects() cil managed + { + // Code size 84 (0x54) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: stloc.0 + IL_000c: ldloc.0 + IL_000d: ldc.i4.1 + IL_000e: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0013: nop + IL_0014: ldloc.0 + IL_0015: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_001a: ldc.i4.0 + IL_001b: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0020: nop + IL_0021: ldloc.0 + IL_0022: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0027: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_002c: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0031: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0036: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_003b: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0040: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0045: ldc.i4.1 + IL_0046: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_004b: nop + IL_004c: ldloc.0 + IL_004d: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0052: nop + IL_0053: ret + } // end of method InitializerTests::ObjectInitializerWithInitializationOfDeeplyNestedObjects + + .method public hidebysig static void CollectionInitializerInsideObjectInitializers() cil managed + { + // Code size 63 (0x3f) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_1) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: stloc.0 + IL_000c: ldloc.0 + IL_000d: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0012: stloc.1 + IL_0013: ldloc.1 + IL_0014: ldc.i4.0 + IL_0015: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_001a: nop + IL_001b: ldloc.1 + IL_001c: ldc.i4.1 + IL_001d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0022: nop + IL_0023: ldloc.1 + IL_0024: callvirt instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + IL_0029: ldc.i4.0 + IL_002a: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002f: nop + IL_0030: ldloc.1 + IL_0031: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + IL_0036: nop + IL_0037: ldloc.0 + IL_0038: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_003d: nop + IL_003e: ret + } // end of method InitializerTests::CollectionInitializerInsideObjectInitializers + + .method public hidebysig static void NotAStructInitializer_DefaultConstructor() cil managed + { + // Code size 44 (0x2c) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: nop + IL_0001: ldloca.s V_0 + IL_0003: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0009: ldloca.s V_0 + IL_000b: ldc.i4.1 + IL_000c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0011: ldloca.s V_0 + IL_0013: ldc.i4.2 + IL_0014: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0019: nop + IL_001a: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_001f: ldloc.0 + IL_0020: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0025: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002a: nop + IL_002b: ret + } // end of method InitializerTests::NotAStructInitializer_DefaultConstructor + + .method public hidebysig static void StructInitializer_DefaultConstructor() cil managed + { + // Code size 44 (0x2c) + .maxstack 3 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: ldloca.s V_0 + IL_0008: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_000e: ldloca.s V_0 + IL_0010: ldc.i4.1 + IL_0011: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0016: ldloca.s V_0 + IL_0018: ldc.i4.2 + IL_0019: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_001e: nop + IL_001f: ldloc.0 + IL_0020: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0025: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002a: nop + IL_002b: ret + } // end of method InitializerTests::StructInitializer_DefaultConstructor + + .method public hidebysig static void NotAStructInitializer_ExplicitConstructor() cil managed + { + // Code size 45 (0x2d) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: nop + IL_0001: ldloca.s V_0 + IL_0003: ldc.i4.0 + IL_0004: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::.ctor(int32) + IL_0009: nop + IL_000a: ldloca.s V_0 + IL_000c: ldc.i4.1 + IL_000d: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0012: ldloca.s V_0 + IL_0014: ldc.i4.2 + IL_0015: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_001a: nop + IL_001b: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0020: ldloc.0 + IL_0021: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0026: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002b: nop + IL_002c: ret + } // end of method InitializerTests::NotAStructInitializer_ExplicitConstructor + + .method public hidebysig static void StructInitializer_ExplicitConstructor() cil managed + { + // Code size 45 (0x2d) + .maxstack 3 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: ldloca.s V_0 + IL_0008: ldc.i4.0 + IL_0009: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::.ctor(int32) + IL_000e: nop + IL_000f: ldloca.s V_0 + IL_0011: ldc.i4.1 + IL_0012: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0017: ldloca.s V_0 + IL_0019: ldc.i4.2 + IL_001a: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_001f: nop + IL_0020: ldloc.0 + IL_0021: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0026: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002b: nop + IL_002c: ret + } // end of method InitializerTests::StructInitializer_ExplicitConstructor + + .method public hidebysig static void StructInitializerWithInitializationOfNestedObjects() cil managed + { + // Code size 79 (0x4f) + .maxstack 3 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: ldloca.s V_0 + IL_0008: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_000e: ldloca.s V_0 + IL_0010: call instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + IL_0015: ldc.i4.0 + IL_0016: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_001b: nop + IL_001c: ldloca.s V_0 + IL_001e: call instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + IL_0023: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0028: ldc.i4.0 + IL_0029: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002e: nop + IL_002f: ldloca.s V_0 + IL_0031: call instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + IL_0036: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_003b: ldc.i4.1 + IL_003c: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0041: nop + IL_0042: ldloc.0 + IL_0043: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0048: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_004d: nop + IL_004e: ret + } // end of method InitializerTests::StructInitializerWithInitializationOfNestedObjects + + .method public hidebysig static void StructInitializerWithinObjectInitializer() cil managed + { + // Code size 54 (0x36) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0, + valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_1) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: stloc.0 + IL_000c: ldloc.0 + IL_000d: ldloca.s V_1 + IL_000f: ldc.i4.2 + IL_0010: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::.ctor(int32) + IL_0015: nop + IL_0016: ldloca.s V_1 + IL_0018: ldc.i4.1 + IL_0019: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_001e: ldloca.s V_1 + IL_0020: ldc.i4.2 + IL_0021: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0026: nop + IL_0027: ldloc.1 + IL_0028: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData) + IL_002d: nop + IL_002e: ldloc.0 + IL_002f: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0034: nop + IL_0035: ret + } // end of method InitializerTests::StructInitializerWithinObjectInitializer + + .method public hidebysig static void Bug270_NestedInitialisers() cil managed + { + // Code size 128 (0x80) + .maxstack 6 + .locals init (class [mscorlib]System.Globalization.NumberFormatInfo[] V_0, + class [mscorlib]System.Threading.Thread V_1, + class [mscorlib]System.Globalization.CultureInfo V_2, + class [mscorlib]System.Globalization.DateTimeFormatInfo V_3) + IL_0000: nop + IL_0001: ldnull + IL_0002: stloc.0 + IL_0003: ldc.i4.0 + IL_0004: ldnull + IL_0005: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Bug270_NestedInitialisers() + IL_000b: newobj instance void [mscorlib]System.Threading.ThreadStart::.ctor(object, + native int) + IL_0010: newobj instance void [mscorlib]System.Threading.Thread::.ctor(class [mscorlib]System.Threading.ThreadStart) + IL_0015: stloc.1 + IL_0016: ldloc.1 + IL_0017: ldc.i4.1 + IL_0018: callvirt instance void [mscorlib]System.Threading.Thread::set_Priority(valuetype [mscorlib]System.Threading.ThreadPriority) + IL_001d: nop + IL_001e: ldloc.1 + IL_001f: ldc.i4.0 + IL_0020: newobj instance void [mscorlib]System.Globalization.CultureInfo::.ctor(int32) + IL_0025: stloc.2 + IL_0026: ldloc.2 + IL_0027: newobj instance void [mscorlib]System.Globalization.DateTimeFormatInfo::.ctor() + IL_002c: stloc.3 + IL_002d: ldloc.3 + IL_002e: ldstr "ddmmyy" + IL_0033: callvirt instance void [mscorlib]System.Globalization.DateTimeFormatInfo::set_ShortDatePattern(string) + IL_0038: nop + IL_0039: ldloc.3 + IL_003a: callvirt instance void [mscorlib]System.Globalization.CultureInfo::set_DateTimeFormat(class [mscorlib]System.Globalization.DateTimeFormatInfo) + IL_003f: nop + IL_0040: ldloc.2 + IL_0041: ldloc.0 + IL_0042: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1a' + IL_0047: brtrue.s IL_005c + + IL_0049: ldnull + IL_004a: ldftn bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'b__19'(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_0050: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0055: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1a' + IL_005a: br.s IL_005c + + IL_005c: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1a' + IL_0061: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, + class [mscorlib]System.Func`2) + IL_0066: call !!0 [System.Core]System.Linq.Enumerable::First(class [mscorlib]System.Collections.Generic.IEnumerable`1) + IL_006b: callvirt instance void [mscorlib]System.Globalization.CultureInfo::set_NumberFormat(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_0070: nop + IL_0071: ldloc.2 + IL_0072: callvirt instance void [mscorlib]System.Threading.Thread::set_CurrentCulture(class [mscorlib]System.Globalization.CultureInfo) + IL_0077: nop + IL_0078: ldloc.1 + IL_0079: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::TestCall(int32, + class [mscorlib]System.Threading.Thread) + IL_007e: nop + IL_007f: ret + } // end of method InitializerTests::Bug270_NestedInitialisers + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -268,6 +1365,24 @@ IL_0006: ret } // end of method InitializerTests::.ctor + .method private hidebysig static bool 'b__19'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 21 (0x15) + .maxstack 2 + .locals init (bool V_0) + IL_0000: ldarg.0 + IL_0001: callvirt instance string [mscorlib]System.Globalization.NumberFormatInfo::get_CurrencySymbol() + IL_0006: ldstr "$" + IL_000b: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0010: stloc.0 + IL_0011: br.s IL_0013 + + IL_0013: ldloc.0 + IL_0014: ret + } // end of method InitializerTests::'b__19' + } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il index ac94bb18e..f7dcef8e8 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il @@ -10,25 +10,30 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly ecxzpbak +.assembly extern System.Core +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly '3csuofts' { - .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .permissionset reqmin = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module ecxzpbak.dll -// MVID: {F67EEE6A-7EFF-4261-9FC7-3F2C4A0972E9} +.module '3csuofts.dll' +// MVID: {F78A061E-BAE5-4B9C-AFCF-4B60D826C849} .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: 0x02430000 +// Image base: 0x00D80000 // =============== CLASS MEMBERS DECLARATION =================== @@ -75,6 +80,370 @@ } // end of class S + .class auto ansi sealed nested private MyEnum + extends [mscorlib]System.Enum + { + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum a = int32(0x00000000) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum b = int32(0x00000001) + } // end of class MyEnum + + .class auto ansi sealed nested private MyEnum2 + extends [mscorlib]System.Enum + { + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum2 c = int32(0x00000000) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum2 d = int32(0x00000001) + } // end of class MyEnum2 + + .class auto ansi nested private beforefieldinit Data + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = ( 01 00 04 49 74 65 6D 00 00 ) // ...Item.. + .field public class [mscorlib]System.Collections.Generic.List`1 FieldList + .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private class [mscorlib]System.Collections.Generic.List`1 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig specialname + instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + get_a() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_a + + .method public hidebysig specialname + instance void set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'value') 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: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_a + + .method public hidebysig specialname + instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + get_b() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_b + + .method public hidebysig specialname + instance void set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'value') 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: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_b + + .method public hidebysig specialname + instance class [mscorlib]System.Collections.Generic.List`1 + get_PropertyList() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_PropertyList + + .method public hidebysig specialname + instance void set_PropertyList(class [mscorlib]System.Collections.Generic.List`1 'value') 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: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_PropertyList + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_MoreData() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_MoreData + + .method public hidebysig specialname + instance void set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') 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: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_MoreData + + .method public hidebysig specialname + instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + get_NestedStruct() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_NestedStruct + + .method public hidebysig specialname + instance void set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData 'value') 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: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_NestedStruct + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_Item(int32 i) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldnull + IL_0001: ret + } // end of method Data::get_Item + + .method public hidebysig specialname + instance void set_Item(int32 i, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Data::set_Item + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_Item(int32 i, + string j) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldnull + IL_0001: ret + } // end of method Data::get_Item + + .method public hidebysig specialname + instance void set_Item(int32 i, + string j, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Data::set_Item + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 18 (0x12) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0006: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_000b: ldarg.0 + IL_000c: call instance void [mscorlib]System.Object::.ctor() + IL_0011: ret + } // end of method Data::.ctor + + .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + a() + { + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_a() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + } // end of property Data::a + .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + b() + { + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_b() + } // end of property Data::b + .property instance class [mscorlib]System.Collections.Generic.List`1 + PropertyList() + { + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_PropertyList(class [mscorlib]System.Collections.Generic.List`1) + .get instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + } // end of property Data::PropertyList + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + MoreData() + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property Data::MoreData + .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + NestedStruct() + { + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_NestedStruct() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData) + } // end of property Data::NestedStruct + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + Item(int32) + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property Data::Item + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + Item(int32, + string) + { + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + string, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32, + string) + } // end of property Data::Item + } // end of class Data + + .class sequential ansi sealed nested private beforefieldinit StructData + extends [mscorlib]System.ValueType + { + .field public int32 Field + .field private int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig specialname + instance int32 get_Property() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0006: ret + } // end of method StructData::get_Property + + .method public hidebysig specialname + instance void set_Property(int32 'value') 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: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0007: ret + } // end of method StructData::set_Property + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_MoreData() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0006: ret + } // end of method StructData::get_MoreData + + .method public hidebysig specialname + instance void set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') 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: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0007: ret + } // end of method StructData::set_MoreData + + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 initialValue) cil managed + { + // Code size 22 (0x16) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0007: ldarg.0 + IL_0008: ldarg.1 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_000e: ldarg.0 + IL_000f: ldarg.1 + IL_0010: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0015: ret + } // end of method StructData::.ctor + + .property instance int32 Property() + { + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_Property() + } // end of property StructData::Property + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + MoreData() + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property StructData::MoreData + } // end of class StructData + + .field private static class [mscorlib]System.Func`2 'CS$<>9__CachedAnonymousMethodDelegate1a' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method private hidebysig static void X(object a, + object b) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method InitializerTests::X + + .method private hidebysig static object + Y() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldnull + IL_0001: ret + } // end of method InitializerTests::Y + + .method public hidebysig static void TestCall(int32 a, + class [mscorlib]System.Threading.Thread thread) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method InitializerTests::TestCall + .method public hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C TestCall(int32 a, class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C c) cil managed @@ -213,6 +582,561 @@ IL_0026: ret } // end of method InitializerTests::Test4 + .method public hidebysig static void CollectionInitializerList() cil managed + { + // Code size 39 (0x27) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000a: stloc.0 + IL_000b: ldloc.0 + IL_000c: ldc.i4.1 + IL_000d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0012: ldloc.0 + IL_0013: ldc.i4.2 + IL_0014: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0019: ldloc.0 + IL_001a: ldc.i4.3 + IL_001b: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0020: ldloc.0 + IL_0021: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0026: ret + } // end of method InitializerTests::CollectionInitializerList + + .method public hidebysig static object + RecursiveCollectionInitializer() cil managed + { + // Code size 15 (0xf) + .maxstack 2 + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0) + IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldloc.0 + IL_0008: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_000d: ldloc.0 + IL_000e: ret + } // end of method InitializerTests::RecursiveCollectionInitializer + + .method public hidebysig static void CollectionInitializerDictionary() cil managed + { + // Code size 54 (0x36) + .maxstack 4 + .locals init (class [mscorlib]System.Collections.Generic.Dictionary`2 V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor() + IL_000a: stloc.0 + IL_000b: ldloc.0 + IL_000c: ldstr "First" + IL_0011: ldc.i4.1 + IL_0012: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0017: ldloc.0 + IL_0018: ldstr "Second" + IL_001d: ldc.i4.2 + IL_001e: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0023: ldloc.0 + IL_0024: ldstr "Third" + IL_0029: ldc.i4.3 + IL_002a: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_002f: ldloc.0 + IL_0030: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0035: ret + } // end of method InitializerTests::CollectionInitializerDictionary + + .method public hidebysig static void CollectionInitializerDictionaryWithEnumTypes() cil managed + { + // Code size 34 (0x22) + .maxstack 4 + .locals init (class [mscorlib]System.Collections.Generic.Dictionary`2 V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor() + IL_000a: stloc.0 + IL_000b: ldloc.0 + IL_000c: ldc.i4.0 + IL_000d: ldc.i4.0 + IL_000e: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0013: ldloc.0 + IL_0014: ldc.i4.1 + IL_0015: ldc.i4.1 + IL_0016: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_001b: ldloc.0 + IL_001c: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0021: ret + } // end of method InitializerTests::CollectionInitializerDictionaryWithEnumTypes + + .method public hidebysig static void NotACollectionInitializer() cil managed + { + // Code size 39 (0x27) + .maxstack 2 + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0) + IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldc.i4.1 + IL_0008: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_000d: ldloc.0 + IL_000e: ldc.i4.2 + IL_000f: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0014: ldloc.0 + IL_0015: ldc.i4.3 + IL_0016: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001b: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0020: ldloc.0 + IL_0021: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0026: ret + } // end of method InitializerTests::NotACollectionInitializer + + .method public hidebysig static void ObjectInitializer() cil managed + { + // Code size 25 (0x19) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: stloc.0 + IL_000b: ldloc.0 + IL_000c: ldc.i4.0 + IL_000d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0012: ldloc.0 + IL_0013: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0018: ret + } // end of method InitializerTests::ObjectInitializer + + .method public hidebysig static void NotAnObjectInitializer() cil managed + { + // Code size 25 (0x19) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldc.i4.0 + IL_0008: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_000d: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0012: ldloc.0 + IL_0013: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0018: ret + } // end of method InitializerTests::NotAnObjectInitializer + + .method public hidebysig static void ObjectInitializerAssignCollectionToField() cil managed + { + // Code size 52 (0x34) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0, + class [mscorlib]System.Collections.Generic.List`1 V_1) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: stloc.0 + IL_000b: ldloc.0 + IL_000c: ldc.i4.0 + IL_000d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0012: ldloc.0 + IL_0013: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0018: stloc.1 + IL_0019: ldloc.1 + IL_001a: ldc.i4.0 + IL_001b: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0020: ldloc.1 + IL_0021: ldc.i4.1 + IL_0022: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0027: ldloc.1 + IL_0028: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_002d: ldloc.0 + IL_002e: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0033: ret + } // end of method InitializerTests::ObjectInitializerAssignCollectionToField + + .method public hidebysig static void ObjectInitializerAddToCollectionInField() cil managed + { + // Code size 49 (0x31) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: stloc.0 + IL_000b: ldloc.0 + IL_000c: ldc.i4.0 + IL_000d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0012: ldloc.0 + IL_0013: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0018: ldc.i4.0 + IL_0019: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001e: ldloc.0 + IL_001f: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0024: ldc.i4.1 + IL_0025: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002a: ldloc.0 + IL_002b: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0030: ret + } // end of method InitializerTests::ObjectInitializerAddToCollectionInField + + .method public hidebysig static void ObjectInitializerAssignCollectionToProperty() cil managed + { + // Code size 52 (0x34) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0, + class [mscorlib]System.Collections.Generic.List`1 V_1) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: stloc.0 + IL_000b: ldloc.0 + IL_000c: ldc.i4.0 + IL_000d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0012: ldloc.0 + IL_0013: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0018: stloc.1 + IL_0019: ldloc.1 + IL_001a: ldc.i4.0 + IL_001b: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0020: ldloc.1 + IL_0021: ldc.i4.1 + IL_0022: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0027: ldloc.1 + IL_0028: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_PropertyList(class [mscorlib]System.Collections.Generic.List`1) + IL_002d: ldloc.0 + IL_002e: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0033: ret + } // end of method InitializerTests::ObjectInitializerAssignCollectionToProperty + + .method public hidebysig static void ObjectInitializerAddToCollectionInProperty() cil managed + { + // Code size 49 (0x31) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: stloc.0 + IL_000b: ldloc.0 + IL_000c: ldc.i4.0 + IL_000d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0012: ldloc.0 + IL_0013: callvirt instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + IL_0018: ldc.i4.0 + IL_0019: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001e: ldloc.0 + IL_001f: callvirt instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + IL_0024: ldc.i4.1 + IL_0025: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002a: ldloc.0 + IL_002b: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0030: ret + } // end of method InitializerTests::ObjectInitializerAddToCollectionInProperty + + .method public hidebysig static void ObjectInitializerWithInitializationOfNestedObjects() cil managed + { + // Code size 47 (0x2f) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: stloc.0 + IL_000b: ldloc.0 + IL_000c: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0011: ldc.i4.0 + IL_0012: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0017: ldloc.0 + IL_0018: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_001d: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0022: ldc.i4.1 + IL_0023: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0028: ldloc.0 + IL_0029: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002e: ret + } // end of method InitializerTests::ObjectInitializerWithInitializationOfNestedObjects + + .method private hidebysig static int32 + GetInt() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } // end of method InitializerTests::GetInt + + .method private hidebysig static string + GetString() cil managed + { + // Code size 6 (0x6) + .maxstack 8 + IL_0000: ldstr "Test" + IL_0005: ret + } // end of method InitializerTests::GetString + + .method public hidebysig static void ObjectInitializerWithInitializationOfDeeplyNestedObjects() cil managed + { + // Code size 79 (0x4f) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: stloc.0 + IL_000b: ldloc.0 + IL_000c: ldc.i4.1 + IL_000d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0012: ldloc.0 + IL_0013: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0018: ldc.i4.0 + IL_0019: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_001e: ldloc.0 + IL_001f: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0024: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0029: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_002e: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0033: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0038: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_003d: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0042: ldc.i4.1 + IL_0043: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0048: ldloc.0 + IL_0049: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_004e: ret + } // end of method InitializerTests::ObjectInitializerWithInitializationOfDeeplyNestedObjects + + .method public hidebysig static void CollectionInitializerInsideObjectInitializers() cil managed + { + // Code size 57 (0x39) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_1) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: stloc.0 + IL_000b: ldloc.0 + IL_000c: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0011: stloc.1 + IL_0012: ldloc.1 + IL_0013: ldc.i4.0 + IL_0014: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0019: ldloc.1 + IL_001a: ldc.i4.1 + IL_001b: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0020: ldloc.1 + IL_0021: callvirt instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + IL_0026: ldc.i4.0 + IL_0027: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002c: ldloc.1 + IL_002d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + IL_0032: ldloc.0 + IL_0033: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0038: ret + } // end of method InitializerTests::CollectionInitializerInsideObjectInitializers + + .method public hidebysig static void NotAStructInitializer_DefaultConstructor() cil managed + { + // Code size 41 (0x29) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: ldloca.s V_0 + IL_0002: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0008: ldloca.s V_0 + IL_000a: ldc.i4.1 + IL_000b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0010: ldloca.s V_0 + IL_0012: ldc.i4.2 + IL_0013: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0018: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_001d: ldloc.0 + IL_001e: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0023: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0028: ret + } // end of method InitializerTests::NotAStructInitializer_DefaultConstructor + + .method public hidebysig static void StructInitializer_DefaultConstructor() cil managed + { + // Code size 41 (0x29) + .maxstack 3 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: ldloca.s V_0 + IL_0007: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_000d: ldloca.s V_0 + IL_000f: ldc.i4.1 + IL_0010: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0015: ldloca.s V_0 + IL_0017: ldc.i4.2 + IL_0018: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_001d: ldloc.0 + IL_001e: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0023: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0028: ret + } // end of method InitializerTests::StructInitializer_DefaultConstructor + + .method public hidebysig static void NotAStructInitializer_ExplicitConstructor() cil managed + { + // Code size 41 (0x29) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: ldloca.s V_0 + IL_0002: ldc.i4.0 + IL_0003: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::.ctor(int32) + IL_0008: ldloca.s V_0 + IL_000a: ldc.i4.1 + IL_000b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0010: ldloca.s V_0 + IL_0012: ldc.i4.2 + IL_0013: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0018: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_001d: ldloc.0 + IL_001e: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0023: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0028: ret + } // end of method InitializerTests::NotAStructInitializer_ExplicitConstructor + + .method public hidebysig static void StructInitializer_ExplicitConstructor() cil managed + { + // Code size 41 (0x29) + .maxstack 3 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: ldloca.s V_0 + IL_0007: ldc.i4.0 + IL_0008: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::.ctor(int32) + IL_000d: ldloca.s V_0 + IL_000f: ldc.i4.1 + IL_0010: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0015: ldloca.s V_0 + IL_0017: ldc.i4.2 + IL_0018: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_001d: ldloc.0 + IL_001e: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0023: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0028: ret + } // end of method InitializerTests::StructInitializer_ExplicitConstructor + + .method public hidebysig static void StructInitializerWithInitializationOfNestedObjects() cil managed + { + // Code size 74 (0x4a) + .maxstack 3 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: ldloca.s V_0 + IL_0007: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_000d: ldloca.s V_0 + IL_000f: call instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + IL_0014: ldc.i4.0 + IL_0015: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_001a: ldloca.s V_0 + IL_001c: call instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + IL_0021: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0026: ldc.i4.0 + IL_0027: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002c: ldloca.s V_0 + IL_002e: call instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + IL_0033: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0038: ldc.i4.1 + IL_0039: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_003e: ldloc.0 + IL_003f: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0044: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0049: ret + } // end of method InitializerTests::StructInitializerWithInitializationOfNestedObjects + + .method public hidebysig static void StructInitializerWithinObjectInitializer() cil managed + { + // Code size 49 (0x31) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0, + valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_1) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: stloc.0 + IL_000b: ldloc.0 + IL_000c: ldloca.s V_1 + IL_000e: ldc.i4.2 + IL_000f: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::.ctor(int32) + IL_0014: ldloca.s V_1 + IL_0016: ldc.i4.1 + IL_0017: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_001c: ldloca.s V_1 + IL_001e: ldc.i4.2 + IL_001f: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0024: ldloc.1 + IL_0025: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData) + IL_002a: ldloc.0 + IL_002b: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0030: ret + } // end of method InitializerTests::StructInitializerWithinObjectInitializer + + .method public hidebysig static void Bug270_NestedInitialisers() cil managed + { + // Code size 119 (0x77) + .maxstack 6 + .locals init (class [mscorlib]System.Globalization.NumberFormatInfo[] V_0, + class [mscorlib]System.Threading.Thread V_1, + class [mscorlib]System.Globalization.CultureInfo V_2, + class [mscorlib]System.Globalization.DateTimeFormatInfo V_3) + IL_0000: ldnull + IL_0001: stloc.0 + IL_0002: ldc.i4.0 + IL_0003: ldnull + IL_0004: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Bug270_NestedInitialisers() + IL_000a: newobj instance void [mscorlib]System.Threading.ThreadStart::.ctor(object, + native int) + IL_000f: newobj instance void [mscorlib]System.Threading.Thread::.ctor(class [mscorlib]System.Threading.ThreadStart) + IL_0014: stloc.1 + IL_0015: ldloc.1 + IL_0016: ldc.i4.1 + IL_0017: callvirt instance void [mscorlib]System.Threading.Thread::set_Priority(valuetype [mscorlib]System.Threading.ThreadPriority) + IL_001c: ldloc.1 + IL_001d: ldc.i4.0 + IL_001e: newobj instance void [mscorlib]System.Globalization.CultureInfo::.ctor(int32) + IL_0023: stloc.2 + IL_0024: ldloc.2 + IL_0025: newobj instance void [mscorlib]System.Globalization.DateTimeFormatInfo::.ctor() + IL_002a: stloc.3 + IL_002b: ldloc.3 + IL_002c: ldstr "ddmmyy" + IL_0031: callvirt instance void [mscorlib]System.Globalization.DateTimeFormatInfo::set_ShortDatePattern(string) + IL_0036: ldloc.3 + IL_0037: callvirt instance void [mscorlib]System.Globalization.CultureInfo::set_DateTimeFormat(class [mscorlib]System.Globalization.DateTimeFormatInfo) + IL_003c: ldloc.2 + IL_003d: ldloc.0 + IL_003e: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1a' + IL_0043: brtrue.s IL_0056 + + IL_0045: ldnull + IL_0046: ldftn bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'b__19'(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_004c: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0051: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1a' + IL_0056: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1a' + IL_005b: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, + class [mscorlib]System.Func`2) + IL_0060: call !!0 [System.Core]System.Linq.Enumerable::First(class [mscorlib]System.Collections.Generic.IEnumerable`1) + IL_0065: callvirt instance void [mscorlib]System.Globalization.CultureInfo::set_NumberFormat(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_006a: ldloc.2 + IL_006b: callvirt instance void [mscorlib]System.Threading.Thread::set_CurrentCulture(class [mscorlib]System.Globalization.CultureInfo) + IL_0070: ldloc.1 + IL_0071: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::TestCall(int32, + class [mscorlib]System.Threading.Thread) + IL_0076: ret + } // end of method InitializerTests::Bug270_NestedInitialisers + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -223,6 +1147,19 @@ IL_0006: ret } // end of method InitializerTests::.ctor + .method private hidebysig static bool 'b__19'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 17 (0x11) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance string [mscorlib]System.Globalization.NumberFormatInfo::get_CurrencySymbol() + IL_0006: ldstr "$" + IL_000b: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0010: ret + } // end of method InitializerTests::'b__19' + } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il index 13eb53fdd..0f0385cd5 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il @@ -10,6 +10,11 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } +.assembly extern System.Core +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} .assembly InitializerTests { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) @@ -25,14 +30,14 @@ .ver 0:0:0:0 } .module InitializerTests.dll -// MVID: {F2C6C41E-98CC-4261-BF7B-1991B54DA121} +// MVID: {4B0BA9B1-521C-4C45-A2B8-8774D5BE797E} .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: 0x00700000 +// Image base: 0x01500000 // =============== CLASS MEMBERS DECLARATION =================== @@ -79,6 +84,409 @@ } // end of class S + .class auto ansi sealed nested private MyEnum + extends [mscorlib]System.Enum + { + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum a = int32(0x00000000) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum b = int32(0x00000001) + } // end of class MyEnum + + .class auto ansi sealed nested private MyEnum2 + extends [mscorlib]System.Enum + { + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum2 c = int32(0x00000000) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum2 d = int32(0x00000001) + } // end of class MyEnum2 + + .class auto ansi nested private beforefieldinit Data + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = ( 01 00 04 49 74 65 6D 00 00 ) // ...Item.. + .field public class [mscorlib]System.Collections.Generic.List`1 FieldList + .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private class [mscorlib]System.Collections.Generic.List`1 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig specialname + instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + get_a() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_a + + .method public hidebysig specialname + instance void set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'value') 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: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_a + + .method public hidebysig specialname + instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + get_b() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_b + + .method public hidebysig specialname + instance void set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'value') 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: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_b + + .method public hidebysig specialname + instance class [mscorlib]System.Collections.Generic.List`1 + get_PropertyList() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_PropertyList + + .method public hidebysig specialname + instance void set_PropertyList(class [mscorlib]System.Collections.Generic.List`1 'value') 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: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_PropertyList + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_MoreData() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_MoreData + + .method public hidebysig specialname + instance void set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') 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: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_MoreData + + .method public hidebysig specialname + instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + get_NestedStruct() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_NestedStruct + + .method public hidebysig specialname + instance void set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData 'value') 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: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_NestedStruct + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_Item(int32 i) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldnull + IL_0001: ret + } // end of method Data::get_Item + + .method public hidebysig specialname + instance void set_Item(int32 i, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Data::set_Item + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_Item(int32 i, + string j) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldnull + IL_0001: ret + } // end of method Data::get_Item + + .method public hidebysig specialname + instance void set_Item(int32 i, + string j, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Data::set_Item + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 18 (0x12) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0006: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_000b: ldarg.0 + IL_000c: call instance void [mscorlib]System.Object::.ctor() + IL_0011: ret + } // end of method Data::.ctor + + .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + a() + { + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_a() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + } // end of property Data::a + .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + b() + { + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_b() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + } // end of property Data::b + .property instance class [mscorlib]System.Collections.Generic.List`1 + PropertyList() + { + .get instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_PropertyList(class [mscorlib]System.Collections.Generic.List`1) + } // end of property Data::PropertyList + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + MoreData() + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property Data::MoreData + .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + NestedStruct() + { + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_NestedStruct() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData) + } // end of property Data::NestedStruct + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + Item(int32) + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property Data::Item + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + Item(int32, + string) + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32, + string) + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + string, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property Data::Item + } // end of class Data + + .class sequential ansi sealed nested private beforefieldinit StructData + extends [mscorlib]System.ValueType + { + .field public int32 Field + .field private int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig specialname + instance int32 get_Property() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0006: ret + } // end of method StructData::get_Property + + .method public hidebysig specialname + instance void set_Property(int32 'value') 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: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0007: ret + } // end of method StructData::set_Property + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_MoreData() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0006: ret + } // end of method StructData::get_MoreData + + .method public hidebysig specialname + instance void set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') 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: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0007: ret + } // end of method StructData::set_MoreData + + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 initialValue) cil managed + { + // Code size 22 (0x16) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0007: ldarg.0 + IL_0008: ldarg.1 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_000e: ldarg.0 + IL_000f: ldarg.1 + IL_0010: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0015: ret + } // end of method StructData::.ctor + + .property instance int32 Property() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_Property() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + } // end of property StructData::Property + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + MoreData() + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property StructData::MoreData + } // end of class StructData + + .class auto ansi serializable sealed nested private beforefieldinit '<>c' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' '<>9' + .field public static class [mscorlib]System.Func`2 '<>9__40_0' + .method private hidebysig specialname rtspecialname static + void .cctor() cil managed + { + // Code size 11 (0xb) + .maxstack 8 + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::.ctor() + IL_0005: stsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9' + IL_000a: ret + } // end of method '<>c'::.cctor + + .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 [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c'::.ctor + + .method assembly hidebysig instance bool + 'b__40_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed + { + // Code size 17 (0x11) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: callvirt instance string [mscorlib]System.Globalization.NumberFormatInfo::get_CurrencySymbol() + IL_0006: ldstr "$" + IL_000b: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0010: ret + } // end of method '<>c'::'b__40_0' + + } // end of class '<>c' + + .method private hidebysig static void X(object a, + object b) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method InitializerTests::X + + .method private hidebysig static object + Y() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldnull + IL_0001: ret + } // end of method InitializerTests::Y + + .method public hidebysig static void TestCall(int32 a, + class [mscorlib]System.Threading.Thread thread) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method InitializerTests::TestCall + .method public hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C TestCall(int32 a, class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C c) cil managed @@ -196,6 +604,582 @@ IL_0024: ret } // end of method InitializerTests::Test4 + .method public hidebysig static void CollectionInitializerList() cil managed + { + // Code size 37 (0x25) + .maxstack 8 + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000a: dup + IL_000b: ldc.i4.1 + IL_000c: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0011: dup + IL_0012: ldc.i4.2 + IL_0013: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0018: dup + IL_0019: ldc.i4.3 + IL_001a: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001f: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0024: ret + } // end of method InitializerTests::CollectionInitializerList + + .method public hidebysig static object + RecursiveCollectionInitializer() cil managed + { + // Code size 13 (0xd) + .maxstack 8 + IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0005: dup + IL_0006: dup + IL_0007: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_000c: ret + } // end of method InitializerTests::RecursiveCollectionInitializer + + .method public hidebysig static void CollectionInitializerDictionary() cil managed + { + // Code size 52 (0x34) + .maxstack 8 + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor() + IL_000a: dup + IL_000b: ldstr "First" + IL_0010: ldc.i4.1 + IL_0011: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0016: dup + IL_0017: ldstr "Second" + IL_001c: ldc.i4.2 + IL_001d: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0022: dup + IL_0023: ldstr "Third" + IL_0028: ldc.i4.3 + IL_0029: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_002e: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0033: ret + } // end of method InitializerTests::CollectionInitializerDictionary + + .method public hidebysig static void CollectionInitializerDictionaryWithEnumTypes() cil managed + { + // Code size 32 (0x20) + .maxstack 8 + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor() + IL_000a: dup + IL_000b: ldc.i4.0 + IL_000c: ldc.i4.0 + IL_000d: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0012: dup + IL_0013: ldc.i4.1 + IL_0014: ldc.i4.1 + IL_0015: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_001a: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_001f: ret + } // end of method InitializerTests::CollectionInitializerDictionaryWithEnumTypes + + .method public hidebysig static void NotACollectionInitializer() cil managed + { + // Code size 39 (0x27) + .maxstack 2 + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0) + IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldc.i4.1 + IL_0008: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_000d: ldloc.0 + IL_000e: ldc.i4.2 + IL_000f: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0014: ldloc.0 + IL_0015: ldc.i4.3 + IL_0016: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001b: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0020: ldloc.0 + IL_0021: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0026: ret + } // end of method InitializerTests::NotACollectionInitializer + + .method public hidebysig static void ObjectInitializer() cil managed + { + // Code size 23 (0x17) + .maxstack 8 + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: dup + IL_000b: ldc.i4.0 + IL_000c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0011: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0016: ret + } // end of method InitializerTests::ObjectInitializer + + .method public hidebysig static void NotAnObjectInitializer() cil managed + { + // Code size 25 (0x19) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldc.i4.0 + IL_0008: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_000d: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0012: ldloc.0 + IL_0013: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0018: ret + } // end of method InitializerTests::NotAnObjectInitializer + + .method public hidebysig static void ObjectInitializerAssignCollectionToField() cil managed + { + // Code size 48 (0x30) + .maxstack 8 + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: dup + IL_000b: ldc.i4.0 + IL_000c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0011: dup + IL_0012: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0017: dup + IL_0018: ldc.i4.0 + IL_0019: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001e: dup + IL_001f: ldc.i4.1 + IL_0020: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0025: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_002a: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002f: ret + } // end of method InitializerTests::ObjectInitializerAssignCollectionToField + + .method public hidebysig static void ObjectInitializerAddToCollectionInField() cil managed + { + // Code size 47 (0x2f) + .maxstack 8 + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: dup + IL_000b: ldc.i4.0 + IL_000c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0011: dup + IL_0012: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0017: ldc.i4.0 + IL_0018: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001d: dup + IL_001e: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0023: ldc.i4.1 + IL_0024: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0029: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002e: ret + } // end of method InitializerTests::ObjectInitializerAddToCollectionInField + + .method public hidebysig static void ObjectInitializerAssignCollectionToProperty() cil managed + { + // Code size 48 (0x30) + .maxstack 8 + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: dup + IL_000b: ldc.i4.0 + IL_000c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0011: dup + IL_0012: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0017: dup + IL_0018: ldc.i4.0 + IL_0019: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001e: dup + IL_001f: ldc.i4.1 + IL_0020: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0025: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_PropertyList(class [mscorlib]System.Collections.Generic.List`1) + IL_002a: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002f: ret + } // end of method InitializerTests::ObjectInitializerAssignCollectionToProperty + + .method public hidebysig static void ObjectInitializerAddToCollectionInProperty() cil managed + { + // Code size 47 (0x2f) + .maxstack 8 + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: dup + IL_000b: ldc.i4.0 + IL_000c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0011: dup + IL_0012: callvirt instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + IL_0017: ldc.i4.0 + IL_0018: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001d: dup + IL_001e: callvirt instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + IL_0023: ldc.i4.1 + IL_0024: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0029: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002e: ret + } // end of method InitializerTests::ObjectInitializerAddToCollectionInProperty + + .method public hidebysig static void ObjectInitializerWithInitializationOfNestedObjects() cil managed + { + // Code size 45 (0x2d) + .maxstack 8 + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: dup + IL_000b: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0010: ldc.i4.0 + IL_0011: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0016: dup + IL_0017: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_001c: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0021: ldc.i4.1 + IL_0022: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0027: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002c: ret + } // end of method InitializerTests::ObjectInitializerWithInitializationOfNestedObjects + + .method private hidebysig static int32 + GetInt() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } // end of method InitializerTests::GetInt + + .method private hidebysig static string + GetString() cil managed + { + // Code size 6 (0x6) + .maxstack 8 + IL_0000: ldstr "Test" + IL_0005: ret + } // end of method InitializerTests::GetString + + .method public hidebysig static void SimpleDictInitializer() cil managed + { + // Code size 41 (0x29) + .maxstack 8 + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: dup + IL_000b: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0010: ldc.i4.0 + IL_0011: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0016: dup + IL_0017: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_001c: ldc.i4.2 + IL_001d: ldnull + IL_001e: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + IL_0023: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0028: ret + } // end of method InitializerTests::SimpleDictInitializer + + .method public hidebysig static void MixedObjectAndDictInitializer() cil managed + { + // Code size 130 (0x82) + .maxstack 6 + .locals init (int32 V_0, + int32 V_1, + string V_2) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: dup + IL_000b: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0010: ldc.i4.0 + IL_0011: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0016: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::GetInt() + IL_001b: stloc.0 + IL_001c: dup + IL_001d: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0022: ldloc.0 + IL_0023: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) + IL_0028: ldc.i4.1 + IL_0029: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_002e: dup + IL_002f: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0034: ldloc.0 + IL_0035: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) + IL_003a: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_003f: ldc.i4.0 + IL_0040: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0045: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::GetInt() + IL_004a: stloc.1 + IL_004b: call string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::GetString() + IL_0050: stloc.2 + IL_0051: dup + IL_0052: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0057: ldloc.0 + IL_0058: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) + IL_005d: ldloc.1 + IL_005e: ldloc.2 + IL_005f: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0064: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + string, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + IL_0069: dup + IL_006a: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_006f: ldloc.0 + IL_0070: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) + IL_0075: ldc.i4.2 + IL_0076: ldnull + IL_0077: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + IL_007c: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0081: ret + } // end of method InitializerTests::MixedObjectAndDictInitializer + + .method public hidebysig static void ObjectInitializerWithInitializationOfDeeplyNestedObjects() cil managed + { + // Code size 77 (0x4d) + .maxstack 4 + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: dup + IL_000b: ldc.i4.1 + IL_000c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0011: dup + IL_0012: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0017: ldc.i4.0 + IL_0018: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_001d: dup + IL_001e: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0023: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0028: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_002d: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0032: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0037: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_003c: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0041: ldc.i4.1 + IL_0042: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0047: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_004c: ret + } // end of method InitializerTests::ObjectInitializerWithInitializationOfDeeplyNestedObjects + + .method public hidebysig static void CollectionInitializerInsideObjectInitializers() cil managed + { + // Code size 53 (0x35) + .maxstack 8 + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: dup + IL_000b: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0010: dup + IL_0011: ldc.i4.0 + IL_0012: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0017: dup + IL_0018: ldc.i4.1 + IL_0019: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_001e: dup + IL_001f: callvirt instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + IL_0024: ldc.i4.0 + IL_0025: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002a: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + IL_002f: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0034: ret + } // end of method InitializerTests::CollectionInitializerInsideObjectInitializers + + .method public hidebysig static void NotAStructInitializer_DefaultConstructor() cil managed + { + // Code size 41 (0x29) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: ldloca.s V_0 + IL_0002: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0008: ldloca.s V_0 + IL_000a: ldc.i4.1 + IL_000b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0010: ldloca.s V_0 + IL_0012: ldc.i4.2 + IL_0013: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0018: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_001d: ldloc.0 + IL_001e: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0023: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0028: ret + } // end of method InitializerTests::NotAStructInitializer_DefaultConstructor + + .method public hidebysig static void StructInitializer_DefaultConstructor() cil managed + { + // Code size 41 (0x29) + .maxstack 3 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: ldloca.s V_0 + IL_0007: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_000d: ldloca.s V_0 + IL_000f: ldc.i4.1 + IL_0010: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0015: ldloca.s V_0 + IL_0017: ldc.i4.2 + IL_0018: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_001d: ldloc.0 + IL_001e: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0023: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0028: ret + } // end of method InitializerTests::StructInitializer_DefaultConstructor + + .method public hidebysig static void NotAStructInitializer_ExplicitConstructor() cil managed + { + // Code size 41 (0x29) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: ldloca.s V_0 + IL_0002: ldc.i4.0 + IL_0003: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::.ctor(int32) + IL_0008: ldloca.s V_0 + IL_000a: ldc.i4.1 + IL_000b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0010: ldloca.s V_0 + IL_0012: ldc.i4.2 + IL_0013: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0018: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_001d: ldloc.0 + IL_001e: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0023: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0028: ret + } // end of method InitializerTests::NotAStructInitializer_ExplicitConstructor + + .method public hidebysig static void StructInitializer_ExplicitConstructor() cil managed + { + // Code size 41 (0x29) + .maxstack 3 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: ldloca.s V_0 + IL_0007: ldc.i4.0 + IL_0008: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::.ctor(int32) + IL_000d: ldloca.s V_0 + IL_000f: ldc.i4.1 + IL_0010: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0015: ldloca.s V_0 + IL_0017: ldc.i4.2 + IL_0018: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_001d: ldloc.0 + IL_001e: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0023: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0028: ret + } // end of method InitializerTests::StructInitializer_ExplicitConstructor + + .method public hidebysig static void StructInitializerWithInitializationOfNestedObjects() cil managed + { + // Code size 74 (0x4a) + .maxstack 3 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: ldloca.s V_0 + IL_0007: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_000d: ldloca.s V_0 + IL_000f: call instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + IL_0014: ldc.i4.0 + IL_0015: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_001a: ldloca.s V_0 + IL_001c: call instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + IL_0021: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0026: ldc.i4.0 + IL_0027: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002c: ldloca.s V_0 + IL_002e: call instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + IL_0033: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0038: ldc.i4.1 + IL_0039: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_003e: ldloc.0 + IL_003f: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0044: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0049: ret + } // end of method InitializerTests::StructInitializerWithInitializationOfNestedObjects + + .method public hidebysig static void StructInitializerWithinObjectInitializer() cil managed + { + // Code size 47 (0x2f) + .maxstack 5 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000a: dup + IL_000b: ldloca.s V_0 + IL_000d: ldc.i4.2 + IL_000e: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::.ctor(int32) + IL_0013: ldloca.s V_0 + IL_0015: ldc.i4.1 + IL_0016: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_001b: ldloca.s V_0 + IL_001d: ldc.i4.2 + IL_001e: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0023: ldloc.0 + IL_0024: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData) + IL_0029: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002e: ret + } // end of method InitializerTests::StructInitializerWithinObjectInitializer + + .method public hidebysig static void Bug270_NestedInitialisers() cil managed + { + // Code size 115 (0x73) + .maxstack 8 + .locals init (class [mscorlib]System.Globalization.NumberFormatInfo[] V_0) + IL_0000: ldnull + IL_0001: stloc.0 + IL_0002: ldc.i4.0 + IL_0003: ldnull + IL_0004: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Bug270_NestedInitialisers() + IL_000a: newobj instance void [mscorlib]System.Threading.ThreadStart::.ctor(object, + native int) + IL_000f: newobj instance void [mscorlib]System.Threading.Thread::.ctor(class [mscorlib]System.Threading.ThreadStart) + IL_0014: dup + IL_0015: ldc.i4.1 + IL_0016: callvirt instance void [mscorlib]System.Threading.Thread::set_Priority(valuetype [mscorlib]System.Threading.ThreadPriority) + IL_001b: dup + IL_001c: ldc.i4.0 + IL_001d: newobj instance void [mscorlib]System.Globalization.CultureInfo::.ctor(int32) + IL_0022: dup + IL_0023: newobj instance void [mscorlib]System.Globalization.DateTimeFormatInfo::.ctor() + IL_0028: dup + IL_0029: ldstr "ddmmyy" + IL_002e: callvirt instance void [mscorlib]System.Globalization.DateTimeFormatInfo::set_ShortDatePattern(string) + IL_0033: callvirt instance void [mscorlib]System.Globalization.CultureInfo::set_DateTimeFormat(class [mscorlib]System.Globalization.DateTimeFormatInfo) + IL_0038: dup + IL_0039: ldloc.0 + IL_003a: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__40_0' + IL_003f: dup + IL_0040: brtrue.s IL_0059 + + IL_0042: pop + IL_0043: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9' + IL_0048: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'b__40_0'(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_004e: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0053: dup + IL_0054: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__40_0' + IL_0059: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, + class [mscorlib]System.Func`2) + IL_005e: call !!0 [System.Core]System.Linq.Enumerable::First(class [mscorlib]System.Collections.Generic.IEnumerable`1) + IL_0063: callvirt instance void [mscorlib]System.Globalization.CultureInfo::set_NumberFormat(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_0068: callvirt instance void [mscorlib]System.Threading.Thread::set_CurrentCulture(class [mscorlib]System.Globalization.CultureInfo) + IL_006d: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::TestCall(int32, + class [mscorlib]System.Threading.Thread) + IL_0072: ret + } // end of method InitializerTests::Bug270_NestedInitialisers + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il index 5db37abe9..d25f8725e 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il @@ -10,6 +10,11 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } +.assembly extern System.Core +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} .assembly InitializerTests { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) @@ -25,14 +30,14 @@ .ver 0:0:0:0 } .module InitializerTests.dll -// MVID: {7000C1D7-C4EC-4376-B053-4BE74428CE7A} +// MVID: {EA222E3F-8F60-413B-AF03-0814FF05742B} .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: 0x005E0000 +// Image base: 0x00C80000 // =============== CLASS MEMBERS DECLARATION =================== @@ -81,6 +86,442 @@ } // end of class S + .class auto ansi sealed nested private MyEnum + extends [mscorlib]System.Enum + { + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum a = int32(0x00000000) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum b = int32(0x00000001) + } // end of class MyEnum + + .class auto ansi sealed nested private MyEnum2 + extends [mscorlib]System.Enum + { + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum2 c = int32(0x00000000) + .field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum2 d = int32(0x00000001) + } // end of class MyEnum2 + + .class auto ansi nested private beforefieldinit Data + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = ( 01 00 04 49 74 65 6D 00 00 ) // ...Item.. + .field public class [mscorlib]System.Collections.Generic.List`1 FieldList + .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .field private class [mscorlib]System.Collections.Generic.List`1 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .field private class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method public hidebysig specialname + instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + get_a() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_a + + .method public hidebysig specialname + instance void set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'value') 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: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_a + + .method public hidebysig specialname + instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + get_b() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_b + + .method public hidebysig specialname + instance void set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'value') 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: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_b + + .method public hidebysig specialname + instance class [mscorlib]System.Collections.Generic.List`1 + get_PropertyList() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_PropertyList + + .method public hidebysig specialname + instance void set_PropertyList(class [mscorlib]System.Collections.Generic.List`1 'value') 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: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_PropertyList + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_MoreData() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_MoreData + + .method public hidebysig specialname + instance void set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') 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: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_MoreData + + .method public hidebysig specialname + instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + get_NestedStruct() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0006: ret + } // end of method Data::get_NestedStruct + + .method public hidebysig specialname + instance void set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData 'value') 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: stfld valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::'k__BackingField' + IL_0007: ret + } // end of method Data::set_NestedStruct + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_Item(int32 i) cil managed + { + // Code size 7 (0x7) + .maxstack 1 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: stloc.0 + IL_0003: br.s IL_0005 + + IL_0005: ldloc.0 + IL_0006: ret + } // end of method Data::get_Item + + .method public hidebysig specialname + instance void set_Item(int32 i, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Data::set_Item + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_Item(int32 i, + string j) cil managed + { + // Code size 7 (0x7) + .maxstack 1 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: stloc.0 + IL_0003: br.s IL_0005 + + IL_0005: ldloc.0 + IL_0006: ret + } // end of method Data::get_Item + + .method public hidebysig specialname + instance void set_Item(int32 i, + string j, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Data::set_Item + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 19 (0x13) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0006: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_000b: ldarg.0 + IL_000c: call instance void [mscorlib]System.Object::.ctor() + IL_0011: nop + IL_0012: ret + } // end of method Data::.ctor + + .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + a() + { + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_a() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + } // end of property Data::a + .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum + b() + { + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_b() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + } // end of property Data::b + .property instance class [mscorlib]System.Collections.Generic.List`1 + PropertyList() + { + .get instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_PropertyList(class [mscorlib]System.Collections.Generic.List`1) + } // end of property Data::PropertyList + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + MoreData() + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property Data::MoreData + .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + NestedStruct() + { + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_NestedStruct() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData) + } // end of property Data::NestedStruct + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + Item(int32) + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property Data::Item + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + Item(int32, + string) + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32, + string) + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + string, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property Data::Item + } // end of class Data + + .class sequential ansi sealed nested private beforefieldinit StructData + extends [mscorlib]System.ValueType + { + .field public int32 Field + .field private int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .field private class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method public hidebysig specialname + instance int32 get_Property() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0006: ret + } // end of method StructData::get_Property + + .method public hidebysig specialname + instance void set_Property(int32 'value') 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: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0007: ret + } // end of method StructData::set_Property + + .method public hidebysig specialname + instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + get_MoreData() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0006: ret + } // end of method StructData::get_MoreData + + .method public hidebysig specialname + instance void set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data 'value') 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: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::'k__BackingField' + IL_0007: ret + } // end of method StructData::set_MoreData + + .method public hidebysig specialname rtspecialname + instance void .ctor(int32 initialValue) cil managed + { + // Code size 24 (0x18) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_000f: ldarg.0 + IL_0010: ldarg.1 + IL_0011: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0016: nop + IL_0017: ret + } // end of method StructData::.ctor + + .property instance int32 Property() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_Property() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + } // end of property StructData::Property + .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data + MoreData() + { + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + } // end of property StructData::MoreData + } // end of class StructData + + .class auto ansi serializable sealed nested private beforefieldinit '<>c' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' '<>9' + .field public static class [mscorlib]System.Func`2 '<>9__40_0' + .method private hidebysig specialname rtspecialname static + void .cctor() cil managed + { + // Code size 11 (0xb) + .maxstack 8 + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::.ctor() + IL_0005: stsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9' + IL_000a: ret + } // end of method '<>c'::.cctor + + .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 '<>c'::.ctor + + .method assembly hidebysig instance bool + 'b__40_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed + { + // Code size 17 (0x11) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: callvirt instance string [mscorlib]System.Globalization.NumberFormatInfo::get_CurrencySymbol() + IL_0006: ldstr "$" + IL_000b: call bool [mscorlib]System.String::op_Equality(string, + string) + IL_0010: ret + } // end of method '<>c'::'b__40_0' + + } // end of class '<>c' + + .method private hidebysig static void X(object a, + object b) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method InitializerTests::X + + .method private hidebysig static object + Y() cil managed + { + // Code size 7 (0x7) + .maxstack 1 + .locals init (object V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: stloc.0 + IL_0003: br.s IL_0005 + + IL_0005: ldloc.0 + IL_0006: ret + } // end of method InitializerTests::Y + + .method public hidebysig static void TestCall(int32 a, + class [mscorlib]System.Threading.Thread thread) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method InitializerTests::TestCall + .method public hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C TestCall(int32 a, class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/C c) cil managed @@ -254,6 +695,704 @@ IL_002b: ret } // end of method InitializerTests::Test4 + .method public hidebysig static void CollectionInitializerList() cil managed + { + // Code size 42 (0x2a) + .maxstack 8 + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_000b: dup + IL_000c: ldc.i4.1 + IL_000d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0012: nop + IL_0013: dup + IL_0014: ldc.i4.2 + IL_0015: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001a: nop + IL_001b: dup + IL_001c: ldc.i4.3 + IL_001d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0022: nop + IL_0023: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0028: nop + IL_0029: ret + } // end of method InitializerTests::CollectionInitializerList + + .method public hidebysig static object + RecursiveCollectionInitializer() cil managed + { + // Code size 21 (0x15) + .maxstack 2 + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, + object V_1) + IL_0000: nop + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldloc.0 + IL_0009: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_000e: nop + IL_000f: ldloc.0 + IL_0010: stloc.1 + IL_0011: br.s IL_0013 + + IL_0013: ldloc.1 + IL_0014: ret + } // end of method InitializerTests::RecursiveCollectionInitializer + + .method public hidebysig static void CollectionInitializerDictionary() cil managed + { + // Code size 57 (0x39) + .maxstack 8 + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor() + IL_000b: dup + IL_000c: ldstr "First" + IL_0011: ldc.i4.1 + IL_0012: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0017: nop + IL_0018: dup + IL_0019: ldstr "Second" + IL_001e: ldc.i4.2 + IL_001f: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0024: nop + IL_0025: dup + IL_0026: ldstr "Third" + IL_002b: ldc.i4.3 + IL_002c: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0031: nop + IL_0032: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0037: nop + IL_0038: ret + } // end of method InitializerTests::CollectionInitializerDictionary + + .method public hidebysig static void CollectionInitializerDictionaryWithEnumTypes() cil managed + { + // Code size 36 (0x24) + .maxstack 8 + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor() + IL_000b: dup + IL_000c: ldc.i4.0 + IL_000d: ldc.i4.0 + IL_000e: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_0013: nop + IL_0014: dup + IL_0015: ldc.i4.1 + IL_0016: ldc.i4.1 + IL_0017: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + !1) + IL_001c: nop + IL_001d: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0022: nop + IL_0023: ret + } // end of method InitializerTests::CollectionInitializerDictionaryWithEnumTypes + + .method public hidebysig static void NotACollectionInitializer() cil managed + { + // Code size 44 (0x2c) + .maxstack 2 + .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0) + IL_0000: nop + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldc.i4.1 + IL_0009: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_000e: nop + IL_000f: ldloc.0 + IL_0010: ldc.i4.2 + IL_0011: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0016: nop + IL_0017: ldloc.0 + IL_0018: ldc.i4.3 + IL_0019: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001e: nop + IL_001f: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0024: ldloc.0 + IL_0025: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002a: nop + IL_002b: ret + } // end of method InitializerTests::NotACollectionInitializer + + .method public hidebysig static void ObjectInitializer() cil managed + { + // Code size 26 (0x1a) + .maxstack 8 + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: dup + IL_000c: ldc.i4.0 + IL_000d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0012: nop + IL_0013: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0018: nop + IL_0019: ret + } // end of method InitializerTests::ObjectInitializer + + .method public hidebysig static void NotAnObjectInitializer() cil managed + { + // Code size 28 (0x1c) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: nop + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldc.i4.0 + IL_0009: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_000e: nop + IL_000f: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0014: ldloc.0 + IL_0015: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_001a: nop + IL_001b: ret + } // end of method InitializerTests::NotAnObjectInitializer + + .method public hidebysig static void ObjectInitializerAssignCollectionToField() cil managed + { + // Code size 53 (0x35) + .maxstack 8 + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: dup + IL_000c: ldc.i4.0 + IL_000d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0012: nop + IL_0013: dup + IL_0014: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0019: dup + IL_001a: ldc.i4.0 + IL_001b: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0020: nop + IL_0021: dup + IL_0022: ldc.i4.1 + IL_0023: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0028: nop + IL_0029: stfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_002e: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0033: nop + IL_0034: ret + } // end of method InitializerTests::ObjectInitializerAssignCollectionToField + + .method public hidebysig static void ObjectInitializerAddToCollectionInField() cil managed + { + // Code size 52 (0x34) + .maxstack 8 + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: dup + IL_000c: ldc.i4.0 + IL_000d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0012: nop + IL_0013: dup + IL_0014: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0019: ldc.i4.0 + IL_001a: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001f: nop + IL_0020: dup + IL_0021: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0026: ldc.i4.1 + IL_0027: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002c: nop + IL_002d: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0032: nop + IL_0033: ret + } // end of method InitializerTests::ObjectInitializerAddToCollectionInField + + .method public hidebysig static void ObjectInitializerAssignCollectionToProperty() cil managed + { + // Code size 54 (0x36) + .maxstack 8 + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: dup + IL_000c: ldc.i4.0 + IL_000d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0012: nop + IL_0013: dup + IL_0014: newobj instance void class [mscorlib]System.Collections.Generic.List`1::.ctor() + IL_0019: dup + IL_001a: ldc.i4.0 + IL_001b: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0020: nop + IL_0021: dup + IL_0022: ldc.i4.1 + IL_0023: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0028: nop + IL_0029: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_PropertyList(class [mscorlib]System.Collections.Generic.List`1) + IL_002e: nop + IL_002f: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0034: nop + IL_0035: ret + } // end of method InitializerTests::ObjectInitializerAssignCollectionToProperty + + .method public hidebysig static void ObjectInitializerAddToCollectionInProperty() cil managed + { + // Code size 52 (0x34) + .maxstack 8 + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: dup + IL_000c: ldc.i4.0 + IL_000d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0012: nop + IL_0013: dup + IL_0014: callvirt instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + IL_0019: ldc.i4.0 + IL_001a: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001f: nop + IL_0020: dup + IL_0021: callvirt instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + IL_0026: ldc.i4.1 + IL_0027: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002c: nop + IL_002d: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0032: nop + IL_0033: ret + } // end of method InitializerTests::ObjectInitializerAddToCollectionInProperty + + .method public hidebysig static void ObjectInitializerWithInitializationOfNestedObjects() cil managed + { + // Code size 49 (0x31) + .maxstack 8 + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: dup + IL_000c: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0011: ldc.i4.0 + IL_0012: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0017: nop + IL_0018: dup + IL_0019: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_001e: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0023: ldc.i4.1 + IL_0024: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0029: nop + IL_002a: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002f: nop + IL_0030: ret + } // end of method InitializerTests::ObjectInitializerWithInitializationOfNestedObjects + + .method private hidebysig static int32 + GetInt() cil managed + { + // Code size 7 (0x7) + .maxstack 1 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldc.i4.1 + IL_0002: stloc.0 + IL_0003: br.s IL_0005 + + IL_0005: ldloc.0 + IL_0006: ret + } // end of method InitializerTests::GetInt + + .method private hidebysig static string + GetString() cil managed + { + // Code size 11 (0xb) + .maxstack 1 + .locals init (string V_0) + IL_0000: nop + IL_0001: ldstr "Test" + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method InitializerTests::GetString + + .method public hidebysig static void SimpleDictInitializer() cil managed + { + // Code size 45 (0x2d) + .maxstack 8 + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: dup + IL_000c: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0011: ldc.i4.0 + IL_0012: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0017: nop + IL_0018: dup + IL_0019: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_001e: ldc.i4.2 + IL_001f: ldnull + IL_0020: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + IL_0025: nop + IL_0026: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002b: nop + IL_002c: ret + } // end of method InitializerTests::SimpleDictInitializer + + .method public hidebysig static void MixedObjectAndDictInitializer() cil managed + { + // Code size 137 (0x89) + .maxstack 6 + .locals init (int32 V_0, + int32 V_1, + string V_2) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: dup + IL_000c: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0011: ldc.i4.0 + IL_0012: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0017: nop + IL_0018: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::GetInt() + IL_001d: stloc.0 + IL_001e: dup + IL_001f: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0024: ldloc.0 + IL_0025: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) + IL_002a: ldc.i4.1 + IL_002b: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0030: nop + IL_0031: dup + IL_0032: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0037: ldloc.0 + IL_0038: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) + IL_003d: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0042: ldc.i4.0 + IL_0043: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0048: nop + IL_0049: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::GetInt() + IL_004e: stloc.1 + IL_004f: call string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::GetString() + IL_0054: stloc.2 + IL_0055: dup + IL_0056: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_005b: ldloc.0 + IL_005c: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) + IL_0061: ldloc.1 + IL_0062: ldloc.2 + IL_0063: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0068: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + string, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + IL_006d: nop + IL_006e: dup + IL_006f: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0074: ldloc.0 + IL_0075: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) + IL_007a: ldc.i4.2 + IL_007b: ldnull + IL_007c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + IL_0081: nop + IL_0082: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0087: nop + IL_0088: ret + } // end of method InitializerTests::MixedObjectAndDictInitializer + + .method public hidebysig static void ObjectInitializerWithInitializationOfDeeplyNestedObjects() cil managed + { + // Code size 82 (0x52) + .maxstack 4 + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: dup + IL_000c: ldc.i4.1 + IL_000d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0012: nop + IL_0013: dup + IL_0014: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0019: ldc.i4.0 + IL_001a: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_001f: nop + IL_0020: dup + IL_0021: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0026: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_002b: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0030: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0035: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_003a: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_003f: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() + IL_0044: ldc.i4.1 + IL_0045: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_004a: nop + IL_004b: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0050: nop + IL_0051: ret + } // end of method InitializerTests::ObjectInitializerWithInitializationOfDeeplyNestedObjects + + .method public hidebysig static void CollectionInitializerInsideObjectInitializers() cil managed + { + // Code size 59 (0x3b) + .maxstack 8 + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: dup + IL_000c: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0011: dup + IL_0012: ldc.i4.0 + IL_0013: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0018: nop + IL_0019: dup + IL_001a: ldc.i4.1 + IL_001b: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_0020: nop + IL_0021: dup + IL_0022: callvirt instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + IL_0027: ldc.i4.0 + IL_0028: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002d: nop + IL_002e: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + IL_0033: nop + IL_0034: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0039: nop + IL_003a: ret + } // end of method InitializerTests::CollectionInitializerInsideObjectInitializers + + .method public hidebysig static void NotAStructInitializer_DefaultConstructor() cil managed + { + // Code size 44 (0x2c) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: nop + IL_0001: ldloca.s V_0 + IL_0003: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0009: ldloca.s V_0 + IL_000b: ldc.i4.1 + IL_000c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0011: ldloca.s V_0 + IL_0013: ldc.i4.2 + IL_0014: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0019: nop + IL_001a: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_001f: ldloc.0 + IL_0020: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0025: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002a: nop + IL_002b: ret + } // end of method InitializerTests::NotAStructInitializer_DefaultConstructor + + .method public hidebysig static void StructInitializer_DefaultConstructor() cil managed + { + // Code size 44 (0x2c) + .maxstack 3 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: ldloca.s V_0 + IL_0008: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_000e: ldloca.s V_0 + IL_0010: ldc.i4.1 + IL_0011: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0016: ldloca.s V_0 + IL_0018: ldc.i4.2 + IL_0019: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_001e: nop + IL_001f: ldloc.0 + IL_0020: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0025: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002a: nop + IL_002b: ret + } // end of method InitializerTests::StructInitializer_DefaultConstructor + + .method public hidebysig static void NotAStructInitializer_ExplicitConstructor() cil managed + { + // Code size 44 (0x2c) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: nop + IL_0001: ldloca.s V_0 + IL_0003: ldc.i4.0 + IL_0004: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::.ctor(int32) + IL_0009: ldloca.s V_0 + IL_000b: ldc.i4.1 + IL_000c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0011: ldloca.s V_0 + IL_0013: ldc.i4.2 + IL_0014: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0019: nop + IL_001a: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_001f: ldloc.0 + IL_0020: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0025: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002a: nop + IL_002b: ret + } // end of method InitializerTests::NotAStructInitializer_ExplicitConstructor + + .method public hidebysig static void StructInitializer_ExplicitConstructor() cil managed + { + // Code size 44 (0x2c) + .maxstack 3 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: ldloca.s V_0 + IL_0008: ldc.i4.0 + IL_0009: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::.ctor(int32) + IL_000e: ldloca.s V_0 + IL_0010: ldc.i4.1 + IL_0011: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_0016: ldloca.s V_0 + IL_0018: ldc.i4.2 + IL_0019: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_001e: nop + IL_001f: ldloc.0 + IL_0020: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0025: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_002a: nop + IL_002b: ret + } // end of method InitializerTests::StructInitializer_ExplicitConstructor + + .method public hidebysig static void StructInitializerWithInitializationOfNestedObjects() cil managed + { + // Code size 79 (0x4f) + .maxstack 3 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: ldloca.s V_0 + IL_0008: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_000e: ldloca.s V_0 + IL_0010: call instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + IL_0015: ldc.i4.0 + IL_0016: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) + IL_001b: nop + IL_001c: ldloca.s V_0 + IL_001e: call instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + IL_0023: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_0028: ldc.i4.0 + IL_0029: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002e: nop + IL_002f: ldloca.s V_0 + IL_0031: call instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_MoreData() + IL_0036: ldfld class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::FieldList + IL_003b: ldc.i4.1 + IL_003c: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0041: nop + IL_0042: ldloc.0 + IL_0043: box ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData + IL_0048: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_004d: nop + IL_004e: ret + } // end of method InitializerTests::StructInitializerWithInitializationOfNestedObjects + + .method public hidebysig static void StructInitializerWithinObjectInitializer() cil managed + { + // Code size 51 (0x33) + .maxstack 5 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData V_0) + IL_0000: nop + IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_000b: dup + IL_000c: ldloca.s V_0 + IL_000e: ldc.i4.2 + IL_000f: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::.ctor(int32) + IL_0014: ldloca.s V_0 + IL_0016: ldc.i4.1 + IL_0017: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::Field + IL_001c: ldloca.s V_0 + IL_001e: ldc.i4.2 + IL_001f: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) + IL_0024: nop + IL_0025: ldloc.0 + IL_0026: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData) + IL_002b: nop + IL_002c: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0031: nop + IL_0032: ret + } // end of method InitializerTests::StructInitializerWithinObjectInitializer + + .method public hidebysig static void Bug270_NestedInitialisers() cil managed + { + // Code size 122 (0x7a) + .maxstack 8 + .locals init (class [mscorlib]System.Globalization.NumberFormatInfo[] V_0) + IL_0000: nop + IL_0001: ldnull + IL_0002: stloc.0 + IL_0003: ldc.i4.0 + IL_0004: ldnull + IL_0005: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Bug270_NestedInitialisers() + IL_000b: newobj instance void [mscorlib]System.Threading.ThreadStart::.ctor(object, + native int) + IL_0010: newobj instance void [mscorlib]System.Threading.Thread::.ctor(class [mscorlib]System.Threading.ThreadStart) + IL_0015: dup + IL_0016: ldc.i4.1 + IL_0017: callvirt instance void [mscorlib]System.Threading.Thread::set_Priority(valuetype [mscorlib]System.Threading.ThreadPriority) + IL_001c: nop + IL_001d: dup + IL_001e: ldc.i4.0 + IL_001f: newobj instance void [mscorlib]System.Globalization.CultureInfo::.ctor(int32) + IL_0024: dup + IL_0025: newobj instance void [mscorlib]System.Globalization.DateTimeFormatInfo::.ctor() + IL_002a: dup + IL_002b: ldstr "ddmmyy" + IL_0030: callvirt instance void [mscorlib]System.Globalization.DateTimeFormatInfo::set_ShortDatePattern(string) + IL_0035: nop + IL_0036: callvirt instance void [mscorlib]System.Globalization.CultureInfo::set_DateTimeFormat(class [mscorlib]System.Globalization.DateTimeFormatInfo) + IL_003b: nop + IL_003c: dup + IL_003d: ldloc.0 + IL_003e: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__40_0' + IL_0043: dup + IL_0044: brtrue.s IL_005d + + IL_0046: pop + IL_0047: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9' + IL_004c: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'b__40_0'(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_0052: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0057: dup + IL_0058: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__40_0' + IL_005d: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, + class [mscorlib]System.Func`2) + IL_0062: call !!0 [System.Core]System.Linq.Enumerable::First(class [mscorlib]System.Collections.Generic.IEnumerable`1) + IL_0067: callvirt instance void [mscorlib]System.Globalization.CultureInfo::set_NumberFormat(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_006c: nop + IL_006d: callvirt instance void [mscorlib]System.Threading.Thread::set_CurrentCulture(class [mscorlib]System.Globalization.CultureInfo) + IL_0072: nop + IL_0073: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::TestCall(int32, + class [mscorlib]System.Threading.Thread) + IL_0078: nop + IL_0079: ret + } // end of method InitializerTests::Bug270_NestedInitialisers + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { From e48dfb7cb29f83fd0371b7d6871086135f2d9a5d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 18 Oct 2017 09:22:17 +0200 Subject: [PATCH 164/190] Add ILStackWasEmpty flag to default.value --- .../ICSharpCode.Decompiler.csproj | 1 + ICSharpCode.Decompiler/IL/ILReader.cs | 4 ++- .../IL/Instructions/DefaultValue.cs | 33 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 ICSharpCode.Decompiler/IL/Instructions/DefaultValue.cs diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index a1e17edfd..c07e50946 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -273,6 +273,7 @@ + diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index 866fe7afd..3e84e95bb 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -1010,7 +1010,9 @@ namespace ICSharpCode.Decompiler.IL ILInstruction InitObj(ILInstruction target, IType type) { - return new StObj(target, new DefaultValue(type), type); + var value = new DefaultValue(type); + value.ILStackWasEmpty = currentStack.IsEmpty; + return new StObj(target, value, type); } private ILInstruction DecodeConstrainedCall() diff --git a/ICSharpCode.Decompiler/IL/Instructions/DefaultValue.cs b/ICSharpCode.Decompiler/IL/Instructions/DefaultValue.cs new file mode 100644 index 000000000..b8ecea156 --- /dev/null +++ b/ICSharpCode.Decompiler/IL/Instructions/DefaultValue.cs @@ -0,0 +1,33 @@ +// Copyright (c) 2017 Siegfried Pammer +// +// 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.Collections.Generic; +using System.Text; + +namespace ICSharpCode.Decompiler.IL +{ + partial class DefaultValue + { + /// + /// Gets whether the IL stack was empty at the point of this instruction. + /// (not counting the argument of the instruction itself) + /// + public bool ILStackWasEmpty; + } +} From 08dcead162917d086f9d865852b9e1c7c383c108 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 18 Oct 2017 09:23:22 +0200 Subject: [PATCH 165/190] Fix false positive in struct initializers with default.value init --- .../TestCases/Pretty/InitializerTests.cs | 14 ++++++++------ .../TransformCollectionAndObjectInitializers.cs | 7 +++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs index 63439bcb7..9a3b12ff4 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs @@ -338,7 +338,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty InitializerTests.X(InitializerTests.Y(), new Data { MoreData = { a = MyEnum.a, - [2] = (Data)null + [2] = null } }); } @@ -348,11 +348,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty InitializerTests.X(InitializerTests.Y(), new Data { MoreData = { a = MyEnum.a, - [GetInt()] = { + [InitializerTests.GetInt()] = { a = MyEnum.b, - FieldList = { MyEnum2.c }, - [GetInt(), GetString()] = new Data(), - [2] = (Data)null + FieldList = { + MyEnum2.c + }, + [InitializerTests.GetInt(), InitializerTests.GetString()] = new Data(), + [2] = null } } }); @@ -397,7 +399,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void NotAStructInitializer_DefaultConstructor() { - StructData structData = new StructData(); + StructData structData = default(StructData); structData.Field = 1; structData.Property = 2; InitializerTests.X(InitializerTests.Y(), structData); diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs index d927bb61f..7813a84fd 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs @@ -66,6 +66,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms instType = newObjInst.Method.DeclaringType; break; case DefaultValue defaultVal: + if (defaultVal.ILStackWasEmpty && v.Kind == VariableKind.Local && !context.Function.Method.IsConstructor) { + // on statement level (no other expressions on IL stack), + // prefer to keep local variables (but not stack slots), + // unless we are in a constructor (where inlining object initializers might be critical + // for the base ctor call) + return false; + } instType = defaultVal.Type; break; case Block existingInitializer: From 461e59bd3f983563f04321baba5ca1957bc59319 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 18 Oct 2017 10:40:20 +0200 Subject: [PATCH 166/190] Clean up and documentation --- ...ransformCollectionAndObjectInitializers.cs | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs index 7813a84fd..12f9db004 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs @@ -46,7 +46,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms ILInstruction inst = body.Instructions[pos]; // Match stloc(v, newobj) if (inst.MatchStLoc(out var v, out var initInst) && (v.Kind == VariableKind.Local || v.Kind == VariableKind.StackSlot)) { - Block initializerBlock = null; IType instType; switch (initInst) { case NewObj newObjInst: @@ -75,22 +74,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms } instType = defaultVal.Type; break; - case Block existingInitializer: - if (existingInitializer.Type == BlockType.CollectionInitializer || existingInitializer.Type == BlockType.ObjectInitializer) { - initializerBlock = existingInitializer; - var value = ((StLoc)initializerBlock.Instructions[0]).Value; - if (value is NewObj no) - instType = no.Method.DeclaringType; - else - instType = ((DefaultValue)value).Type; - break; - } - return false; default: return false; } int initializerItemsCount = 0; - var blockType = initializerBlock?.Type ?? BlockType.CollectionInitializer; + var blockType = BlockType.CollectionInitializer; possibleIndexVariables = new Dictionary(); currentPath = new List(); isCollection = false; @@ -104,24 +92,28 @@ namespace ICSharpCode.Decompiler.IL.Transforms && IsPartOfInitializer(body.Instructions, pos + initializerItemsCount + 1, v, instType, ref blockType)) { initializerItemsCount++; } + // Do not convert the statements into an initializer if there's an incompatible usage of the initializer variable + // directly after the possible initializer. if (IsMethodCallOnVariable(body.Instructions[pos + initializerItemsCount + 1], v)) return false; + // Calculate the correct number of statements inside the initializer: + // All index variables that were used in the initializer have Index set to -1. + // We fetch the first unused variable from the list and remove all instructions after its + // first usage (i.e. the init store) from the initializer. var index = possibleIndexVariables.Where(info => info.Value.Index > -1).Min(info => (int?)info.Value.Index); if (index != null) { initializerItemsCount = index.Value - pos - 1; } + // The initializer would be empty, there's nothing to do here. if (initializerItemsCount <= 0) return false; context.Step("CollectionOrObjectInitializer", inst); - ILVariable finalSlot; - if (initializerBlock == null) { - initializerBlock = new Block(blockType); - finalSlot = context.Function.RegisterVariable(VariableKind.InitializerTarget, v.Type); - initializerBlock.FinalInstruction = new LdLoc(finalSlot); - initializerBlock.Instructions.Add(new StLoc(finalSlot, initInst.Clone())); - } else { - finalSlot = ((LdLoc)initializerBlock.FinalInstruction).Variable; - } + // Create a new block and final slot (initializer target variable) + var initializerBlock = new Block(blockType); + ILVariable finalSlot = context.Function.RegisterVariable(VariableKind.InitializerTarget, v.Type); + initializerBlock.FinalInstruction = new LdLoc(finalSlot); + initializerBlock.Instructions.Add(new StLoc(finalSlot, initInst.Clone())); + // Move all instructions to the initializer block. for (int i = 1; i <= initializerItemsCount; i++) { switch (body.Instructions[i + pos]) { case CallInstruction call: @@ -171,6 +163,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms bool IsPartOfInitializer(InstructionCollection instructions, int pos, ILVariable target, IType rootType, ref BlockType blockType) { + // Include any stores to local variables that are single-assigned and do not reference the initializer-variable + // in the list of possible index variables. + // Index variables are used to implement dictionary initializers. if (instructions[pos] is StLoc stloc && stloc.Variable.Kind == VariableKind.Local && stloc.Variable.IsSingleDefinition) { if (stloc.Value.Descendants.OfType().Any(ld => ld.Variable == target && (ld is LdLoc || ld is LdLoca))) return false; @@ -241,7 +236,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms public override string ToString() => $"[{Member}, {Indices}]"; - public static (AccessPathKind Kind, List Path, List Values, ILVariable Target) GetAccessPath(ILInstruction instruction, IType rootType, Dictionary possibleIndexVariables = null) + public static (AccessPathKind Kind, List Path, List Values, ILVariable Target) GetAccessPath( + ILInstruction instruction, IType rootType, Dictionary possibleIndexVariables = null) { List path = new List(); ILVariable target = null; @@ -261,6 +257,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms var isGetter = property?.Getter == method; var indices = call.Arguments.Skip(1).Take(call.Arguments.Count - (isGetter ? 1 : 2)).ToArray(); if (possibleIndexVariables != null) { + // Mark all index variables as used foreach (var index in indices.OfType()) { if (possibleIndexVariables.TryGetValue(index.Variable, out var info)) possibleIndexVariables[index.Variable] = (-1, info.Value); From bec2f9da2b3bd0ab23d438a5e39e77d6fd5fae3a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 18 Oct 2017 10:50:46 +0200 Subject: [PATCH 167/190] Add event test case. --- .../TestCases/Pretty/InitializerTests.cs | 12 ++ .../TestCases/Pretty/InitializerTests.il | 166 ++++++++++++++++-- .../TestCases/Pretty/InitializerTests.opt.il | 148 ++++++++++++++-- .../Pretty/InitializerTests.opt.roslyn.il | 132 +++++++++++++- .../Pretty/InitializerTests.roslyn.il | 137 ++++++++++++++- 5 files changed, 543 insertions(+), 52 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs index 9a3b12ff4..e272fcd9c 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs @@ -16,6 +16,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -98,6 +99,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty set { } } + + public event EventHandler TestEvent; } private struct StructData @@ -266,6 +269,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty InitializerTests.X(InitializerTests.Y(), data); } + public static void NotAnObjectInitializerWithEvent() + { + Data data = new Data(); + data.TestEvent += delegate(object sender, EventArgs e) { + Console.WriteLine(); + }; + InitializerTests.X(InitializerTests.Y(), data); + } + public static void ObjectInitializerAssignCollectionToField() { InitializerTests.X(InitializerTests.Y(), new Data { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il index 3e9c08183..04af92cf4 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il @@ -15,25 +15,25 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly xws4p1nr +.assembly n0iwoj0v { + .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .permissionset reqmin = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module xws4p1nr.dll -// MVID: {D353AAAB-C54F-4C62-88DC-E9FF995570BA} +.module n0iwoj0v.dll +// MVID: {04AC1961-FA71-4E8B-A77B-45FF217A617C} .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: 0x002F0000 +// Image base: 0x009A0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -102,6 +102,7 @@ { .custom instance void [mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = ( 01 00 04 49 74 65 6D 00 00 ) // ...Item.. .field public class [mscorlib]System.Collections.Generic.List`1 FieldList + .field private class [mscorlib]System.EventHandler TestEvent .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'k__BackingField' .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'k__BackingField' @@ -311,6 +312,86 @@ IL_0001: ret } // end of method Data::set_Item + .method public hidebysig specialname + instance void add_TestEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + // Code size 48 (0x30) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2, + bool V_3) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Combine(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: ceq + IL_0028: ldc.i4.0 + IL_0029: ceq + IL_002b: stloc.3 + IL_002c: ldloc.3 + IL_002d: brtrue.s IL_0007 + + IL_002f: ret + } // end of method Data::add_TestEvent + + .method public hidebysig specialname + instance void remove_TestEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + // Code size 48 (0x30) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2, + bool V_3) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Remove(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: ceq + IL_0028: ldc.i4.0 + IL_0029: ceq + IL_002b: stloc.3 + IL_002c: ldloc.3 + IL_002d: brtrue.s IL_0007 + + IL_002f: ret + } // end of method Data::remove_TestEvent + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -325,6 +406,11 @@ IL_0012: ret } // end of method Data::.ctor + .event [mscorlib]System.EventHandler TestEvent + { + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::remove_TestEvent(class [mscorlib]System.EventHandler) + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::add_TestEvent(class [mscorlib]System.EventHandler) + } // end of event Data::TestEvent .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum a() { @@ -334,33 +420,33 @@ .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum b() { - .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_b() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) } // end of property Data::b .property instance class [mscorlib]System.Collections.Generic.List`1 PropertyList() { - .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_PropertyList(class [mscorlib]System.Collections.Generic.List`1) .get instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_PropertyList(class [mscorlib]System.Collections.Generic.List`1) } // end of property Data::PropertyList .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data MoreData() { - .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() } // end of property Data::MoreData .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData NestedStruct() { - .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_NestedStruct() .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData) + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_NestedStruct() } // end of property Data::NestedStruct .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data Item(int32) { - .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) } // end of property Data::Item .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data Item(int32, @@ -459,8 +545,8 @@ .property instance int32 Property() { - .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_Property() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) } // end of property StructData::Property .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data MoreData() @@ -470,7 +556,9 @@ } // end of property StructData::MoreData } // end of class StructData - .field private static class [mscorlib]System.Func`2 'CS$<>9__CachedAnonymousMethodDelegate1a' + .field private static class [mscorlib]System.EventHandler 'CS$<>9__CachedAnonymousMethodDelegate8' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private static class [mscorlib]System.Func`2 'CS$<>9__CachedAnonymousMethodDelegate1c' .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .method private hidebysig static void X(object a, object b) cil managed @@ -867,6 +955,37 @@ IL_001b: ret } // end of method InitializerTests::NotAnObjectInitializer + .method public hidebysig static void NotAnObjectInitializerWithEvent() cil managed + { + // Code size 58 (0x3a) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: nop + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_000d: brtrue.s IL_0022 + + IL_000f: ldnull + IL_0010: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'b__7'(object, + class [mscorlib]System.EventArgs) + IL_0016: newobj instance void [mscorlib]System.EventHandler::.ctor(object, + native int) + IL_001b: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_0020: br.s IL_0022 + + IL_0022: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_0027: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::add_TestEvent(class [mscorlib]System.EventHandler) + IL_002c: nop + IL_002d: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0032: ldloc.0 + IL_0033: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0038: nop + IL_0039: ret + } // end of method InitializerTests::NotAnObjectInitializerWithEvent + .method public hidebysig static void ObjectInitializerAssignCollectionToField() cil managed { // Code size 57 (0x39) @@ -1329,17 +1448,17 @@ IL_003f: nop IL_0040: ldloc.2 IL_0041: ldloc.0 - IL_0042: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1a' + IL_0042: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1c' IL_0047: brtrue.s IL_005c IL_0049: ldnull - IL_004a: ldftn bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'b__19'(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_004a: ldftn bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'b__1b'(class [mscorlib]System.Globalization.NumberFormatInfo) IL_0050: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) - IL_0055: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1a' + IL_0055: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1c' IL_005a: br.s IL_005c - IL_005c: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1a' + IL_005c: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1c' IL_0061: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, class [mscorlib]System.Func`2) IL_0066: call !!0 [System.Core]System.Linq.Enumerable::First(class [mscorlib]System.Collections.Generic.IEnumerable`1) @@ -1365,7 +1484,18 @@ IL_0006: ret } // end of method InitializerTests::.ctor - .method private hidebysig static bool 'b__19'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed + .method private hidebysig static void 'b__7'(object sender, + class [mscorlib]System.EventArgs e) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: call void [mscorlib]System.Console::WriteLine() + IL_0005: nop + IL_0006: ret + } // end of method InitializerTests::'b__7' + + .method private hidebysig static bool 'b__1b'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) // Code size 21 (0x15) @@ -1381,7 +1511,7 @@ IL_0013: ldloc.0 IL_0014: ret - } // end of method InitializerTests::'b__19' + } // end of method InitializerTests::'b__1b' } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il index f7dcef8e8..bf86fbc0c 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il @@ -15,25 +15,25 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly '3csuofts' +.assembly mo2wq1js { + .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .permissionset reqmin = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module '3csuofts.dll' -// MVID: {F78A061E-BAE5-4B9C-AFCF-4B60D826C849} +.module mo2wq1js.dll +// MVID: {99F5978B-D68E-4578-9D8F-7D47C1F63A30} .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: 0x00D80000 +// Image base: 0x027A0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -101,6 +101,7 @@ { .custom instance void [mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = ( 01 00 04 49 74 65 6D 00 00 ) // ...Item.. .field public class [mscorlib]System.Collections.Generic.List`1 FieldList + .field private class [mscorlib]System.EventHandler TestEvent .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'k__BackingField' .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum 'k__BackingField' @@ -271,6 +272,74 @@ IL_0000: ret } // end of method Data::set_Item + .method public hidebysig specialname + instance void add_TestEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + // Code size 41 (0x29) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Combine(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + + IL_0028: ret + } // end of method Data::add_TestEvent + + .method public hidebysig specialname + instance void remove_TestEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + // Code size 41 (0x29) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Remove(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + + IL_0028: ret + } // end of method Data::remove_TestEvent + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -284,6 +353,11 @@ IL_0011: ret } // end of method Data::.ctor + .event [mscorlib]System.EventHandler TestEvent + { + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::remove_TestEvent(class [mscorlib]System.EventHandler) + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::add_TestEvent(class [mscorlib]System.EventHandler) + } // end of event Data::TestEvent .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum a() { @@ -293,33 +367,33 @@ .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum b() { - .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_b() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_b(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum) } // end of property Data::b .property instance class [mscorlib]System.Collections.Generic.List`1 PropertyList() { - .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_PropertyList(class [mscorlib]System.Collections.Generic.List`1) .get instance class [mscorlib]System.Collections.Generic.List`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_PropertyList() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_PropertyList(class [mscorlib]System.Collections.Generic.List`1) } // end of property Data::PropertyList .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data MoreData() { - .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_MoreData() } // end of property Data::MoreData .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData NestedStruct() { - .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_NestedStruct() .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_NestedStruct(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData) + .get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_NestedStruct() } // end of property Data::NestedStruct .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data Item(int32) { - .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::set_Item(int32, class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data) + .get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::get_Item(int32) } // end of property Data::Item .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data Item(int32, @@ -406,8 +480,8 @@ .property instance int32 Property() { - .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::get_Property() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData::set_Property(int32) } // end of property StructData::Property .property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data MoreData() @@ -417,7 +491,9 @@ } // end of property StructData::MoreData } // end of class StructData - .field private static class [mscorlib]System.Func`2 'CS$<>9__CachedAnonymousMethodDelegate1a' + .field private static class [mscorlib]System.EventHandler 'CS$<>9__CachedAnonymousMethodDelegate8' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private static class [mscorlib]System.Func`2 'CS$<>9__CachedAnonymousMethodDelegate1c' .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .method private hidebysig static void X(object a, object b) cil managed @@ -730,6 +806,32 @@ IL_0018: ret } // end of method InitializerTests::NotAnObjectInitializer + .method public hidebysig static void NotAnObjectInitializerWithEvent() cil managed + { + // Code size 53 (0x35) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_000c: brtrue.s IL_001f + + IL_000e: ldnull + IL_000f: ldftn void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'b__7'(object, + class [mscorlib]System.EventArgs) + IL_0015: newobj instance void [mscorlib]System.EventHandler::.ctor(object, + native int) + IL_001a: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_001f: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate8' + IL_0024: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::add_TestEvent(class [mscorlib]System.EventHandler) + IL_0029: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_002e: ldloc.0 + IL_002f: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0034: ret + } // end of method InitializerTests::NotAnObjectInitializerWithEvent + .method public hidebysig static void ObjectInitializerAssignCollectionToField() cil managed { // Code size 52 (0x34) @@ -1116,15 +1218,15 @@ IL_0037: callvirt instance void [mscorlib]System.Globalization.CultureInfo::set_DateTimeFormat(class [mscorlib]System.Globalization.DateTimeFormatInfo) IL_003c: ldloc.2 IL_003d: ldloc.0 - IL_003e: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1a' + IL_003e: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1c' IL_0043: brtrue.s IL_0056 IL_0045: ldnull - IL_0046: ldftn bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'b__19'(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_0046: ldftn bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'b__1b'(class [mscorlib]System.Globalization.NumberFormatInfo) IL_004c: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) - IL_0051: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1a' - IL_0056: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1a' + IL_0051: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1c' + IL_0056: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::'CS$<>9__CachedAnonymousMethodDelegate1c' IL_005b: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, class [mscorlib]System.Func`2) IL_0060: call !!0 [System.Core]System.Linq.Enumerable::First(class [mscorlib]System.Collections.Generic.IEnumerable`1) @@ -1147,7 +1249,17 @@ IL_0006: ret } // end of method InitializerTests::.ctor - .method private hidebysig static bool 'b__19'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed + .method private hidebysig static void 'b__7'(object sender, + class [mscorlib]System.EventArgs e) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 6 (0x6) + .maxstack 8 + IL_0000: call void [mscorlib]System.Console::WriteLine() + IL_0005: ret + } // end of method InitializerTests::'b__7' + + .method private hidebysig static bool 'b__1b'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) // Code size 17 (0x11) @@ -1158,7 +1270,7 @@ IL_000b: call bool [mscorlib]System.String::op_Equality(string, string) IL_0010: ret - } // end of method InitializerTests::'b__19' + } // end of method InitializerTests::'b__1b' } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il index 0f0385cd5..22e3c0319 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il @@ -30,14 +30,14 @@ .ver 0:0:0:0 } .module InitializerTests.dll -// MVID: {4B0BA9B1-521C-4C45-A2B8-8774D5BE797E} +// MVID: {1A200C9E-AB38-4402-A1D6-E7C3307A45E2} .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: 0x01500000 +// Image base: 0x02C80000 // =============== CLASS MEMBERS DECLARATION =================== @@ -115,6 +115,8 @@ .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData 'k__BackingField' .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private class [mscorlib]System.EventHandler TestEvent + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .method public hidebysig specialname instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum get_a() cil managed @@ -275,6 +277,76 @@ IL_0000: ret } // end of method Data::set_Item + .method public hidebysig specialname + instance void add_TestEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 41 (0x29) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Combine(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + + IL_0028: ret + } // end of method Data::add_TestEvent + + .method public hidebysig specialname + instance void remove_TestEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 41 (0x29) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Remove(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + + IL_0028: ret + } // end of method Data::remove_TestEvent + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -288,6 +360,11 @@ IL_0011: ret } // end of method Data::.ctor + .event [mscorlib]System.EventHandler TestEvent + { + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::add_TestEvent(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::remove_TestEvent(class [mscorlib]System.EventHandler) + } // end of event Data::TestEvent .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum a() { @@ -426,7 +503,8 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' '<>9' - .field public static class [mscorlib]System.Func`2 '<>9__40_0' + .field public static class [mscorlib]System.EventHandler '<>9__23_0' + .field public static class [mscorlib]System.Func`2 '<>9__41_0' .method private hidebysig specialname rtspecialname static void .cctor() cil managed { @@ -447,8 +525,18 @@ IL_0006: ret } // end of method '<>c'::.ctor + .method assembly hidebysig instance void + 'b__23_0'(object sender, + class [mscorlib]System.EventArgs e) cil managed + { + // Code size 6 (0x6) + .maxstack 8 + IL_0000: call void [mscorlib]System.Console::WriteLine() + IL_0005: ret + } // end of method '<>c'::'b__23_0' + .method assembly hidebysig instance bool - 'b__40_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed + 'b__41_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed { // Code size 17 (0x11) .maxstack 8 @@ -458,7 +546,7 @@ IL_000b: call bool [mscorlib]System.String::op_Equality(string, string) IL_0010: ret - } // end of method '<>c'::'b__40_0' + } // end of method '<>c'::'b__41_0' } // end of class '<>c' @@ -737,6 +825,34 @@ IL_0018: ret } // end of method InitializerTests::NotAnObjectInitializer + .method public hidebysig static void NotAnObjectInitializerWithEvent() cil managed + { + // Code size 55 (0x37) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__23_0' + IL_000c: dup + IL_000d: brtrue.s IL_0026 + + IL_000f: pop + IL_0010: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9' + IL_0015: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'b__23_0'(object, + class [mscorlib]System.EventArgs) + IL_001b: newobj instance void [mscorlib]System.EventHandler::.ctor(object, + native int) + IL_0020: dup + IL_0021: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__23_0' + IL_0026: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::add_TestEvent(class [mscorlib]System.EventHandler) + IL_002b: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0030: ldloc.0 + IL_0031: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0036: ret + } // end of method InitializerTests::NotAnObjectInitializerWithEvent + .method public hidebysig static void ObjectInitializerAssignCollectionToField() cil managed { // Code size 48 (0x30) @@ -1159,17 +1275,17 @@ IL_0033: callvirt instance void [mscorlib]System.Globalization.CultureInfo::set_DateTimeFormat(class [mscorlib]System.Globalization.DateTimeFormatInfo) IL_0038: dup IL_0039: ldloc.0 - IL_003a: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__40_0' + IL_003a: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__41_0' IL_003f: dup IL_0040: brtrue.s IL_0059 IL_0042: pop IL_0043: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9' - IL_0048: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'b__40_0'(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_0048: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'b__41_0'(class [mscorlib]System.Globalization.NumberFormatInfo) IL_004e: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_0053: dup - IL_0054: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__40_0' + IL_0054: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__41_0' IL_0059: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, class [mscorlib]System.Func`2) IL_005e: call !!0 [System.Core]System.Linq.Enumerable::First(class [mscorlib]System.Collections.Generic.IEnumerable`1) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il index d25f8725e..69b897be6 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il @@ -30,14 +30,14 @@ .ver 0:0:0:0 } .module InitializerTests.dll -// MVID: {EA222E3F-8F60-413B-AF03-0814FF05742B} +// MVID: {764AEFFE-E491-413B-876B-B40EBE774D84} .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: 0x00C80000 +// Image base: 0x00FC0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -122,6 +122,9 @@ .field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/StructData 'k__BackingField' .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .field private class [mscorlib]System.EventHandler TestEvent + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) .method public hidebysig specialname instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum get_a() cil managed @@ -296,6 +299,76 @@ IL_0001: ret } // end of method Data::set_Item + .method public hidebysig specialname + instance void add_TestEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 41 (0x29) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Combine(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + + IL_0028: ret + } // end of method Data::add_TestEvent + + .method public hidebysig specialname + instance void remove_TestEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 41 (0x29) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Remove(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::TestEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + + IL_0028: ret + } // end of method Data::remove_TestEvent + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -310,6 +383,11 @@ IL_0012: ret } // end of method Data::.ctor + .event [mscorlib]System.EventHandler TestEvent + { + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::add_TestEvent(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::remove_TestEvent(class [mscorlib]System.EventHandler) + } // end of event Data::TestEvent .property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/MyEnum a() { @@ -452,7 +530,8 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' '<>9' - .field public static class [mscorlib]System.Func`2 '<>9__40_0' + .field public static class [mscorlib]System.EventHandler '<>9__23_0' + .field public static class [mscorlib]System.Func`2 '<>9__41_0' .method private hidebysig specialname rtspecialname static void .cctor() cil managed { @@ -474,8 +553,19 @@ IL_0007: ret } // end of method '<>c'::.ctor + .method assembly hidebysig instance void + 'b__23_0'(object sender, + class [mscorlib]System.EventArgs e) cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: call void [mscorlib]System.Console::WriteLine() + IL_0005: nop + IL_0006: ret + } // end of method '<>c'::'b__23_0' + .method assembly hidebysig instance bool - 'b__40_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed + 'b__41_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed { // Code size 17 (0x11) .maxstack 8 @@ -485,7 +575,7 @@ IL_000b: call bool [mscorlib]System.String::op_Equality(string, string) IL_0010: ret - } // end of method '<>c'::'b__40_0' + } // end of method '<>c'::'b__41_0' } // end of class '<>c' @@ -863,6 +953,37 @@ IL_001b: ret } // end of method InitializerTests::NotAnObjectInitializer + .method public hidebysig static void NotAnObjectInitializerWithEvent() cil managed + { + // Code size 58 (0x3a) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data V_0) + IL_0000: nop + IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::.ctor() + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__23_0' + IL_000d: dup + IL_000e: brtrue.s IL_0027 + + IL_0010: pop + IL_0011: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9' + IL_0016: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'b__23_0'(object, + class [mscorlib]System.EventArgs) + IL_001c: newobj instance void [mscorlib]System.EventHandler::.ctor(object, + native int) + IL_0021: dup + IL_0022: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__23_0' + IL_0027: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/Data::add_TestEvent(class [mscorlib]System.EventHandler) + IL_002c: nop + IL_002d: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::Y() + IL_0032: ldloc.0 + IL_0033: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests::X(object, + object) + IL_0038: nop + IL_0039: ret + } // end of method InitializerTests::NotAnObjectInitializerWithEvent + .method public hidebysig static void ObjectInitializerAssignCollectionToField() cil managed { // Code size 53 (0x35) @@ -1369,17 +1490,17 @@ IL_003b: nop IL_003c: dup IL_003d: ldloc.0 - IL_003e: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__40_0' + IL_003e: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__41_0' IL_0043: dup IL_0044: brtrue.s IL_005d IL_0046: pop IL_0047: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9' - IL_004c: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'b__40_0'(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_004c: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'b__41_0'(class [mscorlib]System.Globalization.NumberFormatInfo) IL_0052: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_0057: dup - IL_0058: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__40_0' + IL_0058: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__41_0' IL_005d: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, class [mscorlib]System.Func`2) IL_0062: call !!0 [System.Core]System.Linq.Enumerable::First(class [mscorlib]System.Collections.Generic.IEnumerable`1) From 7e9f60533b8aee19cdab94975264e5d3247e1f8f Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 18 Oct 2017 23:56:59 +0200 Subject: [PATCH 168/190] Use proposedNameForStoresFromNewObj only in case of stack slots. --- ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs index eea8dedae..1cbf92cee 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs @@ -196,7 +196,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms proposedName = proposedNameForLoads[0]; } } - if (string.IsNullOrEmpty(proposedName)) { + if (string.IsNullOrEmpty(proposedName) && variable.Kind == VariableKind.StackSlot) { var proposedNameForStoresFromNewObj = variable.StoreInstructions.OfType() .Select(expr => GetNameByType(GuessType(variable.Type, expr.Value, context))) .Except(currentFieldNames).ToList(); From 818a90af95f2f55c114fa87f726877959f7bec4e Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 19 Oct 2017 09:07:07 +0200 Subject: [PATCH 169/190] #918: CallBuilder: Add fix-up logic for lambda expressions with anonymous parameter types to ensure the correct overload is called after removing the 'implicit' call to 'new Nullable(T value)'. --- ICSharpCode.Decompiler/CSharp/CallBuilder.cs | 38 ++++++++++++++++++- .../CSharp/Resolver/LambdaResolveResult.cs | 2 +- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index 6fb6bc9f7..525758a73 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -143,10 +143,16 @@ namespace ICSharpCode.Decompiler.CSharp .WithILInstruction(inst) .WithRR(rr); } else { + if (IsUnambiguousCall(inst, target, method, Array.Empty(), arguments) != OverloadResolutionErrors.None) { for (int i = 0; i < arguments.Count; i++) { - if (!settings.AnonymousTypes || !expectedParameters[i].Type.ContainsAnonymousType()) + if (settings.AnonymousTypes && expectedParameters[i].Type.ContainsAnonymousType()) { + if (arguments[i].Expression is LambdaExpression lambda) { + ModifyReturnTypeOfLambda(lambda); + } + } else { arguments[i] = arguments[i].ConvertTo(expectedParameters[i].Type, expressionBuilder); + } } } return new ObjectCreateExpression(expressionBuilder.ConvertType(inst.Method.DeclaringType), arguments.SelectArray(arg => arg.Expression)) @@ -180,8 +186,13 @@ namespace ICSharpCode.Decompiler.CSharp if (!argumentsCasted) { argumentsCasted = true; for (int i = 0; i < arguments.Count; i++) { - if (!settings.AnonymousTypes || !expectedParameters[i].Type.ContainsAnonymousType()) + if (settings.AnonymousTypes && expectedParameters[i].Type.ContainsAnonymousType()) { + if (arguments[i].Expression is LambdaExpression lambda) { + ModifyReturnTypeOfLambda(lambda); + } + } else { arguments[i] = arguments[i].ConvertTo(expectedParameters[i].Type, expressionBuilder); + } } } else if (!targetCasted) { targetCasted = true; @@ -213,6 +224,29 @@ namespace ICSharpCode.Decompiler.CSharp } } + private void ModifyReturnTypeOfLambda(LambdaExpression lambda) + { + var resolveResult = (DecompiledLambdaResolveResult)lambda.GetResolveResult(); + if (lambda.Body is Expression exprBody) + lambda.Body = new TranslatedExpression(exprBody.Detach()).ConvertTo(resolveResult.ReturnType, expressionBuilder); + else + ModifyReturnStatementInsideLambda(resolveResult.ReturnType, lambda); + resolveResult.InferredReturnType = resolveResult.ReturnType; + } + + private void ModifyReturnStatementInsideLambda(IType returnType, AstNode parent) + { + foreach (var child in parent.Children) { + if (child is LambdaExpression || child is AnonymousMethodExpression) + continue; + if (child is ReturnStatement ret) { + ret.Expression = new TranslatedExpression(ret.Expression.Detach()).ConvertTo(returnType, expressionBuilder); + continue; + } + ModifyReturnStatementInsideLambda(returnType, child); + } + } + private bool IsDelegateEqualityComparison(IMethod method, IList arguments) { // Comparison on a delegate type is a C# builtin operator diff --git a/ICSharpCode.Decompiler/CSharp/Resolver/LambdaResolveResult.cs b/ICSharpCode.Decompiler/CSharp/Resolver/LambdaResolveResult.cs index e699e15d6..eb6e33475 100644 --- a/ICSharpCode.Decompiler/CSharp/Resolver/LambdaResolveResult.cs +++ b/ICSharpCode.Decompiler/CSharp/Resolver/LambdaResolveResult.cs @@ -109,7 +109,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver /// Can differ from ReturnType if a return statement /// performs an implicit conversion. /// - public readonly IType InferredReturnType; + public IType InferredReturnType; public DecompiledLambdaResolveResult(IL.ILFunction function, IType delegateType, From d783fc68efbe49e5dbba708ca55ddb5fd2eb261a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 19 Oct 2017 09:10:10 +0200 Subject: [PATCH 170/190] Fix #918: Conversion of bool literals to bool? not pretty --- .../CSharp/ExpressionBuilder.cs | 11 +++++-- .../CSharp/TranslatedExpression.cs | 30 ++++++++++++------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 7b8d4ef91..6a0a7d2f3 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -325,8 +325,15 @@ namespace ICSharpCode.Decompiler.CSharp internal ExpressionWithResolveResult GetDefaultValueExpression(IType type) { - var expr = type.IsReferenceType == true ? (Expression)new NullReferenceExpression() : new DefaultValueExpression(ConvertType(type)); - var constantType = type.IsReferenceType == true ? SpecialType.NullType : type; + Expression expr; + IType constantType; + if (type.IsReferenceType == true || type.IsKnownType(KnownTypeCode.NullableOfT)) { + expr = new NullReferenceExpression(); + constantType = SpecialType.NullType; + } else { + expr = new DefaultValueExpression(ConvertType(type)); + constantType = type; + } return expr.WithRR(new ConstantResolveResult(constantType, null)); } diff --git a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs index 3c1c86d84..34075fa46 100644 --- a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs @@ -173,16 +173,26 @@ namespace ICSharpCode.Decompiler.CSharp var type = this.Type; if (type.Equals(targetType)) { // Make explicit conversion implicit, if possible - if (allowImplicitConversion && ResolveResult is ConversionResolveResult conversion) { - if (Expression is CastExpression cast - && (type.IsKnownType(KnownTypeCode.Object) && conversion.Conversion.IsBoxingConversion - || type.Kind == TypeKind.Delegate && conversion.Conversion.IsAnonymousFunctionConversion - )) { - return this.UnwrapChild(cast.Expression); - } else if (Expression is ObjectCreateExpression oce && conversion.Conversion.IsMethodGroupConversion - && oce.Arguments.Count == 1 && expressionBuilder.settings.UseImplicitMethodGroupConversion) - { - return this.UnwrapChild(oce.Arguments.Single()); + if (allowImplicitConversion) { + switch (ResolveResult) { + case ConversionResolveResult conversion: { + if (Expression is CastExpression cast + && (type.IsKnownType(KnownTypeCode.Object) && conversion.Conversion.IsBoxingConversion + || type.Kind == TypeKind.Delegate && conversion.Conversion.IsAnonymousFunctionConversion + )) { + return this.UnwrapChild(cast.Expression); + } else if (Expression is ObjectCreateExpression oce && conversion.Conversion.IsMethodGroupConversion + && oce.Arguments.Count == 1 && expressionBuilder.settings.UseImplicitMethodGroupConversion) { + return this.UnwrapChild(oce.Arguments.Single()); + } + break; + } + case InvocationResolveResult invocation: { + if (Expression is ObjectCreateExpression oce && oce.Arguments.Count == 1 && invocation.Type.IsKnownType(KnownTypeCode.NullableOfT)) { + return this.UnwrapChild(oce.Arguments.Single()); + } + break; + } } } return this; From 9630acd8b7e3705f50467fdf6497da4a8e3208e7 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 19 Oct 2017 09:13:21 +0200 Subject: [PATCH 171/190] SwitchOnNullableTransform: Fix another special case produced by the Roslyn compiler. --- .../TestCases/Pretty/Switch.cs | 26 +++--- .../TestCases/Pretty/Switch.il | 80 +++++++++++++++---- .../TestCases/Pretty/Switch.opt.il | 72 +++++++++++++---- .../TestCases/Pretty/Switch.opt.roslyn.il | 45 ++++++++++- .../TestCases/Pretty/Switch.roslyn.il | 54 ++++++++++++- .../Transforms/SwitchOnNullableTransform.cs | 41 +++++++--- 6 files changed, 258 insertions(+), 60 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index 4f19a857f..0b118981a 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -60,19 +60,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } - //public static bool? SwitchOverNullableEnum(State? state) - //{ - // switch (state) { - // case State.False: - // return false; - // case State.True: - // return true; - // case State.Null: - // return null; - // default: - // throw new InvalidOperationException(); - // } - //} + public static bool? SwitchOverNullableEnum(State? state) + { + switch (state) { + case State.False: + return false; + case State.True: + return true; + case State.Null: + return null; + default: + throw new InvalidOperationException(); + } + } public static string SparseIntegerSwitch(int i) { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il index 581dfad62..9db363234 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly mhfw1ujx +.assembly o03zflju { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module mhfw1ujx.dll -// MVID: {2E35825E-3352-4C5E-B230-3B3F7055B304} +.module o03zflju.dll +// MVID: {0EF64C57-A49E-4138-9C3F-BDAB86B2E450} .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: 0x005A0000 +// Image base: 0x01330000 // =============== CLASS MEMBERS DECLARATION =================== @@ -142,6 +142,52 @@ IL_0034: ret } // end of method Switch::SwitchOverNullableBool + .method public hidebysig static valuetype [mscorlib]System.Nullable`1 + SwitchOverNullableEnum(valuetype [mscorlib]System.Nullable`1 state) cil managed + { + // Code size 75 (0x4b) + .maxstack 2 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State V_1, + valuetype [mscorlib]System.Nullable`1 V_2) + IL_0000: nop + IL_0001: ldarga.s state + IL_0003: dup + IL_0004: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0009: stloc.1 + IL_000a: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000f: brfalse.s IL_0043 + + IL_0011: ldloc.1 + IL_0012: switch ( + IL_0025, + IL_002e, + IL_0037) + IL_0023: br.s IL_0043 + + IL_0025: ldc.i4.0 + IL_0026: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_002b: stloc.0 + IL_002c: br.s IL_0049 + + IL_002e: ldc.i4.1 + IL_002f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0034: stloc.0 + IL_0035: br.s IL_0049 + + IL_0037: ldloca.s V_2 + IL_0039: initobj valuetype [mscorlib]System.Nullable`1 + IL_003f: ldloc.2 + IL_0040: stloc.0 + IL_0041: br.s IL_0049 + + IL_0043: newobj instance void [mscorlib]System.InvalidOperationException::.ctor() + IL_0048: throw + + IL_0049: ldloc.0 + IL_004a: ret + } // end of method Switch::SwitchOverNullableEnum + .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { @@ -834,7 +880,7 @@ IL_0015: brfalse IL_00e9 IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000c-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x600000d-1' IL_0021: brtrue.s IL_0084 IL_0023: ldc.i4.7 @@ -875,9 +921,9 @@ IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007d: volatile. - IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000c-1' + IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x600000d-1' IL_0084: volatile. - IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000c-1' + IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x600000d-1' IL_008b: ldloc.1 IL_008c: ldloca.s V_2 IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -949,7 +995,7 @@ IL_0013: brfalse IL_0158 IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000d-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x600000e-1' IL_001f: brtrue IL_00b8 IL_0024: ldc.i4.s 11 @@ -1010,9 +1056,9 @@ IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00b1: volatile. - IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000d-1' + IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x600000e-1' IL_00b8: volatile. - IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000d-1' + IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x600000e-1' IL_00bf: ldloc.1 IL_00c0: ldloca.s V_2 IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1297,7 +1343,7 @@ IL_0030: brfalse IL_0121 IL_0035: volatile. - IL_0037: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x6000012-1' + IL_0037: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x6000013-1' IL_003c: brtrue.s IL_0093 IL_003e: ldc.i4.6 @@ -1333,9 +1379,9 @@ IL_0087: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_008c: volatile. - IL_008e: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x6000012-1' + IL_008e: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x6000013-1' IL_0093: volatile. - IL_0095: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x6000012-1' + IL_0095: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x6000013-1' IL_009a: ldloc.s V_5 IL_009c: ldloca.s V_6 IL_009e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1562,14 +1608,14 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{2E35825E-3352-4C5E-B230-3B3F7055B304}' +.class private auto ansi '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000c-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000d-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000012-1' -} // end of class '{2E35825E-3352-4C5E-B230-3B3F7055B304}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000e-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000013-1' +} // end of class '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il index 0dbe1fff9..c4fc03c00 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly okac2jza +.assembly pryqrprl { .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 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module okac2jza.dll -// MVID: {7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F} +.module pryqrprl.dll +// MVID: {FFEEBB9C-152A-467A-A4B4-51CF03878E20} .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: 0x01A40000 +// Image base: 0x00B70000 // =============== CLASS MEMBERS DECLARATION =================== @@ -126,6 +126,44 @@ IL_002b: throw } // end of method Switch::SwitchOverNullableBool + .method public hidebysig static valuetype [mscorlib]System.Nullable`1 + SwitchOverNullableEnum(valuetype [mscorlib]System.Nullable`1 state) cil managed + { + // Code size 66 (0x42) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State V_0, + valuetype [mscorlib]System.Nullable`1 V_1) + IL_0000: ldarga.s state + IL_0002: dup + IL_0003: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0008: stloc.0 + IL_0009: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000e: brfalse.s IL_003c + + IL_0010: ldloc.0 + IL_0011: switch ( + IL_0024, + IL_002b, + IL_0032) + IL_0022: br.s IL_003c + + IL_0024: ldc.i4.0 + IL_0025: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_002a: ret + + IL_002b: ldc.i4.1 + IL_002c: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0031: ret + + IL_0032: ldloca.s V_1 + IL_0034: initobj valuetype [mscorlib]System.Nullable`1 + IL_003a: ldloc.1 + IL_003b: ret + + IL_003c: newobj instance void [mscorlib]System.InvalidOperationException::.ctor() + IL_0041: throw + } // end of method Switch::SwitchOverNullableEnum + .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { @@ -711,7 +749,7 @@ IL_0013: brfalse IL_00db IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000c-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x600000d-1' IL_001f: brtrue.s IL_0082 IL_0021: ldc.i4.7 @@ -752,9 +790,9 @@ IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007b: volatile. - IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000c-1' + IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x600000d-1' IL_0082: volatile. - IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000c-1' + IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x600000d-1' IL_0089: ldloc.0 IL_008a: ldloca.s V_1 IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -812,7 +850,7 @@ IL_0011: brfalse IL_013d IL_0016: volatile. - IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000d-1' + IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x600000e-1' IL_001d: brtrue IL_00b6 IL_0022: ldc.i4.s 11 @@ -873,9 +911,9 @@ IL_00aa: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00af: volatile. - IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000d-1' + IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x600000e-1' IL_00b6: volatile. - IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000d-1' + IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x600000e-1' IL_00bd: ldloc.0 IL_00be: ldloca.s V_1 IL_00c0: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1099,7 +1137,7 @@ IL_002d: brfalse IL_0115 IL_0032: volatile. - IL_0034: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x6000012-1' + IL_0034: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x6000013-1' IL_0039: brtrue.s IL_0090 IL_003b: ldc.i4.6 @@ -1135,9 +1173,9 @@ IL_0084: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_0089: volatile. - IL_008b: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x6000012-1' + IL_008b: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x6000013-1' IL_0090: volatile. - IL_0092: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x6000012-1' + IL_0092: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x6000013-1' IL_0097: ldloc.s V_5 IL_0099: ldloca.s V_6 IL_009b: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1331,14 +1369,14 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}' +.class private auto ansi '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000c-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000d-1' - .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000012-1' -} // end of class '{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000e-1' + .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000013-1' +} // end of class '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il index 359906595..c2c1f5cae 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {6F3B5958-B8BE-48C6-82B8-5D3026DEACD1} +// MVID: {5D628BA5-FC59-43EC-A162-63729510F134} .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: 0x03160000 +// Image base: 0x01390000 // =============== CLASS MEMBERS DECLARATION =================== @@ -136,6 +136,47 @@ IL_0027: throw } // end of method Switch::SwitchOverNullableBool + .method public hidebysig static valuetype [mscorlib]System.Nullable`1 + SwitchOverNullableEnum(valuetype [mscorlib]System.Nullable`1 state) cil managed + { + // Code size 69 (0x45) + .maxstack 1 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State V_1, + valuetype [mscorlib]System.Nullable`1 V_2) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_0009: brfalse.s IL_003f + + IL_000b: ldloca.s V_0 + IL_000d: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0012: stloc.1 + IL_0013: ldloc.1 + IL_0014: switch ( + IL_0027, + IL_002e, + IL_0035) + IL_0025: br.s IL_003f + + IL_0027: ldc.i4.0 + IL_0028: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_002d: ret + + IL_002e: ldc.i4.1 + IL_002f: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0034: ret + + IL_0035: ldloca.s V_2 + IL_0037: initobj valuetype [mscorlib]System.Nullable`1 + IL_003d: ldloc.2 + IL_003e: ret + + IL_003f: newobj instance void [mscorlib]System.InvalidOperationException::.ctor() + IL_0044: throw + } // end of method Switch::SwitchOverNullableEnum + .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il index 7cce7b604..ea25c483e 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il @@ -25,7 +25,7 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {7ADDBD28-42D6-469D-B92D-065C803347D0} +// MVID: {EF7D776C-0F54-445C-8A74-2D49ADE35F46} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 @@ -152,6 +152,58 @@ IL_0034: ret } // end of method Switch::SwitchOverNullableBool + .method public hidebysig static valuetype [mscorlib]System.Nullable`1 + SwitchOverNullableEnum(valuetype [mscorlib]System.Nullable`1 state) cil managed + { + // Code size 81 (0x51) + .maxstack 1 + .locals init (valuetype [mscorlib]System.Nullable`1 V_0, + valuetype [mscorlib]System.Nullable`1 V_1, + valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State V_2, + valuetype [mscorlib]System.Nullable`1 V_3, + valuetype [mscorlib]System.Nullable`1 V_4) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: stloc.0 + IL_0005: ldloca.s V_0 + IL_0007: call instance bool valuetype [mscorlib]System.Nullable`1::get_HasValue() + IL_000c: brfalse.s IL_0049 + + IL_000e: ldloca.s V_0 + IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1::GetValueOrDefault() + IL_0015: stloc.2 + IL_0016: ldloc.2 + IL_0017: switch ( + IL_002a, + IL_0033, + IL_003c) + IL_0028: br.s IL_0049 + + IL_002a: ldc.i4.0 + IL_002b: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0030: stloc.3 + IL_0031: br.s IL_004f + + IL_0033: ldc.i4.1 + IL_0034: newobj instance void valuetype [mscorlib]System.Nullable`1::.ctor(!0) + IL_0039: stloc.3 + IL_003a: br.s IL_004f + + IL_003c: ldloca.s V_4 + IL_003e: initobj valuetype [mscorlib]System.Nullable`1 + IL_0044: ldloc.s V_4 + IL_0046: stloc.3 + IL_0047: br.s IL_004f + + IL_0049: newobj instance void [mscorlib]System.InvalidOperationException::.ctor() + IL_004e: throw + + IL_004f: ldloc.3 + IL_0050: ret + } // end of method Switch::SwitchOverNullableEnum + .method public hidebysig static string SparseIntegerSwitch(int32 i) cil managed { diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs index ed538ca8b..af7cc6ae7 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnNullableTransform.cs @@ -142,22 +142,43 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (!condition.MatchLogicNot(out var getHasValue) || !NullableLiftingTransform.MatchHasValueCall(getHasValue, out ILVariable target1) || target1 != tmp) return false; // match second block: switchBlock + // note: I have seen cases where switchVar is inlined into the switch. // stloc switchVar(call GetValueOrDefault(ldloca tmp)) // switch (ldloc switchVar) { // case [0..1): br caseBlock1 // ... more cases ... // case [long.MinValue..0),[1..5),[6..10),[11..long.MaxValue]: br defaultBlock // } - if (switchBlock.Instructions.Count != 2 || switchBlock.IncomingEdgeCount != 1) - return false; - if (!switchBlock.Instructions[0].MatchStLoc(out var switchVar, out var getValueOrDefault)) - return false; - if (!switchVar.IsSingleDefinition || switchVar.LoadCount != 1) - return false; - if (!NullableLiftingTransform.MatchGetValueOrDefault(getValueOrDefault, tmp)) - return false; - if (!(switchBlock.Instructions[1] is SwitchInstruction switchInst)) - return false; + if (switchBlock.IncomingEdgeCount != 1) + return false; + SwitchInstruction switchInst; + switch (switchBlock.Instructions.Count) { + case 2: { + // this is the normal case described by the pattern above + if (!switchBlock.Instructions[0].MatchStLoc(out var switchVar, out var getValueOrDefault)) + return false; + if (!switchVar.IsSingleDefinition || switchVar.LoadCount != 1) + return false; + if (!NullableLiftingTransform.MatchGetValueOrDefault(getValueOrDefault, tmp)) + return false; + if (!(switchBlock.Instructions[1] is SwitchInstruction si)) + return false; + switchInst = si; + break; + } + case 1: { + // this is the special case where `call GetValueOrDefault(ldloca tmp)` is inlined into the switch. + if (!(switchBlock.Instructions[0] is SwitchInstruction si)) + return false; + if (!NullableLiftingTransform.MatchGetValueOrDefault(si.Value, tmp)) + return false; + switchInst = si; + break; + } + default: { + return false; + } + } newSwitch = BuildLiftedSwitch(nullCaseBlock, switchInst, switchValue); return true; } From d645166f3e81dd3d960e6c66d029d7830a9104cc Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 21 Oct 2017 00:22:07 +0200 Subject: [PATCH 172/190] * Fix #920: [Bug]Click one reference will navigate to another. * Add references to constructors of builtin types (decimal and string). --- ICSharpCode.Decompiler/Output/TextTokenWriter.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler/Output/TextTokenWriter.cs b/ICSharpCode.Decompiler/Output/TextTokenWriter.cs index f0d26ef11..5ce584f1d 100644 --- a/ICSharpCode.Decompiler/Output/TextTokenWriter.cs +++ b/ICSharpCode.Decompiler/Output/TextTokenWriter.cs @@ -116,7 +116,7 @@ namespace ICSharpCode.Decompiler if (symbol == null && node.Role == Roles.TargetExpression && node.Parent is InvocationExpression) { symbol = node.Parent.GetSymbol(); } - if (symbol != null && node.Parent is ObjectCreateExpression) { + if (symbol != null && node.Role == Roles.Type && node.Parent is ObjectCreateExpression) { symbol = node.Parent.GetSymbol(); } if (node is IdentifierExpression && node.Role == Roles.TargetExpression && node.Parent is InvocationExpression && symbol is IMember member) { @@ -335,9 +335,15 @@ namespace ICSharpCode.Decompiler case "char": case "string": case "object": - var typeSymbol = (nodeStack.Peek().GetSymbol() as IType)?.GetDefinition(); - if (typeSymbol == null) goto default; - output.WriteReference(type, typeSystem.GetCecil(typeSymbol)); + var node = nodeStack.Peek(); + ISymbol symbol; + if (node.Role == Roles.Type && node.Parent is ObjectCreateExpression) { + symbol = node.Parent.GetSymbol(); + } else { + symbol = nodeStack.Peek().GetSymbol(); + } + if (symbol == null) goto default; + output.WriteReference(type, SymbolToCecil(symbol)); break; default: output.Write(type); From cdaa3e29c968145157a6bc299c1a520055c4ec59 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 21 Oct 2017 16:14:21 +0200 Subject: [PATCH 173/190] Fix highlighting of 'where' keyword in LINQ query clauses. --- ILSpy/Languages/CSharpHighlightingTokenWriter.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ILSpy/Languages/CSharpHighlightingTokenWriter.cs b/ILSpy/Languages/CSharpHighlightingTokenWriter.cs index 633ac75e6..6d91a6a11 100644 --- a/ILSpy/Languages/CSharpHighlightingTokenWriter.cs +++ b/ILSpy/Languages/CSharpHighlightingTokenWriter.cs @@ -127,9 +127,14 @@ namespace ICSharpCode.ILSpy case "global": case "dynamic": case "await": - case "where": color = structureKeywordsColor; break; + case "where": + if (nodeStack.PeekOrDefault() is QueryClause) + color = queryKeywordsColor; + else + color = structureKeywordsColor; + break; case "in": if (nodeStack.PeekOrDefault() is ForeachStatement) color = structureKeywordsColor; From 425d1ae6973859cb7eb217f1934a4e9bc601fd5c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 21 Oct 2017 16:57:50 +0200 Subject: [PATCH 174/190] Fix ArgumentOutOfRangeException in CopyPropagation while decompiling System.Security.Cryptography.CryptoStream.ReadAsyncInternal from mscorlib.v4 --- ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs b/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs index 91a79c6c4..1ef40d116 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs @@ -51,7 +51,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms // dead store to stack if (copiedExpr.Flags == InstructionFlags.None) { // no-op -> delete - context.Step("remove dead store to stack: no-op -> delete", block.Instructions[i - 1]); + context.Step("remove dead store to stack: no-op -> delete", block.Instructions[i]); block.Instructions.RemoveAt(i--); } else { // evaluate the value for its side-effects From 79dec0145a700d452343c534c72d907703ec6578 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 22 Oct 2017 11:21:50 +0200 Subject: [PATCH 175/190] Fix #928: Null literal white space formatting issue --- .../CSharp/OutputVisitor/CSharpOutputVisitor.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs index 8eb432e8b..cc3708c81 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs @@ -890,6 +890,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor { StartNode(nullReferenceExpression); writer.WritePrimitiveValue(null); + isAfterSpace = false; EndNode(nullReferenceExpression); } From 22eb1a10ed02effeb668281b73339e2fcd97ef33 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Mon, 23 Oct 2017 06:54:10 +0200 Subject: [PATCH 176/190] Update nuspec dependencies --- ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec index 93cd2f8fb..ac0c969ca 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec @@ -2,7 +2,7 @@ ICSharpCode.Decompiler - 3.0.0-alpha3 + 3.0.0-beta1 ILSpy Decompiler Engine Daniel Grunwald, David Srbecky, Ed Harvey, Siegfried Pammer Daniel Grunwald, SharpDevelop @@ -15,9 +15,10 @@ Copyright 2011-2017 AlphaSierraPapa C# Decompiler ILSpy - - - + + + + From 3bf182860df0caa6919e692b3c8915eacb501e3f Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 23 Oct 2017 21:00:26 +0200 Subject: [PATCH 177/190] Fix #934: Project generation: absolute path used for AssemblyInfo.cs module --- ICSharpCode.Decompiler/CSharp/WholeProjectDecompiler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/WholeProjectDecompiler.cs b/ICSharpCode.Decompiler/CSharp/WholeProjectDecompiler.cs index 4b36a47db..a36ae5869 100644 --- a/ICSharpCode.Decompiler/CSharp/WholeProjectDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/WholeProjectDecompiler.cs @@ -283,8 +283,8 @@ namespace ICSharpCode.Decompiler.CSharp const string prop = "Properties"; if (directories.Add(prop)) Directory.CreateDirectory(Path.Combine(targetDirectory, prop)); - string assemblyInfo = Path.Combine(targetDirectory, prop, "AssemblyInfo.cs"); - using (StreamWriter w = new StreamWriter(assemblyInfo)) { + string assemblyInfo = Path.Combine(prop, "AssemblyInfo.cs"); + using (StreamWriter w = new StreamWriter(Path.Combine(targetDirectory, assemblyInfo))) { syntaxTree.AcceptVisitor(new CSharpOutputVisitor(w, settings.CSharpFormattingOptions)); } return new Tuple[] { Tuple.Create("Compile", assemblyInfo) }; From 106ac87b665607b1877305ab78e74cdd68bacc41 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 25 Oct 2017 17:56:41 +0200 Subject: [PATCH 178/190] Fix location of assembly reference warning message when selecting assembly tree node. --- ILSpy/Languages/CSharpLanguage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index 0c1836845..4be6e9518 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -327,9 +327,9 @@ namespace ICSharpCode.ILSpy decompiler.ProjectGuid = App.CommandLineArguments.FixedGuid; decompiler.DecompileProject(assembly.ModuleDefinition, options.SaveAsProjectDirectory, new TextOutputWriter(output), options.CancellationToken); } else { - base.DecompileAssembly(assembly, output, options); AddReferenceWarningMessage(assembly.AssemblyDefinition, output); output.WriteLine(); + base.DecompileAssembly(assembly, output, options); ModuleDefinition mainModule = assembly.ModuleDefinition; if (mainModule.Types.Count > 0) { output.Write("// Global type: "); From 4626ba3fc89ec5e8f35642d22c739b4780895668 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 25 Oct 2017 17:58:38 +0200 Subject: [PATCH 179/190] Do not treat missing deps.json file as error. - Fixes #908: Assembly loader issue (very minor) --- ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs b/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs index 5d4478c34..01c54137d 100644 --- a/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs +++ b/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs @@ -52,7 +52,7 @@ namespace ICSharpCode.Decompiler var depsJsonFileName = Path.Combine(basePath, $"{assemblyName}.deps.json"); if (!File.Exists(depsJsonFileName)) { - loadInfo.AddMessage(assemblyName, MessageKind.Error, $"{assemblyName}.deps.json could not be found!"); + loadInfo.AddMessage(assemblyName, MessageKind.Warning, $"{assemblyName}.deps.json could not be found!"); return; } From 4885299816d5300107c1b1dfdde24866ca91b93e Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 25 Oct 2017 22:03:37 +0200 Subject: [PATCH 180/190] Fix #582: Collapse All button for the assemblies list --- ILSpy/Commands/SortAssemblyListCommand.cs | 24 +++++++++++++++++++++- ILSpy/ILSpy.csproj | 1 + ILSpy/Images/CollapseAll.png | Bin 0 -> 436 bytes 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ILSpy/Images/CollapseAll.png diff --git a/ILSpy/Commands/SortAssemblyListCommand.cs b/ILSpy/Commands/SortAssemblyListCommand.cs index 2020cf21d..3f8bc3920 100644 --- a/ILSpy/Commands/SortAssemblyListCommand.cs +++ b/ILSpy/Commands/SortAssemblyListCommand.cs @@ -18,12 +18,13 @@ using System; using System.Collections.Generic; +using ICSharpCode.TreeView; namespace ICSharpCode.ILSpy { [ExportMainMenuCommand(Menu = "_View", Header = "Sort assembly list by name", MenuIcon = "Images/Sort.png", MenuCategory = "View")] [ExportToolbarCommand(ToolTip = "Sort assembly list by name", ToolbarIcon = "Images/Sort.png", ToolbarCategory = "View")] - class SortAssemblyListCommand : SimpleCommand, IComparer + sealed class SortAssemblyListCommand : SimpleCommand, IComparer { public override void Execute(object parameter) { @@ -36,4 +37,25 @@ namespace ICSharpCode.ILSpy return string.Compare(x.ShortName, y.ShortName, StringComparison.CurrentCulture); } } + + [ExportMainMenuCommand(Menu = "_View", Header = "Collapse all tree nodes", MenuIcon = "Images/CollapseAll.png", MenuCategory = "View")] + [ExportToolbarCommand(ToolTip = "Collapse all tree nodes", ToolbarIcon = "Images/CollapseAll.png", ToolbarCategory = "View")] + sealed class CollapseAllCommand : SimpleCommand + { + public override void Execute(object parameter) + { + using (MainWindow.Instance.treeView.LockUpdates()) + CollapseChildren(MainWindow.Instance.treeView.Root); + + void CollapseChildren(SharpTreeNode node) + { + foreach (var child in node.Children) { + if (!child.IsExpanded) + continue; + CollapseChildren(child); + child.IsExpanded = false; + } + } + } + } } diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index 9411c6544..304e82ca8 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -346,6 +346,7 @@ + diff --git a/ILSpy/Images/CollapseAll.png b/ILSpy/Images/CollapseAll.png new file mode 100644 index 0000000000000000000000000000000000000000..5e23dbc8101d5b29ea77efc18dcb648e729250bb GIT binary patch literal 436 zcmV;l0ZaagP)-;1p#7!9TZhash#k@NvuL0%D|VN{Qd0z z^lX1SLI~7xKp4xzi%qPLd%_tfVu>7I&SukIw+pY=L*RJ^8@`XA--k!JN9%i&$w^Zr zlu}K;dlkpn9-r1z=I1rO#~qILX*mDsz>T5^VmQQNv1s+)B?qV;9OGbFpe#!iMS(O; zTLr=}B!SXx6#&6;9E?VzmEtVRQ17t{bo6}?T-QaO=PLrt>pi8i3rHye26&LxBWS)& zpmD%QSb7~3hW`f#onIa3F0eQ-e2akiy8~%Gf@mC6Rb_QxcqP9aygfoN$(O@T*7N~$ zI=2XDUP*!XC*U^L4t!b|&^X{lL2u2UrY*P^@R0{pyhGDm3lMm6og~RIZnmD+e&+e> eOI;&B1sDMOI=@rxNH9SF0000 Date: Thu, 26 Oct 2017 19:47:30 +0200 Subject: [PATCH 181/190] Update appveyor.yml to allow publishing nightly nupkgs. --- BuildTools/appveyor-install.ps1 | 6 ++++-- appveyor.yml | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/BuildTools/appveyor-install.ps1 b/BuildTools/appveyor-install.ps1 index 58b1801f9..63afea63c 100644 --- a/BuildTools/appveyor-install.ps1 +++ b/BuildTools/appveyor-install.ps1 @@ -32,5 +32,7 @@ if ($env:APPVEYOR_PULL_REQUEST_NUMBER) { $revision = [Int32]::Parse((git rev-list --count "$baseCommit..HEAD")) + $baseCommitRev; $newVersion="$major.$minor.$build.$revision"; -$env:appveyor_build_version="$newVersion$branch$versionName$suffix"; -appveyor UpdateBuild -Version "$newVersion$branch$versionName$suffix"; \ No newline at end of file +$env:APPVEYOR_BUILD_VERSION="$newVersion$branch$versionName$suffix"; +$env:ILSPY_VERSION_NUMBER="$newVersion$branch$versionName$suffix"; +appveyor UpdateBuild -Version "$newVersion$branch$versionName$suffix"; +Write-Host "new version: $newVersion$branch$versionName$suffix"; \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 33d571e9d..ad8006791 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,4 +20,6 @@ after_test: - python BuildTools\tidy.py artifacts: - path: ILSpy_binaries.zip - name: ILSpy %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% binaries \ No newline at end of file + name: ILSpy %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% binaries + - path: '**\*.nupkg' + name: ICSharpCode.Decompiler %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% NuGet \ No newline at end of file From 42e41c3f167fc82fbd827dca71b469182c211001 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 26 Oct 2017 20:18:38 +0200 Subject: [PATCH 182/190] Automate versioning of nupkg. Remarks: Edit ICSharpCode.Decompiler.nuspec.template --- BuildTools/update-assemblyinfo.ps1 | 1 + ...compiler.nuspec => ICSharpCode.Decompiler.nuspec.template} | 4 ++-- ILSpy/Properties/AssemblyInfo.template.cs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) rename ICSharpCode.Decompiler/{ICSharpCode.Decompiler.nuspec => ICSharpCode.Decompiler.nuspec.template} (93%) diff --git a/BuildTools/update-assemblyinfo.ps1 b/BuildTools/update-assemblyinfo.ps1 index 38a0f0df4..fbf59b6f9 100644 --- a/BuildTools/update-assemblyinfo.ps1 +++ b/BuildTools/update-assemblyinfo.ps1 @@ -42,6 +42,7 @@ function gitBranch() { $templateFiles = ( @{Input=$globalAssemblyInfoTemplateFile; Output="ILSpy/Properties/AssemblyInfo.cs"}, @{Input="ICSharpCode.Decompiler/Properties/AssemblyInfo.template.cs"; Output="ICSharpCode.Decompiler/Properties/AssemblyInfo.cs"}, + @{Input="ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec.template"; Output="ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec"}, @{Input="ILSpy/Properties/app.config.template"; Output = "ILSpy/app.config"} ); [string]$mutexId = "ILSpyUpdateAssemblyInfo" + $PSScriptRoot.GetHashCode(); diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec.template similarity index 93% rename from ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec rename to ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec.template index ac0c969ca..62f6a6603 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec.template @@ -2,7 +2,7 @@ ICSharpCode.Decompiler - 3.0.0-beta1 + $INSERTVERSION$$INSERTVERSIONNAMEPOSTFIX$ ILSpy Decompiler Engine Daniel Grunwald, David Srbecky, Ed Harvey, Siegfried Pammer Daniel Grunwald, SharpDevelop @@ -12,7 +12,7 @@ false ICSharpCode.Decompiler is the decompiler engine used in ILSpy. - Copyright 2011-2017 AlphaSierraPapa + Copyright 2011-$INSERTYEAR$ AlphaSierraPapa C# Decompiler ILSpy diff --git a/ILSpy/Properties/AssemblyInfo.template.cs b/ILSpy/Properties/AssemblyInfo.template.cs index b40fac15c..140434136 100644 --- a/ILSpy/Properties/AssemblyInfo.template.cs +++ b/ILSpy/Properties/AssemblyInfo.template.cs @@ -42,7 +42,7 @@ internal static class RevisionClass public const string Minor = "0"; public const string Build = "0"; public const string Revision = "$INSERTREVISION$"; - public const string VersionName = null; + public const string VersionName = "beta1"; public const string FullVersion = Major + "." + Minor + "." + Build + ".$INSERTREVISION$$INSERTBRANCHPOSTFIX$$INSERTVERSIONNAMEPOSTFIX$"; } From 472c4fb9365e9c6349d4293153e2baab911d57ee Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 27 Oct 2017 07:21:30 +0200 Subject: [PATCH 183/190] Add EmbedSources flag to allow source stepping in nupkg. --- ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index f8dec72a7..af6e556a3 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -32,6 +32,7 @@ full true + true True $(DefineConstants);STEP @@ -39,6 +40,7 @@ pdbonly true + true @@ -587,4 +589,13 @@ + + + + + + + \ No newline at end of file From 8c5b1faec76c5e800c3f89540ef2ca9a532977f8 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 27 Oct 2017 07:32:07 +0200 Subject: [PATCH 184/190] Change DebugType to portable. --- ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index af6e556a3..e87b0b7ef 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -30,7 +30,7 @@ - full + portable true true True @@ -38,7 +38,7 @@ - pdbonly + portable true true From f035fa822de0af72110a545fa54704e9d7a63aff Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 27 Oct 2017 08:12:52 +0200 Subject: [PATCH 185/190] Test nuget specific options in appveyor.yml --- appveyor.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index ad8006791..7879119a2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,8 +6,16 @@ image: Visual Studio 2017 install: - git submodule update --init --recursive - ps: .\BuildTools\appveyor-install.ps1 +nuget: + account_feed: true + project_feed: true + disable_publish_on_pr: true before_build: - nuget restore ILSpy.sln +build: + publish_nuget: true + publish_nuget_symbols: true + include_nuget_references: true build_script: - msbuild ILSpy.sln /v:minimal /p:ResolveNuGetPackages=false "/logger:%ProgramFiles%\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" after_build: From 0d041952360c45adb93294a8254239309fc157a5 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 27 Oct 2017 09:17:43 +0200 Subject: [PATCH 186/190] Revert "Test nuget specific options in appveyor.yml" This reverts commit f035fa822de0af72110a545fa54704e9d7a63aff. --- appveyor.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 7879119a2..ad8006791 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,16 +6,8 @@ image: Visual Studio 2017 install: - git submodule update --init --recursive - ps: .\BuildTools\appveyor-install.ps1 -nuget: - account_feed: true - project_feed: true - disable_publish_on_pr: true before_build: - nuget restore ILSpy.sln -build: - publish_nuget: true - publish_nuget_symbols: true - include_nuget_references: true build_script: - msbuild ILSpy.sln /v:minimal /p:ResolveNuGetPackages=false "/logger:%ProgramFiles%\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" after_build: From efb2d3d2b907e452f3cd9298ffc4feca04c74de5 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 27 Oct 2017 09:46:56 +0200 Subject: [PATCH 187/190] Fix IncludeSymbolsInPackage --- ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index e87b0b7ef..d94c974fc 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -24,7 +24,7 @@ true - true + true ICSharpCode.Decompiler.nuspec Configuration=$(Configuration) @@ -591,9 +591,7 @@ - + From a3baaa67973d3ae3a195efc05cb9f8d8c1f4de28 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 27 Oct 2017 10:26:13 +0200 Subject: [PATCH 188/190] Remove src from nupkg as we now embed the source code in the pdb. --- ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec.template | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec.template b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec.template index 62f6a6603..030ad559d 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec.template +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec.template @@ -31,9 +31,5 @@ - - - - \ No newline at end of file From 4b23b14a819385d0571c77e0ac96e95f34f8219c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 27 Oct 2017 11:54:43 +0200 Subject: [PATCH 189/190] WIP on #722: Add accelerator keys to OpenListDialog --- ILSpy/OpenListDialog.xaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ILSpy/OpenListDialog.xaml b/ILSpy/OpenListDialog.xaml index edac744f6..8428df3fa 100644 --- a/ILSpy/OpenListDialog.xaml +++ b/ILSpy/OpenListDialog.xaml @@ -28,14 +28,14 @@ - + - - - - + + + + From 14448071a3eaf48842692fd7385c070ac12d6cb2 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 28 Oct 2017 16:45:06 +0200 Subject: [PATCH 190/190] Fix #939: Enum values in bitwise operations are not properly decompiled --- ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 6a0a7d2f3..8c5e3ea8c 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -694,6 +694,12 @@ namespace ICSharpCode.Decompiler.CSharp } } + if ((op == BinaryOperatorType.BitwiseAnd || op == BinaryOperatorType.BitwiseOr || op == BinaryOperatorType.ExclusiveOr) + && (left.Type.Kind == TypeKind.Enum || right.Type.Kind == TypeKind.Enum)) { + left = AdjustConstantExpressionToType(left, right.Type); + right = AdjustConstantExpressionToType(right, left.Type); + } + var rr = resolverWithOverflowCheck.ResolveBinaryOperator(op, left.ResolveResult, right.ResolveResult); if (rr.IsError || NullableType.GetUnderlyingType(rr.Type).GetStackType() != inst.UnderlyingResultType || !IsCompatibleWithSign(left.Type, inst.Sign) || !IsCompatibleWithSign(right.Type, inst.Sign))