From 5dd7eaf12904fee9aebc51bd252838fea19f56ae Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 15 Mar 2018 10:53:04 +0100 Subject: [PATCH] Fix #1093: Remove usage of type or this qualifiers, when possible. --- .../ICSharpCode.Decompiler.Tests.csproj | 1 + .../PrettyTestRunner.cs | 6 + .../TestCases/ILPretty/Issue1047.cs | 2 +- .../TestCases/ILPretty/Issue982.cs | 8 +- .../TestCases/Pretty/AnonymousTypes.cs | 2 +- .../TestCases/Pretty/Async.cs | 4 +- .../TestCases/Pretty/CheckedUnchecked.cs | 6 +- .../Pretty/CompoundAssignmentTest.cs | 116 ++-- .../TestCases/Pretty/DelegateConstruction.cs | 34 +- .../TestCases/Pretty/ExceptionHandling.cs | 14 +- .../TestCases/Pretty/ExpressionTrees.cs | 334 +++++----- .../TestCases/Pretty/InitializerTests.cs | 64 +- .../TestCases/Pretty/InlineAssignmentTest.cs | 34 +- .../TestCases/Pretty/LiftedOperators.cs | 36 +- .../TestCases/Pretty/Loops.cs | 52 +- .../TestCases/Pretty/NullPropagation.cs | 82 +-- .../TestCases/Pretty/PInvoke.cs | 2 +- .../TestCases/Pretty/PropertiesAndEvents.cs | 4 +- .../TestCases/Pretty/QualifierTests.cs | 181 ++++++ .../TestCases/Pretty/QualifierTests.il | 596 ++++++++++++++++++ .../TestCases/Pretty/QualifierTests.opt.il | 519 +++++++++++++++ .../Pretty/QualifierTests.opt.roslyn.il | 523 +++++++++++++++ .../TestCases/Pretty/QualifierTests.roslyn.il | 587 +++++++++++++++++ .../TestCases/Pretty/QueryExpressions.cs | 30 +- .../TestCases/Pretty/ShortCircuit.cs | 74 +-- .../TestCases/Pretty/Switch.cs | 4 +- .../TestCases/Pretty/TypeAnalysisTests.cs | 14 +- .../TestCases/Pretty/UnsafeCode.cs | 46 +- ICSharpCode.Decompiler/CSharp/CallBuilder.cs | 180 ++++-- .../CSharp/ExpressionBuilder.cs | 87 ++- .../CSharp/StatementBuilder.cs | 2 +- .../CSharp/Syntax/AstNodeCollection.cs | 6 + .../ConvertConstructorCallIntoInitializer.cs | 22 +- .../Transforms/IntroduceExtensionMethods.cs | 32 +- .../Transforms/IntroduceUnsafeModifier.cs | 19 +- 35 files changed, 3167 insertions(+), 556 deletions(-) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.cs create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.opt.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.opt.roslyn.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.roslyn.il diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index 358621572..86e44c3d0 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 356c6aa5c..adc2eb24b 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -273,6 +273,12 @@ namespace ICSharpCode.Decompiler.Tests RunForLibrary(cscOptions: cscOptions); } + [Test] + public void QualifierTests([ValueSource("defaultOptions")] CSharpCompilerOptions cscOptions) + { + RunForLibrary(cscOptions: cscOptions); + } + [Test] public void Issue1080([ValueSource(nameof(roslynOnlyOptions))] CSharpCompilerOptions cscOptions) { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.cs b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.cs index 3aa1c7c4a..f5d32e786 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.cs @@ -7,7 +7,7 @@ private void ProblemMethod() { IL_0000: - while (!Issue1047.dummy) { + while (!dummy) { } return; IL_0014: diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue982.cs b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue982.cs index 5f039b7a7..74205c661 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue982.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue982.cs @@ -8,19 +8,19 @@ public string Text { get { - return this.textStr; + return textStr; } set { - this.textStr = value; + textStr = value; } } public string this[int index] { get { - return this.textStr2; + return textStr2; } set { - this.textStr2 = value; + textStr2 = value; } } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.cs index 0120f050f..949ef3f07 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.cs @@ -105,7 +105,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty #if CS70 private void AnonymousTypeOutVar() { - AnonymousTypes.InlineVarDecl(out var anon, new { + InlineVarDecl(out var anon, new { X = 1, Y = 2 }); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Async.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Async.cs index 5ee72d908..bb526b284 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Async.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Async.cs @@ -74,7 +74,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public async void TwoAwaitsWithDifferentAwaiterTypes() { Console.WriteLine("Before"); - if (await this.SimpleBoolTaskMethod()) { + if (await SimpleBoolTaskMethod()) { await Task.Delay(TimeSpan.FromSeconds(1.0)); } Console.WriteLine("After"); @@ -82,7 +82,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public async void AwaitInLoopCondition() { - while (await this.SimpleBoolTaskMethod()) { + while (await SimpleBoolTaskMethod()) { Console.WriteLine("Body"); } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CheckedUnchecked.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CheckedUnchecked.cs index f58fa70b4..58dc08cbb 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CheckedUnchecked.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CheckedUnchecked.cs @@ -63,7 +63,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public void ObjectCreationInitializerChecked() { - this.TestHelp(new { + TestHelp(new { x = 0, l = 0 }, n => checked(new { @@ -74,7 +74,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void ObjectCreationWithOneFieldChecked() { - this.TestHelp(new { + TestHelp(new { x = 0, l = 0 }, n => new { @@ -85,7 +85,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void ArrayInitializerChecked() { - this.TestHelp(new int[2] { + TestHelp(new int[2] { 1, 2 }, (int[] n) => checked(new int[2] { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs index 84077863f..494132abc 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs @@ -204,46 +204,46 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void IntegerField(int i) { - Console.WriteLine(this.test1 += i); - Console.WriteLine(this.test1); - Console.WriteLine(this.test1 -= i); - Console.WriteLine(this.test1); + Console.WriteLine(test1 += i); + Console.WriteLine(test1); + Console.WriteLine(test1 -= i); + Console.WriteLine(test1); } public void Array(int i) { - Console.WriteLine(this.array1[i] += i); - Console.WriteLine(this.array1[i * 2] += i * 2); + Console.WriteLine(array1[i] += i); + Console.WriteLine(array1[i * 2] += i * 2); } public int ArrayUsageWithMethods() { - return this.GetArray()[this.GetIndex()]++; + return GetArray()[GetIndex()]++; } public void NestedField() { - if (this.field1.HasIndex) { - Console.WriteLine(this.field1.Field *= 2); - this.field1.Field++; - Console.WriteLine(this.field1.Field++); + if (field1.HasIndex) { + Console.WriteLine(field1.Field *= 2); + field1.Field++; + Console.WriteLine(field1.Field++); } } public void Enum() { - this.enumField |= MyEnum.Two; - this.enumField &= ~MyEnum.Four; - this.enumField += 2; - this.enumField -= 3; + enumField |= MyEnum.Two; + enumField &= ~MyEnum.Four; + enumField += 2; + enumField -= 3; } public void ShortEnumTest() { - this.shortEnumField |= ShortEnum.Two; - this.shortEnumField &= ShortEnum.Four; - this.shortEnumField += 2; - this.shortEnumField -= 3; + shortEnumField |= ShortEnum.Two; + shortEnumField &= ShortEnum.Four; + shortEnumField += 2; + shortEnumField -= 3; } public int PreIncrementInAddition(int i, int j) @@ -303,27 +303,27 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public int PreIncrementInstanceField() { - return ++this.M().Field; + return ++M().Field; } public int PostIncrementInstanceField() { - return this.M().Field++; + return M().Field++; } public void IncrementInstanceField() { - this.M().Field++; + M().Field++; } public void DoubleInstanceField() { - this.M().Field *= 2; + M().Field *= 2; } public int DoubleInstanceFieldAndReturn() { - return this.M().Field *= 2; + return M().Field *= 2; } public int PreIncrementInstanceField2(MutableClass m) @@ -343,157 +343,157 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public int PreIncrementInstanceFieldShort() { - return ++this.M().ShortField; + return ++M().ShortField; } public int PostIncrementInstanceFieldShort() { - return this.M().ShortField++; + return M().ShortField++; } public void IncrementInstanceFieldShort() { - this.M().ShortField++; + M().ShortField++; } public int PreIncrementInstanceProperty() { - return ++this.M().Property; + return ++M().Property; } public int PostIncrementInstanceProperty() { - return this.M().Property++; + return M().Property++; } public void IncrementInstanceProperty() { - this.M().Property++; + M().Property++; } public void DoubleInstanceProperty() { - this.M().Property *= 2; + M().Property *= 2; } public int DoubleInstancePropertyAndReturn() { - return this.M().Property *= 2; + return M().Property *= 2; } public int PreIncrementInstancePropertyByte() { - return ++this.M().ByteProperty; + return ++M().ByteProperty; } public int PostIncrementInstancePropertyByte() { - return this.M().ByteProperty++; + return M().ByteProperty++; } public void IncrementInstancePropertyByte() { - this.M().ByteProperty++; + M().ByteProperty++; } public void DoubleInstancePropertyByte() { - this.M().ByteProperty *= 2; + M().ByteProperty *= 2; } public int DoubleInstancePropertyByteAndReturn() { - return this.M().ByteProperty *= 2; + return M().ByteProperty *= 2; } public int PreIncrementStaticField() { - return ++CompoundAssignmentTest.StaticField; + return ++StaticField; } public int PostIncrementStaticField() { - return CompoundAssignmentTest.StaticField++; + return StaticField++; } public void IncrementStaticField() { - CompoundAssignmentTest.StaticField++; + StaticField++; } public void DoubleStaticField() { - CompoundAssignmentTest.StaticField *= 2; + StaticField *= 2; } public int DoubleStaticFieldAndReturn() { - return CompoundAssignmentTest.StaticField *= 2; + return StaticField *= 2; } public int PreIncrementStaticFieldShort() { - return ++CompoundAssignmentTest.StaticShortField; + return ++StaticShortField; } public int PostIncrementStaticFieldShort() { - return CompoundAssignmentTest.StaticShortField++; + return StaticShortField++; } public void IncrementStaticFieldShort() { - CompoundAssignmentTest.StaticShortField++; + StaticShortField++; } public void DoubleStaticFieldShort() { - CompoundAssignmentTest.StaticShortField *= 2; + StaticShortField *= 2; } public short DoubleStaticFieldAndReturnShort() { - return CompoundAssignmentTest.StaticShortField *= 2; + return StaticShortField *= 2; } public int PreIncrementStaticProperty() { - return ++CompoundAssignmentTest.StaticProperty; + return ++StaticProperty; } public int PostIncrementStaticProperty() { - return CompoundAssignmentTest.StaticProperty++; + return StaticProperty++; } public void IncrementStaticProperty() { - CompoundAssignmentTest.StaticProperty++; + StaticProperty++; } public void DoubleStaticProperty() { - CompoundAssignmentTest.StaticProperty *= 2; + StaticProperty *= 2; } public int DoubleStaticPropertyAndReturn() { - return CompoundAssignmentTest.StaticProperty *= 2; + return StaticProperty *= 2; } public ShortEnum PreIncrementStaticPropertyShort() { - return ++CompoundAssignmentTest.StaticShortProperty; + return ++StaticShortProperty; } public ShortEnum PostIncrementStaticPropertyShort() { - return CompoundAssignmentTest.StaticShortProperty++; + return StaticShortProperty++; } public void IncrementStaticPropertyShort() { - CompoundAssignmentTest.StaticShortProperty++; + StaticShortProperty++; } private static Item GetItem(object obj) @@ -503,7 +503,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty private static void Issue882() { - Item item = CompoundAssignmentTest.GetItem(null); + Item item = GetItem(null); item.Self = item; } @@ -512,12 +512,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty // cannot decompile to: "a %= b;", because the % operator does not apply to enums a = (MyEnum)((int)a % (int)b); // same with enum field: - this.enumField = (MyEnum)((int)this.enumField % (int)b); + enumField = (MyEnum)((int)enumField % (int)b); } private void Issue588(ushort val) { - this.ushortDict.Add(this.ushortField++, val); + ushortDict.Add(ushortField++, val); } private void Issue1007(TimeSpan[] items, int startIndex, TimeSpan item) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs index e39e9f5f8..7d5e48a65 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs @@ -35,14 +35,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public Action CaptureOfThis() { return delegate { - this.CaptureOfThis(); + CaptureOfThis(); }; } public Action CaptureOfThisAndParameter(int a) { return delegate { - this.CaptureOfThisAndParameter(a); + CaptureOfThisAndParameter(a); }; } @@ -51,7 +51,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty foreach (int item in Enumerable.Empty()) { if (item > 0) { return delegate { - this.CaptureOfThisAndParameter(item + a); + CaptureOfThisAndParameter(item + a); }; } } @@ -64,7 +64,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty int copyOfItem = item; if (item > 0) { return delegate { - this.CaptureOfThisAndParameter(item + a + copyOfItem); + CaptureOfThisAndParameter(item + a + copyOfItem); }; } } @@ -74,7 +74,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void LambdaInForLoop() { for (int i = 0; i < 100000; i++) { - this.Bar(() => this.Foo()); + Bar(() => Foo()); } } @@ -95,34 +95,34 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void Bug951(int amount) { - this.DoAction(delegate { + DoAction(delegate { if (amount < 0) { amount = 0; } - this.DoAction(delegate { - this.NoOp(amount); + DoAction(delegate { + NoOp(amount); }); }); } public void Bug951b() { - int amount = this.Foo(); - this.DoAction(delegate { + int amount = Foo(); + DoAction(delegate { if (amount < 0) { amount = 0; } - this.DoAction(delegate { - this.NoOp(amount); + DoAction(delegate { + NoOp(amount); }); }); } public void Bug951c(SomeData data) { - this.DoAction(delegate { - this.DoAction(delegate { - this.DoSomething(data.Value); + DoAction(delegate { + DoAction(delegate { + DoSomething(data.Value); }); }); } @@ -152,7 +152,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static Action ExtensionMethodUnbound() { - return DelegateConstruction.Test; + return Test; } public static Action ExtensionMethodBound() @@ -167,7 +167,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static object StaticMethod() { - return new Func(DelegateConstruction.ExtensionMethodBound); + return new Func(ExtensionMethodBound); } public static object InstanceMethod() diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs index 859cd59aa..e73422857 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs @@ -34,8 +34,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public bool ConditionalReturnInThrow() { try { - if (this.B(0)) { - return this.B(1); + if (B(0)) { + return B(1); } } catch { } @@ -46,7 +46,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { try { Console.WriteLine("Try"); - return this.B(new Random().Next()); + return B(new Random().Next()); } catch (Exception) { Console.WriteLine("CatchException"); } @@ -57,7 +57,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { try { Console.WriteLine("Try"); - return this.B(new Random().Next()); + return B(new Random().Next()); } catch (Exception ex) { Console.WriteLine("CatchException ex: " + ex.ToString()); } @@ -69,7 +69,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { try { Console.WriteLine("Try"); - return this.B(new Random().Next()); + return B(new Random().Next()); } catch (Exception ex) when (ex.Message.Contains("test")) { Console.WriteLine("CatchException ex: " + ex.ToString()); } @@ -80,7 +80,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { try { Console.WriteLine("Try"); - return this.B(new Random().Next()); + return B(new Random().Next()); } catch (Exception ex) when (ex is ArgumentException || ex is IOException) { Console.WriteLine("CatchException ex: " + ex.ToString()); } @@ -91,7 +91,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { try { Console.WriteLine("Try"); - return await this.T(); + return await T(); } catch (Exception ex) when (ex is ArgumentException || ex is IOException) { Console.WriteLine("CatchException ex: " + ex.ToString()); } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs index 96b586056..db40b39b1 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs @@ -77,28 +77,28 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void Parameter(bool a) { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => a); + ToCode(X(), () => a); } public void LocalVariable() { bool a = true; - ExpressionTrees.ToCode(ExpressionTrees.X(), () => a); + ToCode(X(), () => a); } public void LambdaParameter() { - ExpressionTrees.ToCode(ExpressionTrees.X(), (bool a) => a); + ToCode(X(), (bool a) => a); } public void AddOperator(int x) { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => 1 + x + 2); + ToCode(X(), () => 1 + x + 2); } public void AnonymousClasses() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new { + ToCode(X(), () => new { X = 3, A = "a" }); @@ -106,7 +106,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void ArrayIndex() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => (new int[3] { + ToCode(X(), () => (new int[3] { 3, 4, 5 @@ -115,7 +115,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void ArrayLengthAndDoubles() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new double[3] { + ToCode(X(), () => new double[3] { 1.0, 2.01, 3.5 @@ -127,38 +127,38 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void AsOperator() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new object() as string); + ToCode(X(), () => new object() as string); } public void ComplexGenericName() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ((Func)((int x) => x > 0))(0)); + ToCode(X(), () => ((Func)((int x) => x > 0))(0)); } public void DefaultValue() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new TimeSpan(1, 2, 3) == default(TimeSpan)); + ToCode(X(), () => new TimeSpan(1, 2, 3) == default(TimeSpan)); } public void EnumConstant() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new object().Equals(MidpointRounding.ToEven)); + ToCode(X(), () => new object().Equals(MidpointRounding.ToEven)); } public void IndexerAccess() { Dictionary dict = Enumerable.Range(1, 20).ToDictionary((int n) => n.ToString()); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => dict["3"] == 3); + ToCode(X(), () => dict["3"] == 3); } public void IsOperator() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new object() is string); + ToCode(X(), () => new object() is string); } public void ListInitializer() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new Dictionary { + ToCode(X(), () => new Dictionary { { 1, 1 @@ -176,7 +176,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void ListInitializer2() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new List(50) { + ToCode(X(), () => new List(50) { 1, 2, 3 @@ -185,7 +185,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void ListInitializer3() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new List { + ToCode(X(), () => new List { 1, 2, 3 @@ -194,51 +194,51 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void LiteralCharAndProperty() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new string(' ', 3).Length == 1); + ToCode(X(), () => new string(' ', 3).Length == 1); } public void CharNoCast() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => "abc"[1] == 'b'); + ToCode(X(), () => "abc"[1] == 'b'); } public void StringsImplicitCast() { int i = 1; string x = "X"; - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ((("a\n\\b" ?? x) + x).Length == 2) ? false : (true && (1m + (decimal)(-i) > 0m || false))); + ToCode(X(), () => ((("a\n\\b" ?? x) + x).Length == 2) ? false : (true && (1m + (decimal)(-i) > 0m || false))); } public void NotImplicitCast() { byte z = 42; - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ~z == 0); + ToCode(X(), () => ~z == 0); } public void MembersBuiltin() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => 1.23m.ToString()); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ((Enum)(object)AttributeTargets.All).HasFlag((Enum)AttributeTargets.Assembly)); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => "abc".Length == 3); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => 'a'.CompareTo('b') < 0); + ToCode(X(), () => 1.23m.ToString()); + ToCode(X(), () => ((Enum)(object)AttributeTargets.All).HasFlag((Enum)AttributeTargets.Assembly)); + ToCode(X(), () => "abc".Length == 3); + ToCode(X(), () => 'a'.CompareTo('b') < 0); } public void MembersDefault() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => default(DateTime).Ticks == 0); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ((Array)null).Length == 0); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ((Type)null).IsLayoutSequential); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ((List)null).Count); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ((Array)null).Clone() == null); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ((Type)null).IsInstanceOfType(new object())); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ((List)null).AsReadOnly()); + ToCode(X(), () => default(DateTime).Ticks == 0); + ToCode(X(), () => ((Array)null).Length == 0); + ToCode(X(), () => ((Type)null).IsLayoutSequential); + ToCode(X(), () => ((List)null).Count); + ToCode(X(), () => ((Array)null).Clone() == null); + ToCode(X(), () => ((Type)null).IsInstanceOfType(new object())); + ToCode(X(), () => ((List)null).AsReadOnly()); } public void DoAssert() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => this.field != this.C()); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => !object.ReferenceEquals(this, new ExpressionTrees())); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => this.MyEquals(this) && !this.MyEquals(null)); + ToCode(X(), () => field != C()); + ToCode(X(), () => !object.ReferenceEquals(this, new ExpressionTrees())); + ToCode(X(), () => MyEquals(this) && !MyEquals(null)); } private int C() @@ -253,7 +253,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void MethodGroupAsExtensionMethod() { - ExpressionTrees.ToCode(ExpressionTrees.X(), (Expression>>)(() => ((IEnumerable)new int[4] { + ToCode(X(), (Expression>>)(() => ((IEnumerable)new int[4] { 2000, 2004, 2008, @@ -263,7 +263,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void MethodGroupConstant() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => Array.TrueForAll(new int[4] { + ToCode(X(), () => Array.TrueForAll(new int[4] { 2000, 2004, 2008, @@ -271,7 +271,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty }, DateTime.IsLeapYear)); HashSet set = new HashSet(); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new int[4] { + ToCode(X(), () => new int[4] { 2000, 2004, 2008, @@ -279,32 +279,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty }.All(set.Add)); Func, bool> sink = (Func f) => f(null, null); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => sink(object.Equals)); + ToCode(X(), () => sink(object.Equals)); } public void MultipleCasts() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => 1 == (int)(object)1); + ToCode(X(), () => 1 == (int)(object)1); } public void MultipleDots() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => 3.ToString().ToString().Length > 0); + ToCode(X(), () => 3.ToString().ToString().Length > 0); } public void NestedLambda() { Func, int> call = (Func f) => f(); //no params - ExpressionTrees.ToCode(ExpressionTrees.X(), () => call(() => 42)); + ToCode(X(), () => call(() => 42)); //one param - ExpressionTrees.ToCode(ExpressionTrees.X(), () => from x in new int[2] { - 37, - 42 - } - select x * 2); + ToCode(X(), () => from x in new int[2] { + 37, + 42 + } + select x * 2); //two params - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new int[2] { + ToCode(X(), () => new int[2] { 37, 42 }.Select((int x, int i) => x * 2)); @@ -312,7 +312,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void CurriedLambda() { - ExpressionTrees.ToCode(ExpressionTrees.X(), (Expression>>>)((int a) => (int b) => (int c) => a + b + c)); + ToCode(X(), (Expression>>>)((int a) => (int b) => (int c) => a + b + c)); } private bool Fizz(Func a) @@ -337,19 +337,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void NestedLambda2() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => this.Fizz((string x) => x == "a")); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => this.Fizz((string x) => x != "a")); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => this.Fizz((Action x) => x == new Action(this.NestedLambda2))); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => this.Fizz((Action x) => x != new Action(this.NestedLambda2))); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => this.Fizz((int x) => x == 37)); + ToCode(X(), () => Fizz((string x) => x == "a")); + ToCode(X(), () => Fizz((string x) => x != "a")); + ToCode(X(), () => Fizz((Action x) => x == new Action(NestedLambda2))); + ToCode(X(), () => Fizz((Action x) => x != new Action(NestedLambda2))); + ToCode(X(), () => Fizz((int x) => x == 37)); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => this.Fizz((int x) => true)); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => this.Buzz((int x) => true)); + ToCode(X(), () => Fizz((int x) => true)); + ToCode(X(), () => Buzz((int x) => true)); } public void NewArrayAndExtensionMethod() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new double[3] { + ToCode(X(), () => new double[3] { 1.0, 2.01, 3.5 @@ -362,12 +362,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void NewMultiDimArray() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new int[3, 4].Length == 1); + ToCode(X(), () => new int[3, 4].Length == 1); } public void NewObject() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new object() != new object()); + ToCode(X(), () => new object() != new object()); } public void NotOperator() @@ -375,9 +375,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty bool x = true; int y = 3; byte z = 42; - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ~z == 0); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ~y == 0); - ExpressionTrees.ToCode(ExpressionTrees.X(), () => !x); + ToCode(X(), () => ~z == 0); + ToCode(X(), () => ~y == 0); + ToCode(X(), () => !x); } public void ObjectInitializers() @@ -386,7 +386,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty CloseInput = false, CheckCharacters = false }; - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new XmlReaderSettings { + ToCode(X(), () => new XmlReaderSettings { CloseInput = s.CloseInput, CheckCharacters = s.CheckCharacters }.Equals(s)); @@ -394,17 +394,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void Quoted() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => (Expression>)((int n, string s) => s + n.ToString()) != null); + ToCode(X(), () => (Expression>)((int n, string s) => s + n.ToString()) != null); } public void Quoted2() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ExpressionTrees.ToCode(ExpressionTrees.X(), () => true).Equals(null)); + ToCode(X(), () => ToCode(X(), () => true).Equals(null)); } public void QuotedWithAnonymous() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => (from o in new[] { + ToCode(X(), () => (from o in new[] { new { X = "a", Y = "b" @@ -415,22 +415,22 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void StaticCall() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => object.Equals(3, 0)); + ToCode(X(), () => object.Equals(3, 0)); } public void ThisCall() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => !this.Equals(3)); + ToCode(X(), () => !Equals(3)); } public void ThisExplicit() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => object.Equals(this, 3)); + ToCode(X(), () => object.Equals(this, 3)); } public void TypedConstant() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => new Type[2] { + ToCode(X(), () => new Type[2] { typeof(int), typeof(string) }); @@ -438,34 +438,34 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void StaticCallImplicitCast() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => object.Equals(3, 0)); + ToCode(X(), () => object.Equals(3, 0)); } public void StaticMembers() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => (DateTime.Now > DateTime.Now + TimeSpan.FromMilliseconds(10.001)).ToString() == "False"); + ToCode(X(), () => (DateTime.Now > DateTime.Now + TimeSpan.FromMilliseconds(10.001)).ToString() == "False"); } public void Strings() { int i = 1; string x = "X"; - ExpressionTrees.ToCode(ExpressionTrees.X(), () => ((("a\n\\b" ?? x) + x).Length == 2) ? false : (true && (1m + (decimal)(-i) > 0m || false))); + ToCode(X(), () => ((("a\n\\b" ?? x) + x).Length == 2) ? false : (true && (1m + (decimal)(-i) > 0m || false))); } public void GenericClassInstance() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => (double)new GenericClass().InstanceField + new GenericClass().InstanceProperty); + ToCode(X(), () => (double)new GenericClass().InstanceField + new GenericClass().InstanceProperty); } public void GenericClassStatic() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => (double)GenericClass.StaticField + GenericClass.StaticProperty); + ToCode(X(), () => (double)GenericClass.StaticField + GenericClass.StaticProperty); } public void InvokeGenericMethod() { - ExpressionTrees.ToCode(ExpressionTrees.X(), () => GenericClass.GenericMethod()); + ToCode(X(), () => GenericClass.GenericMethod()); } private static void Test(T delegateExpression, Expression expressionTree) @@ -474,165 +474,165 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ArrayIndexer() { - ExpressionTrees.Test((Func)((int[] array) => array[0]), (Expression>)((int[] array) => array[0])); - ExpressionTrees.Test((Func)((int[] array, int index) => array[index]), (Expression>)((int[] array, int index) => array[index])); - ExpressionTrees.Test((Func)((int[,] array) => array[0, 5]), (Expression>)((int[,] array) => array[0, 5])); - ExpressionTrees.Test((Func)((int[,] array, int index) => array[index, 7]), (Expression>)((int[,] array, int index) => array[index, 7])); - ExpressionTrees.Test((Func)((int[][] array, int index) => array[index][7]), (Expression>)((int[][] array, int index) => array[index][7])); + Test((Func)((int[] array) => array[0]), (Expression>)((int[] array) => array[0])); + Test((Func)((int[] array, int index) => array[index]), (Expression>)((int[] array, int index) => array[index])); + Test((Func)((int[,] array) => array[0, 5]), (Expression>)((int[,] array) => array[0, 5])); + Test((Func)((int[,] array, int index) => array[index, 7]), (Expression>)((int[,] array, int index) => array[index, 7])); + Test((Func)((int[][] array, int index) => array[index][7]), (Expression>)((int[][] array, int index) => array[index][7])); } public static void ArrayLength() { - ExpressionTrees.Test((Func)((int[] array) => array.Length), (Expression>)((int[] array) => array.Length)); - ExpressionTrees.Test((Func)(() => ((Array)null).Length), (Expression>)(() => ((Array)null).Length)); + Test((Func)((int[] array) => array.Length), (Expression>)((int[] array) => array.Length)); + Test((Func)(() => ((Array)null).Length), (Expression>)(() => ((Array)null).Length)); } public static void NewObj() { - ExpressionTrees.Test((Func)(() => new SimpleType()), (Expression>)(() => new SimpleType())); - ExpressionTrees.Test((Func)(() => new SimpleTypeWithCtor(5)), (Expression>)(() => new SimpleTypeWithCtor(5))); - ExpressionTrees.Test((Func)(() => new SimpleTypeWithMultipleCtors()), (Expression>)(() => new SimpleTypeWithMultipleCtors())); - ExpressionTrees.Test((Func)(() => new SimpleTypeWithMultipleCtors(5)), (Expression>)(() => new SimpleTypeWithMultipleCtors(5))); - ExpressionTrees.Test((Func)(() => new GenericClass()), (Expression>)(() => new GenericClass())); - ExpressionTrees.Test((Func)(() => new GenericClassWithCtor()), (Expression>)(() => new GenericClassWithCtor())); - ExpressionTrees.Test((Func)(() => new GenericClassWithMultipleCtors(5)), (Expression>)(() => new GenericClassWithMultipleCtors(5))); + Test((Func)(() => new SimpleType()), (Expression>)(() => new SimpleType())); + Test((Func)(() => new SimpleTypeWithCtor(5)), (Expression>)(() => new SimpleTypeWithCtor(5))); + Test((Func)(() => new SimpleTypeWithMultipleCtors()), (Expression>)(() => new SimpleTypeWithMultipleCtors())); + Test((Func)(() => new SimpleTypeWithMultipleCtors(5)), (Expression>)(() => new SimpleTypeWithMultipleCtors(5))); + Test((Func)(() => new GenericClass()), (Expression>)(() => new GenericClass())); + Test((Func)(() => new GenericClassWithCtor()), (Expression>)(() => new GenericClassWithCtor())); + Test((Func)(() => new GenericClassWithMultipleCtors(5)), (Expression>)(() => new GenericClassWithMultipleCtors(5))); } public unsafe static void TypeOfExpr() { - ExpressionTrees.Test((Func)(() => typeof(int)), (Expression>)(() => typeof(int))); - ExpressionTrees.Test((Func)(() => typeof(object)), (Expression>)(() => typeof(object))); - ExpressionTrees.Test((Func)(() => typeof(List<>)), (Expression>)(() => typeof(List<>))); - ExpressionTrees.Test((Func)(() => typeof(List)), (Expression>)(() => typeof(List))); - ExpressionTrees.Test((Func)(() => typeof(int*)), (Expression>)(() => typeof(int*))); + Test((Func)(() => typeof(int)), (Expression>)(() => typeof(int))); + Test((Func)(() => typeof(object)), (Expression>)(() => typeof(object))); + Test((Func)(() => typeof(List<>)), (Expression>)(() => typeof(List<>))); + Test((Func)(() => typeof(List)), (Expression>)(() => typeof(List))); + Test((Func)(() => typeof(int*)), (Expression>)(() => typeof(int*))); } public static void AsTypeExpr() { - ExpressionTrees.Test((Func)((object obj) => obj as MyClass), (Expression>)((object obj) => obj as MyClass)); - ExpressionTrees.Test((Func>)((object obj) => obj as GenericClass), (Expression>>)((object obj) => obj as GenericClass)); + Test((Func)((object obj) => obj as MyClass), (Expression>)((object obj) => obj as MyClass)); + Test((Func>)((object obj) => obj as GenericClass), (Expression>>)((object obj) => obj as GenericClass)); } public static void IsTypeExpr() { - ExpressionTrees.Test((Func)((object obj) => obj is MyClass), (Expression>)((object obj) => obj is MyClass)); + Test((Func)((object obj) => obj is MyClass), (Expression>)((object obj) => obj is MyClass)); } public static void UnaryLogicalOperators() { - ExpressionTrees.Test((Func)((bool a) => !a), (Expression>)((bool a) => !a)); + Test((Func)((bool a) => !a), (Expression>)((bool a) => !a)); } public static void ConditionalOperator() { - ExpressionTrees.ToCode(null, (bool a) => a ? 5 : 10); - ExpressionTrees.ToCode(null, (object a) => a ?? new MyClass()); + ToCode(null, (bool a) => a ? 5 : 10); + ToCode(null, (object a) => a ?? new MyClass()); } public static void BinaryLogicalOperators() { - ExpressionTrees.ToCode(null, (int a, int b) => a == b); - ExpressionTrees.ToCode(null, (int a, int b) => a != b); - ExpressionTrees.ToCode(null, (int a, int b) => a < b); - ExpressionTrees.ToCode(null, (int a, int b) => a <= b); - ExpressionTrees.ToCode(null, (int a, int b) => a > b); - ExpressionTrees.ToCode(null, (int a, int b) => a >= b); - ExpressionTrees.ToCode(null, (int a, int b) => a == 1 && b == 2); - ExpressionTrees.ToCode(null, (int a, int b) => a == 1 || b == 2); - ExpressionTrees.ToCode(null, (int a, short b) => a == b); - ExpressionTrees.ToCode(null, (ushort a, int b) => a != b); - ExpressionTrees.ToCode(null, (int a, long b) => (long)a < b); - ExpressionTrees.ToCode(null, (ulong a, uint b) => a <= (ulong)b); - ExpressionTrees.ToCode(null, (int a, uint b) => (long)a <= (long)b); - ExpressionTrees.ToCode(null, (int a, long b) => (long)a > b); - ExpressionTrees.ToCode(null, (short a, long b) => (long)a >= b); - ExpressionTrees.ToCode(null, (int a, int b) => a == 1 && b == 2); - ExpressionTrees.ToCode(null, (int a, int b) => a == 1 || b == 2); + ToCode(null, (int a, int b) => a == b); + ToCode(null, (int a, int b) => a != b); + ToCode(null, (int a, int b) => a < b); + ToCode(null, (int a, int b) => a <= b); + ToCode(null, (int a, int b) => a > b); + ToCode(null, (int a, int b) => a >= b); + ToCode(null, (int a, int b) => a == 1 && b == 2); + ToCode(null, (int a, int b) => a == 1 || b == 2); + ToCode(null, (int a, short b) => a == b); + ToCode(null, (ushort a, int b) => a != b); + ToCode(null, (int a, long b) => (long)a < b); + ToCode(null, (ulong a, uint b) => a <= (ulong)b); + ToCode(null, (int a, uint b) => (long)a <= (long)b); + ToCode(null, (int a, long b) => (long)a > b); + ToCode(null, (short a, long b) => (long)a >= b); + ToCode(null, (int a, int b) => a == 1 && b == 2); + ToCode(null, (int a, int b) => a == 1 || b == 2); } public static void UnaryArithmeticOperators() { - ExpressionTrees.Test((Func)((int a) => a), (Expression>)((int a) => a)); - ExpressionTrees.Test((Func)((int a) => -a), (Expression>)((int a) => -a)); + Test((Func)((int a) => a), (Expression>)((int a) => a)); + Test((Func)((int a) => -a), (Expression>)((int a) => -a)); } public static void BinaryArithmeticOperators() { - ExpressionTrees.Test((Func)((int a, int b) => a + b), (Expression>)((int a, int b) => a + b)); - ExpressionTrees.Test((Func)((int a, int b) => a - b), (Expression>)((int a, int b) => a - b)); - ExpressionTrees.Test((Func)((int a, int b) => a * b), (Expression>)((int a, int b) => a * b)); - ExpressionTrees.Test((Func)((int a, int b) => a / b), (Expression>)((int a, int b) => a / b)); - ExpressionTrees.Test((Func)((int a, int b) => a % b), (Expression>)((int a, int b) => a % b)); - ExpressionTrees.Test((Func)((long a, int b) => a + b), (Expression>)((long a, int b) => a + (long)b)); - ExpressionTrees.Test((Func)((long a, int b) => a - b), (Expression>)((long a, int b) => a - (long)b)); - ExpressionTrees.Test((Func)((long a, int b) => a * b), (Expression>)((long a, int b) => a * (long)b)); - ExpressionTrees.Test((Func)((long a, int b) => a / b), (Expression>)((long a, int b) => a / (long)b)); - ExpressionTrees.Test((Func)((long a, int b) => a % b), (Expression>)((long a, int b) => a % (long)b)); - ExpressionTrees.Test((Func)((short a, int b) => a + b), (Expression>)((short a, int b) => a + b)); - ExpressionTrees.Test((Func)((int a, short b) => a - b), (Expression>)((int a, short b) => a - b)); - ExpressionTrees.Test((Func)((short a, int b) => a * b), (Expression>)((short a, int b) => a * b)); - ExpressionTrees.Test((Func)((int a, short b) => a / b), (Expression>)((int a, short b) => a / b)); - ExpressionTrees.Test((Func)((short a, int b) => a % b), (Expression>)((short a, int b) => a % b)); + Test((Func)((int a, int b) => a + b), (Expression>)((int a, int b) => a + b)); + Test((Func)((int a, int b) => a - b), (Expression>)((int a, int b) => a - b)); + Test((Func)((int a, int b) => a * b), (Expression>)((int a, int b) => a * b)); + Test((Func)((int a, int b) => a / b), (Expression>)((int a, int b) => a / b)); + Test((Func)((int a, int b) => a % b), (Expression>)((int a, int b) => a % b)); + Test((Func)((long a, int b) => a + b), (Expression>)((long a, int b) => a + (long)b)); + Test((Func)((long a, int b) => a - b), (Expression>)((long a, int b) => a - (long)b)); + Test((Func)((long a, int b) => a * b), (Expression>)((long a, int b) => a * (long)b)); + Test((Func)((long a, int b) => a / b), (Expression>)((long a, int b) => a / (long)b)); + Test((Func)((long a, int b) => a % b), (Expression>)((long a, int b) => a % (long)b)); + Test((Func)((short a, int b) => a + b), (Expression>)((short a, int b) => a + b)); + Test((Func)((int a, short b) => a - b), (Expression>)((int a, short b) => a - b)); + Test((Func)((short a, int b) => a * b), (Expression>)((short a, int b) => a * b)); + Test((Func)((int a, short b) => a / b), (Expression>)((int a, short b) => a / b)); + Test((Func)((short a, int b) => a % b), (Expression>)((short a, int b) => a % b)); } public static void BitOperators() { - ExpressionTrees.Test((Func)((int a) => ~a), (Expression>)((int a) => ~a)); - ExpressionTrees.Test((Func)((int a, int b) => a & b), (Expression>)((int a, int b) => a & b)); - ExpressionTrees.Test((Func)((int a, int b) => a | b), (Expression>)((int a, int b) => a | b)); - ExpressionTrees.Test((Func)((int a, int b) => a ^ b), (Expression>)((int a, int b) => a ^ b)); + Test((Func)((int a) => ~a), (Expression>)((int a) => ~a)); + Test((Func)((int a, int b) => a & b), (Expression>)((int a, int b) => a & b)); + Test((Func)((int a, int b) => a | b), (Expression>)((int a, int b) => a | b)); + Test((Func)((int a, int b) => a ^ b), (Expression>)((int a, int b) => a ^ b)); } public static void ShiftOperators() { - ExpressionTrees.Test((Func)((int a) => a >> 2), (Expression>)((int a) => a >> 2)); - ExpressionTrees.Test((Func)((int a) => a << 2), (Expression>)((int a) => a << 2)); - ExpressionTrees.Test((Func)((long a) => a >> 2), (Expression>)((long a) => a >> 2)); - ExpressionTrees.Test((Func)((long a) => a << 2), (Expression>)((long a) => a << 2)); + Test((Func)((int a) => a >> 2), (Expression>)((int a) => a >> 2)); + Test((Func)((int a) => a << 2), (Expression>)((int a) => a << 2)); + Test((Func)((long a) => a >> 2), (Expression>)((long a) => a >> 2)); + Test((Func)((long a) => a << 2), (Expression>)((long a) => a << 2)); } public static void SimpleExpressions() { - ExpressionTrees.Test((Func)(() => 0), (Expression>)(() => 0)); - ExpressionTrees.Test((Func)((int a) => a), (Expression>)((int a) => a)); + Test((Func)(() => 0), (Expression>)(() => 0)); + Test((Func)((int a) => a), (Expression>)((int a) => a)); } public static void Capturing() { int captured = 5; - ExpressionTrees.Test((Func)(() => captured), (Expression>)(() => captured)); + Test((Func)(() => captured), (Expression>)(() => captured)); } public static void FieldAndPropertyAccess() { - ExpressionTrees.ToCode(null, () => 1); - ExpressionTrees.ToCode(null, () => SimpleType.StaticField); - ExpressionTrees.ToCode(null, () => SimpleType.StaticReadonlyField); - ExpressionTrees.ToCode(null, () => SimpleType.StaticProperty); - ExpressionTrees.ToCode(null, () => SimpleType.StaticReadonlyProperty); - ExpressionTrees.ToCode(null, (SimpleType a) => a.Field); - ExpressionTrees.ToCode(null, (SimpleType a) => a.Property); - ExpressionTrees.ToCode(null, (SimpleType a) => a.ReadonlyField); - ExpressionTrees.ToCode(null, (SimpleType a) => a.ReadonlyProperty); + ToCode(null, () => 1); + ToCode(null, () => SimpleType.StaticField); + ToCode(null, () => SimpleType.StaticReadonlyField); + ToCode(null, () => SimpleType.StaticProperty); + ToCode(null, () => SimpleType.StaticReadonlyProperty); + ToCode(null, (SimpleType a) => a.Field); + ToCode(null, (SimpleType a) => a.Property); + ToCode(null, (SimpleType a) => a.ReadonlyField); + ToCode(null, (SimpleType a) => a.ReadonlyProperty); } public static void Call() { - ExpressionTrees.ToCode(null, (string a) => Console.WriteLine(a)); - ExpressionTrees.Test((Func)((string a) => a.ToString()), (Expression>)((string a) => a.ToString())); - ExpressionTrees.Test((Func)((int a) => a.ToString()), (Expression>)((int a) => a.ToString())); - ExpressionTrees.Test((Func)((string a) => a.ToArray()), (Expression>)((string a) => a.ToArray())); - ExpressionTrees.Test((Func)(() => 'a'.CompareTo('b') < 0), (Expression>)(() => 'a'.CompareTo('b') < 0)); + ToCode(null, (string a) => Console.WriteLine(a)); + Test((Func)((string a) => a.ToString()), (Expression>)((string a) => a.ToString())); + Test((Func)((int a) => a.ToString()), (Expression>)((int a) => a.ToString())); + Test((Func)((string a) => a.ToArray()), (Expression>)((string a) => a.ToArray())); + Test((Func)(() => 'a'.CompareTo('b') < 0), (Expression>)(() => 'a'.CompareTo('b') < 0)); } public static void Quote() { - ExpressionTrees.Test((Func)(() => (Expression>)((int n, string s) => s + n.ToString()) != null), (Expression>)(() => (Expression>)((int n, string s) => s + n.ToString()) != null)); + Test((Func)(() => (Expression>)((int n, string s) => s + n.ToString()) != null), (Expression>)(() => (Expression>)((int n, string s) => s + n.ToString()) != null)); } public static void ArrayInitializer() { - ExpressionTrees.Test((Func)(() => new int[3] { + Test((Func)(() => new int[3] { 1, 2, 3 @@ -641,10 +641,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty 2, 3 })); - ExpressionTrees.Test((Func)(() => new int[3]), (Expression>)(() => new int[3])); - ExpressionTrees.Test((Func)(() => new int[3, 5]), (Expression>)(() => new int[3, 5])); - ExpressionTrees.Test((Func)(() => new int[3][]), (Expression>)(() => new int[3][])); - ExpressionTrees.Test((Func)(() => new int[1][] { + Test((Func)(() => new int[3]), (Expression>)(() => new int[3])); + Test((Func)(() => new int[3, 5]), (Expression>)(() => new int[3, 5])); + Test((Func)(() => new int[3][]), (Expression>)(() => new int[3][])); + Test((Func)(() => new int[1][] { new int[3] { 1, 2, @@ -661,7 +661,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void AnonymousTypes() { - ExpressionTrees.Test((Func)(() => new { + Test((Func)(() => new { A = 5, B = "Test" }), (Expression>)(() => new { @@ -672,7 +672,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ObjectInit() { - ExpressionTrees.ToCode(null, () => new SimpleType { + ToCode(null, () => new SimpleType { Property = 4, Field = 3 }); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs index 462c9fe16..87cd568f8 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs @@ -41,8 +41,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public S(int a) { - this.A = a; - this.B = 0; + A = a; + B = 0; } } @@ -119,8 +119,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public StructData(int initialValue) { this = default(StructData); - this.Field = initialValue; - this.Property = initialValue; + Field = initialValue; + Property = initialValue; } } @@ -155,7 +155,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public C Test1Alternative() { - return InitializerTests.TestCall(1, new C { + return TestCall(1, new C { L = new List { new S(1) } @@ -180,7 +180,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public C Test3b() { - return InitializerTests.TestCall(0, new C { + return TestCall(0, new C { Z = 1, Y = { A = 2 @@ -200,7 +200,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CollectionInitializerList() { - InitializerTests.X(InitializerTests.Y(), new List { + X(Y(), new List { 1, 2, 3 @@ -216,7 +216,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CollectionInitializerDictionary() { - InitializerTests.X(InitializerTests.Y(), new Dictionary { + X(Y(), new Dictionary { { "First", 1 @@ -234,7 +234,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CollectionInitializerDictionaryWithEnumTypes() { - InitializerTests.X(InitializerTests.Y(), new Dictionary { + X(Y(), new Dictionary { { MyEnum.a, MyEnum2.c @@ -252,12 +252,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty list.Add(1); list.Add(2); list.Add(3); - InitializerTests.X(InitializerTests.Y(), list); + X(Y(), list); } public static void ObjectInitializer() { - InitializerTests.X(InitializerTests.Y(), new Data { + X(Y(), new Data { a = MyEnum.a }); } @@ -266,7 +266,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { Data data = new Data(); data.a = MyEnum.a; - InitializerTests.X(InitializerTests.Y(), data); + X(Y(), data); } public static void NotAnObjectInitializerWithEvent() @@ -275,12 +275,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty data.TestEvent += delegate { Console.WriteLine(); }; - InitializerTests.X(InitializerTests.Y(), data); + X(Y(), data); } public static void ObjectInitializerAssignCollectionToField() { - InitializerTests.X(InitializerTests.Y(), new Data { + X(Y(), new Data { a = MyEnum.a, FieldList = new List { MyEnum2.c, @@ -291,7 +291,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ObjectInitializerAddToCollectionInField() { - InitializerTests.X(InitializerTests.Y(), new Data { + X(Y(), new Data { a = MyEnum.a, FieldList = { MyEnum2.c, @@ -302,7 +302,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ObjectInitializerAssignCollectionToProperty() { - InitializerTests.X(InitializerTests.Y(), new Data { + X(Y(), new Data { a = MyEnum.a, PropertyList = new List { MyEnum2.c, @@ -313,7 +313,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ObjectInitializerAddToCollectionInProperty() { - InitializerTests.X(InitializerTests.Y(), new Data { + X(Y(), new Data { a = MyEnum.a, PropertyList = { MyEnum2.c, @@ -324,7 +324,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ObjectInitializerWithInitializationOfNestedObjects() { - InitializerTests.X(InitializerTests.Y(), new Data { + X(Y(), new Data { MoreData = { a = MyEnum.a, MoreData = { @@ -352,7 +352,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty #if CS60 public static void SimpleDictInitializer() { - InitializerTests.X(InitializerTests.Y(), new Data { + X(Y(), new Data { MoreData = { a = MyEnum.a, [2] = null @@ -362,15 +362,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void MixedObjectAndDictInitializer() { - InitializerTests.X(InitializerTests.Y(), new Data { + X(Y(), new Data { MoreData = { a = MyEnum.a, - [InitializerTests.GetInt()] = { + [GetInt()] = { a = MyEnum.b, FieldList = { MyEnum2.c }, - [InitializerTests.GetInt(), InitializerTests.GetString()] = new Data(), + [GetInt(), GetString()] = new Data(), [2] = null } } @@ -395,7 +395,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ObjectInitializerWithInitializationOfDeeplyNestedObjects() { - InitializerTests.X(InitializerTests.Y(), new Data { + X(Y(), new Data { a = MyEnum.b, MoreData = { a = MyEnum.a, @@ -418,7 +418,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CollectionInitializerInsideObjectInitializers() { - InitializerTests.X(InitializerTests.Y(), new Data { + X(Y(), new Data { MoreData = new Data { a = MyEnum.a, b = MyEnum.b, @@ -434,12 +434,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty StructData structData = default(StructData); structData.Field = 1; structData.Property = 2; - InitializerTests.X(InitializerTests.Y(), structData); + X(Y(), structData); } public static void StructInitializer_DefaultConstructor() { - InitializerTests.X(InitializerTests.Y(), new StructData { + X(Y(), new StructData { Field = 1, Property = 2 }); @@ -450,12 +450,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty StructData structData = new StructData(0); structData.Field = 1; structData.Property = 2; - InitializerTests.X(InitializerTests.Y(), structData); + X(Y(), structData); } public static void StructInitializer_ExplicitConstructor() { - InitializerTests.X(InitializerTests.Y(), new StructData(0) { + X(Y(), new StructData(0) { Field = 1, Property = 2 }); @@ -463,7 +463,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void StructInitializerWithInitializationOfNestedObjects() { - InitializerTests.X(InitializerTests.Y(), new StructData { + X(Y(), new StructData { MoreData = { a = MyEnum.a, FieldList = { @@ -476,7 +476,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void StructInitializerWithinObjectInitializer() { - InitializerTests.X(InitializerTests.Y(), new Data { + X(Y(), new Data { NestedStruct = new StructData(2) { Field = 1, Property = 2 @@ -488,7 +488,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { NumberFormatInfo[] source = null; - InitializerTests.TestCall(0, new Thread(InitializerTests.Bug270_NestedInitialisers) { + TestCall(0, new Thread(Bug270_NestedInitialisers) { Priority = ThreadPriority.BelowNormal, CurrentCulture = new CultureInfo(0) { DateTimeFormat = new DateTimeFormatInfo { @@ -503,7 +503,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void Bug953_MissingNullableSpecifierForArrayInitializer() { - InitializerTests.NoOp(new Guid?[1] { + NoOp(new Guid?[1] { Guid.Empty }); } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InlineAssignmentTest.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InlineAssignmentTest.cs index 89a70cf98..9620accb5 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InlineAssignmentTest.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InlineAssignmentTest.cs @@ -40,30 +40,30 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void SimpleInlineWithLocals() { int index; - Console.WriteLine(this.GetFormat(), index = this.GetIndex()); + Console.WriteLine(GetFormat(), index = GetIndex()); Console.WriteLine(index); InlineAssignmentTest value; - Console.WriteLine(this.GetFormat(), value = new InlineAssignmentTest()); + Console.WriteLine(GetFormat(), value = new InlineAssignmentTest()); Console.WriteLine(value); } public void SimpleInlineWithFields() { - Console.WriteLine(this.field1 = 5); - Console.WriteLine(InlineAssignmentTest.field2 = new InlineAssignmentTest()); + Console.WriteLine(field1 = 5); + Console.WriteLine(field2 = new InlineAssignmentTest()); } public void SimpleInlineWithFields2() { - Console.WriteLine(this.field1 = 5); - Console.WriteLine(this.field1); - Console.WriteLine(InlineAssignmentTest.field2 = new InlineAssignmentTest()); - Console.WriteLine(InlineAssignmentTest.field2); - this.UseShort(this.field4 = 6); - this.UseShort(this.field4 = -10000); - this.UseShort(this.field4 = (short)this.field1); - this.UseShort(this.field4 = this.UseShort(0)); - Console.WriteLine(this.field4); + Console.WriteLine(field1 = 5); + Console.WriteLine(field1); + Console.WriteLine(field2 = new InlineAssignmentTest()); + Console.WriteLine(field2); + UseShort(field4 = 6); + UseShort(field4 = -10000); + UseShort(field4 = (short)field1); + UseShort(field4 = UseShort(0)); + Console.WriteLine(field4); } public short UseShort(short s) @@ -99,7 +99,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public int Array2(int i) { - return this.field3[i] = 1; + return field3[i] = 1; } public int GetIndex() @@ -124,17 +124,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public int ArrayUsageWithMethods() { - return this.GetArray()[this.GetIndex()] = this.GetValue(this.GetIndex()); + return GetArray()[GetIndex()] = GetValue(GetIndex()); } public int StaticPropertyTest() { - return InlineAssignmentTest.StaticProperty = this.GetIndex(); + return StaticProperty = GetIndex(); } public int InstancePropertyTest() { - return this.InstanceProperty = this.GetIndex(); + return InstanceProperty = GetIndex(); } } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/LiftedOperators.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/LiftedOperators.cs index 96aaa38a6..58d674f9d 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/LiftedOperators.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/LiftedOperators.cs @@ -868,21 +868,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UncheckedCasts(int? i4, long? i8, float? f) { - LiftedExplicitConversions.Print((byte?)i4); - LiftedExplicitConversions.Print((short?)i4); - LiftedExplicitConversions.Print((uint?)i4); - LiftedExplicitConversions.Print((uint?)i8); - LiftedExplicitConversions.Print((uint?)f); + Print((byte?)i4); + Print((short?)i4); + Print((uint?)i4); + Print((uint?)i8); + Print((uint?)f); } public static void CheckedCasts(int? i4, long? i8, float? f) { checked { - LiftedExplicitConversions.Print((byte?)i4); - LiftedExplicitConversions.Print((short?)i4); - LiftedExplicitConversions.Print((uint?)i4); - LiftedExplicitConversions.Print((uint?)i8); - //LiftedExplicitConversions.Print((uint?)f); TODO + Print((byte?)i4); + Print((short?)i4); + Print((uint?)i4); + Print((uint?)i8); + //Print((uint?)f); TODO } } } @@ -896,45 +896,45 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void Objects(object a, object b) { - NullCoalescingTests.Print(a ?? b); + Print(a ?? b); } public static void Nullables(int? a, int? b) { - NullCoalescingTests.Print(a ?? b); + Print(a ?? b); } public static void NullableWithNonNullableFallback(int? a, int b) { - NullCoalescingTests.Print(a ?? b); + Print(a ?? b); } public static void NullableWithImplicitConversion(short? a, int? b) { - NullCoalescingTests.Print(a ?? b); + Print(a ?? b); } public static void NullableWithImplicitConversionAndNonNullableFallback(short? a, int b) { // TODO: unnecessary cast - //NullCoalescingTests.Print(a ?? b); + //Print(a ?? b); } public static void Chain(int? a, int? b, int? c, int d) { - NullCoalescingTests.Print(a ?? b ?? c ?? d); + Print(a ?? b ?? c ?? d); } public static void ChainWithImplicitConversions(int? a, short? b, long? c, byte d) { // TODO: unnecessary casts - //NullCoalescingTests.Print(a ?? b ?? c ?? d); + //Print(a ?? b ?? c ?? d); } public static void ChainWithComputation(int? a, short? b, long? c, byte d) { // TODO: unnecessary casts - //NullCoalescingTests.Print((a + 1) ?? (b + 2) ?? (c + 3) ?? (d + 4)); + //Print((a + 1) ?? (b + 2) ?? (c + 3) ?? (d + 4)); } public static object ReturnObjects(object a, object b) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs index ffb245669..832f17f0b 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs @@ -290,7 +290,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void ForEachOnField() { - foreach (string alternative in this.alternatives) { + foreach (string alternative in alternatives) { alternative.ToLower(); } } @@ -418,10 +418,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty #if ROSLYN && OPT // The variable name differs based on whether roslyn optimizes out the 'item' variable int current = item; - Loops.Operation(ref current); + Operation(ref current); #else int num = item; - Loops.Operation(ref num); + Operation(ref num); #endif } } @@ -430,7 +430,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { foreach (int item in items) { int c = item; - Loops.Operation(() => c == 5); + Operation(() => c == 5); } } @@ -621,14 +621,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void WhileLoop() { Console.WriteLine("Initial"); - if (this.Condition("if")) { - while (this.Condition("while")) { + if (Condition("if")) { + while (Condition("while")) { Console.WriteLine("Loop Body"); - if (this.Condition("test")) { - if (this.Condition("continue")) { + if (Condition("test")) { + if (Condition("continue")) { continue; } - if (!this.Condition("break")) { + if (!Condition("break")) { break; } } @@ -641,12 +641,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty //public void WhileWithGoto() //{ - // while (this.Condition("Main Loop")) { - // if (!this.Condition("Condition")) + // while (Condition("Main Loop")) { + // if (!Condition("Condition")) // goto block2; // block1: // Console.WriteLine("Block1"); - // if (this.Condition("Condition2")) + // if (Condition("Condition2")) // continue; // block2: // Console.WriteLine("Block2"); @@ -657,18 +657,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty //public void DoWhileLoop() //{ // Console.WriteLine("Initial"); - // if (this.Condition("if")) { + // if (Condition("if")) { // do { // Console.WriteLine("Loop Body"); - // if (this.Condition("test")) { - // if (this.Condition("continue")) { + // if (Condition("test")) { + // if (Condition("continue")) { // continue; // } - // if (!this.Condition("break")) + // if (!Condition("break")) // break; // } // Console.WriteLine("End of loop body"); - // } while (this.Condition("while")); + // } while (Condition("while")); // Console.WriteLine("After loop"); // } // Console.WriteLine("End of method"); @@ -677,14 +677,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void ForLoop() { Console.WriteLine("Initial"); - if (this.Condition("if")) { - for (int i = 0; this.Condition("for"); i++) { + if (Condition("if")) { + for (int i = 0; Condition("for"); i++) { Console.WriteLine("Loop Body"); - if (this.Condition("test")) { - if (this.Condition("continue")) { + if (Condition("test")) { + if (Condition("continue")) { continue; } - if (!this.Condition("not-break")) { + if (!Condition("not-break")) { break; } } @@ -699,10 +699,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { try { do { - if (this.Condition("return")) { + if (Condition("return")) { return; } - } while (this.Condition("repeat")); + } while (Condition("repeat")); Environment.GetCommandLineArgs(); } finally { @@ -716,7 +716,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { for (int i = 0; i < ids.Length; i++) { Item item = null; - this.TryGetItem(ids[i], out item); + TryGetItem(ids[i], out item); if (item == null) { break; } @@ -726,7 +726,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void ForeachLoopWithEarlyReturn(List items) { foreach (object item in items) { - if ((this.someObject = item) == null) { + if ((someObject = item) == null) { break; } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/NullPropagation.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/NullPropagation.cs index da87140d4..5804e0624 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/NullPropagation.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/NullPropagation.cs @@ -81,12 +81,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public string Substring() { - return this.GetString()?.Substring(this.GetInt()); + return GetString()?.Substring(GetInt()); } public void CallSubstringAndIgnoreResult() { - this.GetString()?.Substring(this.GetInt()); + GetString()?.Substring(GetInt()); } private void Use(T t) @@ -95,35 +95,35 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void CallDone() { - this.GetMyClass()?.Done(); - this.GetMyClass()?.Field?.Done(); - this.GetMyClass()?.Field.Done(); - this.GetMyClass()?.Property?.Done(); - this.GetMyClass()?.Property.Done(); - this.GetMyClass()?.Method(this.GetInt())?.Done(); - this.GetMyClass()?.Method(this.GetInt()).Done(); - this.GetMyClass()?[this.GetInt()]?.Done(); - this.GetMyClass()?[this.GetInt()].Done(); + GetMyClass()?.Done(); + GetMyClass()?.Field?.Done(); + GetMyClass()?.Field.Done(); + GetMyClass()?.Property?.Done(); + GetMyClass()?.Property.Done(); + GetMyClass()?.Method(GetInt())?.Done(); + GetMyClass()?.Method(GetInt()).Done(); + GetMyClass()?[GetInt()]?.Done(); + GetMyClass()?[GetInt()].Done(); } public void CallDoneStruct() { - this.GetMyStruct()?.Done(); + GetMyStruct()?.Done(); #if STRUCT_SPLITTING_IMPROVED - this.GetMyStruct()?.Field?.Done(); - this.GetMyStruct()?.Field.Done(); - this.GetMyStruct()?.Property1?.Done(); - this.GetMyStruct()?.Property2.Done(); - this.GetMyStruct()?.Method1(this.GetInt())?.Done(); - this.GetMyStruct()?.Method2(this.GetInt()).Done(); - this.GetMyStruct()?[this.GetInt()]?.Done(); + GetMyStruct()?.Field?.Done(); + GetMyStruct()?.Field.Done(); + GetMyStruct()?.Property1?.Done(); + GetMyStruct()?.Property2.Done(); + GetMyStruct()?.Method1(GetInt())?.Done(); + GetMyStruct()?.Method2(GetInt()).Done(); + GetMyStruct()?[GetInt()]?.Done(); #endif } public void RequiredParentheses() { - (this.GetMyClass()?.Field).Done(); - (this.GetMyClass()?.Method(this.GetInt())).Done(); + (GetMyClass()?.Field).Done(); + (GetMyClass()?.Method(GetInt())).Done(); #if STRUCT_SPLITTING_IMPROVED (GetMyStruct()?.Property2)?.Done(); #endif @@ -132,15 +132,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public int?[] ChainsOnClass() { return new int?[9] { - this.GetMyClass()?.IntVal, - this.GetMyClass()?.Field.IntVal, - this.GetMyClass()?.Field?.IntVal, - this.GetMyClass()?.Property.IntVal, - this.GetMyClass()?.Property?.IntVal, - this.GetMyClass()?.Method(this.GetInt()).IntVal, - this.GetMyClass()?.Method(this.GetInt())?.IntVal, - this.GetMyClass()?[this.GetInt()].IntVal, - this.GetMyClass()?[this.GetInt()]?.IntVal + GetMyClass()?.IntVal, + GetMyClass()?.Field.IntVal, + GetMyClass()?.Field?.IntVal, + GetMyClass()?.Property.IntVal, + GetMyClass()?.Property?.IntVal, + GetMyClass()?.Method(GetInt()).IntVal, + GetMyClass()?.Method(GetInt())?.IntVal, + GetMyClass()?[GetInt()].IntVal, + GetMyClass()?[GetInt()]?.IntVal }; } @@ -148,31 +148,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public int?[] ChainsStruct() { return new int?[8] { - this.GetMyStruct()?.IntVal, - this.GetMyStruct()?.Field.IntVal, - this.GetMyStruct()?.Field?.IntVal, - this.GetMyStruct()?.Property2.IntVal, - this.GetMyStruct()?.Property1?.IntVal, - this.GetMyStruct()?.Method2(this.GetInt()).IntVal, - this.GetMyStruct()?.Method1(this.GetInt())?.IntVal, - this.GetMyStruct()?[this.GetInt()]?.IntVal + GetMyStruct()?.IntVal, + GetMyStruct()?.Field.IntVal, + GetMyStruct()?.Field?.IntVal, + GetMyStruct()?.Property2.IntVal, + GetMyStruct()?.Property1?.IntVal, + GetMyStruct()?.Method2(GetInt()).IntVal, + GetMyStruct()?.Method1(GetInt())?.IntVal, + GetMyStruct()?[GetInt()]?.IntVal }; } #endif public int CoalescingReturn() { - return this.GetMyClass()?.IntVal ?? 1; + return GetMyClass()?.IntVal ?? 1; } public void Coalescing() { - this.Use(this.GetMyClass()?.IntVal ?? 1); + Use(GetMyClass()?.IntVal ?? 1); } public void CoalescingString() { - this.Use(this.GetMyClass()?.Text ?? "Hello"); + Use(GetMyClass()?.Text ?? "Hello"); } public void InvokeDelegate(EventHandler eh) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.cs index 4952fd02c..46c71a644 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.cs @@ -93,7 +93,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void CallMethodWithInOutParameter() { int num = 0; - PInvoke.ioctlsocket(IntPtr.Zero, 0, ref num); + ioctlsocket(IntPtr.Zero, 0, ref num); } } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs index b20cb9cb3..92e9a63b9 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs @@ -45,10 +45,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public event EventHandler CustomEvent { add { - this.AutomaticEvent += value; + AutomaticEvent += value; } remove { - this.AutomaticEvent -= value; + AutomaticEvent -= value; } } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.cs new file mode 100644 index 000000000..1640e853d --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.cs @@ -0,0 +1,181 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ICSharpCode.Decompiler.Tests.Pretty +{ + internal class QualifierTests + { + private struct Test + { + private int dummy; + + private void DeclaringType(QualifierTests instance) + { + instance.NoParameters(); + } + + private void DeclaringType() + { + StaticNoParameteres(); + Parameter(null); + StaticParameter(null); + // The unnecessary cast is added, because we add casts before we add the qualifier. + // normally it's preferable to have casts over having qualifiers, + // this is an ugly edge case. + QualifierTests.StaticParameter((object)null); + } + + private void Parameter(object o) + { + + } + + private static void StaticParameter(object o) + { + } + + private void Parameter(QualifierTests test) + { + // TODO : fix this + //Delegate(Parameter); + //Delegate(StaticParameter); + Delegate(test.Parameter); + Delegate(QualifierTests.StaticParameter); + } + + private static void StaticParameter(QualifierTests test) + { + } + + private static void DeclaringTypeStatic() + { + } + + private void DeclaringTypeConflict(QualifierTests instance) + { + DeclaringType(); + instance.DeclaringType(); + fieldConflict(); + instance.fieldConflict = 5; + } + + private void DeclaringTypeConflict() + { + DeclaringTypeStatic(); + QualifierTests.DeclaringTypeStatic(); + } + + private void fieldConflict() + { + + } + + private void Delegate(Action action) + { + + } + } + + private int fieldConflict; + private int innerConflict; + + private void NoParameters() + { + Delegate(Parameter); + Delegate(StaticParameter); + } + + private static void StaticNoParameteres() + { + + } + + private void Parameter(object o) + { + + } + + private static void StaticParameter(object o) + { + + } + + private void DeclaringType() + { + + } + + private static void DeclaringTypeStatic() + { + + } + + private void conflictWithParameter() + { + + } + + private void conflictWithVariable(int val) + { + + } + + private void Conflicts(int conflictWithParameter) + { + this.conflictWithParameter(); + } + + private void Conflicts() + { + int conflictWithVariable = 5; + this.conflictWithVariable(conflictWithVariable); + // workaround for missing identifiers in il + Capturer(() => conflictWithVariable); + } + + private void Capturing() + { + int fieldConflict = 5; + Capturer(() => this.fieldConflict + fieldConflict); + Capturer(delegate { + int innerConflict = 5; + return this.fieldConflict + fieldConflict + Capturer2(() => this.innerConflict + innerConflict + this.fieldConflict + fieldConflict); + }); + } + + private void Capturer(Func func) + { + + } + + private int Capturer2(Func func) + { + return 0; + } + + private void Delegate(Action action) + { + + } + } + + internal static class Ext + { + public static void Do(this int test) + { + + } + public static void Do(this object test) + { + + } + + public static void Do2(this int test) + { + test.Do(); + ((IEnumerable)null).Any(); + ((object)null).Do(); + } + } +} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.il new file mode 100644 index 000000000..e6996f77e --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.il @@ -0,0 +1,596 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// 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 pmidbhuu +{ + .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 ) + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module pmidbhuu.dll +// MVID: {29FFF9F6-E3AF-492E-8C7A-9BA99576954E} +.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: 0x030F0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.Pretty.QualifierTests + extends [mscorlib]System.Object +{ + .class sequential ansi sealed nested private beforefieldinit Test + extends [mscorlib]System.ValueType + { + .field private int32 dummy + .method private hidebysig instance void + DeclaringType(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests 'instance') cil managed + { + // Code size 9 (0x9) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: callvirt instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::NoParameters() + IL_0007: nop + IL_0008: ret + } // end of method Test::DeclaringType + + .method private hidebysig instance void + DeclaringType() cil managed + { + // Code size 30 (0x1e) + .maxstack 8 + IL_0000: nop + IL_0001: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticNoParameteres() + IL_0006: nop + IL_0007: ldarg.0 + IL_0008: ldnull + IL_0009: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::Parameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests) + IL_000e: nop + IL_000f: ldnull + IL_0010: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::StaticParameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests) + IL_0015: nop + IL_0016: ldnull + IL_0017: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticParameter(object) + IL_001c: nop + IL_001d: ret + } // end of method Test::DeclaringType + + .method private hidebysig instance void + Parameter(object o) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Test::Parameter + + .method private hidebysig static void + StaticParameter(object o) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Test::StaticParameter + + .method private hidebysig instance void + Parameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests test) cil managed + { + // Code size 40 (0x28) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: ldftn instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Parameter(object) + IL_0009: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000e: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::Delegate(class [mscorlib]System.Action`1) + IL_0013: nop + IL_0014: ldarg.0 + IL_0015: ldnull + IL_0016: ldftn void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticParameter(object) + IL_001c: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0021: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::Delegate(class [mscorlib]System.Action`1) + IL_0026: nop + IL_0027: ret + } // end of method Test::Parameter + + .method private hidebysig static void + StaticParameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests test) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Test::StaticParameter + + .method private hidebysig static void + DeclaringTypeStatic() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Test::DeclaringTypeStatic + + .method private hidebysig instance void + DeclaringTypeConflict(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests 'instance') cil managed + { + // Code size 30 (0x1e) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::DeclaringType() + IL_0007: nop + IL_0008: ldarg.1 + IL_0009: callvirt instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::DeclaringType() + IL_000e: nop + IL_000f: ldarg.0 + IL_0010: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::fieldConflict() + IL_0015: nop + IL_0016: ldarg.1 + IL_0017: ldc.i4.5 + IL_0018: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_001d: ret + } // end of method Test::DeclaringTypeConflict + + .method private hidebysig instance void + DeclaringTypeConflict() cil managed + { + // Code size 14 (0xe) + .maxstack 8 + IL_0000: nop + IL_0001: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::DeclaringTypeStatic() + IL_0006: nop + IL_0007: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::DeclaringTypeStatic() + IL_000c: nop + IL_000d: ret + } // end of method Test::DeclaringTypeConflict + + .method private hidebysig instance void + fieldConflict() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Test::fieldConflict + + .method private hidebysig instance void + Delegate(class [mscorlib]System.Action`1 action) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Test::Delegate + + } // end of class Test + + .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 conflictWithVariable + .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 int32 + 'b__0'() cil managed + { + // Code size 11 (0xb) + .maxstack 1 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass1'::conflictWithVariable + IL_0006: stloc.0 + IL_0007: br.s IL_0009 + + IL_0009: ldloc.0 + IL_000a: ret + } // end of method '<>c__DisplayClass1'::'b__0' + + } // end of class '<>c__DisplayClass1' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass6' + 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__DisplayClass8' + extends [mscorlib]System.Object + { + .field public class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6' 'CS$<>8__locals7' + .field public int32 innerConflict + .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'::.ctor + + .method public hidebysig instance int32 + 'b__5'() cil managed + { + // Code size 57 (0x39) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::'CS$<>8__locals7' + IL_0006: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'<>4__this' + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::innerConflict + IL_0010: ldarg.0 + IL_0011: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::innerConflict + IL_0016: add + IL_0017: ldarg.0 + IL_0018: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::'CS$<>8__locals7' + IL_001d: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'<>4__this' + IL_0022: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_0027: add + IL_0028: ldarg.0 + IL_0029: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::'CS$<>8__locals7' + IL_002e: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::fieldConflict + IL_0033: add + IL_0034: stloc.0 + IL_0035: br.s IL_0037 + + IL_0037: ldloc.0 + IL_0038: ret + } // end of method '<>c__DisplayClass8'::'b__5' + + } // end of class '<>c__DisplayClass8' + + .field public int32 fieldConflict + .field public class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests '<>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__DisplayClass6'::.ctor + + .method public hidebysig instance int32 + 'b__3'() cil managed + { + // Code size 23 (0x17) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'<>4__this' + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_000b: ldarg.0 + IL_000c: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::fieldConflict + IL_0011: add + IL_0012: stloc.0 + IL_0013: br.s IL_0015 + + IL_0015: ldloc.0 + IL_0016: ret + } // end of method '<>c__DisplayClass6'::'b__3' + + .method public hidebysig instance int32 + 'b__4'() cil managed + { + // Code size 68 (0x44) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8' V_0, + int32 V_1) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::'CS$<>8__locals7' + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldc.i4.5 + IL_0010: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::innerConflict + IL_0015: ldarg.0 + IL_0016: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'<>4__this' + IL_001b: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_0020: ldarg.0 + IL_0021: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::fieldConflict + IL_0026: add + IL_0027: ldarg.0 + IL_0028: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'<>4__this' + IL_002d: ldloc.0 + IL_002e: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::'b__5'() + IL_0034: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0039: call instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer2(class [mscorlib]System.Func`1) + IL_003e: add + IL_003f: stloc.1 + IL_0040: br.s IL_0042 + + IL_0042: ldloc.1 + IL_0043: ret + } // end of method '<>c__DisplayClass6'::'b__4' + + } // end of class '<>c__DisplayClass6' + + .field private int32 fieldConflict + .field private int32 innerConflict + .method private hidebysig instance void + NoParameters() cil managed + { + // Code size 40 (0x28) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldarg.0 + IL_0003: ldftn instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Parameter(object) + IL_0009: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000e: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Delegate(class [mscorlib]System.Action`1) + IL_0013: nop + IL_0014: ldarg.0 + IL_0015: ldnull + IL_0016: ldftn void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticParameter(object) + IL_001c: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0021: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Delegate(class [mscorlib]System.Action`1) + IL_0026: nop + IL_0027: ret + } // end of method QualifierTests::NoParameters + + .method private hidebysig static void StaticNoParameteres() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::StaticNoParameteres + + .method private hidebysig instance void + Parameter(object o) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::Parameter + + .method private hidebysig static void StaticParameter(object o) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::StaticParameter + + .method private hidebysig instance void + DeclaringType() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::DeclaringType + + .method private hidebysig static void DeclaringTypeStatic() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::DeclaringTypeStatic + + .method private hidebysig instance void + conflictWithParameter() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::conflictWithParameter + + .method private hidebysig instance void + conflictWithVariable(int32 val) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::conflictWithVariable + + .method private hidebysig instance void + Conflicts(int32 conflictWithParameter) cil managed + { + // Code size 9 (0x9) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::conflictWithParameter() + IL_0007: nop + IL_0008: ret + } // end of method QualifierTests::Conflicts + + .method private hidebysig instance void + Conflicts() cil managed + { + // Code size 48 (0x30) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass1' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass1'::.ctor() + IL_0005: stloc.0 + IL_0006: nop + IL_0007: ldloc.0 + IL_0008: ldc.i4.5 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass1'::conflictWithVariable + IL_000e: ldarg.0 + IL_000f: ldloc.0 + IL_0010: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass1'::conflictWithVariable + IL_0015: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::conflictWithVariable(int32) + IL_001a: nop + IL_001b: ldarg.0 + IL_001c: ldloc.0 + IL_001d: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass1'::'b__0'() + IL_0023: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0028: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer(class [mscorlib]System.Func`1) + IL_002d: nop + IL_002e: nop + IL_002f: ret + } // end of method QualifierTests::Conflicts + + .method private hidebysig instance void + Capturing() cil managed + { + // Code size 61 (0x3d) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'<>4__this' + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldc.i4.5 + IL_0010: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::fieldConflict + IL_0015: ldarg.0 + IL_0016: ldloc.0 + IL_0017: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'b__3'() + IL_001d: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0022: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer(class [mscorlib]System.Func`1) + IL_0027: nop + IL_0028: ldarg.0 + IL_0029: ldloc.0 + IL_002a: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'b__4'() + IL_0030: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0035: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer(class [mscorlib]System.Func`1) + IL_003a: nop + IL_003b: nop + IL_003c: ret + } // end of method QualifierTests::Capturing + + .method private hidebysig instance void + Capturer(class [mscorlib]System.Func`1 func) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::Capturer + + .method private hidebysig instance int32 + Capturer2(class [mscorlib]System.Func`1 func) 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 QualifierTests::Capturer2 + + .method private hidebysig instance void + Delegate(class [mscorlib]System.Action`1 action) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::Delegate + + .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 QualifierTests::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests + +.class private abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.Pretty.Ext + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig static void Do(int32 test) 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 Ext::Do + + .method public hidebysig static void Do(object test) 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 Ext::Do + + .method public hidebysig static void Do2(int32 test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 23 (0x17) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: call void ICSharpCode.Decompiler.Tests.Pretty.Ext::Do(int32) + IL_0007: nop + IL_0008: ldnull + IL_0009: call bool [System.Core]System.Linq.Enumerable::Any(class [mscorlib]System.Collections.Generic.IEnumerable`1) + IL_000e: pop + IL_000f: ldnull + IL_0010: call void ICSharpCode.Decompiler.Tests.Pretty.Ext::Do(object) + IL_0015: nop + IL_0016: ret + } // end of method Ext::Do2 + +} // end of class ICSharpCode.Decompiler.Tests.Pretty.Ext + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// WARNING: Created Win32 resource file C:\Users\Siegfried\Projects\ILSpy\ICSharpCode.Decompiler.Tests\bin\Debug\net46\../../../TestCases/Pretty\QualifierTests.res diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.opt.il new file mode 100644 index 000000000..883d05425 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.opt.il @@ -0,0 +1,519 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// 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 '011f0dbt' +{ + .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 ) + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module '011f0dbt.dll' +// MVID: {EB97E647-5276-4D71-871C-EC7FC2A37905} +.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: 0x00DD0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.Pretty.QualifierTests + extends [mscorlib]System.Object +{ + .class sequential ansi sealed nested private beforefieldinit Test + extends [mscorlib]System.ValueType + { + .field private int32 dummy + .method private hidebysig instance void + DeclaringType(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests 'instance') cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: callvirt instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::NoParameters() + IL_0006: ret + } // end of method Test::DeclaringType + + .method private hidebysig instance void + DeclaringType() cil managed + { + // Code size 25 (0x19) + .maxstack 8 + IL_0000: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticNoParameteres() + IL_0005: ldarg.0 + IL_0006: ldnull + IL_0007: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::Parameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests) + IL_000c: ldnull + IL_000d: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::StaticParameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests) + IL_0012: ldnull + IL_0013: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticParameter(object) + IL_0018: ret + } // end of method Test::DeclaringType + + .method private hidebysig instance void + Parameter(object o) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Test::Parameter + + .method private hidebysig static void + StaticParameter(object o) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Test::StaticParameter + + .method private hidebysig instance void + Parameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests test) cil managed + { + // Code size 37 (0x25) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldftn instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Parameter(object) + IL_0008: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000d: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::Delegate(class [mscorlib]System.Action`1) + IL_0012: ldarg.0 + IL_0013: ldnull + IL_0014: ldftn void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticParameter(object) + IL_001a: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_001f: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::Delegate(class [mscorlib]System.Action`1) + IL_0024: ret + } // end of method Test::Parameter + + .method private hidebysig static void + StaticParameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests test) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Test::StaticParameter + + .method private hidebysig static void + DeclaringTypeStatic() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Test::DeclaringTypeStatic + + .method private hidebysig instance void + DeclaringTypeConflict(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests 'instance') cil managed + { + // Code size 26 (0x1a) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::DeclaringType() + IL_0006: ldarg.1 + IL_0007: callvirt instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::DeclaringType() + IL_000c: ldarg.0 + IL_000d: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::fieldConflict() + IL_0012: ldarg.1 + IL_0013: ldc.i4.5 + IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_0019: ret + } // end of method Test::DeclaringTypeConflict + + .method private hidebysig instance void + DeclaringTypeConflict() cil managed + { + // Code size 11 (0xb) + .maxstack 8 + IL_0000: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::DeclaringTypeStatic() + IL_0005: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::DeclaringTypeStatic() + IL_000a: ret + } // end of method Test::DeclaringTypeConflict + + .method private hidebysig instance void + fieldConflict() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Test::fieldConflict + + .method private hidebysig instance void + Delegate(class [mscorlib]System.Action`1 action) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Test::Delegate + + } // end of class Test + + .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 conflictWithVariable + .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 int32 + 'b__0'() cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass1'::conflictWithVariable + IL_0006: ret + } // end of method '<>c__DisplayClass1'::'b__0' + + } // end of class '<>c__DisplayClass1' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass6' + 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__DisplayClass8' + extends [mscorlib]System.Object + { + .field public class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6' 'CS$<>8__locals7' + .field public int32 innerConflict + .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'::.ctor + + .method public hidebysig instance int32 + 'b__5'() cil managed + { + // Code size 53 (0x35) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::'CS$<>8__locals7' + IL_0006: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'<>4__this' + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::innerConflict + IL_0010: ldarg.0 + IL_0011: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::innerConflict + IL_0016: add + IL_0017: ldarg.0 + IL_0018: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::'CS$<>8__locals7' + IL_001d: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'<>4__this' + IL_0022: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_0027: add + IL_0028: ldarg.0 + IL_0029: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::'CS$<>8__locals7' + IL_002e: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::fieldConflict + IL_0033: add + IL_0034: ret + } // end of method '<>c__DisplayClass8'::'b__5' + + } // end of class '<>c__DisplayClass8' + + .field public int32 fieldConflict + .field public class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests '<>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__DisplayClass6'::.ctor + + .method public hidebysig instance int32 + 'b__3'() cil managed + { + // Code size 19 (0x13) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'<>4__this' + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_000b: ldarg.0 + IL_000c: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::fieldConflict + IL_0011: add + IL_0012: ret + } // end of method '<>c__DisplayClass6'::'b__3' + + .method public hidebysig instance int32 + 'b__4'() cil managed + { + // Code size 63 (0x3f) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::'CS$<>8__locals7' + IL_000d: ldloc.0 + IL_000e: ldc.i4.5 + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::innerConflict + IL_0014: ldarg.0 + IL_0015: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'<>4__this' + IL_001a: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_001f: ldarg.0 + IL_0020: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::fieldConflict + IL_0025: add + IL_0026: ldarg.0 + IL_0027: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'<>4__this' + IL_002c: ldloc.0 + IL_002d: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'/'<>c__DisplayClass8'::'b__5'() + IL_0033: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0038: call instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer2(class [mscorlib]System.Func`1) + IL_003d: add + IL_003e: ret + } // end of method '<>c__DisplayClass6'::'b__4' + + } // end of class '<>c__DisplayClass6' + + .field private int32 fieldConflict + .field private int32 innerConflict + .method private hidebysig instance void + NoParameters() cil managed + { + // Code size 37 (0x25) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.0 + IL_0002: ldftn instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Parameter(object) + IL_0008: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000d: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Delegate(class [mscorlib]System.Action`1) + IL_0012: ldarg.0 + IL_0013: ldnull + IL_0014: ldftn void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticParameter(object) + IL_001a: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_001f: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Delegate(class [mscorlib]System.Action`1) + IL_0024: ret + } // end of method QualifierTests::NoParameters + + .method private hidebysig static void StaticNoParameteres() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::StaticNoParameteres + + .method private hidebysig instance void + Parameter(object o) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::Parameter + + .method private hidebysig static void StaticParameter(object o) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::StaticParameter + + .method private hidebysig instance void + DeclaringType() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::DeclaringType + + .method private hidebysig static void DeclaringTypeStatic() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::DeclaringTypeStatic + + .method private hidebysig instance void + conflictWithParameter() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::conflictWithParameter + + .method private hidebysig instance void + conflictWithVariable(int32 val) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::conflictWithVariable + + .method private hidebysig instance void + Conflicts(int32 conflictWithParameter) cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::conflictWithParameter() + IL_0006: ret + } // end of method QualifierTests::Conflicts + + .method private hidebysig instance void + Conflicts() cil managed + { + // Code size 44 (0x2c) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass1' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass1'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldc.i4.5 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass1'::conflictWithVariable + IL_000d: ldarg.0 + IL_000e: ldloc.0 + IL_000f: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass1'::conflictWithVariable + IL_0014: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::conflictWithVariable(int32) + IL_0019: ldarg.0 + IL_001a: ldloc.0 + IL_001b: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass1'::'b__0'() + IL_0021: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0026: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer(class [mscorlib]System.Func`1) + IL_002b: ret + } // end of method QualifierTests::Conflicts + + .method private hidebysig instance void + Capturing() cil managed + { + // Code size 57 (0x39) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'<>4__this' + IL_000d: ldloc.0 + IL_000e: ldc.i4.5 + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::fieldConflict + IL_0014: ldarg.0 + IL_0015: ldloc.0 + IL_0016: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'b__3'() + IL_001c: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0021: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer(class [mscorlib]System.Func`1) + IL_0026: ldarg.0 + IL_0027: ldloc.0 + IL_0028: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass6'::'b__4'() + IL_002e: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0033: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer(class [mscorlib]System.Func`1) + IL_0038: ret + } // end of method QualifierTests::Capturing + + .method private hidebysig instance void + Capturer(class [mscorlib]System.Func`1 func) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::Capturer + + .method private hidebysig instance int32 + Capturer2(class [mscorlib]System.Func`1 func) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } // end of method QualifierTests::Capturer2 + + .method private hidebysig instance void + Delegate(class [mscorlib]System.Action`1 action) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::Delegate + + .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 QualifierTests::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests + +.class private abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.Pretty.Ext + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig static void Do(int32 test) 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 Ext::Do + + .method public hidebysig static void Do(object test) 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 Ext::Do + + .method public hidebysig static void Do2(int32 test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 20 (0x14) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call void ICSharpCode.Decompiler.Tests.Pretty.Ext::Do(int32) + IL_0006: ldnull + IL_0007: call bool [System.Core]System.Linq.Enumerable::Any(class [mscorlib]System.Collections.Generic.IEnumerable`1) + IL_000c: pop + IL_000d: ldnull + IL_000e: call void ICSharpCode.Decompiler.Tests.Pretty.Ext::Do(object) + IL_0013: ret + } // end of method Ext::Do2 + +} // end of class ICSharpCode.Decompiler.Tests.Pretty.Ext + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// WARNING: Created Win32 resource file C:\Users\Siegfried\Projects\ILSpy\ICSharpCode.Decompiler.Tests\bin\Debug\net46\../../../TestCases/Pretty\QualifierTests.opt.res diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.opt.roslyn.il new file mode 100644 index 000000000..be3a13a48 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.opt.roslyn.il @@ -0,0 +1,523 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// 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 QualifierTests +{ + .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 QualifierTests.dll +// MVID: {7AC69EDD-DA5A-4332-98FC-F0C038BF00B0} +.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: 0x04D00000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.Pretty.QualifierTests + extends [mscorlib]System.Object +{ + .class sequential ansi sealed nested private beforefieldinit Test + extends [mscorlib]System.ValueType + { + .field private int32 dummy + .method private hidebysig instance void + DeclaringType(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests 'instance') cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: callvirt instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::NoParameters() + IL_0006: ret + } // end of method Test::DeclaringType + + .method private hidebysig instance void + DeclaringType() cil managed + { + // Code size 25 (0x19) + .maxstack 8 + IL_0000: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticNoParameteres() + IL_0005: ldarg.0 + IL_0006: ldnull + IL_0007: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::Parameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests) + IL_000c: ldnull + IL_000d: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::StaticParameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests) + IL_0012: ldnull + IL_0013: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticParameter(object) + IL_0018: ret + } // end of method Test::DeclaringType + + .method private hidebysig instance void + Parameter(object o) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Test::Parameter + + .method private hidebysig static void + StaticParameter(object o) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Test::StaticParameter + + .method private hidebysig instance void + Parameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests test) cil managed + { + // Code size 37 (0x25) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldftn instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Parameter(object) + IL_0008: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000d: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::Delegate(class [mscorlib]System.Action`1) + IL_0012: ldarg.0 + IL_0013: ldnull + IL_0014: ldftn void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticParameter(object) + IL_001a: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_001f: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::Delegate(class [mscorlib]System.Action`1) + IL_0024: ret + } // end of method Test::Parameter + + .method private hidebysig static void + StaticParameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests test) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Test::StaticParameter + + .method private hidebysig static void + DeclaringTypeStatic() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Test::DeclaringTypeStatic + + .method private hidebysig instance void + DeclaringTypeConflict(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests 'instance') cil managed + { + // Code size 26 (0x1a) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::DeclaringType() + IL_0006: ldarg.1 + IL_0007: callvirt instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::DeclaringType() + IL_000c: ldarg.0 + IL_000d: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::fieldConflict() + IL_0012: ldarg.1 + IL_0013: ldc.i4.5 + IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_0019: ret + } // end of method Test::DeclaringTypeConflict + + .method private hidebysig instance void + DeclaringTypeConflict() cil managed + { + // Code size 11 (0xb) + .maxstack 8 + IL_0000: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::DeclaringTypeStatic() + IL_0005: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::DeclaringTypeStatic() + IL_000a: ret + } // end of method Test::DeclaringTypeConflict + + .method private hidebysig instance void + fieldConflict() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Test::fieldConflict + + .method private hidebysig instance void + Delegate(class [mscorlib]System.Action`1 action) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Test::Delegate + + } // end of class Test + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass12_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 conflictWithVariable + .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__DisplayClass12_0'::.ctor + + .method assembly hidebysig instance int32 + 'b__0'() cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass12_0'::conflictWithVariable + IL_0006: ret + } // end of method '<>c__DisplayClass12_0'::'b__0' + + } // end of class '<>c__DisplayClass12_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass13_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests '<>4__this' + .field public int32 fieldConflict + .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_0'::.ctor + + .method assembly hidebysig instance int32 + 'b__0'() cil managed + { + // Code size 19 (0x13) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'<>4__this' + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_000b: ldarg.0 + IL_000c: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::fieldConflict + IL_0011: add + IL_0012: ret + } // end of method '<>c__DisplayClass13_0'::'b__0' + + .method assembly hidebysig instance int32 + 'b__1'() cil managed + { + // Code size 63 (0x3f) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::'CS$<>8__locals1' + IL_000d: ldloc.0 + IL_000e: ldc.i4.5 + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::innerConflict + IL_0014: ldarg.0 + IL_0015: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'<>4__this' + IL_001a: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_001f: ldarg.0 + IL_0020: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::fieldConflict + IL_0025: add + IL_0026: ldarg.0 + IL_0027: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'<>4__this' + IL_002c: ldloc.0 + IL_002d: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::'b__2'() + IL_0033: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0038: call instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer2(class [mscorlib]System.Func`1) + IL_003d: add + IL_003e: ret + } // end of method '<>c__DisplayClass13_0'::'b__1' + + } // end of class '<>c__DisplayClass13_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass13_1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 innerConflict + .field public class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_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__DisplayClass13_1'::.ctor + + .method assembly hidebysig instance int32 + 'b__2'() cil managed + { + // Code size 53 (0x35) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::'CS$<>8__locals1' + IL_0006: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'<>4__this' + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::innerConflict + IL_0010: ldarg.0 + IL_0011: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::innerConflict + IL_0016: add + IL_0017: ldarg.0 + IL_0018: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::'CS$<>8__locals1' + IL_001d: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'<>4__this' + IL_0022: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_0027: add + IL_0028: ldarg.0 + IL_0029: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::'CS$<>8__locals1' + IL_002e: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::fieldConflict + IL_0033: add + IL_0034: ret + } // end of method '<>c__DisplayClass13_1'::'b__2' + + } // end of class '<>c__DisplayClass13_1' + + .field private int32 fieldConflict + .field private int32 innerConflict + .method private hidebysig instance void + NoParameters() cil managed + { + // Code size 37 (0x25) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.0 + IL_0002: ldftn instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Parameter(object) + IL_0008: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000d: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Delegate(class [mscorlib]System.Action`1) + IL_0012: ldarg.0 + IL_0013: ldnull + IL_0014: ldftn void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticParameter(object) + IL_001a: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_001f: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Delegate(class [mscorlib]System.Action`1) + IL_0024: ret + } // end of method QualifierTests::NoParameters + + .method private hidebysig static void StaticNoParameteres() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::StaticNoParameteres + + .method private hidebysig instance void + Parameter(object o) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::Parameter + + .method private hidebysig static void StaticParameter(object o) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::StaticParameter + + .method private hidebysig instance void + DeclaringType() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::DeclaringType + + .method private hidebysig static void DeclaringTypeStatic() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::DeclaringTypeStatic + + .method private hidebysig instance void + conflictWithParameter() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::conflictWithParameter + + .method private hidebysig instance void + conflictWithVariable(int32 val) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::conflictWithVariable + + .method private hidebysig instance void + Conflicts(int32 conflictWithParameter) cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::conflictWithParameter() + IL_0006: ret + } // end of method QualifierTests::Conflicts + + .method private hidebysig instance void + Conflicts() cil managed + { + // Code size 44 (0x2c) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass12_0' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass12_0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldc.i4.5 + IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass12_0'::conflictWithVariable + IL_000d: ldarg.0 + IL_000e: ldloc.0 + IL_000f: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass12_0'::conflictWithVariable + IL_0014: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::conflictWithVariable(int32) + IL_0019: ldarg.0 + IL_001a: ldloc.0 + IL_001b: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass12_0'::'b__0'() + IL_0021: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0026: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer(class [mscorlib]System.Func`1) + IL_002b: ret + } // end of method QualifierTests::Conflicts + + .method private hidebysig instance void + Capturing() cil managed + { + // Code size 57 (0x39) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'<>4__this' + IL_000d: ldloc.0 + IL_000e: ldc.i4.5 + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::fieldConflict + IL_0014: ldarg.0 + IL_0015: ldloc.0 + IL_0016: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'b__0'() + IL_001c: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0021: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer(class [mscorlib]System.Func`1) + IL_0026: ldarg.0 + IL_0027: ldloc.0 + IL_0028: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'b__1'() + IL_002e: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0033: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer(class [mscorlib]System.Func`1) + IL_0038: ret + } // end of method QualifierTests::Capturing + + .method private hidebysig instance void + Capturer(class [mscorlib]System.Func`1 func) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::Capturer + + .method private hidebysig instance int32 + Capturer2(class [mscorlib]System.Func`1 func) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } // end of method QualifierTests::Capturer2 + + .method private hidebysig instance void + Delegate(class [mscorlib]System.Action`1 action) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method QualifierTests::Delegate + + .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 QualifierTests::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests + +.class private abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.Pretty.Ext + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig static void Do(int32 test) 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 Ext::Do + + .method public hidebysig static void Do(object test) 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 Ext::Do + + .method public hidebysig static void Do2(int32 test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 20 (0x14) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call void ICSharpCode.Decompiler.Tests.Pretty.Ext::Do(int32) + IL_0006: ldnull + IL_0007: call bool [System.Core]System.Linq.Enumerable::Any(class [mscorlib]System.Collections.Generic.IEnumerable`1) + IL_000c: pop + IL_000d: ldnull + IL_000e: call void ICSharpCode.Decompiler.Tests.Pretty.Ext::Do(object) + IL_0013: ret + } // end of method Ext::Do2 + +} // end of class ICSharpCode.Decompiler.Tests.Pretty.Ext + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.roslyn.il new file mode 100644 index 000000000..86636ef4f --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.roslyn.il @@ -0,0 +1,587 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// 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 QualifierTests +{ + .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 QualifierTests.dll +// MVID: {9E09B16E-E984-4C3B-B21E-D42961F40D2B} +.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: 0x030D0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.Pretty.QualifierTests + extends [mscorlib]System.Object +{ + .class sequential ansi sealed nested private beforefieldinit Test + extends [mscorlib]System.ValueType + { + .field private int32 dummy + .method private hidebysig instance void + DeclaringType(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests 'instance') cil managed + { + // Code size 9 (0x9) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: callvirt instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::NoParameters() + IL_0007: nop + IL_0008: ret + } // end of method Test::DeclaringType + + .method private hidebysig instance void + DeclaringType() cil managed + { + // Code size 30 (0x1e) + .maxstack 8 + IL_0000: nop + IL_0001: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticNoParameteres() + IL_0006: nop + IL_0007: ldarg.0 + IL_0008: ldnull + IL_0009: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::Parameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests) + IL_000e: nop + IL_000f: ldnull + IL_0010: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::StaticParameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests) + IL_0015: nop + IL_0016: ldnull + IL_0017: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticParameter(object) + IL_001c: nop + IL_001d: ret + } // end of method Test::DeclaringType + + .method private hidebysig instance void + Parameter(object o) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Test::Parameter + + .method private hidebysig static void + StaticParameter(object o) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Test::StaticParameter + + .method private hidebysig instance void + Parameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests test) cil managed + { + // Code size 40 (0x28) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: ldftn instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Parameter(object) + IL_0009: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000e: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::Delegate(class [mscorlib]System.Action`1) + IL_0013: nop + IL_0014: ldarg.0 + IL_0015: ldnull + IL_0016: ldftn void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticParameter(object) + IL_001c: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0021: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::Delegate(class [mscorlib]System.Action`1) + IL_0026: nop + IL_0027: ret + } // end of method Test::Parameter + + .method private hidebysig static void + StaticParameter(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests test) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Test::StaticParameter + + .method private hidebysig static void + DeclaringTypeStatic() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Test::DeclaringTypeStatic + + .method private hidebysig instance void + DeclaringTypeConflict(class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests 'instance') cil managed + { + // Code size 30 (0x1e) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::DeclaringType() + IL_0007: nop + IL_0008: ldarg.1 + IL_0009: callvirt instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::DeclaringType() + IL_000e: nop + IL_000f: ldarg.0 + IL_0010: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::fieldConflict() + IL_0015: nop + IL_0016: ldarg.1 + IL_0017: ldc.i4.5 + IL_0018: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_001d: ret + } // end of method Test::DeclaringTypeConflict + + .method private hidebysig instance void + DeclaringTypeConflict() cil managed + { + // Code size 14 (0xe) + .maxstack 8 + IL_0000: nop + IL_0001: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/Test::DeclaringTypeStatic() + IL_0006: nop + IL_0007: call void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::DeclaringTypeStatic() + IL_000c: nop + IL_000d: ret + } // end of method Test::DeclaringTypeConflict + + .method private hidebysig instance void + fieldConflict() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Test::fieldConflict + + .method private hidebysig instance void + Delegate(class [mscorlib]System.Action`1 action) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Test::Delegate + + } // end of class Test + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass12_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 conflictWithVariable + .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__DisplayClass12_0'::.ctor + + .method assembly hidebysig instance int32 + 'b__0'() cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass12_0'::conflictWithVariable + IL_0006: ret + } // end of method '<>c__DisplayClass12_0'::'b__0' + + } // end of class '<>c__DisplayClass12_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass13_0' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests '<>4__this' + .field public int32 fieldConflict + .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__DisplayClass13_0'::.ctor + + .method assembly hidebysig instance int32 + 'b__0'() cil managed + { + // Code size 19 (0x13) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'<>4__this' + IL_0006: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_000b: ldarg.0 + IL_000c: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::fieldConflict + IL_0011: add + IL_0012: ret + } // end of method '<>c__DisplayClass13_0'::'b__0' + + .method assembly hidebysig instance int32 + 'b__1'() cil managed + { + // Code size 68 (0x44) + .maxstack 4 + .locals init (class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1' V_0, + int32 V_1) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::'CS$<>8__locals1' + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldc.i4.5 + IL_0010: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::innerConflict + IL_0015: ldarg.0 + IL_0016: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'<>4__this' + IL_001b: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_0020: ldarg.0 + IL_0021: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::fieldConflict + IL_0026: add + IL_0027: ldarg.0 + IL_0028: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'<>4__this' + IL_002d: ldloc.0 + IL_002e: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::'b__2'() + IL_0034: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0039: call instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer2(class [mscorlib]System.Func`1) + IL_003e: add + IL_003f: stloc.1 + IL_0040: br.s IL_0042 + + IL_0042: ldloc.1 + IL_0043: ret + } // end of method '<>c__DisplayClass13_0'::'b__1' + + } // end of class '<>c__DisplayClass13_0' + + .class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass13_1' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 innerConflict + .field public class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_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__DisplayClass13_1'::.ctor + + .method assembly hidebysig instance int32 + 'b__2'() cil managed + { + // Code size 53 (0x35) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::'CS$<>8__locals1' + IL_0006: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'<>4__this' + IL_000b: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::innerConflict + IL_0010: ldarg.0 + IL_0011: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::innerConflict + IL_0016: add + IL_0017: ldarg.0 + IL_0018: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::'CS$<>8__locals1' + IL_001d: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'<>4__this' + IL_0022: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::fieldConflict + IL_0027: add + IL_0028: ldarg.0 + IL_0029: ldfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0' ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_1'::'CS$<>8__locals1' + IL_002e: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::fieldConflict + IL_0033: add + IL_0034: ret + } // end of method '<>c__DisplayClass13_1'::'b__2' + + } // end of class '<>c__DisplayClass13_1' + + .field private int32 fieldConflict + .field private int32 innerConflict + .method private hidebysig instance void + NoParameters() cil managed + { + // Code size 40 (0x28) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldarg.0 + IL_0003: ldftn instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Parameter(object) + IL_0009: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_000e: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Delegate(class [mscorlib]System.Action`1) + IL_0013: nop + IL_0014: ldarg.0 + IL_0015: ldnull + IL_0016: ldftn void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::StaticParameter(object) + IL_001c: newobj instance void class [mscorlib]System.Action`1::.ctor(object, + native int) + IL_0021: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Delegate(class [mscorlib]System.Action`1) + IL_0026: nop + IL_0027: ret + } // end of method QualifierTests::NoParameters + + .method private hidebysig static void StaticNoParameteres() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::StaticNoParameteres + + .method private hidebysig instance void + Parameter(object o) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::Parameter + + .method private hidebysig static void StaticParameter(object o) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::StaticParameter + + .method private hidebysig instance void + DeclaringType() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::DeclaringType + + .method private hidebysig static void DeclaringTypeStatic() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::DeclaringTypeStatic + + .method private hidebysig instance void + conflictWithParameter() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::conflictWithParameter + + .method private hidebysig instance void + conflictWithVariable(int32 val) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::conflictWithVariable + + .method private hidebysig instance void + Conflicts(int32 conflictWithParameter) cil managed + { + // Code size 9 (0x9) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::conflictWithParameter() + IL_0007: nop + IL_0008: ret + } // end of method QualifierTests::Conflicts + + .method private hidebysig instance void + Conflicts() cil managed + { + // Code size 47 (0x2f) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass12_0' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass12_0'::.ctor() + IL_0005: stloc.0 + IL_0006: nop + IL_0007: ldloc.0 + IL_0008: ldc.i4.5 + IL_0009: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass12_0'::conflictWithVariable + IL_000e: ldarg.0 + IL_000f: ldloc.0 + IL_0010: ldfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass12_0'::conflictWithVariable + IL_0015: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::conflictWithVariable(int32) + IL_001a: nop + IL_001b: ldarg.0 + IL_001c: ldloc.0 + IL_001d: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass12_0'::'b__0'() + IL_0023: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0028: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer(class [mscorlib]System.Func`1) + IL_002d: nop + IL_002e: ret + } // end of method QualifierTests::Conflicts + + .method private hidebysig instance void + Capturing() cil managed + { + // Code size 60 (0x3c) + .maxstack 3 + .locals init (class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0' V_0) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'<>4__this' + IL_000d: nop + IL_000e: ldloc.0 + IL_000f: ldc.i4.5 + IL_0010: stfld int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::fieldConflict + IL_0015: ldarg.0 + IL_0016: ldloc.0 + IL_0017: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'b__0'() + IL_001d: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0022: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer(class [mscorlib]System.Func`1) + IL_0027: nop + IL_0028: ldarg.0 + IL_0029: ldloc.0 + IL_002a: ldftn instance int32 ICSharpCode.Decompiler.Tests.Pretty.QualifierTests/'<>c__DisplayClass13_0'::'b__1'() + IL_0030: newobj instance void class [mscorlib]System.Func`1::.ctor(object, + native int) + IL_0035: call instance void ICSharpCode.Decompiler.Tests.Pretty.QualifierTests::Capturer(class [mscorlib]System.Func`1) + IL_003a: nop + IL_003b: ret + } // end of method QualifierTests::Capturing + + .method private hidebysig instance void + Capturer(class [mscorlib]System.Func`1 func) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::Capturer + + .method private hidebysig instance int32 + Capturer2(class [mscorlib]System.Func`1 func) 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 QualifierTests::Capturer2 + + .method private hidebysig instance void + Delegate(class [mscorlib]System.Action`1 action) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method QualifierTests::Delegate + + .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 QualifierTests::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.Pretty.QualifierTests + +.class private abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.Pretty.Ext + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig static void Do(int32 test) 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 Ext::Do + + .method public hidebysig static void Do(object test) 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 Ext::Do + + .method public hidebysig static void Do2(int32 test) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 23 (0x17) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: call void ICSharpCode.Decompiler.Tests.Pretty.Ext::Do(int32) + IL_0007: nop + IL_0008: ldnull + IL_0009: call bool [System.Core]System.Linq.Enumerable::Any(class [mscorlib]System.Collections.Generic.IEnumerable`1) + IL_000e: pop + IL_000f: ldnull + IL_0010: call void ICSharpCode.Decompiler.Tests.Pretty.Ext::Do(object) + IL_0015: nop + IL_0016: ret + } // end of method Ext::Do2 + +} // end of class ICSharpCode.Decompiler.Tests.Pretty.Ext + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs index bd6e5bf8f..8b7326e16 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs @@ -54,7 +54,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public object MultipleWhere() { - return from c in this.customers + return from c in customers where c.Orders.Count() > 10 where c.Country == "DE" select c; @@ -62,7 +62,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public object SelectManyFollowedBySelect() { - return from c in this.customers + return from c in customers from o in c.Orders select new { c.Name, @@ -73,7 +73,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public object SelectManyFollowedByOrderBy() { - return from c in this.customers + return from c in customers from o in c.Orders orderby o.Total descending select new { @@ -85,7 +85,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public object MultipleSelectManyFollowedBySelect() { - return from c in this.customers + return from c in customers from o in c.Orders from d in o.Details select new { @@ -97,7 +97,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public object MultipleSelectManyFollowedByLet() { - return from c in this.customers + return from c in customers from o in c.Orders from d in o.Details let x = (decimal)d.Quantity * d.UnitPrice @@ -110,7 +110,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public object FromLetWhereSelect() { - return from o in this.orders + return from o in orders let t = o.Details.Sum((OrderDetail d) => d.UnitPrice * (decimal)d.Quantity) where t >= 1000m select new { @@ -121,7 +121,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public object MultipleLet() { - return from a in this.customers + return from a in customers let b = a.Country let c = a.Name select b + c; @@ -129,8 +129,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public object Join() { - return from c in this.customers - join o in this.orders on c.CustomerID equals o.CustomerID + return from c in customers + join o in orders on c.CustomerID equals o.CustomerID select new { c.Name, o.OrderDate, @@ -140,8 +140,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public object JoinInto() { - return from c in this.customers - join o in this.orders on c.CustomerID equals o.CustomerID into co + return from c in customers + join o in orders on c.CustomerID equals o.CustomerID into co let n = co.Count() where n >= 10 select new { @@ -152,27 +152,27 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public object OrderBy() { - return from o in this.orders + return from o in orders orderby o.Customer.Name, o.Total descending select o; } public object GroupBy() { - return from c in this.customers + return from c in customers group c.Name by c.Country; } public object ExplicitType() { - return from Customer c in this.customers + return from Customer c in customers where c.City == "London" select c; } public object QueryContinuation() { - return from c in this.customers + return from c in customers group c by c.Country into g select new { Country = g.Key, diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ShortCircuit.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ShortCircuit.cs index 1bfb799a4..8395774c5 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ShortCircuit.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ShortCircuit.cs @@ -34,112 +34,112 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void ExprAnd() { - this.B(this.F(0) && this.F(1)); + B(F(0) && F(1)); } public void ExprOr() { - this.B(this.F(0) || this.F(1)); + B(F(0) || F(1)); } public void ExprCond() { - this.B(this.F(0) ? this.F(1) : this.F(2)); + B(F(0) ? F(1) : F(2)); } public void ExprCondAnd() { - this.B((this.F(0) && this.F(1)) ? this.F(2) : this.F(3)); + B((F(0) && F(1)) ? F(2) : F(3)); } public void StmtAnd2() { - if (this.F(0) && this.F(1)) { - this.M1(); + if (F(0) && F(1)) { + M1(); } else { - this.M2(); + M2(); } - this.E(); + E(); } public void StmtOr2() { - if (this.F(0) || this.F(1)) { - this.M1(); + if (F(0) || F(1)) { + M1(); } else { - this.M2(); + M2(); } - this.E(); + E(); } public void StmtAnd3() { - if (this.F(0) && this.F(1) && this.F(2)) { - this.M1(); + if (F(0) && F(1) && F(2)) { + M1(); } else { - this.M2(); + M2(); } - this.E(); + E(); } public void StmtOr3() { - if (this.F(0) || this.F(1) || this.F(3)) { - this.M1(); + if (F(0) || F(1) || F(3)) { + M1(); } else { - this.M2(); + M2(); } - this.E(); + E(); } public void StmtOr4() { - if (this.GetInt(0) != 0 || this.GetInt(1) != 0) { - this.M1(); + if (GetInt(0) != 0 || GetInt(1) != 0) { + M1(); } else { - this.M2(); + M2(); } - this.E(); + E(); } public void StmtComplex() { - if (this.F(0) && this.F(1) && !this.F(2) && (this.F(3) || this.F(4))) { - this.M1(); + if (F(0) && F(1) && !F(2) && (F(3) || F(4))) { + M1(); } else { - this.M2(); + M2(); } - this.E(); + E(); } public void StmtComplex2(int i) { if (i > 1000 || (i >= 1 && i <= 8) || i == 42) { - this.M1(); + M1(); } else { - this.M2(); + M2(); } - this.E(); + E(); } public void StmtComplex3(int i) { if (i > 1000 || (i >= 1 && i <= 8) || (i >= 100 && i <= 200) || i == 42) { - this.M1(); + M1(); } else { - this.M2(); + M2(); } - this.E(); + E(); } public void StmtComplex4(int i) { if (i > 1000 || (i >= 1 && i <= 8) || i == 42 || i == 23) { - this.M1(); + M1(); } else { - this.M2(); + M2(); } - this.E(); + E(); } } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index 143824d0b..7e71ca0f5 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -35,7 +35,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public SetProperty(PropertyInfo property) { - this.Property = property; + Property = property; } } @@ -378,7 +378,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { List list = new List(); List list2 = new List(); - SetProperty[] properties = Switch.GetProperties(); + SetProperty[] properties = GetProperties(); for (int i = 0; i < properties.Length; i++) { Console.WriteLine("In for-loop"); SetProperty setProperty = properties[i]; diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs index e8c5fd591..fe6f8aadb 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs @@ -156,38 +156,38 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public byte UseArrayWithInt(int i) { - return this.byteArray[i]; + return byteArray[i]; } public byte UseArrayWithUInt(uint i) { - return this.byteArray[i]; + return byteArray[i]; } public byte UseArrayWithLong(long i) { - return this.byteArray[i]; + return byteArray[i]; } public byte UseArrayWithULong(ulong i) { - return this.byteArray[i]; + return byteArray[i]; } public byte UseArrayWithShort(short i) { - return this.byteArray[i]; + return byteArray[i]; } public byte UseArrayWithUShort(ushort i) { - return this.byteArray[i]; + return byteArray[i]; } public byte UseArrayWithCastToUShort(int i) { // Unchecked cast = truncate to 16 bits - return this.byteArray[(ushort)i]; + return byteArray[(ushort)i]; } public StringComparison EnumDiffNumber(StringComparison data) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs index 9620c34ab..77df38079 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs @@ -70,12 +70,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty unsafe static UnsafeCode() { - UnsafeCode.staticUnsafeDelegate = UnsafeCode.UnsafeStaticMethod; + staticUnsafeDelegate = UnsafeStaticMethod; } public unsafe UnsafeCode() { - this.unsafeDelegate = this.UnsafeMethod; + unsafeDelegate = UnsafeMethod; } public unsafe int SizeOf() @@ -99,18 +99,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public unsafe void PointerComparison(int* a, double* b) { - UnsafeCode.UseBool(a == b); - UnsafeCode.UseBool(a != b); - UnsafeCode.UseBool(a < b); - UnsafeCode.UseBool(a > b); - UnsafeCode.UseBool(a <= b); - UnsafeCode.UseBool(a >= b); + UseBool(a == b); + UseBool(a != b); + UseBool(a < b); + UseBool(a > b); + UseBool(a <= b); + UseBool(a >= b); } public unsafe void PointerComparisonWithNull(int* a) { - UnsafeCode.UseBool(a == null); - UnsafeCode.UseBool(a != null); + UseBool(a == null); + UseBool(a != null); } public unsafe int* PointerCast(long* p) @@ -149,25 +149,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public unsafe void PassRefParameterAsPointer(ref int p) { fixed (int* ptr = &p) { - this.UsePointer(ptr); + UsePointer(ptr); } } public unsafe void PassPointerAsRefParameter(int* p) { - this.UseReference(ref *p); + UseReference(ref *p); } public unsafe void PassPointerCastAsRefParameter(uint* p) { - this.UseReference(ref *(int*)p); + UseReference(ref *(int*)p); } public unsafe void AddressInMultiDimensionalArray(double[,] matrix) { fixed (double* d = &matrix[1, 2]) { - this.PointerReferenceExpression(d); - this.PointerReferenceExpression(d); + PointerReferenceExpression(d); + PointerReferenceExpression(d); } } @@ -306,19 +306,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public unsafe void UseFixedMemberAsPointer(StructWithFixedSizeMembers* m) { - this.UsePointer(m->Integers); + UsePointer(m->Integers); } public unsafe void UseFixedMemberAsReference(StructWithFixedSizeMembers* m) { - this.UseReference(ref *m->Integers); - this.UseReference(ref m->Integers[1]); + UseReference(ref *m->Integers); + UseReference(ref m->Integers[1]); } public unsafe void PinFixedMember(ref StructWithFixedSizeMembers m) { fixed (int* ptr = m.Integers) { - this.UsePointer(ptr); + UsePointer(ptr); } } @@ -344,7 +344,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty ptr[i] = (char)i; ptr2[i] = '\0'; } - return this.UsePointer((double*)ptr); + return UsePointer((double*)ptr); } public unsafe string StackAllocStruct(int count) @@ -356,19 +356,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty for (int i = 2; i < 10; i++) { ptr[i].X = count; } - return this.UsePointer(&ptr->Y); + return UsePointer(&ptr->Y); } unsafe ~UnsafeCode() { - this.PassPointerAsRefParameter(this.NullPointer); + PassPointerAsRefParameter(NullPointer); } private unsafe void Issue990() { Data data = default(Data); Data* ptr = &data; - this.ConvertIntToFloat(ptr->Position.GetHashCode()); + ConvertIntToFloat(ptr->Position.GetHashCode()); } private unsafe static void Issue1021(ref byte* bytePtr, ref short* shortPtr) diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index 89d8bdd7a..045a33846 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -117,7 +117,7 @@ namespace ICSharpCode.Decompiler.CSharp expandedArguments.Add(expressionBuilder.GetDefaultValueExpression(elementType).WithoutILInstruction()); } } - if (IsUnambiguousCall(expectedTargetDetails, method, target, Empty.Array, expandedArguments) == OverloadResolutionErrors.None) { + if (IsUnambiguousCall(expectedTargetDetails, method, target.ResolveResult, Empty.Array, expandedArguments) == OverloadResolutionErrors.None) { isExpandedForm = true; expectedParameters = expandedParameters; arguments = expandedArguments.SelectList(a => new TranslatedExpression(a.Expression.Detach())); @@ -136,6 +136,7 @@ namespace ICSharpCode.Decompiler.CSharp else brrr = new ByReferenceResolveResult(brrr.ElementResult, isOut: true); dirExpr.AddAnnotation(brrr); + arguments[i] = new TranslatedExpression(dirExpr); } } @@ -175,8 +176,7 @@ namespace ICSharpCode.Decompiler.CSharp return atce .WithRR(rr); } else { - - if (IsUnambiguousCall(expectedTargetDetails, method, target, Empty.Array, arguments) != OverloadResolutionErrors.None) { + if (IsUnambiguousCall(expectedTargetDetails, method, null, Empty.Array, arguments) != OverloadResolutionErrors.None) { for (int i = 0; i < arguments.Count; i++) { if (settings.AnonymousTypes && expectedParameters[i].Type.ContainsAnonymousType()) { if (arguments[i].Expression is LambdaExpression lambda) { @@ -203,12 +203,21 @@ namespace ICSharpCode.Decompiler.CSharp return HandleImplicitConversion(method, arguments[0]); } else { bool requireTypeArguments = false; + bool requireTarget; + if (expressionBuilder.HidesVariableWithName(method.Name)) { + requireTarget = true; + } else { + if (method.IsStatic) + requireTarget = !expressionBuilder.IsCurrentOrContainingType(method.DeclaringTypeDefinition) || method.Name == ".cctor"; + else + requireTarget = !(target.Expression is ThisReferenceExpression) || method.Name == ".ctor"; + } bool targetCasted = false; bool argumentsCasted = false; IType[] typeArguments = Empty.Array; - + var targetResolveResult = requireTarget ? target.ResolveResult : null; OverloadResolutionErrors errors; - while ((errors = IsUnambiguousCall(expectedTargetDetails, method, target, typeArguments, arguments)) != OverloadResolutionErrors.None) { + while ((errors = IsUnambiguousCall(expectedTargetDetails, method, targetResolveResult, typeArguments, arguments)) != OverloadResolutionErrors.None) { switch (errors) { case OverloadResolutionErrors.TypeInferenceFailed: case OverloadResolutionErrors.WrongNumberOfTypeArguments: @@ -217,6 +226,8 @@ namespace ICSharpCode.Decompiler.CSharp typeArguments = method.TypeArguments.ToArray(); continue; default: + // TODO : implement some more intelligent algorithm that decides which of these fixes (cast args, add target, cast target, add type args) + // is best in this case. Additionally we should not cast all arguments at once, but step-by-step try to add only a minimal number of casts. if (!argumentsCasted) { argumentsCasted = true; for (int i = 0; i < arguments.Count; i++) { @@ -228,9 +239,13 @@ namespace ICSharpCode.Decompiler.CSharp arguments[i] = arguments[i].ConvertTo(expectedParameters[i].Type, expressionBuilder); } } + } else if (!requireTarget) { + requireTarget = true; + targetResolveResult = target.ResolveResult; } else if (!targetCasted) { targetCasted = true; target = target.ConvertTo(method.DeclaringType, expressionBuilder); + targetResolveResult = target.ResolveResult; } else if (!requireTypeArguments) { requireTypeArguments = true; typeArguments = method.TypeArguments.ToArray(); @@ -242,18 +257,29 @@ namespace ICSharpCode.Decompiler.CSharp break; } - Expression targetExpr = target.Expression; + Expression targetExpr; string methodName = method.Name; - // HACK : convert this.Dispose() to ((IDisposable)this).Dispose(), if Dispose is an explicitly implemented interface method. - if (method.IsExplicitInterfaceImplementation && targetExpr is ThisReferenceExpression) { - targetExpr = new CastExpression(expressionBuilder.ConvertType(method.ImplementedInterfaceMembers[0].DeclaringType), targetExpr); - methodName = method.ImplementedInterfaceMembers[0].Name; + AstNodeCollection typeArgumentList; + if (requireTarget) { + targetExpr = new MemberReferenceExpression(target.Expression, methodName); + typeArgumentList = ((MemberReferenceExpression)targetExpr).TypeArguments; + + // HACK : convert this.Dispose() to ((IDisposable)this).Dispose(), if Dispose is an explicitly implemented interface method. + if (method.IsExplicitInterfaceImplementation && target.Expression is ThisReferenceExpression) { + var castExpression = new CastExpression(expressionBuilder.ConvertType(method.ImplementedInterfaceMembers[0].DeclaringType), target.Expression); + methodName = method.ImplementedInterfaceMembers[0].Name; + targetExpr = new MemberReferenceExpression(castExpression, methodName); + typeArgumentList = ((MemberReferenceExpression)targetExpr).TypeArguments; + } + } else { + targetExpr = new IdentifierExpression(methodName); + typeArgumentList = ((IdentifierExpression)targetExpr).TypeArguments; } - var mre = new MemberReferenceExpression(targetExpr, methodName); + if (requireTypeArguments && (!settings.AnonymousTypes || !method.TypeArguments.Any(a => a.ContainsAnonymousType()))) - mre.TypeArguments.AddRange(method.TypeArguments.Select(expressionBuilder.ConvertType)); + typeArgumentList.AddRange(method.TypeArguments.Select(expressionBuilder.ConvertType)); var argumentExpressions = arguments.Select(arg => arg.Expression); - return new InvocationExpression(mre, argumentExpressions).WithRR(rr); + return new InvocationExpression(targetExpr, argumentExpressions).WithRR(rr); } } } @@ -323,7 +349,7 @@ namespace ICSharpCode.Decompiler.CSharp } OverloadResolutionErrors IsUnambiguousCall(ExpectedTargetDetails expectedTargetDetails, IMethod method, - TranslatedExpression target, IType[] typeArguments, IList arguments) + ResolveResult target, IType[] typeArguments, IList arguments) { var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly); var or = new OverloadResolution(resolver.Compilation, arguments.SelectArray(a => a.ResolveResult), typeArguments: typeArguments); @@ -333,8 +359,13 @@ namespace ICSharpCode.Decompiler.CSharp or.AddCandidate(ctor); } } + } else if (target == null) { + var result = resolver.ResolveSimpleName(method.Name, typeArguments, isInvocationTarget: true) as MethodGroupResolveResult; + if (result == null) + return OverloadResolutionErrors.AmbiguousMatch; + or.AddMethodLists(result.MethodsGroupedByDeclaringType.ToArray()); } else { - var result = lookup.Lookup(target.ResolveResult, method.Name, EmptyList.Instance, true) as MethodGroupResolveResult; + var result = lookup.Lookup(target, method.Name, EmptyList.Instance, isInvocation: true) as MethodGroupResolveResult; if (result == null) return OverloadResolutionErrors.AmbiguousMatch; or.AddMethodLists(result.MethodsGroupedByDeclaringType.ToArray()); @@ -364,25 +395,56 @@ namespace ICSharpCode.Decompiler.CSharp return true; } - ExpressionWithResolveResult HandleAccessorCall(ExpectedTargetDetails expectedTargetDetails, IMethod method, TranslatedExpression target, IList arguments) + bool IsUnambiguousAccess(ExpectedTargetDetails expectedTargetDetails, ResolveResult target, IMethod method) { - var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly); - var result = lookup.Lookup(target.ResolveResult, method.AccessorOwner.Name, EmptyList.Instance, isInvocation: false); + if (target == null) { + var result = resolver.ResolveSimpleName(method.AccessorOwner.Name, EmptyList.Instance, isInvocationTarget: false) as MemberResolveResult; + return !(result == null || result.IsError || !IsAppropriateCallTarget(expectedTargetDetails, method.AccessorOwner, result.Member)); + } else { + var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly); + var result = lookup.Lookup(target, method.AccessorOwner.Name, EmptyList.Instance, isInvocation: false) as MemberResolveResult; + return !(result == null || result.IsError || !IsAppropriateCallTarget(expectedTargetDetails, method.AccessorOwner, result.Member)); + } + } - if (result.IsError || (result is MemberResolveResult && !IsAppropriateCallTarget(expectedTargetDetails, method.AccessorOwner, ((MemberResolveResult)result).Member))) - target = target.ConvertTo(method.AccessorOwner.DeclaringType, expressionBuilder); + ExpressionWithResolveResult HandleAccessorCall(ExpectedTargetDetails expectedTargetDetails, IMethod method, TranslatedExpression target, IList arguments) + { + bool requireTarget = expressionBuilder.HidesVariableWithName(method.AccessorOwner.Name) + || (method.IsStatic ? !expressionBuilder.IsCurrentOrContainingType(method.DeclaringTypeDefinition) : !(target.Expression is ThisReferenceExpression)); + bool targetCasted = false; + var targetResolveResult = requireTarget ? target.ResolveResult : null; + + while (!IsUnambiguousAccess(expectedTargetDetails, targetResolveResult, method)) { + if (!requireTarget) { + requireTarget = true; + targetResolveResult = target.ResolveResult; + } else if (!targetCasted) { + targetCasted = true; + target = target.ConvertTo(method.AccessorOwner.DeclaringType, expressionBuilder); + targetResolveResult = target.ResolveResult; + } else { + break; + } + } + var rr = new MemberResolveResult(target.ResolveResult, method.AccessorOwner); if (method.ReturnType.IsKnownType(KnownTypeCode.Void)) { var value = arguments.Last(); arguments.Remove(value); TranslatedExpression expr; - if (arguments.Count == 0) + + if (arguments.Count != 0) { + expr = new IndexerExpression(target.Expression, arguments.Select(a => a.Expression)) + .WithoutILInstruction().WithRR(rr); + } else if (requireTarget) { expr = new MemberReferenceExpression(target.Expression, method.AccessorOwner.Name) .WithoutILInstruction().WithRR(rr); - else - expr = new IndexerExpression(target.Expression, arguments.Select(a => a.Expression)) + } else { + expr = new IdentifierExpression(method.AccessorOwner.Name) .WithoutILInstruction().WithRR(rr); + } + var op = AssignmentOperatorType.Assign; var parentEvent = method.AccessorOwner as IEvent; if (parentEvent != null) { @@ -395,10 +457,16 @@ namespace ICSharpCode.Decompiler.CSharp } return new AssignmentExpression(expr, op, value.Expression).WithRR(new TypeResolveResult(method.AccessorOwner.ReturnType)); } else { - if (arguments.Count == 0) - return new MemberReferenceExpression(target.Expression, method.AccessorOwner.Name).WithRR(rr); - else - return new IndexerExpression(target.Expression, arguments.Select(a => a.Expression)).WithRR(rr); + if (arguments.Count != 0) { + return new IndexerExpression(target.Expression, arguments.Select(a => a.Expression)) + .WithoutILInstruction().WithRR(rr); + } else if (requireTarget) { + return new MemberReferenceExpression(target.Expression, method.AccessorOwner.Name) + .WithoutILInstruction().WithRR(rr); + } else { + return new IdentifierExpression(method.AccessorOwner.Name) + .WithoutILInstruction().WithRR(rr); + } } } @@ -437,34 +505,58 @@ namespace ICSharpCode.Decompiler.CSharp var invokeMethod = inst.Method.DeclaringType.GetDelegateInvokeMethod(); TranslatedExpression target; IType targetType; + bool requireTarget; if (method.IsExtensionMethod && invokeMethod != null && method.Parameters.Count - 1 == invokeMethod.Parameters.Count) { targetType = method.Parameters[0].Type; target = expressionBuilder.Translate(inst.Arguments[0], targetType); + requireTarget = true; } else { targetType = method.DeclaringType; target = expressionBuilder.TranslateTarget(method, inst.Arguments[0], func.OpCode == OpCode.LdFtn); + requireTarget = expressionBuilder.HidesVariableWithName(method.Name) + || (method.IsStatic ? !expressionBuilder.IsCurrentOrContainingType(method.DeclaringTypeDefinition) : !(target.Expression is ThisReferenceExpression)); } - 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, false); - - bool needsCast = true; - if (result is MethodGroupResolveResult mgrr) { - or.AddMethodLists(mgrr.MethodsGroupedByDeclaringType.ToArray()); - var expectedTargetDetails = new ExpectedTargetDetails { - CallOpCode = inst.OpCode - }; - needsCast = (or.BestCandidateErrors != OverloadResolutionErrors.None || !IsAppropriateCallTarget(expectedTargetDetails, method, or.BestCandidate)); + var expectedTargetDetails = new ExpectedTargetDetails { + CallOpCode = inst.OpCode + }; + bool needsCast = false; + ResolveResult result = null; + ResolveResult targetResolveResult = requireTarget ? target.ResolveResult : null; + if (targetResolveResult == null) { + var rr = resolver.ResolveSimpleName(method.Name, method.TypeArguments, isInvocationTarget: false); + result = rr; + requireTarget = (!(result is MethodGroupResolveResult mgrr) || mgrr.IsError || !mgrr.Methods.Any() || mgrr.Methods.Skip(1).Any() || !IsAppropriateCallTarget(expectedTargetDetails, method, mgrr.Methods.First())); + } + MemberLookup lookup = null; + if (requireTarget) { + targetResolveResult = target.ResolveResult; + lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly); + var or = new OverloadResolution(resolver.Compilation, method.Parameters.SelectArray(p => new TypeResolveResult(p.Type))); + var rr = lookup.Lookup(targetResolveResult, method.Name, method.TypeArguments, false) ; + needsCast = true; + result = rr; + if (rr is MethodGroupResolveResult mgrr) { + or.AddMethodLists(mgrr.MethodsGroupedByDeclaringType.ToArray()); + needsCast = (or.BestCandidateErrors != OverloadResolutionErrors.None || !IsAppropriateCallTarget(expectedTargetDetails, method, or.BestCandidate)); + } } if (needsCast) { + Debug.Assert(requireTarget); target = target.ConvertTo(targetType, expressionBuilder); - result = lookup.Lookup(target.ResolveResult, method.Name, method.TypeArguments, false); + result = lookup.Lookup(targetResolveResult, 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) + Expression targetExpression; + if (requireTarget) { + var mre = new MemberReferenceExpression(target, method.Name); + mre.TypeArguments.AddRange(method.TypeArguments.Select(expressionBuilder.ConvertType)); + mre.WithRR(result); + targetExpression = mre; + } else { + var ide = new IdentifierExpression(method.Name) + .WithRR(result); + targetExpression = ide; + } + var oce = new ObjectCreateExpression(expressionBuilder.ConvertType(inst.Method.DeclaringType), targetExpression) .WithILInstruction(inst) .WithRR(new ConversionResolveResult( inst.Method.DeclaringType, diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 23ce483ae..71504a0c8 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -69,6 +69,7 @@ namespace ICSharpCode.Decompiler.CSharp { readonly IDecompilerTypeSystem typeSystem; readonly ITypeResolveContext decompilationContext; + internal readonly ILFunction currentFunction; internal readonly ICompilation compilation; internal readonly CSharpResolver resolver; readonly TypeSystemAstBuilder astBuilder; @@ -76,11 +77,12 @@ namespace ICSharpCode.Decompiler.CSharp internal readonly DecompilerSettings settings; readonly CancellationToken cancellationToken; - public ExpressionBuilder(IDecompilerTypeSystem typeSystem, ITypeResolveContext decompilationContext, DecompilerSettings settings, CancellationToken cancellationToken) + public ExpressionBuilder(IDecompilerTypeSystem typeSystem, ITypeResolveContext decompilationContext, ILFunction currentFunction, DecompilerSettings settings, CancellationToken cancellationToken) { Debug.Assert(decompilationContext != null); this.typeSystem = typeSystem; this.decompilationContext = decompilationContext; + this.currentFunction = currentFunction; this.settings = settings; this.cancellationToken = cancellationToken; this.compilation = decompilationContext.Compilation; @@ -185,18 +187,51 @@ namespace ICSharpCode.Decompiler.CSharp } } - ExpressionWithResolveResult ConvertField(IField field, ILInstruction target = null) + internal bool HidesVariableWithName(string name) { - var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly); - var targetExpression = TranslateTarget(field, target, true); - - var result = lookup.Lookup(targetExpression.ResolveResult, field.Name, EmptyList.Instance, false) as MemberResolveResult; - - if (result == null || !result.Member.Equals(field)) - targetExpression = targetExpression.ConvertTo(field.DeclaringType, this); - - return new MemberReferenceExpression(targetExpression, field.Name) - .WithRR(new MemberResolveResult(targetExpression.ResolveResult, field)); + return currentFunction.Ancestors.OfType().SelectMany(f => f.Variables).Any(v => v.Name == name); + } + + ExpressionWithResolveResult ConvertField(IField field, ILInstruction targetInstruction = null) + { + var target = TranslateTarget(field, targetInstruction, true); + bool requireTarget = HidesVariableWithName(field.Name) + || (field.IsStatic ? !IsCurrentOrContainingType(field.DeclaringTypeDefinition) : !(target.Expression is ThisReferenceExpression)); + bool targetCasted = false; + var targetResolveResult = requireTarget ? target.ResolveResult : null; + + bool IsUnambiguousAccess() + { + if (targetResolveResult == null) { + var result = resolver.ResolveSimpleName(field.Name, EmptyList.Instance, isInvocationTarget: false) as MemberResolveResult; + return !(result == null || result.IsError || !result.Member.Equals(field)); + } else { + var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly); + var result = lookup.Lookup(target.ResolveResult, field.Name, EmptyList.Instance, false) as MemberResolveResult; + return !(result == null || result.IsError || !result.Member.Equals(field)); + } + } + + while (!IsUnambiguousAccess()) { + if (!requireTarget) { + requireTarget = true; + targetResolveResult = target.ResolveResult; + } else if (!targetCasted) { + targetCasted = true; + target = target.ConvertTo(field.DeclaringType, this); + targetResolveResult = target.ResolveResult; + } else { + break; + } + } + + if (requireTarget) { + return new MemberReferenceExpression(target, field.Name) + .WithRR(new MemberResolveResult(target.ResolveResult, field)); + } else { + return new IdentifierExpression(field.Name) + .WithRR(new MemberResolveResult(target.ResolveResult, field)); + } } TranslatedExpression IsType(IsInst inst) @@ -1363,6 +1398,17 @@ namespace ICSharpCode.Decompiler.CSharp return expr; } + internal bool IsCurrentOrContainingType(ITypeDefinition type) + { + var currentTypeDefinition = decompilationContext.CurrentTypeDefinition; + while (currentTypeDefinition != null) { + if (type == currentTypeDefinition) + return true; + currentTypeDefinition = currentTypeDefinition.DeclaringTypeDefinition; + } + return false; + } + internal ExpressionWithResolveResult TranslateFunction(IType delegateType, ILFunction function) { var method = function.Method?.MemberDefinition as IMethod; @@ -1877,9 +1923,9 @@ namespace ICSharpCode.Decompiler.CSharp .WithILInstruction(inst).WithRR(memberRR); elementsStack.Peek().Add(Assignment(indexer, Translate(info.Values.Single(), typeHint: indexer.Type))); } else { - var target = new IdentifierExpression(lastElement.Member.Name) + var assignment = new NamedExpression(lastElement.Member.Name, Translate(info.Values.Single(), typeHint: memberRR.Type)) .WithILInstruction(inst).WithRR(memberRR); - elementsStack.Peek().Add(Assignment(target, Translate(info.Values.Single(), typeHint: target.Type))); + elementsStack.Peek().Add(assignment); } break; } @@ -1897,13 +1943,18 @@ namespace ICSharpCode.Decompiler.CSharp Expression MakeInitializerAssignment(IMember method, IL.Transforms.AccessPathElement member, List values, Dictionary indexVariables) { - var target = member.Indices?.Length > 0 ? (Expression)new IndexerExpression(null, member.Indices.SelectArray(i => Translate(i is LdLoc ld ? indexVariables[ld.Variable] : i).Expression)) : new IdentifierExpression(member.Member.Name); Expression value; - if (values.Count == 1 && !(values[0] is AssignmentExpression) && !(method.SymbolKind == SymbolKind.Method && method.Name == "Add")) + if (values.Count == 1 && !(values[0] is AssignmentExpression || values[0] is NamedExpression) && !(method.SymbolKind == SymbolKind.Method && method.Name == "Add")) { value = values[0]; - else + } else { value = new ArrayInitializerExpression(values); - return new AssignmentExpression(target, value); + } + if (member.Indices?.Length > 0) { + var index = new IndexerExpression(null, member.Indices.SelectArray(i => Translate(i is LdLoc ld ? indexVariables[ld.Variable] : i).Expression)); + return new AssignmentExpression(index, value); + } else { + return new NamedExpression(member.Member.Name, value); + } } Expression MakeInitializerElements(List values, IReadOnlyList parameters) diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index ccf459757..1792b1787 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.CSharp public StatementBuilder(IDecompilerTypeSystem typeSystem, ITypeResolveContext decompilationContext, ILFunction currentFunction, DecompilerSettings settings, CancellationToken cancellationToken) { Debug.Assert(typeSystem != null && decompilationContext != null); - this.exprBuilder = new ExpressionBuilder(typeSystem, decompilationContext, settings, cancellationToken); + this.exprBuilder = new ExpressionBuilder(typeSystem, decompilationContext, currentFunction, settings, cancellationToken); this.currentFunction = currentFunction; this.typeSystem = typeSystem; this.settings = settings; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/AstNodeCollection.cs b/ICSharpCode.Decompiler/CSharp/Syntax/AstNodeCollection.cs index 7820945da..4355c4cbb 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/AstNodeCollection.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/AstNodeCollection.cs @@ -129,6 +129,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax foreach (T item in this) item.Remove(); } + + public IEnumerable Detach() + { + foreach (T item in this) + yield return item.Detach(); + } /// /// Returns the first element for which the predicate returns true, diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/ConvertConstructorCallIntoInitializer.cs b/ICSharpCode.Decompiler/CSharp/Transforms/ConvertConstructorCallIntoInitializer.cs index 053777942..7deba49d7 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/ConvertConstructorCallIntoInitializer.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/ConvertConstructorCallIntoInitializer.cs @@ -85,10 +85,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms static readonly ExpressionStatement fieldInitializerPattern = new ExpressionStatement { Expression = new AssignmentExpression { - Left = new NamedNode("fieldAccess", new MemberReferenceExpression { - Target = new ThisReferenceExpression(), - MemberName = Pattern.AnyString - }), + Left = new Choice { + new NamedNode("fieldAccess", new MemberReferenceExpression { + Target = new ThisReferenceExpression(), + MemberName = Pattern.AnyString + }), + new NamedNode("fieldAccess", new IdentifierExpression(Pattern.AnyString)) + }, Operator = AssignmentOperatorType.Assign, Right = new AnyNode("initializer") } @@ -127,7 +130,6 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms Match m = fieldInitializerPattern.Match(instanceCtorsNotChainingWithThis[0].Body.FirstOrDefault()); if (!m.Success) break; - IMember fieldOrPropertyOrEvent = (m.Get("fieldAccess").Single().GetSymbol() as IMember)?.MemberDefinition; if (!(fieldOrPropertyOrEvent is IField) && !(fieldOrPropertyOrEvent is IProperty) && !(fieldOrPropertyOrEvent is IEvent)) break; @@ -142,7 +144,15 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms allSame = true; for (int i = 1; i < instanceCtorsNotChainingWithThis.Length; i++) { - if (!instanceCtorsNotChainingWithThis[0].Body.First().IsMatch(instanceCtorsNotChainingWithThis[i].Body.FirstOrDefault())) + var otherMatch = fieldInitializerPattern.Match(instanceCtorsNotChainingWithThis[i].Body.FirstOrDefault()); + if (!otherMatch.Success) { + allSame = false; + break; + } + var otherMember = (otherMatch.Get("fieldAccess").Single().GetSymbol() as IMember)?.MemberDefinition; + if (!otherMember.Equals(fieldOrPropertyOrEvent)) + allSame = false; + if (!initializer.IsMatch(otherMatch.Get("initializer").Single())) allSame = false; } if (allSame) { diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs index 45ccaa296..b5e22abfc 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs @@ -35,10 +35,12 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms { TransformContext context; CSharpResolver resolver; + CSharpConversions conversions; public void Run(AstNode rootNode, TransformContext context) { this.context = context; + this.conversions = CSharpConversions.Get(context.TypeSystem.Compilation); InitializeContext(rootNode.Annotation()); rootNode.AcceptVisitor(this); } @@ -93,20 +95,40 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms public override void VisitInvocationExpression(InvocationExpression invocationExpression) { base.VisitInvocationExpression(invocationExpression); - var mre = invocationExpression.Target as MemberReferenceExpression; var method = invocationExpression.GetSymbol() as IMethod; - if (method == null || !method.IsExtensionMethod || mre == null || !(mre.Target is TypeReferenceExpression) || !invocationExpression.Arguments.Any()) + if (method == null || !method.IsExtensionMethod || !invocationExpression.Arguments.Any()) return; - var typeArguments = mre.TypeArguments.Any() ? method.TypeArguments : EmptyList.Instance; + IReadOnlyList typeArguments; + MemberReferenceExpression memberRefExpr; + switch (invocationExpression.Target) { + case MemberReferenceExpression mre: + typeArguments = mre.TypeArguments.Any() ? method.TypeArguments : EmptyList.Instance; + memberRefExpr = mre; + break; + case IdentifierExpression ide: + typeArguments = ide.TypeArguments.Any() ? method.TypeArguments : EmptyList.Instance; + memberRefExpr = null; + break; + default: return; + } + var firstArgument = invocationExpression.Arguments.First(); var target = firstArgument.GetResolveResult(); + if (target is ConstantResolveResult crr && crr.ConstantValue == null) { + target = new ConversionResolveResult(method.Parameters[0].Type, crr, Conversion.NullLiteralConversion); + } var args = invocationExpression.Arguments.Skip(1).Select(a => a.GetResolveResult()).ToArray(); if (!CanTransformToExtensionMethodCall(resolver, method, typeArguments, target, args)) return; if (firstArgument is NullReferenceExpression) firstArgument = firstArgument.ReplaceWith(expr => new CastExpression(context.TypeSystemAstBuilder.ConvertType(method.Parameters[0].Type), expr.Detach())); - else - mre.Target = firstArgument.Detach(); + if (invocationExpression.Target is IdentifierExpression identifierExpression) { + identifierExpression.Detach(); + memberRefExpr = new MemberReferenceExpression(firstArgument.Detach(), method.Name, identifierExpression.TypeArguments.Detach()); + invocationExpression.Target = memberRefExpr; + } else { + memberRefExpr.Target = firstArgument.Detach(); + } } public static bool CanTransformToExtensionMethodCall(CSharpResolver resolver, IMethod method, IReadOnlyList typeArguments, ResolveResult target, ResolveResult[] arguments) diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs index f5fa6f30e..6424ebdd5 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs @@ -121,7 +121,24 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms return result; } - + + public override bool VisitIdentifierExpression(IdentifierExpression identifierExpression) + { + bool result = base.VisitIdentifierExpression(identifierExpression); + var rr = identifierExpression.GetResolveResult(); + if (rr != null) { + if (rr.Type is PointerType) + return true; + if (rr is MemberResolveResult mrr && mrr.Member.ReturnType.Kind == TypeKind.Delegate) { + var method = mrr.Member.ReturnType.GetDefinition()?.GetDelegateInvokeMethod(); + if (method != null && (method.ReturnType is PointerType || method.Parameters.Any(p => p.Type is PointerType))) + return true; + } + } + + return result; + } + public override bool VisitStackAllocExpression(StackAllocExpression stackAllocExpression) { base.VisitStackAllocExpression(stackAllocExpression);