Browse Source

#1083: Add support for optional arguments to constructors and refactor CallBuilder a bit.

pull/1236/head
Siegfried Pammer 8 years ago
parent
commit
82dcc09acf
  1. 30
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.cs
  2. 97
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.il
  3. 87
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.opt.il
  4. 93
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.opt.roslyn.il
  5. 103
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.roslyn.il
  6. 60
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs

30
ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.cs

@ -16,12 +16,27 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{ {
internal class OptionalArguments internal class OptionalArguments : List<int>
{ {
public OptionalArguments(string name, int a = 5)
{
}
public OptionalArguments(int num, bool flag = true)
{
}
public void Add(string name, int a = 5)
{
}
private void SimpleTests() private void SimpleTests()
{ {
Test(); Test();
@ -61,6 +76,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
CallerLineNumber(0); CallerLineNumber(0);
} }
private void Constructor(out OptionalArguments a, out OptionalArguments b, out OptionalArguments c)
{
a = new OptionalArguments("Hallo");
b = new OptionalArguments(10);
c = new OptionalArguments(10) {
{
"Test",
10
},
"Test2"
};
}
private void CallerMemberName([CallerMemberName] string memberName = null) private void CallerMemberName([CallerMemberName] string memberName = null)
{ {

97
ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.il

@ -30,8 +30,49 @@
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments .class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments
extends [mscorlib]System.Object extends class [mscorlib]System.Collections.Generic.List`1<int32>
{ {
.method public hidebysig specialname rtspecialname
instance void .ctor(string name,
[opt] int32 a) cil managed
{
.param [2] = int32(0x00000005)
// Code size 10 (0xa)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void class [mscorlib]System.Collections.Generic.List`1<int32>::.ctor()
IL_0006: nop
IL_0007: nop
IL_0008: nop
IL_0009: ret
} // end of method OptionalArguments::.ctor
.method public hidebysig specialname rtspecialname
instance void .ctor(int32 num,
[opt] bool flag) cil managed
{
.param [2] = bool(true)
// Code size 10 (0xa)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void class [mscorlib]System.Collections.Generic.List`1<int32>::.ctor()
IL_0006: nop
IL_0007: nop
IL_0008: nop
IL_0009: ret
} // end of method OptionalArguments::.ctor
.method public hidebysig instance void
Add(string name,
[opt] int32 a) cil managed
{
.param [2] = int32(0x00000005)
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method OptionalArguments::Add
.method private hidebysig instance void .method private hidebysig instance void
SimpleTests() cil managed SimpleTests() cil managed
{ {
@ -225,6 +266,50 @@
IL_0026: ret IL_0026: ret
} // end of method OptionalArguments::CallerInfo } // end of method OptionalArguments::CallerInfo
.method private hidebysig instance void
Constructor([out] class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments& a,
[out] class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments& b,
[out] class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments& c) cil managed
{
// Code size 64 (0x40)
.maxstack 4
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldstr "Hallo"
IL_0007: ldc.i4.5
IL_0008: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::.ctor(string,
int32)
IL_000d: stind.ref
IL_000e: ldarg.2
IL_000f: ldc.i4.s 10
IL_0011: ldc.i4.1
IL_0012: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::.ctor(int32,
bool)
IL_0017: stind.ref
IL_0018: ldarg.3
IL_0019: ldc.i4.s 10
IL_001b: ldc.i4.1
IL_001c: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::.ctor(int32,
bool)
IL_0021: stloc.0
IL_0022: ldloc.0
IL_0023: ldstr "Test"
IL_0028: ldc.i4.s 10
IL_002a: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::Add(string,
int32)
IL_002f: nop
IL_0030: ldloc.0
IL_0031: ldstr "Test2"
IL_0036: ldc.i4.5
IL_0037: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::Add(string,
int32)
IL_003c: nop
IL_003d: ldloc.0
IL_003e: stind.ref
IL_003f: ret
} // end of method OptionalArguments::Constructor
.method private hidebysig instance void .method private hidebysig instance void
CallerMemberName([opt] string memberName) cil managed CallerMemberName([opt] string memberName) cil managed
{ {
@ -373,16 +458,6 @@
IL_0002: throw IL_0002: throw
} // end of method OptionalArguments::Get } // end of method OptionalArguments::Get
.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 OptionalArguments::.ctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments

87
ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.opt.il

@ -30,8 +30,42 @@
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments .class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments
extends [mscorlib]System.Object extends class [mscorlib]System.Collections.Generic.List`1<int32>
{ {
.method public hidebysig specialname rtspecialname
instance void .ctor(string name,
[opt] int32 a) cil managed
{
.param [2] = int32(0x00000005)
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void class [mscorlib]System.Collections.Generic.List`1<int32>::.ctor()
IL_0006: ret
} // end of method OptionalArguments::.ctor
.method public hidebysig specialname rtspecialname
instance void .ctor(int32 num,
[opt] bool flag) cil managed
{
.param [2] = bool(true)
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void class [mscorlib]System.Collections.Generic.List`1<int32>::.ctor()
IL_0006: ret
} // end of method OptionalArguments::.ctor
.method public hidebysig instance void
Add(string name,
[opt] int32 a) cil managed
{
.param [2] = int32(0x00000005)
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method OptionalArguments::Add
.method private hidebysig instance void .method private hidebysig instance void
SimpleTests() cil managed SimpleTests() cil managed
{ {
@ -201,6 +235,47 @@
IL_0021: ret IL_0021: ret
} // end of method OptionalArguments::CallerInfo } // end of method OptionalArguments::CallerInfo
.method private hidebysig instance void
Constructor([out] class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments& a,
[out] class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments& b,
[out] class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments& c) cil managed
{
// Code size 61 (0x3d)
.maxstack 4
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments V_0)
IL_0000: ldarg.1
IL_0001: ldstr "Hallo"
IL_0006: ldc.i4.5
IL_0007: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::.ctor(string,
int32)
IL_000c: stind.ref
IL_000d: ldarg.2
IL_000e: ldc.i4.s 10
IL_0010: ldc.i4.1
IL_0011: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::.ctor(int32,
bool)
IL_0016: stind.ref
IL_0017: ldarg.3
IL_0018: ldc.i4.s 10
IL_001a: ldc.i4.1
IL_001b: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::.ctor(int32,
bool)
IL_0020: stloc.0
IL_0021: ldloc.0
IL_0022: ldstr "Test"
IL_0027: ldc.i4.s 10
IL_0029: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::Add(string,
int32)
IL_002e: ldloc.0
IL_002f: ldstr "Test2"
IL_0034: ldc.i4.5
IL_0035: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::Add(string,
int32)
IL_003a: ldloc.0
IL_003b: stind.ref
IL_003c: ret
} // end of method OptionalArguments::Constructor
.method private hidebysig instance void .method private hidebysig instance void
CallerMemberName([opt] string memberName) cil managed CallerMemberName([opt] string memberName) cil managed
{ {
@ -336,16 +411,6 @@
IL_0001: throw IL_0001: throw
} // end of method OptionalArguments::Get } // end of method OptionalArguments::Get
.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 OptionalArguments::.ctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments

93
ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.opt.roslyn.il

@ -34,8 +34,42 @@
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments .class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments
extends [mscorlib]System.Object extends class [mscorlib]System.Collections.Generic.List`1<int32>
{ {
.method public hidebysig specialname rtspecialname
instance void .ctor(string name,
[opt] int32 a) cil managed
{
.param [2] = int32(0x00000005)
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void class [mscorlib]System.Collections.Generic.List`1<int32>::.ctor()
IL_0006: ret
} // end of method OptionalArguments::.ctor
.method public hidebysig specialname rtspecialname
instance void .ctor(int32 num,
[opt] bool flag) cil managed
{
.param [2] = bool(true)
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void class [mscorlib]System.Collections.Generic.List`1<int32>::.ctor()
IL_0006: ret
} // end of method OptionalArguments::.ctor
.method public hidebysig instance void
Add(string name,
[opt] int32 a) cil managed
{
.param [2] = int32(0x00000005)
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method OptionalArguments::Add
.method private hidebysig instance void .method private hidebysig instance void
SimpleTests() cil managed SimpleTests() cil managed
{ {
@ -180,6 +214,44 @@
IL_0021: ret IL_0021: ret
} // end of method OptionalArguments::CallerInfo } // end of method OptionalArguments::CallerInfo
.method private hidebysig instance void
Constructor([out] class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments& a,
[out] class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments& b,
[out] class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments& c) cil managed
{
// Code size 59 (0x3b)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ldstr "Hallo"
IL_0006: ldc.i4.5
IL_0007: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::.ctor(string,
int32)
IL_000c: stind.ref
IL_000d: ldarg.2
IL_000e: ldc.i4.s 10
IL_0010: ldc.i4.1
IL_0011: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::.ctor(int32,
bool)
IL_0016: stind.ref
IL_0017: ldarg.3
IL_0018: ldc.i4.s 10
IL_001a: ldc.i4.1
IL_001b: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::.ctor(int32,
bool)
IL_0020: dup
IL_0021: ldstr "Test"
IL_0026: ldc.i4.s 10
IL_0028: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::Add(string,
int32)
IL_002d: dup
IL_002e: ldstr "Test2"
IL_0033: ldc.i4.5
IL_0034: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::Add(string,
int32)
IL_0039: stind.ref
IL_003a: ret
} // end of method OptionalArguments::Constructor
.method private hidebysig instance void .method private hidebysig instance void
CallerMemberName([opt] string memberName) cil managed CallerMemberName([opt] string memberName) cil managed
{ {
@ -315,16 +387,6 @@
IL_0001: throw IL_0001: throw
} // end of method OptionalArguments::Get } // end of method OptionalArguments::Get
.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 OptionalArguments::.ctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments
.class private auto ansi sealed '<PrivateImplementationDetails>' .class private auto ansi sealed '<PrivateImplementationDetails>'
@ -338,16 +400,15 @@
.size 12 .size 12
} // end of class '__StaticArrayInitTypeSize=12' } // end of class '__StaticArrayInitTypeSize=12'
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '0F3DD643C5167ACFC541F72809FFF828A6E41494' at I_00002BE8 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '0F3DD643C5167ACFC541F72809FFF828A6E41494' at I_00002D2C
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' E429CCA3F703A39CC5954A6572FEC9086135B34E at I_00002BF8 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' E429CCA3F703A39CC5954A6572FEC9086135B34E at I_00002D3C
} // end of class '<PrivateImplementationDetails>' } // end of class '<PrivateImplementationDetails>'
// ============================================================= // =============================================================
.data cil I_00002BE8 = bytearray ( .data cil I_00002D2C = bytearray (
0A 00 00 00 09 00 00 00 08 00 00 00) 0A 00 00 00 09 00 00 00 08 00 00 00)
.data cil I_00002BF4 = int8[4] .data cil I_00002D3C = bytearray (
.data cil I_00002BF8 = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00) 01 00 00 00 02 00 00 00 03 00 00 00)
// *********** DISASSEMBLY COMPLETE *********************** // *********** DISASSEMBLY COMPLETE ***********************

103
ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.roslyn.il

@ -34,8 +34,47 @@
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments .class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments
extends [mscorlib]System.Object extends class [mscorlib]System.Collections.Generic.List`1<int32>
{ {
.method public hidebysig specialname rtspecialname
instance void .ctor(string name,
[opt] int32 a) cil managed
{
.param [2] = int32(0x00000005)
// Code size 9 (0x9)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void class [mscorlib]System.Collections.Generic.List`1<int32>::.ctor()
IL_0006: nop
IL_0007: nop
IL_0008: ret
} // end of method OptionalArguments::.ctor
.method public hidebysig specialname rtspecialname
instance void .ctor(int32 num,
[opt] bool flag) cil managed
{
.param [2] = bool(true)
// Code size 9 (0x9)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void class [mscorlib]System.Collections.Generic.List`1<int32>::.ctor()
IL_0006: nop
IL_0007: nop
IL_0008: ret
} // end of method OptionalArguments::.ctor
.method public hidebysig instance void
Add(string name,
[opt] int32 a) cil managed
{
.param [2] = int32(0x00000005)
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method OptionalArguments::Add
.method private hidebysig instance void .method private hidebysig instance void
SimpleTests() cil managed SimpleTests() cil managed
{ {
@ -205,6 +244,47 @@
IL_0026: ret IL_0026: ret
} // end of method OptionalArguments::CallerInfo } // end of method OptionalArguments::CallerInfo
.method private hidebysig instance void
Constructor([out] class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments& a,
[out] class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments& b,
[out] class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments& c) cil managed
{
// Code size 62 (0x3e)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldstr "Hallo"
IL_0007: ldc.i4.5
IL_0008: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::.ctor(string,
int32)
IL_000d: stind.ref
IL_000e: ldarg.2
IL_000f: ldc.i4.s 10
IL_0011: ldc.i4.1
IL_0012: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::.ctor(int32,
bool)
IL_0017: stind.ref
IL_0018: ldarg.3
IL_0019: ldc.i4.s 10
IL_001b: ldc.i4.1
IL_001c: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::.ctor(int32,
bool)
IL_0021: dup
IL_0022: ldstr "Test"
IL_0027: ldc.i4.s 10
IL_0029: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::Add(string,
int32)
IL_002e: nop
IL_002f: dup
IL_0030: ldstr "Test2"
IL_0035: ldc.i4.5
IL_0036: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::Add(string,
int32)
IL_003b: nop
IL_003c: stind.ref
IL_003d: ret
} // end of method OptionalArguments::Constructor
.method private hidebysig instance void .method private hidebysig instance void
CallerMemberName([opt] string memberName) cil managed CallerMemberName([opt] string memberName) cil managed
{ {
@ -353,17 +433,6 @@
IL_0002: throw IL_0002: throw
} // end of method OptionalArguments::Get } // end of method OptionalArguments::Get
.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 OptionalArguments::.ctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments
.class private auto ansi sealed '<PrivateImplementationDetails>' .class private auto ansi sealed '<PrivateImplementationDetails>'
@ -377,16 +446,16 @@
.size 12 .size 12
} // end of class '__StaticArrayInitTypeSize=12' } // end of class '__StaticArrayInitTypeSize=12'
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '0F3DD643C5167ACFC541F72809FFF828A6E41494' at I_00002C10 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '0F3DD643C5167ACFC541F72809FFF828A6E41494' at I_00002D58
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' E429CCA3F703A39CC5954A6572FEC9086135B34E at I_00002C20 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' E429CCA3F703A39CC5954A6572FEC9086135B34E at I_00002D68
} // end of class '<PrivateImplementationDetails>' } // end of class '<PrivateImplementationDetails>'
// ============================================================= // =============================================================
.data cil I_00002C10 = bytearray ( .data cil I_00002D58 = bytearray (
0A 00 00 00 09 00 00 00 08 00 00 00) 0A 00 00 00 09 00 00 00 08 00 00 00)
.data cil I_00002C1C = int8[4] .data cil I_00002D64 = int8[4]
.data cil I_00002C20 = bytearray ( .data cil I_00002D68 = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00) 01 00 00 00 02 00 00 00 03 00 00 00)
// *********** DISASSEMBLY COMPLETE *********************** // *********** DISASSEMBLY COMPLETE ***********************

60
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -201,15 +201,12 @@ namespace ICSharpCode.Decompiler.CSharp
expectedParameters = method.Parameters.ToList(); expectedParameters = method.Parameters.ToList();
} }
var argumentResolveResults = arguments.Select(arg => arg.ResolveResult).ToList();
if (callOpCode == OpCode.NewObj) { if (callOpCode == OpCode.NewObj) {
ResolveResult rr = new CSharpInvocationResolveResult(target.ResolveResult, method, argumentResolveResults,
isExpandedForm: isExpandedForm, argumentToParameterMap: argumentToParameterMap);
if (settings.AnonymousTypes && method.DeclaringType.IsAnonymousType()) { if (settings.AnonymousTypes && method.DeclaringType.IsAnonymousType()) {
Debug.Assert(argumentToParameterMap == null && argumentNames == null); Debug.Assert(argumentToParameterMap == null && argumentNames == null && firstOptionalArgumentIndex < 0);
var argumentExpressions = arguments.SelectArray(arg => arg.Expression); var argumentExpressions = arguments.SelectArray(arg => arg.Expression);
AnonymousTypeCreateExpression atce = new AnonymousTypeCreateExpression(); var atce = new AnonymousTypeCreateExpression();
if (CanInferAnonymousTypePropertyNamesFromArguments(argumentExpressions, expectedParameters)) { if (CanInferAnonymousTypePropertyNamesFromArguments(argumentExpressions, expectedParameters)) {
atce.Initializers.AddRange(argumentExpressions); atce.Initializers.AddRange(argumentExpressions);
} else { } else {
@ -221,30 +218,50 @@ namespace ICSharpCode.Decompiler.CSharp
}); });
} }
} }
return atce return atce.WithRR(new CSharpInvocationResolveResult(
.WithRR(rr); target.ResolveResult, method, arguments.SelectArray(arg => arg.ResolveResult),
isExpandedForm: isExpandedForm, argumentToParameterMap: argumentToParameterMap
));
} else { } else {
if (IsUnambiguousCall(expectedTargetDetails, method, null, Empty<IType>.Array, arguments, argumentNames, firstOptionalArgumentIndex, out _) != OverloadResolutionErrors.None) { while (IsUnambiguousCall(expectedTargetDetails, method, null, Empty<IType>.Array, arguments,
argumentNames, firstOptionalArgumentIndex, out _) != OverloadResolutionErrors.None) {
if (firstOptionalArgumentIndex >= 0) {
firstOptionalArgumentIndex = -1;
continue;
}
CastArguments(arguments, expectedParameters); CastArguments(arguments, expectedParameters);
break; // make sure that we don't not end up in an infinite loop
} }
return new ObjectCreateExpression( return new ObjectCreateExpression(
expressionBuilder.ConvertType(method.DeclaringType), expressionBuilder.ConvertType(method.DeclaringType),
GetArgumentExpressions(arguments, argumentNames) GetArgumentExpressions(arguments, argumentNames, firstOptionalArgumentIndex)
).WithRR(rr); ).WithRR(new CSharpInvocationResolveResult(
target.ResolveResult, method,
firstOptionalArgumentIndex < 0
? arguments.SelectArray(arg => arg.ResolveResult)
: arguments.Take(firstOptionalArgumentIndex).Select(arg => arg.ResolveResult).ToArray(),
isExpandedForm: isExpandedForm, argumentToParameterMap: argumentToParameterMap
));
} }
} else { } else {
int allowedParamCount = (method.ReturnType.IsKnownType(KnownTypeCode.Void) ? 1 : 0); int allowedParamCount = (method.ReturnType.IsKnownType(KnownTypeCode.Void) ? 1 : 0);
if (method.IsAccessor && (method.AccessorOwner.SymbolKind == SymbolKind.Indexer || expectedParameters.Count == allowedParamCount)) { if (method.IsAccessor && (method.AccessorOwner.SymbolKind == SymbolKind.Indexer || expectedParameters.Count == allowedParamCount)) {
Debug.Assert(argumentToParameterMap == null && argumentNames == null); Debug.Assert(argumentToParameterMap == null && argumentNames == null && firstOptionalArgumentIndex < 0);
return HandleAccessorCall(expectedTargetDetails, method, target, arguments.ToList(), argumentNames); return HandleAccessorCall(expectedTargetDetails, method, target, arguments.ToList(), argumentNames);
} else if (method.Name == "Invoke" && method.DeclaringType.Kind == TypeKind.Delegate && !IsNullConditional(target)) { } else if (method.Name == "Invoke" && method.DeclaringType.Kind == TypeKind.Delegate && !IsNullConditional(target)) {
return new InvocationExpression(target, GetArgumentExpressions(arguments, argumentNames)) return new InvocationExpression(target, GetArgumentExpressions(arguments, argumentNames, firstOptionalArgumentIndex))
.WithRR(new CSharpInvocationResolveResult(target.ResolveResult, method, argumentResolveResults, isExpandedForm: isExpandedForm)); .WithRR(new CSharpInvocationResolveResult(target.ResolveResult, method,
firstOptionalArgumentIndex < 0
? arguments.SelectArray(arg => arg.ResolveResult)
: arguments.Take(firstOptionalArgumentIndex).Select(arg => arg.ResolveResult).ToArray(),
isExpandedForm: isExpandedForm));
} else if (IsDelegateEqualityComparison(method, arguments)) { } else if (IsDelegateEqualityComparison(method, arguments)) {
Debug.Assert(argumentToParameterMap == null && argumentNames == null); Debug.Assert(argumentToParameterMap == null && argumentNames == null && firstOptionalArgumentIndex < 0);
return HandleDelegateEqualityComparison(method, arguments) return HandleDelegateEqualityComparison(method, arguments)
.WithRR(new CSharpInvocationResolveResult(target.ResolveResult, method, argumentResolveResults, isExpandedForm: isExpandedForm)); .WithRR(new CSharpInvocationResolveResult(target.ResolveResult, method,
arguments.SelectArray(arg => arg.ResolveResult), isExpandedForm: isExpandedForm));
} else if (method.IsOperator && method.Name == "op_Implicit" && arguments.Count == 1) { } else if (method.IsOperator && method.Name == "op_Implicit" && arguments.Count == 1) {
Debug.Assert(firstOptionalArgumentIndex < 0);
return HandleImplicitConversion(method, arguments[0]); return HandleImplicitConversion(method, arguments[0]);
} else { } else {
var transform = GetRequiredTransformationsForCall(expectedTargetDetails, method, ref target, var transform = GetRequiredTransformationsForCall(expectedTargetDetails, method, ref target,
@ -279,9 +296,9 @@ namespace ICSharpCode.Decompiler.CSharp
if ((transform & CallTransformation.RequireTypeArguments) != 0 && (!settings.AnonymousTypes || !method.TypeArguments.Any(a => a.ContainsAnonymousType()))) if ((transform & CallTransformation.RequireTypeArguments) != 0 && (!settings.AnonymousTypes || !method.TypeArguments.Any(a => a.ContainsAnonymousType())))
typeArgumentList.AddRange(method.TypeArguments.Select(expressionBuilder.ConvertType)); typeArgumentList.AddRange(method.TypeArguments.Select(expressionBuilder.ConvertType));
var argumentExpressions = GetArgumentExpressions(arguments, argumentNames); var argumentExpressions = GetArgumentExpressions(arguments, argumentNames, firstOptionalArgumentIndex);
return new InvocationExpression(targetExpr, firstOptionalArgumentIndex < 0 ? argumentExpressions : argumentExpressions.Take(firstOptionalArgumentIndex).ToArray()) return new InvocationExpression(targetExpr, argumentExpressions)
.WithRR(new CSharpInvocationResolveResult(target.ResolveResult, foundMethod, firstOptionalArgumentIndex < 0 ? argumentResolveResults : argumentResolveResults.Take(firstOptionalArgumentIndex).ToList(), isExpandedForm: isExpandedForm)); .WithRR(new CSharpInvocationResolveResult(target.ResolveResult, foundMethod, firstOptionalArgumentIndex < 0 ? arguments.Select(arg => arg.ResolveResult).ToList() : arguments.Select(arg => arg.ResolveResult).ToList().Take(firstOptionalArgumentIndex).ToList(), isExpandedForm: isExpandedForm));
} }
} }
} }
@ -625,10 +642,13 @@ namespace ICSharpCode.Decompiler.CSharp
} }
} }
private IEnumerable<Expression> GetArgumentExpressions(List<TranslatedExpression> arguments, string[] argumentNames) private IEnumerable<Expression> GetArgumentExpressions(List<TranslatedExpression> arguments,
string[] argumentNames, int firstOptionalArgumentIndex)
{ {
if (argumentNames == null) { if (argumentNames == null) {
return arguments.Select(arg => arg.Expression); if (firstOptionalArgumentIndex < 0)
return arguments.Select(arg => arg.Expression);
return arguments.Take(firstOptionalArgumentIndex).Select(arg => arg.Expression);
} else { } else {
return arguments.Zip(argumentNames, return arguments.Zip(argumentNames,
(arg, name) => { (arg, name) => {

Loading…
Cancel
Save