diff options
Diffstat (limited to 'Test')
-rw-r--r-- | Test/Mono.Cecil.Tests.csproj | 1 | ||||
-rw-r--r-- | Test/Mono.Cecil.Tests/TypeTests.cs | 15 | ||||
-rw-r--r-- | Test/Resources/il/explicitthis.il | 113 |
3 files changed, 129 insertions, 0 deletions
diff --git a/Test/Mono.Cecil.Tests.csproj b/Test/Mono.Cecil.Tests.csproj index 31f2978..2ff2951 100644 --- a/Test/Mono.Cecil.Tests.csproj +++ b/Test/Mono.Cecil.Tests.csproj @@ -116,6 +116,7 @@ <Compile Include="Mono.Cecil.Tests\ImageReadTests.cs" /> <Compile Include="Mono.Cecil.Tests\ModuleTests.cs" /> <Compile Include="Mono.Cecil.Tests\NestedTypesTests.cs" /> + <None Include="Resources\il\explicitthis.il" /> <None Include="Resources\cs\CustomAttributes.cs" /> <None Include="Resources\cs\Generics.cs" /> <None Include="Resources\cs\Interfaces.cs" /> diff --git a/Test/Mono.Cecil.Tests/TypeTests.cs b/Test/Mono.Cecil.Tests/TypeTests.cs index 878885b..3ceb0aa 100644 --- a/Test/Mono.Cecil.Tests/TypeTests.cs +++ b/Test/Mono.Cecil.Tests/TypeTests.cs @@ -209,5 +209,20 @@ namespace Mono.Cecil.Tests { Assert.IsTrue (int32_def.IsPrimitive); Assert.AreEqual (MetadataType.Int32, int32_def.MetadataType); } + + [TestIL ("explicitthis.il", Verify = false)] + public void ExplicitThis (ModuleDefinition module) + { + var type = module.GetType ("MakeDecision"); + var method = type.GetMethod ("Decide"); + var fptr = method.ReturnType as FunctionPointerType; + + Assert.IsNotNull (fptr); + Assert.IsTrue (fptr.HasThis); + Assert.IsTrue (fptr.ExplicitThis); + + Assert.AreEqual (0, fptr.Parameters [0].Sequence); + Assert.AreEqual (1, fptr.Parameters [1].Sequence); + } } } diff --git a/Test/Resources/il/explicitthis.il b/Test/Resources/il/explicitthis.il new file mode 100644 index 0000000..3671a40 --- /dev/null +++ b/Test/Resources/il/explicitthis.il @@ -0,0 +1,113 @@ +.assembly extern mscorlib +{ + .ver 0:0:0:0 +} + +.assembly fptr +{ + .ver 0:0:0:0 +} +.module fptr.exe + +.method public static void Main() cil managed +{ + .entrypoint + .locals init (class MakeDecision d, method instance explicit int32 *(class MakeDecision, int32) m, int32 i) + + ldc.i4.1 + ldc.i4 42 + newobj instance void MakeDecision::.ctor(bool, int32) + stloc d + + ldc.i4.0 + stloc i + br test + +loop: + ldloc d + call instance method instance explicit int32 *(class MakeDecision, int32) MakeDecision::Decide() + stloc m + + ldloc d + ldc.i4.1 + ldloc m + calli instance int32(int32) + call void [mscorlib]System.Console::WriteLine(int32) + + ldloc i + ldc.i4.1 + add + stloc i + +test: + ldloc i + ldc.i4 10 + blt loop + + ret +} + +.class public auto ansi sealed MakeDecision + extends [mscorlib]System.Object +{ + .field private bool Oscillate + .field private int32 Value + + .method public instance method instance explicit int32 *(class MakeDecision, int32) + Decide() cil managed + { + .locals init (bool t) + ldarg.0 + ldfld bool MakeDecision::Oscillate + stloc t + + ldarg.0 + ldloc t + ldc.i4.0 + ceq + stfld bool MakeDecision::Oscillate + + ldloc t + brfalse subs + + ldftn instance int32 MakeDecision::Add(int32) + ret + +subs: + ldftn instance int32 MakeDecision::Sub(int32) + ret + } + + .method public int32 Add(int32 i) cil managed + { + ldarg.0 + ldfld int32 MakeDecision::Value + ldarg i + add + ret + } + + .method public int32 Sub(int32 i) cil managed + { + ldarg.0 + ldfld int32 MakeDecision::Value + ldarg i + sub + ret + } + + .method public hidebysig specialname rtspecialname instance void .ctor(bool s, int32 val) cil managed + { + ldarg.0 + ldarg s + stfld bool MakeDecision::Oscillate + + ldarg.0 + ldarg val + stfld int32 MakeDecision::Value + + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} |