* EventDef.cs: New file - An event definition.
authorJackson Harper <jackson@novell.com>
Sun, 8 Jun 2003 23:22:26 +0000 (23:22 -0000)
committerJackson Harper <jackson@novell.com>
Sun, 8 Jun 2003 23:22:26 +0000 (23:22 -0000)
* FeatureAttr.cs: New file - Attributes for features (events and
properties)
* MethodRef.cs: Only resolve methods once.
* TypeDef.cs: Allow Events to be added to types. Also add
functionality to add generic type parameters to types. The
actually emission of these type parameters is commented out untill
I commit my patches to PEAPI and work out the syntax of constraints.

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

mcs/ilasm/codegen/ChangeLog
mcs/ilasm/codegen/EventDef.cs [new file with mode: 0644]
mcs/ilasm/codegen/FeatureAttr.cs [new file with mode: 0644]
mcs/ilasm/codegen/MethodRef.cs
mcs/ilasm/codegen/TypeDef.cs

index 05fe68aa245569d4500eb953a2b31a86106f978c..74466b0f8b7069527696452df4b181ce3bdf47c8 100644 (file)
@@ -1,3 +1,14 @@
+2003-06-08 Jackson Harper <jackson@latitudegeo.com>
+
+       * EventDef.cs: New file - An event definition.
+       * FeatureAttr.cs: New file - Attributes for features (events and
+       properties)
+       * MethodRef.cs: Only resolve methods once.
+       * TypeDef.cs: Allow Events to be added to types. Also add
+       functionality to add generic type parameters to types. The
+       actually emission of these type parameters is commented out untill
+       I commit my patches to PEAPI and work out the syntax of constraints.
+               
 2003-05-31 Jackson Harper <jackson@latitudegeo.com>
 
        * CodeGen.cs: Allow this assembly name to be set.
diff --git a/mcs/ilasm/codegen/EventDef.cs b/mcs/ilasm/codegen/EventDef.cs
new file mode 100644 (file)
index 0000000..81360d0
--- /dev/null
@@ -0,0 +1,125 @@
+//
+// Mono.ILASM.EventDef
+//
+// Author(s):
+//  Jackson Harper (Jackson@LatitudeGeo.com)
+//
+// (C) 2003 Jackson Harper, All right reserved
+//
+
+
+using System;
+using System.Collections;
+
+namespace Mono.ILASM {
+
+        public class EventDef {
+
+                private FeatureAttr attr;
+                private string name;
+                private ITypeRef type;
+                private PEAPI.Event event_def;
+                private bool is_resolved;
+
+                private ArrayList addon_list;
+                private ArrayList fire_list;
+                private ArrayList other_list;
+                private ArrayList removeon_list;
+
+                public EventDef (FeatureAttr attr, ITypeRef type, string name)
+                {
+                        this.attr = attr;
+                        this.name = name;
+                        this.type = type;
+                        is_resolved = false;
+                }
+
+                public PEAPI.Event Resolve (CodeGen code_gen, PEAPI.ClassDef classdef)
+                {
+                        if (is_resolved)
+                                return event_def;
+
+                        type.Resolve (code_gen);
+                        event_def = classdef.AddEvent (name, type.PeapiType);
+
+                        if ((attr & FeatureAttr.Rtspecialname) != 0)
+                                event_def.SetRTSpecialName ();
+
+                        if ((attr & FeatureAttr.Specialname) != 0)
+                                event_def.SetSpecialName ();
+
+                        is_resolved = true;
+
+                        return event_def;
+                }
+
+                public void Define (CodeGen code_gen, PEAPI.ClassDef classdef)
+                {
+                        if (!is_resolved)
+                                Resolve (code_gen, classdef);
+
+                        if (addon_list != null) {
+                                foreach (MethodRef methodref in addon_list) {
+                                        methodref.Resolve (code_gen);
+                                        event_def.AddAddon ((PEAPI.MethodDef) methodref.PeapiMethod);
+                                }
+                        }
+
+                        if (fire_list != null) {
+                                foreach (MethodRef methodref in fire_list) {
+                                        methodref.Resolve (code_gen);
+                                        event_def.AddFire ((PEAPI.MethodDef) methodref.PeapiMethod);
+                                }
+                        }
+
+                        if (other_list != null) {
+                                foreach (MethodRef methodref in other_list) {
+                                        methodref.Resolve (code_gen);
+                                        event_def.AddOther ((PEAPI.MethodDef) methodref.PeapiMethod);
+                                }
+                        }
+
+                        if (removeon_list != null) {
+                                foreach (MethodRef methodref in removeon_list) {
+                                        methodref.Resolve (code_gen);
+                                        event_def.AddRemoveOn ((PEAPI.MethodDef) methodref.PeapiMethod);
+                                }
+                        }
+                }
+
+                public void AddAddon (MethodRef method_ref)
+                {
+                        if (addon_list == null)
+                                addon_list = new ArrayList ();
+
+                        addon_list.Add (method_ref);
+                }
+
+                public void AddFire (MethodRef method_ref)
+                {
+                        if (fire_list == null)
+                                fire_list = new ArrayList ();
+
+                        fire_list.Add (method_ref);
+                }
+
+                public void AddOther (MethodRef method_ref)
+                {
+                        if (other_list == null)
+                                other_list = new ArrayList ();
+
+                        other_list.Add (method_ref);
+                }
+
+                public void AddRemoveon (MethodRef method_ref)
+                {
+                        if (removeon_list == null)
+                                removeon_list = new ArrayList ();
+
+                        removeon_list.Add (method_ref);
+                }
+
+        }
+
+}
+
diff --git a/mcs/ilasm/codegen/FeatureAttr.cs b/mcs/ilasm/codegen/FeatureAttr.cs
new file mode 100644 (file)
index 0000000..78fa03d
--- /dev/null
@@ -0,0 +1,21 @@
+//
+// Mono.ILASM.FeatureAttr
+//
+// Author(s):
+//  Jackson Harper (Jackson@LatitudeGeo.com)
+//
+// (C) 2003 Jackson Harper, All rights reserved
+//
+
+
+using System;
+
+namespace Mono.ILASM {
+
+        public enum FeatureAttr {
+                Rtspecialname,
+                Specialname
+        }
+
+}
+
index 16bdca792907ec4e3f458db272974649b2d2d601..5393ff6ad79ec6978e332a9f8e8d992d07775c35 100644 (file)
@@ -22,6 +22,7 @@ namespace Mono.ILASM {
                 private ITypeRef[] param;
 
                 private PEAPI.Method peapi_method;
+                private bool is_resolved;
 
                 public MethodRef (TypeRef owner, PEAPI.CallConv call_conv,
                         ITypeRef ret_type, string name, ITypeRef[] param)
@@ -31,6 +32,7 @@ namespace Mono.ILASM {
                         this.ret_type = ret_type;
                         this.name = name;
                         this.param = param;
+                        is_resolved = false;
                 }
 
                 public PEAPI.Method PeapiMethod {
@@ -39,6 +41,9 @@ namespace Mono.ILASM {
 
                 public void Resolve (CodeGen code_gen)
                 {
+                        if (is_resolved)
+                                return;
+
                         TypeDef owner_def = code_gen.TypeManager[owner.FullName];
                         string write_name;
 
@@ -67,6 +72,8 @@ namespace Mono.ILASM {
                                                 (PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
                         }
 
+                        is_resolved = true;
+
                 }
 
         }
index dbcb3850a413e9e8264442f398a4f073f45fa8db..7875e23eb1d8416406175597f240eed1c50430d5 100644 (file)
@@ -27,8 +27,12 @@ namespace Mono.ILASM {
                 private Hashtable method_table;
                 private ArrayList data_list;
                 private ArrayList customattr_list;
+                private ArrayList event_list;
+                private ArrayList typar_list;
                 private TypeDef outer;
 
+                private EventDef current_event;
+
                 private int size;
                 private int pack;
 
@@ -72,10 +76,18 @@ namespace Mono.ILASM {
                         get { return classdef; }
                 }
 
+                public bool IsGenericType {
+                        get { return (typar_list == null); }
+                }
+
                 public bool IsDefined {
                         get { return is_defined; }
                 }
 
+                public EventDef CurrentEvent {
+                        get { return current_event; }
+                }
+
                 public void SetSize (int size)
                 {
                         this.size = size;
@@ -101,6 +113,23 @@ namespace Mono.ILASM {
                         method_table.Add (methoddef.Signature, methoddef);
                 }
 
+                public void BeginEventDef (EventDef event_def)
+                {
+                        if (current_event != null)
+                                throw new Exception ("An event definition was not closed.");
+
+                        current_event = event_def;
+                }
+
+                public void EndEventDef ()
+                {
+                        if (event_list == null)
+                                event_list = new ArrayList ();
+
+                        event_list.Add (current_event);
+                        current_event = null;
+                }
+
                 public void AddCustomAttribute (CustomAttr customattr)
                 {
                         if (customattr_list == null)
@@ -109,6 +138,21 @@ namespace Mono.ILASM {
                         customattr_list.Add (customattr);
                 }
 
+                // Lamespec: Is id just for debugging? I don't see a spot for it
+                // in the metadata, unless it overrides name.
+                public void AddGenericParam (string name, string id)
+                {
+                        AddGenericParam (name, id, null);
+                }
+
+                public void AddGenericParam (string name, string id, ITypeRef constraint)
+                {
+                        if (typar_list == null)
+                                typar_list = new ArrayList ();
+
+                        typar_list.Add (new DictionaryEntry (name, constraint));
+                }
+
                 public void Define (CodeGen code_gen)
                 {
                         if (is_defined)
@@ -151,6 +195,24 @@ namespace Mono.ILASM {
                         if (size != -1)
                                 classdef.AddLayoutInfo (pack, size);
 
+                        /*
+                          ///
+                          /// Commented out until I checkin PEAPI generics fixes
+                          ///
+                        if (typar_list != null) {
+                                short index = 0;
+                                foreach (DictionaryEntry typar in typar_list) {
+                                        if (typar.Value == null) {
+                                                classdef.AddGenericParameter (index++, (string) typar.Key);
+                                        } else {
+                                                ITypeRef constraint = (ITypeRef) typar.Value;
+                                                constraint.Resolve (code_gen);
+                                                classdef.AddGenericParameter (index++, (string) typar.Key,
+                                                                constraint.PeapiType);
+                                        }
+                                }
+                        }
+                        */
                         is_intransit = false;
                         is_defined = true;
 
@@ -167,13 +229,17 @@ namespace Mono.ILASM {
                                 methoddef.Define (code_gen, classdef);
                         }
 
+                        foreach (EventDef eventdef in event_list) {
+                                eventdef.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)
+                public PEAPI.MethodDef ResolveMethod (string signature, CodeGen code_gen)
                 {
                         MethodDef methoddef = (MethodDef) method_table[signature];