* CustomAttr.cs: New file - Custom attributes
authorJackson Harper <jackson@novell.com>
Sat, 31 May 2003 17:53:45 +0000 (17:53 -0000)
committerJackson Harper <jackson@novell.com>
Sat, 31 May 2003 17:53:45 +0000 (17:53 -0000)
* InstrTable.cs: Add stelem.r4 and stelem.r8 instructions. Add
. tail to unaligned modifier.
* LdtokenInstr.cs: Add type tokens.
* MethodDef.cs: Fix IsVararg, add method to add custom attributes,
emitting custom attributes when writing code, allow for Ellipsises
in param lists, add coma between args in signatures.
* ParamDef.cs: Add the Ellipsis pseudo param
* PrimitiveTypeRef.cs: System.String and System.Object can be
referenced without an [mscorlib] assembly prefix.
* TypeDef.cs: Add Custom attributes.

svn path=/trunk/mcs/; revision=15025

mcs/ilasm/codegen/ChangeLog
mcs/ilasm/codegen/CustomAttr.cs [new file with mode: 0644]
mcs/ilasm/codegen/InstrTable.cs
mcs/ilasm/codegen/LdtokenInstr.cs
mcs/ilasm/codegen/MethodDef.cs
mcs/ilasm/codegen/ParamDef.cs
mcs/ilasm/codegen/PrimitiveTypeRef.cs
mcs/ilasm/codegen/TypeDef.cs

index 27fbf8fff89765ece01ffb9f91be8ec78a630951..33e2ca7e33e463b50a825b6171fbcd79fdc2511e 100644 (file)
@@ -1,3 +1,17 @@
+2003-05-31 Jackson Harper <jackson@latitudegeo.com>
+
+       * CustomAttr.cs: New file - Custom attributes
+       * InstrTable.cs: Add stelem.r4 and stelem.r8 instructions. Add
+       . tail to unaligned modifier.
+       * LdtokenInstr.cs: Add type tokens.
+       * MethodDef.cs: Fix IsVararg, add method to add custom attributes,
+       emitting custom attributes when writing code, allow for Ellipsises
+       in param lists, add coma between args in signatures.
+       * ParamDef.cs: Add the Ellipsis pseudo param
+       * PrimitiveTypeRef.cs: System.String and System.Object can be
+       referenced without an [mscorlib] assembly prefix. 
+       * TypeDef.cs: Add Custom attributes.
+               
 2003-05-25 Jackson Harper <jackson@latitudegeo.com>
 
        * CodeGen.cs: Add method to resolve global vararg methods.
diff --git a/mcs/ilasm/codegen/CustomAttr.cs b/mcs/ilasm/codegen/CustomAttr.cs
new file mode 100644 (file)
index 0000000..0bfe7dc
--- /dev/null
@@ -0,0 +1,37 @@
+//
+// Mono.ILASM.CustomAttr
+//
+// Author(s):
+//  Jackson Harper (Jackson@LatitudeGeo.com)
+//
+// (C) 2003 Jackson Harper, All rights reserved
+//
+
+
+using System;
+
+
+namespace Mono.ILASM {
+
+        public class CustomAttr {
+
+                private IMethodRef method_ref;
+                private byte[] data;
+
+                public CustomAttr (IMethodRef method_ref, byte[] data)
+                {
+                        this.method_ref = method_ref;
+                        this.data = data;
+                }
+
+                public void AddTo (CodeGen code_gen, PEAPI.MetaDataElement elem)
+                {
+                        method_ref.Resolve (code_gen);
+
+                        elem.AddCustomAttribute (method_ref.PeapiMethod, data);
+                }
+
+        }
+
+}
+
index ca144c1e83e3cf7be18b8cef2038be1511385bd5..76d3d0dc3d6fdf14cb179bc197875d7a3dbb1abe 100644 (file)
@@ -134,6 +134,8 @@ namespace Mono.ILASM {
                         inst_table["stelem.i2"] = new ILToken (Token.INSTR_NONE, Op.stelem_i2);
                         inst_table["stelem.i4"] = new ILToken (Token.INSTR_NONE, Op.stelem_i4);
                         inst_table["stelem.i8"] = new ILToken (Token.INSTR_NONE, Op.stelem_i8);
+                        inst_table["stelem.r4"] = new ILToken (Token.INSTR_NONE, Op.stelem_r4);
+                        inst_table["stelem.r8"] = new ILToken (Token.INSTR_NONE, Op.stelem_r8);
                         inst_table["stelem.ref"] = new ILToken (Token.INSTR_NONE, Op.stelem_ref);
                         inst_table["conv.ovf.i1"] = new ILToken (Token.INSTR_NONE, Op.conv_ovf_i1);
                         inst_table["conv.ovf.u1"] = new ILToken (Token.INSTR_NONE, Op.conv_ovf_u1);
@@ -203,7 +205,7 @@ namespace Mono.ILASM {
 
                         inst_table["ldc.i4.s"] = new ILToken (Token.INSTR_I, IntOp.ldc_i4_s);
                         inst_table["ldc.i4"] = new ILToken (Token.INSTR_I, IntOp.ldc_i4);
-                        inst_table["unaligned"] =  new ILToken (Token.INSTR_I, IntOp.unaligned);
+                        inst_table["unaligned."] =  new ILToken (Token.INSTR_I, IntOp.unaligned);
 
                         //
                         // Type operations
index ceea30cd27e898be030991b04ec1b4193b8c832e..284bad2f348ddf372f9c5ebbe6a842c9664d3e23 100644 (file)
@@ -16,6 +16,7 @@ namespace Mono.ILASM {
 
                 private IFieldRef field_ref;
                 private IMethodRef method_ref;
+                private ITypeRef type_ref;
 
                 public LdtokenInstr (IFieldRef field_ref)
                 {
@@ -27,6 +28,11 @@ namespace Mono.ILASM {
                         this.method_ref = method_ref;
                 }
 
+                public LdtokenInstr (ITypeRef type_ref)
+                {
+                        this.type_ref = type_ref;
+                }
+
                 public void Emit (CodeGen code_gen, PEAPI.CILInstructions cil)
                 {
                         if (field_ref != null) {
@@ -37,6 +43,10 @@ namespace Mono.ILASM {
                                 method_ref.Resolve (code_gen);
                                 cil.MethInst (PEAPI.MethodOp.ldtoken,
                                                 method_ref.PeapiMethod);
+                        } else if (type_ref != null) {
+                                type_ref.Resolve (code_gen);
+                                cil.TypeInst (PEAPI.TypeOp.ldtoken,
+                                                type_ref.PeapiType);
                         }
                 }
 
index a49afce1b73f4874d404265c0bf980bfcf58dd78..cb5c475f3c151b66010c1da28b8abbc4478a94fa 100644 (file)
@@ -55,6 +55,7 @@ namespace Mono.ILASM {
                 private ArrayList param_list;
                 private Hashtable named_param_table;
                 private ArrayList inst_list;
+                private ArrayList customattr_list;
                 private Hashtable label_table;
                 private PEAPI.MethodDef methoddef;
                 private bool entry_point;
@@ -77,6 +78,7 @@ namespace Mono.ILASM {
                         this.param_list = param_list;
 
                         inst_list = new ArrayList ();
+                        customattr_list = new ArrayList ();
                         label_table = new Hashtable ();
                         local_list = new ArrayList ();
                         named_local_table = new Hashtable ();
@@ -104,7 +106,7 @@ namespace Mono.ILASM {
                 }
 
                 public bool IsVararg {
-                        get { return (call_conv & PEAPI.CallConv.Vararg) == 0; }
+                        get { return (call_conv & PEAPI.CallConv.Vararg) != 0; }
                 }
 
                 public void AddLocals (ArrayList local_list)
@@ -158,6 +160,11 @@ namespace Mono.ILASM {
                         this.max_stack = max_stack;
                 }
 
+                public void AddCustomAttr (CustomAttr customattr)
+                {
+                        customattr_list.Add (customattr);
+                }
+
                 public PEAPI.MethodDef Resolve (CodeGen code_gen)
                 {
                         if (is_resolved)
@@ -166,11 +173,16 @@ namespace Mono.ILASM {
                         PEAPI.Param[] param_array;
 
                         if (param_list != null) {
-                                param_array = new PEAPI.Param[param_list.Count];
+                                int param_count = param_list.Count;
+                                //if (IsVararg)
+                                //       param_count--;
+                                param_array = new PEAPI.Param[param_count];
                                 int count = 0;
                                 ret_type.Resolve (code_gen);
 
                                 foreach (ParamDef paramdef in param_list) {
+                                        if (paramdef == ParamDef.Ellipsis)
+                                                break;
                                         paramdef.Define (code_gen);
                                         param_array[count++] = paramdef.PeapiParam;
                                 }
@@ -197,11 +209,16 @@ namespace Mono.ILASM {
                         PEAPI.Param[] param_array;
 
                         if (param_list != null) {
-                                param_array = new PEAPI.Param[param_list.Count];
+                                int param_count = param_list.Count;
+                                if (IsVararg)
+                                        param_count--;
+                                param_array = new PEAPI.Param[param_count];
                                 int count = 0;
                                 ret_type.Resolve (code_gen);
 
                                 foreach (ParamDef paramdef in param_list) {
+                                        if (paramdef == ParamDef.Ellipsis)
+                                                break;
                                         paramdef.Define (code_gen);
                                         param_array[count++] = paramdef.PeapiParam;
                                 }
@@ -285,6 +302,10 @@ namespace Mono.ILASM {
                                 max_stack = 8;
                         methoddef.SetMaxStack (max_stack);
 
+                        /// Add the custrom attributes to this method
+                        foreach (CustomAttr customattr in customattr_list)
+                                customattr.AddTo (code_gen, methoddef);
+
                         if (inst_list.Count < 1)
                                 return;
 
@@ -355,9 +376,12 @@ namespace Mono.ILASM {
                         if (param_list != null) {
                                 bool first = true;
                                 foreach (ParamDef paramdef in param_list) {
+                                        if (ParamDef.Ellipsis == paramdef)
+                                                break;
                                         if (!first)
                                                 builder.Append (',');
                                         builder.Append (paramdef.TypeName);
+                                        first = false;
                                 }
                         }
                         builder.Append (')');
@@ -380,11 +404,11 @@ namespace Mono.ILASM {
                                         if (!first)
                                                 builder.Append (',');
                                         builder.Append (param.FullName);
+                                        first = false;
                                 }
                         }
                         builder.Append (')');
 
-
                         return builder.ToString ();
                 }
 
index 3f534091f71877884a75704137e08a21862be0c4..36a7e3a6b3ccc24ebf9016a055fafdb90f8fc16a 100644 (file)
@@ -24,6 +24,8 @@ namespace Mono.ILASM {
                 private bool is_defined;
                 private PEAPI.Param peapi_param;
 
+                public static readonly ParamDef Ellipsis = new ParamDef (new PEAPI.ParamAttr (), "ELLIPSIS", null);
+
                 public ParamDef (PEAPI.ParamAttr attr, string name,
                                 ITypeRef typeref) {
                         this.attr = attr;
index 480ba38c9961984aaa420138ed186cdb9722941a..c21ab5d44f647e76525f11602ca1f8dc17d3e755 100644 (file)
@@ -23,6 +23,24 @@ namespace Mono.ILASM {
 
                 }
 
+                /// <summary>
+                /// Primitive types can be created like this System.String instead
+                /// of like a normal type that would be [mscorlib]System.String This
+                /// method returns a proper primitive type if the supplied name is
+                /// the name of a primitive type.
+                /// </summary>
+                public static PrimitiveTypeRef GetPrimitiveType (string full_name)
+                {
+                        switch (full_name) {
+                        case "System.String":
+                                return new PrimitiveTypeRef (PEAPI.PrimitiveType.String, full_name);
+                        case "System.Object":
+                                return new PrimitiveTypeRef (PEAPI.PrimitiveType.Object, full_name);
+                        default:
+                                return null;
+                        }
+                }
+
                 public IClassRef AsClassRef (CodeGen code_gen)
                 {
                         PEAPI.ClassRef class_ref = code_gen.ExternTable.GetValueClass ("corlib", FullName);
index bc55138502f63f5bb5b29e3a3d5c7e4b3ff7757e..dbcb3850a413e9e8264442f398a4f073f45fa8db 100644 (file)
@@ -26,6 +26,7 @@ namespace Mono.ILASM {
                 private Hashtable field_table;
                 private Hashtable method_table;
                 private ArrayList data_list;
+                private ArrayList customattr_list;
                 private TypeDef outer;
 
                 private int size;
@@ -100,6 +101,14 @@ namespace Mono.ILASM {
                         method_table.Add (methoddef.Signature, methoddef);
                 }
 
+                public void AddCustomAttribute (CustomAttr customattr)
+                {
+                        if (customattr_list == null)
+                                customattr_list = new ArrayList ();
+
+                        customattr_list.Add (customattr);
+                }
+
                 public void Define (CodeGen code_gen)
                 {
                         if (is_defined)
@@ -157,6 +166,11 @@ namespace Mono.ILASM {
                         foreach (MethodDef methoddef in method_table.Values) {
                                 methoddef.Define (code_gen, classdef);
                         }
+
+                        if (customattr_list != null) {
+                                foreach (CustomAttr customattr in customattr_list)
+                                        customattr.AddTo (code_gen, classdef);
+                        }
                 }
 
                 public PEAPI.Method ResolveMethod (string signature, CodeGen code_gen)