From: Jürg Billeter Date: Fri, 24 Oct 2008 14:47:05 +0000 (+0000) Subject: Add GObjectSignalModule X-Git-Tag: VALA_0_5_1~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfbe05880ab2eb69768a95abd6da67dce75edb3a;p=thirdparty%2Fvala.git Add GObjectSignalModule 2008-10-24 Jürg Billeter * gobject/Makefile.am: * gobject/valaccodedynamicsignalmodule.vala: * gobject/valaccodegenerator.vala: * gobject/valaccodemodule.vala: * gobject/valadbusmodule.vala: * gobject/valagobjectmodule.vala: * gobject/valagobjectsignalmodule.vala: Add GObjectSignalModule svn path=/trunk/; revision=1898 --- diff --git a/ChangeLog b/ChangeLog index 8f7a02965..f038875ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-10-24 Jürg Billeter + + * gobject/Makefile.am: + * gobject/valaccodedynamicsignalmodule.vala: + * gobject/valaccodegenerator.vala: + * gobject/valaccodemodule.vala: + * gobject/valadbusmodule.vala: + * gobject/valagobjectmodule.vala: + * gobject/valagobjectsignalmodule.vala: + + Add GObjectSignalModule + 2008-10-24 Jürg Billeter * gobject/valaccodegenerator.vala: diff --git a/gobject/Makefile.am b/gobject/Makefile.am index 80e86e4c3..c9b47e3b2 100644 --- a/gobject/Makefile.am +++ b/gobject/Makefile.am @@ -20,7 +20,6 @@ libvala_la_VALASOURCES = \ valaccodedynamicsignalmodule.vala \ valaccodeelementaccessmodule.vala \ valaccodegenerator.vala \ - valaccodegeneratorsignal.vala \ valaccodegeneratorsourcefile.vala \ valaccodegeneratorstruct.vala \ valaccodeinvocationexpressionmodule.vala \ @@ -33,6 +32,7 @@ libvala_la_VALASOURCES = \ valagobjectclassmodule.vala \ valagobjectinterfacemodule.vala \ valagobjectmodule.vala \ + valagobjectsignalmodule.vala \ valainterfaceregisterfunction.vala \ valatyperegisterfunction.vala \ $(NULL) diff --git a/gobject/valaccodedynamicsignalmodule.vala b/gobject/valaccodedynamicsignalmodule.vala index f8b9c60dc..81bfc93a1 100644 --- a/gobject/valaccodedynamicsignalmodule.vala +++ b/gobject/valaccodedynamicsignalmodule.vala @@ -124,8 +124,8 @@ public class Vala.CCodeDynamicSignalModule : CCodeModule { // FIXME should only be done once per marshaller var register_call = new CCodeFunctionCall (new CCodeIdentifier ("dbus_g_object_register_marshaller")); - codegen.generate_marshaller (node.get_parameters (), node.return_type, true); - register_call.add_argument (new CCodeIdentifier (codegen.get_marshaller_function (node.get_parameters (), node.return_type, null, true))); + head.generate_marshaller (node.get_parameters (), node.return_type, true); + register_call.add_argument (new CCodeIdentifier (head.get_marshaller_function (node.get_parameters (), node.return_type, null, true))); register_call.add_argument (new CCodeIdentifier ("G_TYPE_NONE")); var add_call = new CCodeFunctionCall (new CCodeIdentifier ("dbus_g_proxy_add_signal")); diff --git a/gobject/valaccodegenerator.vala b/gobject/valaccodegenerator.vala index 801019ecf..ba24cec41 100644 --- a/gobject/valaccodegenerator.vala +++ b/gobject/valaccodegenerator.vala @@ -153,6 +153,7 @@ public class Vala.CCodeGenerator : CodeGenerator { head = new GObjectModule (this, head); head = new GObjectClassModule (this, head); head = new GObjectInterfaceModule (this, head); + head = new GObjectSignalModule (this, head); head = new DBusModule (this, head); predefined_marshal_set = new HashSet (str_hash, str_equal); @@ -998,6 +999,10 @@ public class Vala.CCodeGenerator : CodeGenerator { current_return_type = null; } + public override void visit_signal (Signal sig) { + head.visit_signal (sig); + } + public override void visit_constructor (Constructor c) { current_method_inner_error = false; in_constructor = true; diff --git a/gobject/valaccodemodule.vala b/gobject/valaccodemodule.vala index 0f8875b3b..50845ebac 100644 --- a/gobject/valaccodemodule.vala +++ b/gobject/valaccodemodule.vala @@ -64,6 +64,10 @@ public abstract class Vala.CCodeModule { next.visit_method (m); } + public virtual void visit_signal (Signal sig) { + next.visit_signal (sig); + } + public virtual void visit_creation_method (CreationMethod m) { next.visit_creation_method (m); } @@ -143,4 +147,12 @@ public abstract class Vala.CCodeModule { public virtual string get_dynamic_signal_disconnect_wrapper_name (DynamicSignal node) { return next.get_dynamic_signal_disconnect_wrapper_name (node); } + + public virtual void generate_marshaller (Gee.List params, DataType return_type, bool dbus = false) { + next.generate_marshaller (params, return_type, dbus); + } + + public virtual string get_marshaller_function (Gee.List params, DataType return_type, string? prefix = null, bool dbus = false) { + return next.get_marshaller_function (params, return_type, prefix, dbus); + } } diff --git a/gobject/valadbusmodule.vala b/gobject/valadbusmodule.vala index 66e36f965..51e51927f 100644 --- a/gobject/valadbusmodule.vala +++ b/gobject/valadbusmodule.vala @@ -534,12 +534,12 @@ public class Vala.DBusModule : CCodeModule { dbus_methods.append ("{ (GCallback) "); dbus_methods.append (generate_dbus_wrapper (m, bindable)); dbus_methods.append (", "); - dbus_methods.append (codegen.get_marshaller_function (parameters, codegen.bool_type, null, true)); + dbus_methods.append (head.get_marshaller_function (parameters, codegen.bool_type, null, true)); dbus_methods.append (", "); dbus_methods.append (blob_len.to_string ()); dbus_methods.append (" },\n"); - codegen.generate_marshaller (parameters, codegen.bool_type, true); + head.generate_marshaller (parameters, codegen.bool_type, true); long start = blob.len; diff --git a/gobject/valagobjectmodule.vala b/gobject/valagobjectmodule.vala index 9860c9ae1..ec03e4f95 100644 --- a/gobject/valagobjectmodule.vala +++ b/gobject/valagobjectmodule.vala @@ -213,7 +213,7 @@ public class Vala.GObjectModule : CCodeModule { csignew.add_argument (new CCodeConstant ("NULL")); csignew.add_argument (new CCodeConstant ("NULL")); - string marshaller = codegen.get_marshaller_function (sig.get_parameters (), sig.return_type); + string marshaller = head.get_marshaller_function (sig.get_parameters (), sig.return_type); var marshal_arg = new CCodeIdentifier (marshaller); csignew.add_argument (marshal_arg); diff --git a/gobject/valaccodegeneratorsignal.vala b/gobject/valagobjectsignalmodule.vala similarity index 90% rename from gobject/valaccodegeneratorsignal.vala rename to gobject/valagobjectsignalmodule.vala index bb996c16e..a39c69be8 100644 --- a/gobject/valaccodegeneratorsignal.vala +++ b/gobject/valagobjectsignalmodule.vala @@ -1,4 +1,4 @@ -/* valaccodegeneratorsignal.vala +/* valagobjectsignalmodule.vala * * Copyright (C) 2006-2008 Jürg Billeter, Raffaele Sandrini * @@ -23,7 +23,11 @@ using GLib; -public class Vala.CCodeGenerator { +public class Vala.GObjectSignalModule : CCodeModule { + public GObjectSignalModule (CCodeGenerator codegen, CCodeModule? next) { + base (codegen, next); + } + private string get_marshaller_type_name (DataType t, bool dbus = false) { if (t is PointerType || t.type_parameter != null) { return ("POINTER"); @@ -33,7 +37,7 @@ public class Vala.CCodeGenerator { if (dbus) { return ("BOXED"); } else { - if (((ArrayType) t).element_type.data_type == string_type.data_type) { + if (((ArrayType) t).element_type.data_type == codegen.string_type.data_type) { return ("BOXED_INT"); } else { return ("POINTER_INT"); @@ -56,12 +60,12 @@ public class Vala.CCodeGenerator { } } - public string get_marshaller_function (Gee.List params, DataType return_type, string? prefix = null, bool dbus = false) { + public override string get_marshaller_function (Gee.List params, DataType return_type, string? prefix = null, bool dbus = false) { var signature = get_marshaller_signature (params, return_type, dbus); string ret; if (prefix == null) { - if (predefined_marshal_set.contains (signature)) { + if (codegen.predefined_marshal_set.contains (signature)) { prefix = "g_cclosure_marshal"; } else { prefix = "g_cclosure_user_marshal"; @@ -86,7 +90,7 @@ public class Vala.CCodeGenerator { return "gpointer"; } else if (t is VoidType) { return "void"; - } else if (t.data_type == string_type.data_type) { + } else if (t.data_type == codegen.string_type.data_type) { return "const char*"; } else if (t.data_type is Class || t.data_type is Interface) { return "gpointer"; @@ -141,25 +145,25 @@ public class Vala.CCodeGenerator { // parent_symbol may be null for late bound signals if (sig.parent_symbol != null) { var dt = sig.parent_symbol as TypeSymbol; - if (!dt.is_subtype_of (gobject_type)) { + if (!dt.is_subtype_of (codegen.gobject_type)) { sig.error = true; Report.error (sig.source_reference, "Only classes and interfaces deriving from GLib.Object support signals. `%s' does not derive from GLib.Object.".printf (dt.get_full_name ())); return; } } - sig.accept_children (this); + sig.accept_children (codegen); generate_marshaller (sig.get_parameters (), sig.return_type); } - public void generate_marshaller (Gee.List params, DataType return_type, bool dbus = false) { + public override void generate_marshaller (Gee.List params, DataType return_type, bool dbus = false) { string signature; int n_params, i; /* check whether a signal with the same signature already exists for this source file (or predefined) */ signature = get_marshaller_signature (params, return_type, dbus); - if (predefined_marshal_set.contains (signature) || user_marshal_set.contains (signature)) { + if (codegen.predefined_marshal_set.contains (signature) || codegen.user_marshal_set.contains (signature)) { return; } @@ -173,7 +177,7 @@ public class Vala.CCodeGenerator { signal_marshaller.add_parameter (new CCodeFormalParameter ("invocation_hint", "gpointer")); signal_marshaller.add_parameter (new CCodeFormalParameter ("marshal_data", "gpointer")); - source_signal_marshaller_declaration.append (signal_marshaller.copy ()); + codegen.source_signal_marshaller_declaration.append (signal_marshaller.copy ()); var marshaller_body = new CCodeBlock (); @@ -250,7 +254,7 @@ public class Vala.CCodeGenerator { if (dbus) { get_value_function = "g_value_get_boxed"; } else { - if (((ArrayType) p.parameter_type).element_type.data_type == string_type.data_type) { + if (((ArrayType) p.parameter_type).element_type.data_type == codegen.string_type.data_type) { get_value_function = "g_value_get_boxed"; } else { get_value_function = "g_value_get_pointer"; @@ -286,7 +290,7 @@ public class Vala.CCodeGenerator { if (dbus) { set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_take_boxed")); } else { - if (((ArrayType) return_type).element_type.data_type == string_type.data_type) { + if (((ArrayType) return_type).element_type.data_type == codegen.string_type.data_type) { set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_take_boxed")); } else { set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_set_pointer")); @@ -296,7 +300,7 @@ public class Vala.CCodeGenerator { set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_set_pointer")); } else if (return_type is ErrorType) { set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_set_pointer")); - } else if (return_type.data_type == string_type.data_type) { + } else if (return_type.data_type == codegen.string_type.data_type) { set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_take_string")); } else if (return_type.data_type is Class || return_type.data_type is Interface) { set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_take_object")); @@ -315,8 +319,8 @@ public class Vala.CCodeGenerator { signal_marshaller.block = marshaller_body; - source_signal_marshaller_definition.append (signal_marshaller); - user_marshal_set.add (signature); + codegen.source_signal_marshaller_definition.append (signal_marshaller); + codegen.user_marshal_set.add (signature); } }