vala r1485 - in trunk: . gobject vala
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1485 - in trunk: . gobject vala
- Date: Thu, 29 May 2008 17:42:26 +0000 (UTC)
Author: juergbi
Date: Thu May 29 17:42:25 2008
New Revision: 1485
URL: http://svn.gnome.org/viewvc/vala?rev=1485&view=rev
Log:
2008-05-29 Juerg Billeter <j bitron ch>
* vala/valainterface.vala:
* gobject/valaccodeclassbinding.vala:
* gobject/valaccodegenerator.vala:
* gobject/valaccodeinterfacebinding.vala:
* gobject/valaccodemethodbinding.vala:
Add support for non-GObject classes with generic type parameters
Modified:
trunk/ChangeLog
trunk/gobject/valaccodeclassbinding.vala
trunk/gobject/valaccodegenerator.vala
trunk/gobject/valaccodeinterfacebinding.vala
trunk/gobject/valaccodemethodbinding.vala
trunk/vala/valainterface.vala
Modified: trunk/gobject/valaccodeclassbinding.vala
==============================================================================
--- trunk/gobject/valaccodeclassbinding.vala (original)
+++ trunk/gobject/valaccodeclassbinding.vala Thu May 29 17:42:25 2008
@@ -457,6 +457,20 @@
foreach (Signal sig in cl.get_signals ()) {
init_block.add_statement (new CCodeExpressionStatement (get_signal_creation (sig, cl)));
}
+ } else if (!cl.is_compact) {
+ /* create type, dup_func, and destroy_func fields for generic types */
+ foreach (TypeParameter type_param in cl.get_type_parameters ()) {
+ string func_name;
+
+ func_name = "%s_type".printf (type_param.name.down ());
+ codegen.instance_priv_struct.add_field ("GType", func_name);
+
+ func_name = "%s_dup_func".printf (type_param.name.down ());
+ codegen.instance_priv_struct.add_field ("GBoxedCopyFunc", func_name);
+
+ func_name = "%s_destroy_func".printf (type_param.name.down ());
+ codegen.instance_priv_struct.add_field ("GDestroyNotify", func_name);
+ }
}
init_block.add_statement (register_dbus_info (cl));
Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala (original)
+++ trunk/gobject/valaccodegenerator.vala Thu May 29 17:42:25 2008
@@ -2771,7 +2771,7 @@
}
if (type.type_parameter != null) {
- if (!(current_type_symbol is Class) || !current_class.is_subtype_of (gobject_type)) {
+ if (!(current_type_symbol is Class) || current_class.is_compact) {
return false;
}
}
@@ -2785,7 +2785,7 @@
}
if (type.type_parameter != null) {
- if (!(current_type_symbol is Class) || !current_class.is_subtype_of (gobject_type)) {
+ if (!(current_type_symbol is Class) || current_class.is_compact) {
return false;
}
}
@@ -2910,7 +2910,8 @@
creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance));
}
- if (expr.type_reference.data_type is Class && expr.type_reference.data_type.is_subtype_of (gobject_type)) {
+ var cl = expr.type_reference.data_type as Class;
+ if (cl != null && !cl.is_compact) {
foreach (DataType type_arg in expr.type_reference.get_type_arguments ()) {
creation_call.add_argument (get_type_id_expression (type_arg));
if (requires_copy (type_arg)) {
Modified: trunk/gobject/valaccodeinterfacebinding.vala
==============================================================================
--- trunk/gobject/valaccodeinterfacebinding.vala (original)
+++ trunk/gobject/valaccodeinterfacebinding.vala Thu May 29 17:42:25 2008
@@ -116,17 +116,19 @@
var cif = new CCodeIfStatement (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("initialized")), init_block);
base_init.block.add_statement (cif);
init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("initialized"), new CCodeConstant ("TRUE"))));
-
- /* create properties */
- var props = iface.get_properties ();
- foreach (Property prop in props) {
- var cinst = new CCodeFunctionCall (new CCodeIdentifier ("g_object_interface_install_property"));
- cinst.add_argument (new CCodeIdentifier ("iface"));
- cinst.add_argument (get_param_spec (prop));
- init_block.add_statement (new CCodeExpressionStatement (cinst));
+ if (iface.is_subtype_of (codegen.gobject_type)) {
+ /* create properties */
+ var props = iface.get_properties ();
+ foreach (Property prop in props) {
+ var cinst = new CCodeFunctionCall (new CCodeIdentifier ("g_object_interface_install_property"));
+ cinst.add_argument (new CCodeIdentifier ("iface"));
+ cinst.add_argument (get_param_spec (prop));
+
+ init_block.add_statement (new CCodeExpressionStatement (cinst));
+ }
}
-
+
/* create signals */
foreach (Signal sig in iface.get_signals ()) {
init_block.add_statement (new CCodeExpressionStatement (get_signal_creation (sig, iface)));
Modified: trunk/gobject/valaccodemethodbinding.vala
==============================================================================
--- trunk/gobject/valaccodemethodbinding.vala (original)
+++ trunk/gobject/valaccodemethodbinding.vala Thu May 29 17:42:25 2008
@@ -179,7 +179,7 @@
cparam_map.set (codegen.get_param_pos (m.cinstance_parameter_position), class_param);
}
- if (in_gobject_creation_method) {
+ if (in_gtypeinstance_creation_method) {
// memory management for generic types
int type_param_index = 0;
foreach (TypeParameter type_param in codegen.current_class.get_type_parameters ()) {
@@ -320,6 +320,26 @@
ccall.add_argument (new CCodeIdentifier (cl.get_type_id ()));
cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("self", new CCodeCastExpression (ccall, cl.get_cname () + "*")));
cinit.append (cdecl);
+
+ /* type, dup func, and destroy func fields for generic types */
+ foreach (TypeParameter type_param in codegen.current_class.get_type_parameters ()) {
+ CCodeIdentifier param_name;
+ CCodeAssignment assign;
+
+ var priv_access = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv");
+
+ param_name = new CCodeIdentifier ("%s_type".printf (type_param.name.down ()));
+ assign = new CCodeAssignment (new CCodeMemberAccess.pointer (priv_access, param_name.name), param_name);
+ cinit.append (new CCodeExpressionStatement (assign));
+
+ param_name = new CCodeIdentifier ("%s_dup_func".printf (type_param.name.down ()));
+ assign = new CCodeAssignment (new CCodeMemberAccess.pointer (priv_access, param_name.name), param_name);
+ cinit.append (new CCodeExpressionStatement (assign));
+
+ param_name = new CCodeIdentifier ("%s_destroy_func".printf (type_param.name.down ()));
+ assign = new CCodeAssignment (new CCodeMemberAccess.pointer (priv_access, param_name.name), param_name);
+ cinit.append (new CCodeExpressionStatement (assign));
+ }
} else if (codegen.current_type_symbol is Class) {
var cl = (Class) m.parent_symbol;
var cdecl = new CCodeDeclaration (cl.get_cname () + "*");
Modified: trunk/vala/valainterface.vala
==============================================================================
--- trunk/vala/valainterface.vala (original)
+++ trunk/vala/valainterface.vala Thu May 29 17:42:25 2008
@@ -177,6 +177,9 @@
public void add_property (Property prop) {
properties.add (prop);
scope.add (prop.name, prop);
+
+ prop.this_parameter = new FormalParameter ("this", new ObjectType (this));
+ prop.scope.add (prop.this_parameter.name, prop.this_parameter);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]