diff options
author | Ankit Jain <radical@corewars.org> | 2006-06-01 13:33:05 +0400 |
---|---|---|
committer | Ankit Jain <radical@corewars.org> | 2006-06-01 13:33:05 +0400 |
commit | dae78680fdeeee9bfe79165917a29d38f6402bb9 (patch) | |
tree | a939348f6626f547617c1e8e9057422374fb9b7b /mcs/ilasm | |
parent | d19c05dbf4252bf7cd4d3f469a0bfec89ec33925 (diff) |
In ilasm/tests:
* test-cattr-1.il: New. Test for custom attributes on return type of
a method.
In ilasm/codegen:
* MethodDef.cs (MethodDef): Use a ParamDef for return type, instead of a
BaseTypeRef.
(MethodDef.ctor): Update.
(MethodDef.AddParamDefaultValue): Remove.
(MethodDef.GetParam): Likewise.
(MethodDef.Resolve): Update to use ret_param instead of ret_type.
In ilasm/errors:
* err-cattr.il: New.
In ilasm/parser:
* ILParser.jay (method_decl | D_PARAM ..): Param index is zero-based,
with zero representing the return value.
Update to check CurrentCustomAttrTarget for null before using it.
In class/PEAPI:
* PEAPI.cs (PEFile.AddMethod): Add overload for return type as Param
instead of PEAPI.Type .
* Metadata.cs (MetaDataElement.HasCustomAttr): New. Temporary hack.
(Param.HasMarshalInfo): New.
(ClassDef.AddMethod): Add overload for return type as Param.
(MethodDef.ctor): Change internal .ctor's sig to take Param instead of
PEAPI.Type for return type.
(MethodDef.retType): Remove.
(MethodDef.TypeSig): Update to use ret_param always.
(MethodDef.BuildTables): Add ret_param to Param table only if it has
marshal info or custom attributes.
svn path=/trunk/mcs/; revision=61358
Diffstat (limited to 'mcs/ilasm')
-rw-r--r-- | mcs/ilasm/codegen/ChangeLog | 9 | ||||
-rw-r--r-- | mcs/ilasm/codegen/MethodDef.cs | 38 | ||||
-rw-r--r-- | mcs/ilasm/errors/ChangeLog | 4 | ||||
-rw-r--r-- | mcs/ilasm/errors/err-cattr.il | 49 | ||||
-rw-r--r-- | mcs/ilasm/parser/ChangeLog | 6 | ||||
-rw-r--r-- | mcs/ilasm/parser/ILParser.jay | 27 | ||||
-rw-r--r-- | mcs/ilasm/tests/ChangeLog | 5 | ||||
-rw-r--r-- | mcs/ilasm/tests/test-cattr-1.il | 43 |
8 files changed, 155 insertions, 26 deletions
diff --git a/mcs/ilasm/codegen/ChangeLog b/mcs/ilasm/codegen/ChangeLog index 06dbe9a2694..8da4f261aec 100644 --- a/mcs/ilasm/codegen/ChangeLog +++ b/mcs/ilasm/codegen/ChangeLog @@ -1,3 +1,12 @@ +2006-06-01 Ankit Jain <jankit@novell.com> + + * MethodDef.cs (MethodDef): Use a ParamDef for return type, instead of a + BaseTypeRef. + (MethodDef.ctor): Update. + (MethodDef.AddParamDefaultValue): Remove. + (MethodDef.GetParam): Likewise. + (MethodDef.Resolve): Update to use ret_param instead of ret_type. + 2006-05-31 Ankit Jain <jankit@novell.com> * TypeDef.cs (TypeDef.IsValueType): New. diff --git a/mcs/ilasm/codegen/MethodDef.cs b/mcs/ilasm/codegen/MethodDef.cs index 90bbd29e840..f8eef204910 100644 --- a/mcs/ilasm/codegen/MethodDef.cs +++ b/mcs/ilasm/codegen/MethodDef.cs @@ -23,7 +23,7 @@ namespace Mono.ILASM { private string name; private string signature; private Hashtable vararg_sig_table; - private BaseTypeRef ret_type; + private ParamDef ret_param; private ArrayList param_list; private ArrayList inst_list; private ArrayList customattr_list; @@ -45,7 +45,6 @@ namespace Mono.ILASM { private string pinvoke_name; private PEAPI.PInvokeAttr pinvoke_attr; private SourceMethod source; - private PEAPI.NativeType ret_native_type; private TypeDef type_def; private GenericParameters gen_params; @@ -58,10 +57,10 @@ namespace Mono.ILASM { this.call_conv = call_conv; this.impl_attr = impl_attr; this.name = name; - this.ret_type = ret_type; this.param_list = param_list; this.type_def = type_def; this.gen_params = gen_params; + this.ret_param = new ParamDef (PEAPI.ParamAttr.Default, "", ret_type); inst_list = new ArrayList (); label_table = new Hashtable (); @@ -96,7 +95,7 @@ namespace Mono.ILASM { } public BaseTypeRef RetType { - get { return ret_type; } + get { return ret_param.Type; } } public PEAPI.CallConv CallConv { @@ -185,13 +184,6 @@ namespace Mono.ILASM { return gen_params.GetGenericParamNum (id); } - public void AddParamDefaultValue (int index, PEAPI.Constant defval) - { - if (param_list [index] != null) { - ((ParamDef)param_list [index]).AddDefaultValue (defval); - } - } - public void AddCustomAttribute (CustomAttr customattr) { if (customattr_list == null) @@ -202,7 +194,7 @@ namespace Mono.ILASM { public void AddRetTypeMarshalInfo (PEAPI.NativeType native_type) { - this.ret_native_type = native_type; + this.ret_param.AddMarshalInfo (native_type); } public void AddLocals (ArrayList local_list) @@ -249,8 +241,19 @@ namespace Mono.ILASM { return pos; } + /* index - 0: return type + * 1: params start from this + */ public ParamDef GetParam (int index) { + if (index == 0) + return ret_param; + + if ((param_list == null) || (index < 0) || (index > param_list.Count)) + return null; + + index --; /* param_list has params zero-based */ + if (param_list [index] != null) return (ParamDef)param_list [index]; else @@ -305,7 +308,7 @@ namespace Mono.ILASM { if (gen_params != null) gen_params.ResolveConstraints (type_params, gen_params); - BaseGenericTypeRef gtr = ret_type as BaseGenericTypeRef; + BaseGenericTypeRef gtr = RetType as BaseGenericTypeRef; if (gtr != null) gtr.Resolve (type_params, gen_params); @@ -331,20 +334,17 @@ namespace Mono.ILASM { PEAPI.Param [] param_array = GenerateParams (code_gen); FixAttributes (); - ret_type.Resolve (code_gen); + ret_param.Define (code_gen); if (classdef == null) methoddef = code_gen.PEFile.AddMethod (meth_attr, impl_attr, - name, ret_type.PeapiType, param_array); + name, ret_param.PeapiParam, param_array); else methoddef = classdef.AddMethod (meth_attr, impl_attr, - name, ret_type.PeapiType, param_array); + name, ret_param.PeapiParam, param_array); methoddef.AddCallConv (call_conv); - if (ret_native_type != null) - methoddef.AddRetTypeMarshallInfo (ret_native_type); - is_resolved = true; return methoddef; diff --git a/mcs/ilasm/errors/ChangeLog b/mcs/ilasm/errors/ChangeLog index 928561773ed..206d4105507 100644 --- a/mcs/ilasm/errors/ChangeLog +++ b/mcs/ilasm/errors/ChangeLog @@ -1,3 +1,7 @@ +2006-06-01 Ankit Jain <jankit@novell.com> + + * err-cattr.il: New. + 2006-05-09 Ankit Jain <jankit@novell.com> * err-dup-label.il: New. diff --git a/mcs/ilasm/errors/err-cattr.il b/mcs/ilasm/errors/err-cattr.il new file mode 100644 index 00000000000..dd4eb384bec --- /dev/null +++ b/mcs/ilasm/errors/err-cattr.il @@ -0,0 +1,49 @@ +// Test for custom attributes for method params, with
+// invalid indices
+// The generated assembly will have no custom attributes
+// on method params.
+
+.assembly extern mscorlib
+{
+}
+.assembly bb
+{
+ .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
+ .hash algorithm 0x00008004
+ .ver 0:0:0:0
+}
+.module bb.exe
+
+.class private auto ansi beforefieldinit GenParAttribute
+ extends [mscorlib]System.Attribute
+{
+ .method public hidebysig specialname rtspecialname
+ instance void .ctor() cil managed
+ {
+ .maxstack 8
+ IL_0000: ldarg.0
+ IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
+ IL_0006: ret
+ }
+
+}
+
+.class private auto ansi beforefieldinit foo
+ extends [mscorlib]System.Object
+{
+
+ .method public hidebysig static void
+ abc () cil managed
+ {
+ .param [-1]
+ .custom instance void GenParAttribute::.ctor() = ( 01 00 00 00 )
+
+ .param [2]
+ .custom instance void GenParAttribute::.ctor() = ( 01 00 00 00 )
+
+ .entrypoint
+ .maxstack 8
+ IL_0000: nop
+ IL_0001: ret
+ }
+}
diff --git a/mcs/ilasm/parser/ChangeLog b/mcs/ilasm/parser/ChangeLog index 2d09e0f8aff..3e0ba950eac 100644 --- a/mcs/ilasm/parser/ChangeLog +++ b/mcs/ilasm/parser/ChangeLog @@ -1,3 +1,9 @@ +2006-06-01 Ankit Jain <jankit@novell.com> + + * ILParser.jay (method_decl | D_PARAM ..): Param index is zero-based, + with zero representing the return value. + Update to check CurrentCustomAttrTarget for null before using it. + 2006-05-26 Ankit Jain <jankit@novell.com> * ILParser.jay: Update to use new Assembly class. diff --git a/mcs/ilasm/parser/ILParser.jay b/mcs/ilasm/parser/ILParser.jay index 29431572f7e..a8dc2c42268 100644 --- a/mcs/ilasm/parser/ILParser.jay +++ b/mcs/ilasm/parser/ILParser.jay @@ -874,7 +874,8 @@ class_decl : method_all | extsource_spec
| customattr_decl
{
- codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
+ if (codegen.CurrentCustomAttrTarget != null)
+ codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
}
| param_type_decl
| D_SIZE int32
@@ -2136,8 +2137,16 @@ method_decl : D_EMITBYTE int32 | scope_block
| D_PARAM OPEN_BRACKET int32 CLOSE_BRACKET init_opt
{
- codegen.CurrentMethodDef.AddParamDefaultValue ((int)$3 - 1, (Constant)$5);
- codegen.CurrentCustomAttrTarget = codegen.CurrentMethodDef.GetParam ((int)$3 - 1);
+ int index = (int) $3;
+ ParamDef param = codegen.CurrentMethodDef.GetParam (index);
+ codegen.CurrentCustomAttrTarget = param;
+
+ if (param == null) {
+ Console.Error.WriteLine ("{0} Warning -- invalid param index ({1}) with .param", tokenizer.Location, index);
+ break;
+ }
+ if ($5 != null)
+ param.AddDefaultValue ((Constant) $5);
}
| param_type_decl
| id COLON
@@ -2154,7 +2163,8 @@ method_decl : D_EMITBYTE int32 | language_decl
| customattr_decl
{
- codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
+ if (codegen.CurrentCustomAttrTarget != null)
+ codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
}
| data_decl
;
@@ -2669,7 +2679,8 @@ event_decl : D_ADDON method_ref }
| customattr_decl
{
- codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
+ if (codegen.CurrentCustomAttrTarget != null)
+ codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
}
| extsource_spec
| language_decl
@@ -2730,7 +2741,8 @@ prop_decl : D_SET method_ref }
| customattr_decl
{
- codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
+ if (codegen.CurrentCustomAttrTarget != null)
+ codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
}
| extsource_spec
| language_decl
@@ -3141,7 +3153,8 @@ assemblyref_decl : D_VER int32 COLON int32 COLON int32 COLON int32 }
| customattr_decl
{
- codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
+ if (codegen.CurrentCustomAttrTarget != null)
+ codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
}
;
diff --git a/mcs/ilasm/tests/ChangeLog b/mcs/ilasm/tests/ChangeLog index 92a9ed0d7c6..87013a02040 100644 --- a/mcs/ilasm/tests/ChangeLog +++ b/mcs/ilasm/tests/ChangeLog @@ -1,3 +1,8 @@ +2006-06-01 Ankit Jain <jankit@novell.com> + + * test-cattr-1.il: New. Test for custom attributes on return type of + a method. + 2006-05-26 Ankit Jain <jankit@novell.com> * test-perm_pass-3.il: New. Test for 2.0 style declarative security diff --git a/mcs/ilasm/tests/test-cattr-1.il b/mcs/ilasm/tests/test-cattr-1.il new file mode 100644 index 00000000000..b98eb3f843d --- /dev/null +++ b/mcs/ilasm/tests/test-cattr-1.il @@ -0,0 +1,43 @@ +//Test for custom attributes on return type of a method
+
+.assembly extern mscorlib
+{
+}
+.assembly bb
+{
+ .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
+ .hash algorithm 0x00008004
+ .ver 0:0:0:0
+}
+.module bb.exe
+
+.class private auto ansi beforefieldinit GenParAttribute
+ extends [mscorlib]System.Attribute
+{
+ .method public hidebysig specialname rtspecialname
+ instance void .ctor() cil managed
+ {
+ .maxstack 8
+ IL_0000: ldarg.0
+ IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
+ IL_0006: ret
+ }
+
+}
+
+.class private auto ansi beforefieldinit foo
+ extends [mscorlib]System.Object
+{
+
+ .method public hidebysig static void
+ abc () cil managed
+ {
+ .param [0]
+ .custom instance void GenParAttribute::.ctor() = ( 01 00 00 00 )
+
+ .entrypoint
+ .maxstack 8
+ IL_0000: nop
+ IL_0001: ret
+ }
+}
|