Browse Source

#907: Add tests

pull/1347/head
Daniel Grunwald 7 years ago
parent
commit
4a3185c823
  1. 21
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs
  2. 71
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.il
  3. 47
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.il
  4. 47
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.roslyn.il
  5. 71
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.roslyn.il
  6. 3
      ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs

21
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Reflection;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
@ -230,6 +231,26 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -230,6 +231,26 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return a == null;
}
public bool CompareType(Type a, Type b)
{
return a == b;
}
public bool CompareTypeByReference(Type a, Type b)
{
return (object)a == b;
}
public bool CompareTypeWithNull(Type t)
{
return t == null;
}
public Attribute CallExtensionMethodViaBaseClass(Type type)
{
return type.GetCustomAttribute<AttributeUsageAttribute>();
}
public decimal ImplicitConversionToDecimal(byte v)
{
return v;

71
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.il

@ -785,6 +785,77 @@ @@ -785,6 +785,77 @@
IL_0009: ret
} // end of method TypeAnalysisTests::CompareStringWithNull
.method public hidebysig instance bool
CompareType(class [mscorlib]System.Type a,
class [mscorlib]System.Type b) cil managed
{
// Code size 13 (0xd)
.maxstack 2
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldarg.2
IL_0003: call bool [mscorlib]System.Type::op_Equality(class [mscorlib]System.Type,
class [mscorlib]System.Type)
IL_0008: stloc.0
IL_0009: br.s IL_000b
IL_000b: ldloc.0
IL_000c: ret
} // end of method TypeAnalysisTests::CompareType
.method public hidebysig instance bool
CompareTypeByReference(class [mscorlib]System.Type a,
class [mscorlib]System.Type b) cil managed
{
// Code size 10 (0xa)
.maxstack 2
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldarg.2
IL_0003: ceq
IL_0005: stloc.0
IL_0006: br.s IL_0008
IL_0008: ldloc.0
IL_0009: ret
} // end of method TypeAnalysisTests::CompareTypeByReference
.method public hidebysig instance bool
CompareTypeWithNull(class [mscorlib]System.Type t) cil managed
{
// Code size 13 (0xd)
.maxstack 2
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldnull
IL_0003: call bool [mscorlib]System.Type::op_Equality(class [mscorlib]System.Type,
class [mscorlib]System.Type)
IL_0008: stloc.0
IL_0009: br.s IL_000b
IL_000b: ldloc.0
IL_000c: ret
} // end of method TypeAnalysisTests::CompareTypeWithNull
.method public hidebysig instance class [mscorlib]System.Attribute
CallExtensionMethodViaBaseClass(class [mscorlib]System.Type 'type') cil managed
{
// Code size 12 (0xc)
.maxstack 1
.locals init (class [mscorlib]System.Attribute V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: call !!0 [mscorlib]System.Reflection.CustomAttributeExtensions::GetCustomAttribute<class [mscorlib]System.AttributeUsageAttribute>(class [mscorlib]System.Reflection.MemberInfo)
IL_0007: stloc.0
IL_0008: br.s IL_000a
IL_000a: ldloc.0
IL_000b: ret
} // end of method TypeAnalysisTests::CallExtensionMethodViaBaseClass
.method public hidebysig instance valuetype [mscorlib]System.Decimal
ImplicitConversionToDecimal(uint8 v) cil managed
{

47
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.il

@ -542,6 +542,53 @@ @@ -542,6 +542,53 @@
IL_0004: ret
} // end of method TypeAnalysisTests::CompareStringWithNull
.method public hidebysig instance bool
CompareType(class [mscorlib]System.Type a,
class [mscorlib]System.Type b) cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ldarg.2
IL_0002: call bool [mscorlib]System.Type::op_Equality(class [mscorlib]System.Type,
class [mscorlib]System.Type)
IL_0007: ret
} // end of method TypeAnalysisTests::CompareType
.method public hidebysig instance bool
CompareTypeByReference(class [mscorlib]System.Type a,
class [mscorlib]System.Type b) cil managed
{
// Code size 5 (0x5)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ldarg.2
IL_0002: ceq
IL_0004: ret
} // end of method TypeAnalysisTests::CompareTypeByReference
.method public hidebysig instance bool
CompareTypeWithNull(class [mscorlib]System.Type t) cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ldnull
IL_0002: call bool [mscorlib]System.Type::op_Equality(class [mscorlib]System.Type,
class [mscorlib]System.Type)
IL_0007: ret
} // end of method TypeAnalysisTests::CompareTypeWithNull
.method public hidebysig instance class [mscorlib]System.Attribute
CallExtensionMethodViaBaseClass(class [mscorlib]System.Type 'type') cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.1
IL_0001: call !!0 [mscorlib]System.Reflection.CustomAttributeExtensions::GetCustomAttribute<class [mscorlib]System.AttributeUsageAttribute>(class [mscorlib]System.Reflection.MemberInfo)
IL_0006: ret
} // end of method TypeAnalysisTests::CallExtensionMethodViaBaseClass
.method public hidebysig instance valuetype [mscorlib]System.Decimal
ImplicitConversionToDecimal(uint8 v) cil managed
{

47
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.roslyn.il

@ -544,6 +544,53 @@ @@ -544,6 +544,53 @@
IL_0004: ret
} // end of method TypeAnalysisTests::CompareStringWithNull
.method public hidebysig instance bool
CompareType(class [mscorlib]System.Type a,
class [mscorlib]System.Type b) cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ldarg.2
IL_0002: call bool [mscorlib]System.Type::op_Equality(class [mscorlib]System.Type,
class [mscorlib]System.Type)
IL_0007: ret
} // end of method TypeAnalysisTests::CompareType
.method public hidebysig instance bool
CompareTypeByReference(class [mscorlib]System.Type a,
class [mscorlib]System.Type b) cil managed
{
// Code size 5 (0x5)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ldarg.2
IL_0002: ceq
IL_0004: ret
} // end of method TypeAnalysisTests::CompareTypeByReference
.method public hidebysig instance bool
CompareTypeWithNull(class [mscorlib]System.Type t) cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ldnull
IL_0002: call bool [mscorlib]System.Type::op_Equality(class [mscorlib]System.Type,
class [mscorlib]System.Type)
IL_0007: ret
} // end of method TypeAnalysisTests::CompareTypeWithNull
.method public hidebysig instance class [mscorlib]System.Attribute
CallExtensionMethodViaBaseClass(class [mscorlib]System.Type 'type') cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.1
IL_0001: call !!0 [mscorlib]System.Reflection.CustomAttributeExtensions::GetCustomAttribute<class [mscorlib]System.AttributeUsageAttribute>(class [mscorlib]System.Reflection.MemberInfo)
IL_0006: ret
} // end of method TypeAnalysisTests::CallExtensionMethodViaBaseClass
.method public hidebysig instance valuetype [mscorlib]System.Decimal
ImplicitConversionToDecimal(uint8 v) cil managed
{

71
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.roslyn.il

@ -784,6 +784,77 @@ @@ -784,6 +784,77 @@
IL_0009: ret
} // end of method TypeAnalysisTests::CompareStringWithNull
.method public hidebysig instance bool
CompareType(class [mscorlib]System.Type a,
class [mscorlib]System.Type b) cil managed
{
// Code size 13 (0xd)
.maxstack 2
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldarg.2
IL_0003: call bool [mscorlib]System.Type::op_Equality(class [mscorlib]System.Type,
class [mscorlib]System.Type)
IL_0008: stloc.0
IL_0009: br.s IL_000b
IL_000b: ldloc.0
IL_000c: ret
} // end of method TypeAnalysisTests::CompareType
.method public hidebysig instance bool
CompareTypeByReference(class [mscorlib]System.Type a,
class [mscorlib]System.Type b) cil managed
{
// Code size 10 (0xa)
.maxstack 2
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldarg.2
IL_0003: ceq
IL_0005: stloc.0
IL_0006: br.s IL_0008
IL_0008: ldloc.0
IL_0009: ret
} // end of method TypeAnalysisTests::CompareTypeByReference
.method public hidebysig instance bool
CompareTypeWithNull(class [mscorlib]System.Type t) cil managed
{
// Code size 13 (0xd)
.maxstack 2
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldnull
IL_0003: call bool [mscorlib]System.Type::op_Equality(class [mscorlib]System.Type,
class [mscorlib]System.Type)
IL_0008: stloc.0
IL_0009: br.s IL_000b
IL_000b: ldloc.0
IL_000c: ret
} // end of method TypeAnalysisTests::CompareTypeWithNull
.method public hidebysig instance class [mscorlib]System.Attribute
CallExtensionMethodViaBaseClass(class [mscorlib]System.Type 'type') cil managed
{
// Code size 12 (0xc)
.maxstack 1
.locals init (class [mscorlib]System.Attribute V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: call !!0 [mscorlib]System.Reflection.CustomAttributeExtensions::GetCustomAttribute<class [mscorlib]System.AttributeUsageAttribute>(class [mscorlib]System.Reflection.MemberInfo)
IL_0007: stloc.0
IL_0008: br.s IL_000a
IL_000a: ldloc.0
IL_000b: ret
} // end of method TypeAnalysisTests::CallExtensionMethodViaBaseClass
.method public hidebysig instance valuetype [mscorlib]System.Decimal
ImplicitConversionToDecimal(uint8 v) cil managed
{

3
ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs

@ -343,6 +343,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -343,6 +343,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (parent is ILiftableInstruction liftable && liftable.IsLifted) {
return true; // inline into lifted operators
}
// decide based on the new parent into which we are inlining:
switch (parent.OpCode) {
case OpCode.NullCoalescingInstruction:
if (NullableType.IsNullable(v.Type))
@ -360,7 +361,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -360,7 +361,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return true; // inline into dynamic compound assignments
break;
}
// decide based on the target into which we are inlining
// decide based on the top-level target instruction into which we are inlining:
switch (next.OpCode) {
case OpCode.Leave:
case OpCode.YieldReturn:

Loading…
Cancel
Save