summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuerg Billeter <j@bitron.ch>2007-09-21 13:03:35 +0000
committerJürg Billeter <juergbi@src.gnome.org>2007-09-21 13:03:35 +0000
commit1f88b5ea3096433dc89c8ed4651044fe8ccac881 (patch)
tree4de170ba16b63b47fbf296d12b1219e5cdec8adc
parent9204c84c2aaf486605de91c35fa2125f8673217c (diff)
downloadvala-1f88b5ea3096433dc89c8ed4651044fe8ccac881.tar.gz
prepare support for classes based on GTypeInstance but not on GObject add
2007-09-21 Juerg Billeter <j@bitron.ch> * gobject/valaccodegeneratorclass.vala: prepare support for classes based on GTypeInstance but not on GObject * tests/classes.exp, tests/classes.vala: add simple test cases for GTypeInstance-based classes svn path=/trunk/; revision=627
-rw-r--r--ChangeLog7
-rw-r--r--gobject/valaccodegeneratorclass.vala17
-rw-r--r--tests/classes.exp7
-rw-r--r--tests/classes.vala32
4 files changed, 57 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index c09649bb5..d51523490 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2007-09-21 Jürg Billeter <j@bitron.ch>
+ * gobject/valaccodegeneratorclass.vala: prepare support for classes
+ based on GTypeInstance but not on GObject
+ * tests/classes.exp, tests/classes.vala: add simple test cases for
+ GTypeInstance-based classes
+
+2007-09-21 Jürg Billeter <j@bitron.ch>
+
* gobject/valaccodegeneratorclass.vala: add missing parent field for
derived non-GObject classes
diff --git a/gobject/valaccodegeneratorclass.vala b/gobject/valaccodegeneratorclass.vala
index d41af8c3c..e1bf6afc9 100644
--- a/gobject/valaccodegeneratorclass.vala
+++ b/gobject/valaccodegeneratorclass.vala
@@ -39,6 +39,7 @@ public class Vala.CCodeGenerator {
current_type_symbol = cl;
current_class = cl;
+ bool is_gtypeinstance = cl.is_subtype_of (gtypeinstance_type);
bool is_gobject = cl.is_subtype_of (gobject_type);
if (cl.get_cname().len () < 3) {
@@ -68,9 +69,9 @@ public class Vala.CCodeGenerator {
def_frag = source_type_member_declaration;
}
- var macro = "(%s_get_type ())".printf (cl.get_lower_case_cname (null));
- if (is_gobject) {
+ if (is_gtypeinstance) {
decl_frag.append (new CCodeNewline ());
+ var macro = "(%s_get_type ())".printf (cl.get_lower_case_cname (null));
decl_frag.append (new CCodeMacroReplacement (cl.get_upper_case_cname ("TYPE_"), macro));
macro = "(G_TYPE_CHECK_INSTANCE_CAST ((obj), %s, %s))".printf (cl.get_upper_case_cname ("TYPE_"), cl.get_cname ());
@@ -99,14 +100,18 @@ public class Vala.CCodeGenerator {
instance_struct.add_field (cl.base_class.get_cname (), "parent");
}
- if (is_gobject) {
+ if (is_gtypeinstance) {
if (cl.source_reference.file.cycle == null) {
decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator ("%sClass".printf (cl.get_cname ()))));
}
decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (instance_priv_struct.name), new CCodeVariableDeclarator ("%sPrivate".printf (cl.get_cname ()))));
instance_struct.add_field ("%sPrivate *".printf (cl.get_cname ()), "priv");
- type_struct.add_field ("%sClass".printf (cl.base_class.get_cname ()), "parent");
+ if (cl.base_class == gtypeinstance_type) {
+ type_struct.add_field ("GTypeClass", "parent");
+ } else {
+ type_struct.add_field ("%sClass".printf (cl.base_class.get_cname ()), "parent");
+ }
}
if (!cl.is_static) {
@@ -116,12 +121,12 @@ public class Vala.CCodeGenerator {
def_frag.append (instance_struct);
}
- if (is_gobject) {
+ if (is_gtypeinstance) {
def_frag.append (type_struct);
/* only add the *Private struct if it is not empty, i.e. we actually have private data */
if (cl.has_private_fields || cl.get_type_parameters ().size > 0) {
source_type_member_declaration.append (instance_priv_struct);
- macro = "(G_TYPE_INSTANCE_GET_PRIVATE ((o), %s, %sPrivate))".printf (cl.get_upper_case_cname ("TYPE_"), cl.get_cname ());
+ var macro = "(G_TYPE_INSTANCE_GET_PRIVATE ((o), %s, %sPrivate))".printf (cl.get_upper_case_cname ("TYPE_"), cl.get_cname ());
source_type_member_declaration.append (new CCodeMacroReplacement ("%s_GET_PRIVATE(o)".printf (cl.get_upper_case_cname (null)), macro));
}
source_type_member_declaration.append (prop_enum);
diff --git a/tests/classes.exp b/tests/classes.exp
index 645de25b0..2be747b7d 100644
--- a/tests/classes.exp
+++ b/tests/classes.exp
@@ -6,6 +6,13 @@ new ClassWithCreationMethod ()
ClassWithCreationMethod
new ClassWithNamedCreationMethod ()
ClassWithNamedCreationMethod
+new SimpleGTypeInstanceClass ()
+new DerivedGTypeInstanceClass ()
+new PublicGTypeInstanceClass ()
+new GTypeInstanceClassWithCreationMethod ()
+GTypeInstanceClassWithCreationMethod
+new GTypeInstanceClassWithNamedCreationMethod ()
+GTypeInstanceClassWithNamedCreationMethod
new SimpleGObjectClass ()
new DerivedGObjectClass ()
new PublicGObjectClass ()
diff --git a/tests/classes.vala b/tests/classes.vala
index ccf561047..5bfe2967a 100644
--- a/tests/classes.vala
+++ b/tests/classes.vala
@@ -34,6 +34,27 @@ class ClassWithNamedCreationMethod {
public int field;
}
+class SimpleGTypeInstanceClass : TypeInstance {
+}
+
+class DerivedGTypeInstanceClass : SimpleGTypeInstanceClass {
+}
+
+public class PublicGTypeInstanceClass : TypeInstance {
+}
+
+class GTypeInstanceClassWithCreationMethod : TypeInstance {
+ public GTypeInstanceClassWithCreationMethod () {
+ stdout.printf ("GTypeInstanceClassWithCreationMethod\n");
+ }
+}
+
+class GTypeInstanceClassWithNamedCreationMethod : TypeInstance {
+ public GTypeInstanceClassWithNamedCreationMethod.named () {
+ stdout.printf ("GTypeInstanceClassWithNamedCreationMethod\n");
+ }
+}
+
class SimpleGObjectClass : Object {
}
@@ -71,6 +92,17 @@ static class ClassesTest {
stdout.printf ("new ClassWithNamedCreationMethod ()\n");
var class_with_named_creation_method = new ClassWithNamedCreationMethod.named ();
+ stdout.printf ("new SimpleGTypeInstanceClass ()\n");
+ var simple_gtypeinstance_class = new SimpleGTypeInstanceClass ();
+ stdout.printf ("new DerivedGTypeInstanceClass ()\n");
+ var derived_gtypeinstance_class = new DerivedGTypeInstanceClass ();
+ stdout.printf ("new PublicGTypeInstanceClass ()\n");
+ var public_gtypeinstance_class = new PublicGTypeInstanceClass ();
+ stdout.printf ("new GTypeInstanceClassWithCreationMethod ()\n");
+ var gtypeinstance_class_with_creation_method = new GTypeInstanceClassWithCreationMethod ();
+ stdout.printf ("new GTypeInstanceClassWithNamedCreationMethod ()\n");
+ var gtypeinstance_class_with_named_creation_method = new GTypeInstanceClassWithNamedCreationMethod.named ();
+
stdout.printf ("new SimpleGObjectClass ()\n");
var simple_gobject_class = new SimpleGObjectClass ();
stdout.printf ("new DerivedGObjectClass ()\n");