2005-12-27 Alp Toker <alp@atoker.com>
authorAlp Toker <alp@mono-cvs.ximian.com>
Tue, 27 Dec 2005 09:32:06 +0000 (09:32 -0000)
committerAlp Toker <alp@mono-cvs.ximian.com>
Tue, 27 Dec 2005 09:32:06 +0000 (09:32 -0000)
  * cilc.cs: Start work on GInterface support
  * Test.cs: Update tests

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

mcs/tools/cilc/ChangeLog
mcs/tools/cilc/Test.cs
mcs/tools/cilc/cilc.cs

index 5527c21834908b1df0c49ac0e6107cd1ecf36d20..6a303ab993487c123a76f09f1ddade7e480e260e 100644 (file)
@@ -1,3 +1,8 @@
+2005-12-27  Alp Toker  <alp@atoker.com>
+
+       * cilc.cs: Start work on GInterface support
+       * Test.cs: Update tests
+
 2005-12-24  Alp Toker  <alp@atoker.com>
 
        * cilc.cs: Fix generation of mono method signature a bit (still needs work),
index 3de9a17cc8b82a03c169267a359af17487e0675b..893aff9697adca82613c96351c926344427d6d1f 100644 (file)
@@ -2,7 +2,12 @@ namespace Demo
 {
        using System;
 
-       public class Counter
+       public interface INumbered
+       {
+               void Increment ();
+       }
+
+       public class Counter : INumbered
        {
                int counter;
 
index d6c9e7f2787cd68151441f0dae835ffc55a7da71..2c694a7ba177e417bfbaf1f13b878743168f3120 100644 (file)
@@ -536,6 +536,8 @@ public class cilc
                EventInfo[] events;
                events = t.GetEvents (BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly);
 
+               Type[] ifaces;
+               ifaces = t.GetInterfaces ();
 
                H.WriteLine ("G_BEGIN_DECLS");
                H.WriteLine ();
@@ -580,7 +582,9 @@ public class cilc
                H.WriteLine ("struct _" + CurTypeClass);
                H.WriteLine ("{");
                H.WriteLine (ParentNameClass + " parent_class;" + " /* inherits " + t.BaseType.Namespace + " " + t.BaseType.Name + " */");
-               H.WriteLine ();
+
+               if (events.Length != 0)
+                       H.WriteLine ();
 
                //TODO: event arguments
                foreach (EventInfo ei in events)
@@ -659,7 +663,21 @@ public class cilc
                C.WriteLine ("}");
 
                C.WriteLine ();
+               C.WriteLine ("static void " + cur_type + "_interface_init (gpointer g_iface, gpointer iface_data)");
+               C.WriteLine ("{");
+               
+               foreach (Type iface in ifaces) {
+                       C.WriteLine ("//" + CsTypeToG (iface) + "Interface" + " *iface = (" + CsTypeToG (iface) + "Interface" + ")g_iface;");
+                       foreach (MethodInfo imi in iface.GetMethods (BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly)) {
+                               string funcname = ToValidFuncName (CamelToC (imi.Name));
+                               C.WriteLine ("//iface->" + funcname + " = " + cur_type + "_" + funcname + ";");
+                       }
+                       //TODO: properties etc.
+               }
+               
+               C.WriteLine ("}");
 
+               C.WriteLine ();
 
                //generate the GObject get_type function
                C.WriteLine ("GType " + cur_type + "_get_type (void)", H, ";");
@@ -672,9 +690,9 @@ public class cilc
                C.WriteLine ("static const GTypeInfo object_info =");
                C.WriteLine ("{");
                C.WriteLine ("sizeof (" + CurTypeClass + "),");
-               C.WriteLine ("(GBaseInitFunc) NULL,");
-               C.WriteLine ("(GBaseFinalizeFunc) NULL,");
-               C.WriteLine ("(GClassInitFunc) " + cur_type + "_class_init,");
+               C.WriteLine ("(GBaseInitFunc) NULL, /* base_init */");
+               C.WriteLine ("(GBaseFinalizeFunc) NULL, /* base_finalize */");
+               C.WriteLine ("(GClassInitFunc) " + cur_type + "_class_init, /* class_init */");
                C.WriteLine ("NULL, /* class_finalize */");
                C.WriteLine ("NULL, /* class_data */");
                C.WriteLine ("sizeof (" + CurType + "),");
@@ -683,11 +701,18 @@ public class cilc
                C.WriteLine ("};");
                C.WriteLine ();
 
+               foreach (Type iface in ifaces) {
+                       C.WriteLine ("//static const GInterfaceInfo bar_ifoo_info = {};");
+               }
+
                string parent_type = "G_TYPE_OBJECT";
                if (IsRegistered (t.BaseType))
                        parent_type = NsToC (t.BaseType.Namespace).ToUpper () + "_TYPE_" + CamelToC (t.BaseType.Name).ToUpper ();
 
                C.WriteLine ("object_type = g_type_register_static (" + parent_type + ", \"" + CurType + "\", &object_info, 0);");
+
+               foreach (Type iface in ifaces)
+                       C.WriteLine ("//g_type_add_interface_static (object_type, BAR_IFOO_TYPE, bar_ifoo_info);");
                C.WriteLine ();
                C.WriteLine ("return object_type;");
                C.WriteLine ("}");