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
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) {
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 ());
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) {
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);
ClassWithCreationMethod
new ClassWithNamedCreationMethod ()
ClassWithNamedCreationMethod
+new SimpleGTypeInstanceClass ()
+new DerivedGTypeInstanceClass ()
+new PublicGTypeInstanceClass ()
+new GTypeInstanceClassWithCreationMethod ()
+GTypeInstanceClassWithCreationMethod
+new GTypeInstanceClassWithNamedCreationMethod ()
+GTypeInstanceClassWithNamedCreationMethod
new SimpleGObjectClass ()
new DerivedGObjectClass ()
new PublicGObjectClass ()
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 {
}
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");