diff options
author | Ankit Jain <radical@corewars.org> | 2006-06-07 17:22:15 +0400 |
---|---|---|
committer | Ankit Jain <radical@corewars.org> | 2006-06-07 17:22:15 +0400 |
commit | 93181fdf4257c94d77143dabfd2c495843f25620 (patch) | |
tree | 78a9e5ed51dd2fc644600ca8e5e64f378e52cb70 /mcs/ilasm | |
parent | 1bac8ca50e87644776201670dce05b9fdb371dc8 (diff) |
In ilasm/tests:
* test-no-body.il: New. Test for method with no body.
* test-perm-pass-3.il: Make the class abstract.
In ilasm/codegen:
* TypeDef.cs (TypeDef.IsAbstract): New.
* MethodDef.cs (MethodDef.WriteCode): Parent type must also be abstract
for an abstract method. Abstract methods cannot have a body.
Report errors for body with different implementation attributes like
native/runtime/unmanaged etc.
If the method has no body, then emit a 'ret'.
In ilasm/errors:
* err-native.il:
* err-pinvoke-a.il:
* err-abstract.il:
* err-runtime.il:
* err-internalcall.il: New.
svn path=/trunk/mcs/; revision=61524
Diffstat (limited to 'mcs/ilasm')
-rw-r--r-- | mcs/ilasm/codegen/ChangeLog | 9 | ||||
-rw-r--r-- | mcs/ilasm/codegen/MethodDef.cs | 40 | ||||
-rw-r--r-- | mcs/ilasm/codegen/TypeDef.cs | 4 | ||||
-rw-r--r-- | mcs/ilasm/errors/ChangeLog | 8 | ||||
-rw-r--r-- | mcs/ilasm/errors/err-abstract.il | 16 | ||||
-rw-r--r-- | mcs/ilasm/errors/err-internalcall.il | 19 | ||||
-rw-r--r-- | mcs/ilasm/errors/err-native.il | 18 | ||||
-rw-r--r-- | mcs/ilasm/errors/err-pinvoke-a.il | 23 | ||||
-rw-r--r-- | mcs/ilasm/errors/err-runtime.il | 19 | ||||
-rw-r--r-- | mcs/ilasm/tests/ChangeLog | 5 | ||||
-rw-r--r-- | mcs/ilasm/tests/test-no-body.il | 18 | ||||
-rw-r--r-- | mcs/ilasm/tests/test-perm_pass-3.il | 2 |
12 files changed, 177 insertions, 4 deletions
diff --git a/mcs/ilasm/codegen/ChangeLog b/mcs/ilasm/codegen/ChangeLog index 4fa5fc7bca9..d5a01f2a2dc 100644 --- a/mcs/ilasm/codegen/ChangeLog +++ b/mcs/ilasm/codegen/ChangeLog @@ -1,5 +1,14 @@ 2006-06-07 Ankit Jain <jankit@novell.com> + * TypeDef.cs (TypeDef.IsAbstract): New. + * MethodDef.cs (MethodDef.WriteCode): Parent type must also be abstract + for an abstract method. Abstract methods cannot have a body. + Report errors for body with different implementation attributes like + native/runtime/unmanaged etc. + If the method has no body, then emit a 'ret'. + +2006-06-07 Ankit Jain <jankit@novell.com> + * TypeDef.cs (TypeDef.AddFieldDef): (TypeDef.Define): Use Report.Warning instead of Console.Error.WriteLine (TypeDef.AddMethodDef): Likewise. Also, use methoddef.Location . diff --git a/mcs/ilasm/codegen/MethodDef.cs b/mcs/ilasm/codegen/MethodDef.cs index fc4714beb1c..da3a313f573 100644 --- a/mcs/ilasm/codegen/MethodDef.cs +++ b/mcs/ilasm/codegen/MethodDef.cs @@ -457,8 +457,14 @@ namespace Mono.ILASM { if (gen_params != null) gen_params.Resolve (code_gen, methoddef); - if (IsAbstract) + if (IsAbstract) { + if (!type_def.IsAbstract) + Report.Error (start, String.Format ("Abstract method '{0}' in non-abstract class '{1}'", + Name, type_def.FullName)); + if (inst_list.Count > 0) + Report.Error (start, "Method cannot have body if it is abstract."); return; + } if (entry_point) methoddef.DeclareEntryPoint (); @@ -491,8 +497,36 @@ namespace Mono.ILASM { (pinvoke_name != null ? pinvoke_name : name), pinvoke_attr); } - if (inst_list.Count < 1) - return; + if ((impl_attr & PEAPI.ImplAttr.Runtime) == PEAPI.ImplAttr.Runtime) { + if (inst_list.Count > 0) + Report.Error (start, String.Format ("Method cannot have body if it is non-IL runtime-supplied, '{0}.{1}'", + type_def.FullName, Name)); + } else { + if (((impl_attr & PEAPI.ImplAttr.Native) != 0) || + ((impl_attr & PEAPI.ImplAttr.Unmanaged) != 0)) + Report.Error (start, String.Format ("Cannot compile native/unmanaged method, '{0}.{1}'", + type_def.FullName, Name)); + } + + if (inst_list.Count > 0) { + /* Has body */ + if ((impl_attr & PEAPI.ImplAttr.InternalCall) != 0) + Report.Error (start, String.Format ("Method cannot have body if it is an internal call, '{0}.{1}'", + type_def.FullName, Name)); + + if (pinvoke_info) + Report.Error (start, String.Format ("Method cannot have body if it is pinvoke, '{0}.{1}'", + type_def.FullName, Name)); + } else { + if (pinvoke_info || + ((impl_attr & PEAPI.ImplAttr.Runtime) != 0) || + ((impl_attr & PEAPI.ImplAttr.InternalCall) != 0)) + /* No body required */ + return; + + Report.Warning (start, "Method has no body, 'ret' emitted."); + AddInstr (new SimpInstr (PEAPI.Op.ret, start)); + } PEAPI.CILInstructions cil = methoddef.CreateCodeBuffer (); /// Create all the labels diff --git a/mcs/ilasm/codegen/TypeDef.cs b/mcs/ilasm/codegen/TypeDef.cs index ea8a414262d..2aab8489de4 100644 --- a/mcs/ilasm/codegen/TypeDef.cs +++ b/mcs/ilasm/codegen/TypeDef.cs @@ -131,6 +131,10 @@ namespace Mono.ILASM { get { return (attr & PEAPI.TypeAttr.Interface) != 0; } } + public bool IsAbstract { + get { return (attr & PEAPI.TypeAttr.Abstract) != 0; } + } + public GenericParameters TypeParameters { get { return gen_params; } } diff --git a/mcs/ilasm/errors/ChangeLog b/mcs/ilasm/errors/ChangeLog index 25179a6f5d7..5bac743f75b 100644 --- a/mcs/ilasm/errors/ChangeLog +++ b/mcs/ilasm/errors/ChangeLog @@ -1,3 +1,11 @@ +2006-06-07 Ankit Jain <jankit@novell.com> + + * err-native.il: + * err-pinvoke-a.il: + * err-abstract.il: + * err-runtime.il: + * err-internalcall.il: New. + 2006-06-01 Ankit Jain <jankit@novell.com> * err-ldarg.il: New. diff --git a/mcs/ilasm/errors/err-abstract.il b/mcs/ilasm/errors/err-abstract.il new file mode 100644 index 00000000000..45f984c299c --- /dev/null +++ b/mcs/ilasm/errors/err-abstract.il @@ -0,0 +1,16 @@ +//Test for abstract method with body + +.namespace MonoTest +{ +.class private auto autochar beforefieldinit Abc extends +[mscorlib]System.Object +{ + .method assembly hidebysig abstract static void + Test() cil managed + { + // Code size 74 (0x4a) + .maxstack 2 + ret + } +} +} diff --git a/mcs/ilasm/errors/err-internalcall.il b/mcs/ilasm/errors/err-internalcall.il new file mode 100644 index 00000000000..c0ec127d5d5 --- /dev/null +++ b/mcs/ilasm/errors/err-internalcall.il @@ -0,0 +1,19 @@ +//Test for internalcall method with a body + +.assembly Test +{ +} + +.namespace MonoTest +{ + .class private auto autochar beforefieldinit ConsoleApp + extends [mscorlib]System.Object + { + .method assembly hidebysig static void Test() internalcall + { + // Code size 74 (0x4a) + .maxstack 2 + ret + } + } +} diff --git a/mcs/ilasm/errors/err-native.il b/mcs/ilasm/errors/err-native.il new file mode 100644 index 00000000000..e3b23d42f15 --- /dev/null +++ b/mcs/ilasm/errors/err-native.il @@ -0,0 +1,18 @@ +//Test for unmanaged method. Should not compile + +.assembly Test +{ +} + +.namespace MonoTest +{ + .class private auto autochar beforefieldinit ConsoleApp + extends [mscorlib]System.Object + { + .method assembly hidebysig static void Test() unmanaged + { + // Code size 74 (0x4a) + .maxstack 2 + } + } +} diff --git a/mcs/ilasm/errors/err-pinvoke-a.il b/mcs/ilasm/errors/err-pinvoke-a.il new file mode 100644 index 00000000000..2a6b13a418b --- /dev/null +++ b/mcs/ilasm/errors/err-pinvoke-a.il @@ -0,0 +1,23 @@ +// Test for a pinvoke method with a body. + +.assembly extern mscorlib { } +.assembly 'err-pinvoke-a' { } + + +.class public T { + + .method public static pinvokeimpl ("test-pinvoke" as "ret_one" cdecl) + int32 RetOne () cil managed + { + ret + } + + .method public static int32 test () + { + .entrypoint + + ret + } + +} + diff --git a/mcs/ilasm/errors/err-runtime.il b/mcs/ilasm/errors/err-runtime.il new file mode 100644 index 00000000000..9c492c992e1 --- /dev/null +++ b/mcs/ilasm/errors/err-runtime.il @@ -0,0 +1,19 @@ +//Test for runtime method with a body + +.assembly Test +{ +} + +.namespace MonoTest +{ + .class private auto autochar beforefieldinit ConsoleApp + extends [mscorlib]System.Object + { + .method assembly hidebysig static void Test() runtime + { + // Code size 74 (0x4a) + .maxstack 2 + ret + } + } +} diff --git a/mcs/ilasm/tests/ChangeLog b/mcs/ilasm/tests/ChangeLog index 87013a02040..435571e7244 100644 --- a/mcs/ilasm/tests/ChangeLog +++ b/mcs/ilasm/tests/ChangeLog @@ -1,3 +1,8 @@ +2006-06-07 Ankit Jain <jankit@novell.com> + + * test-no-body.il: New. Test for method with no body. + * test-perm-pass-3.il: Make the class abstract. + 2006-06-01 Ankit Jain <jankit@novell.com> * test-cattr-1.il: New. Test for custom attributes on return type of diff --git a/mcs/ilasm/tests/test-no-body.il b/mcs/ilasm/tests/test-no-body.il new file mode 100644 index 00000000000..4a37fe3410d --- /dev/null +++ b/mcs/ilasm/tests/test-no-body.il @@ -0,0 +1,18 @@ +//Test for method with no body. ilasm emits 'ret' + +.assembly Test +{ +} + +.namespace MonoTest +{ + .class private auto autochar beforefieldinit ConsoleApp + extends [mscorlib]System.Object + { + .method assembly hidebysig static void Test() cil managed + { + // Code size 74 (0x4a) + .maxstack 2 + } + } +} diff --git a/mcs/ilasm/tests/test-perm_pass-3.il b/mcs/ilasm/tests/test-perm_pass-3.il index 77e3ffe3450..60e079d6efe 100644 --- a/mcs/ilasm/tests/test-perm_pass-3.il +++ b/mcs/ilasm/tests/test-perm_pass-3.il @@ -28,7 +28,7 @@ .subsystem 0x0003
.corflags 0x00000001
-.class public foo
+.class public abstract foo
{
.permissionset assert = {
[mscorlib]System.Security.Permissions.ReflectionPermissionAttribute = {
|