[vala/staging: 5/9] codegen: Use g_object_notify_by_pspec() to notify property-changes



commit 0815e5e89da94d02f6d6cd66e5c3acbf6d765e96
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Apr 11 14:42:46 2017 +0200

    codegen: Use g_object_notify_by_pspec() to notify property-changes

 codegen/valaccodebasemodule.vala |   10 +++++++---
 codegen/valagtypemodule.vala     |   30 ++++++++++++++++++++++++++----
 2 files changed, 33 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 8a95c64..3e51c96 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1787,9 +1787,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        if (is_gobject_property (prop) &&
                            prop.notify &&
                            (acc.writable || acc.construction)) {
-                               var notify_call = new CCodeFunctionCall (new CCodeIdentifier 
("g_object_notify"));
+                               var notify_call = new CCodeFunctionCall (new CCodeIdentifier 
("g_object_notify_by_pspec"));
                                notify_call.add_argument (new CCodeCastExpression (new CCodeIdentifier 
("self"), "GObject *"));
-                               notify_call.add_argument (get_property_canonical_cconstant (prop));
+                               notify_call.add_argument (get_param_spec_cexpression (prop));
 
                                var get_accessor = prop.get_accessor;
                                if (get_accessor != null && get_accessor.automatic_body) {
@@ -6614,7 +6614,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                return false;
        }
 
-       public virtual CCodeFunctionCall get_param_spec (Property prop) {
+       public virtual CCodeExpression get_param_spec_cexpression (Property prop) {
+               return new CCodeFunctionCall (new CCodeIdentifier (""));
+       }
+
+       public virtual CCodeExpression get_param_spec (Property prop) {
                return new CCodeFunctionCall (new CCodeIdentifier (""));
        }
 
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 86a6474..6d0f0d2 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -522,7 +522,6 @@ public class Vala.GTypeModule : GErrorModule {
                                string macro = "(G_TYPE_CLASS_GET_PRIVATE (klass, %s, 
%sClassPrivate))".printf (get_ccode_type_id (cl), get_ccode_name (cl));
                                decl_space.add_type_member_declaration (new CCodeMacroReplacement 
("%s_GET_CLASS_PRIVATE(klass)".printf (get_ccode_upper_case_name (cl, null)), macro));
                        }
-                       decl_space.add_type_member_declaration (prop_enum);
                } else {
                        if (cl.has_private_fields) {
                                Report.error (cl.source_reference, "Private fields not supported in compact 
classes");
@@ -563,10 +562,19 @@ public class Vala.GTypeModule : GErrorModule {
                instance_init_context = new EmitContext (cl);
                instance_finalize_context = new EmitContext (cl);
 
-
                generate_class_struct_declaration (cl, cfile);
                generate_class_private_declaration (cl, cfile);
 
+               var last_prop = "%s_LAST_PROPERTY".printf (get_ccode_upper_case_name (cl));
+               if (is_gtypeinstance) {
+                       cfile.add_type_declaration (prop_enum);
+
+                       var prop_array_decl = new CCodeDeclaration ("GParamSpec*");
+                       prop_array_decl.modifiers |= CCodeModifiers.STATIC;
+                       prop_array_decl.add_declarator (new CCodeVariableDeclarator ("%s_properties".printf 
(get_ccode_lower_case_name (cl)), null, new CCodeDeclaratorSuffix.with_array (new CCodeIdentifier 
(last_prop))));
+                       cfile.add_type_declaration (prop_array_decl);
+               }
+
                if (!cl.is_internal_symbol ()) {
                        generate_class_struct_declaration (cl, header_file);
                }
@@ -619,6 +627,8 @@ public class Vala.GTypeModule : GErrorModule {
                                pop_context ();
                        }
 
+                       prop_enum.add_value (new CCodeEnumValue (last_prop));
+
                        if (cl.get_signals ().size > 0) {
                                var last_signal = "%s_LAST_SIGNAL".printf (get_ccode_upper_case_name (cl));
                                signal_enum.add_value (new CCodeEnumValue (last_signal));
@@ -1719,7 +1729,15 @@ public class Vala.GTypeModule : GErrorModule {
                cfile.add_function (instance_finalize_context.ccode);
        }
 
-       public override CCodeFunctionCall get_param_spec (Property prop) {
+       public override CCodeExpression get_param_spec_cexpression (Property prop) {
+               var cl = (TypeSymbol) prop.parent_symbol;
+               var prop_array = new CCodeIdentifier ("%s_properties".printf (get_ccode_lower_case_name 
(cl)));
+               var prop_enum_value = new CCodeIdentifier (get_ccode_upper_case_name (prop));
+
+               return new CCodeElementAccess (prop_array, prop_enum_value);
+       }
+
+       public override CCodeExpression get_param_spec (Property prop) {
                var cspec = new CCodeFunctionCall ();
                cspec.add_argument (get_property_canonical_cconstant (prop));
                cspec.add_argument (new CCodeConstant ("\"%s\"".printf (prop.nick)));
@@ -1900,7 +1918,11 @@ public class Vala.GTypeModule : GErrorModule {
                }
                cspec.add_argument (new CCodeConstant (pflags));
 
-               return cspec;
+               if (prop.parent_symbol is Interface) {
+                       return cspec;
+               } else {
+                       return new CCodeAssignment (get_param_spec_cexpression (prop), cspec);
+               }
        }
 
        public override void generate_interface_declaration (Interface iface, CCodeFile decl_space) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]