[vala/staging] codegen: Make type-parameter properties readable
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Make type-parameter properties readable
- Date: Mon, 4 Nov 2019 10:29:56 +0000 (UTC)
commit a06892eaa472ad26233ddcbcfbaf8ebdf12015f8
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Nov 2 07:37:33 2019 +0100
codegen: Make type-parameter properties readable
Those are immutable while being construct-only properties.
See https://gitlab.gnome.org/GNOME/vala/issues/190
codegen/valagobjectmodule.vala | 43 +++++++++++++++++++++++++--
tests/Makefile.am | 1 +
tests/generics/type-parameter-properties.vala | 29 ++++++++++++++++++
3 files changed, 70 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valagobjectmodule.vala b/codegen/valagobjectmodule.vala
index 65726fe68..674f18d8a 100644
--- a/codegen/valagobjectmodule.vala
+++ b/codegen/valagobjectmodule.vala
@@ -93,7 +93,7 @@ public class Vala.GObjectModule : GTypeModule {
cspec.add_argument (new CCodeConstant ("\"type\""));
cspec.add_argument (new CCodeConstant ("\"type\""));
cspec.add_argument (new CCodeIdentifier ("G_TYPE_NONE"));
- cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY"));
+ cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY"));
cinst.add_argument (cspec);
ccode.add_expression (cinst);
prop_enum.add_value (new CCodeEnumValue (enum_value));
@@ -109,7 +109,7 @@ public class Vala.GObjectModule : GTypeModule {
cspec.add_argument (func_name_constant);
cspec.add_argument (new CCodeConstant ("\"dup func\""));
cspec.add_argument (new CCodeConstant ("\"dup func\""));
- cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY"));
+ cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY"));
cinst.add_argument (cspec);
ccode.add_expression (cinst);
prop_enum.add_value (new CCodeEnumValue (enum_value));
@@ -125,7 +125,7 @@ public class Vala.GObjectModule : GTypeModule {
cspec.add_argument (func_name_constant);
cspec.add_argument (new CCodeConstant ("\"destroy func\""));
cspec.add_argument (new CCodeConstant ("\"destroy func\""));
- cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY"));
+ cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY"));
cinst.add_argument (cspec);
ccode.add_expression (cinst);
prop_enum.add_value (new CCodeEnumValue (enum_value));
@@ -284,6 +284,43 @@ public class Vala.GObjectModule : GTypeModule {
}
ccode.add_break ();
}
+
+ /* type, dup func, and destroy func properties for generic types */
+ foreach (TypeParameter type_param in cl.get_type_parameters ()) {
+ string func_name, enum_value;
+ CCodeMemberAccess cfield;
+ CCodeFunctionCall csetcall;
+
+ func_name = "%s_type".printf (type_param.name.ascii_down ());
+ enum_value = "%s_%s".printf (get_ccode_lower_case_name (cl, null),
func_name).ascii_up ();
+ ccode.add_case (new CCodeIdentifier (enum_value));
+ cfield = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new
CCodeIdentifier ("self"), "priv"), func_name);
+ csetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_set_gtype"));
+ csetcall.add_argument (new CCodeIdentifier ("value"));
+ csetcall.add_argument (cfield);
+ ccode.add_expression (csetcall);
+ ccode.add_break ();
+
+ func_name = "%s_dup_func".printf (type_param.name.ascii_down ());
+ enum_value = "%s_%s".printf (get_ccode_lower_case_name (cl, null),
func_name).ascii_up ();
+ ccode.add_case (new CCodeIdentifier (enum_value));
+ cfield = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new
CCodeIdentifier ("self"), "priv"), func_name);
+ csetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_set_pointer"));
+ csetcall.add_argument (new CCodeIdentifier ("value"));
+ csetcall.add_argument (cfield);
+ ccode.add_expression (csetcall);
+ ccode.add_break ();
+
+ func_name = "%s_destroy_func".printf (type_param.name.ascii_down ());
+ enum_value = "%s_%s".printf (get_ccode_lower_case_name (cl, null),
func_name).ascii_up ();
+ ccode.add_case (new CCodeIdentifier (enum_value));
+ cfield = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new
CCodeIdentifier ("self"), "priv"), func_name);
+ csetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_set_pointer"));
+ csetcall.add_argument (new CCodeIdentifier ("value"));
+ csetcall.add_argument (cfield);
+ ccode.add_expression (csetcall);
+ ccode.add_break ();
+ }
ccode.add_default ();
emit_invalid_property_id_warn ();
ccode.add_break ();
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 95c67c6a0..0265bc99c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -502,6 +502,7 @@ TESTS = \
generics/constructor-chain-up.vala \
generics/inference-static-function.vala \
generics/parameter-sizeof-initializer.vala \
+ generics/type-parameter-properties.vala \
generics/bug640330.test \
generics/bug640330.vala \
generics/bug694765-1.vala \
diff --git a/tests/generics/type-parameter-properties.vala b/tests/generics/type-parameter-properties.vala
new file mode 100644
index 000000000..3004d198a
--- /dev/null
+++ b/tests/generics/type-parameter-properties.vala
@@ -0,0 +1,29 @@
+class Foo<G> : Object {
+}
+
+class Bar<T> : Foo<T> {
+}
+
+void main () {
+ var bar = new Bar<string> ();
+ {
+ Type type;
+ BoxedCopyFunc dup_func;
+ DestroyNotify destroy_func;
+
+ bar.get ("t-type", out type, "t-dup-func", out dup_func, "t-destroy-func", out destroy_func);
+ assert (type == typeof(string));
+ assert (dup_func == (BoxedCopyFunc) string.dup);
+ assert (destroy_func == (DestroyNotify) free);
+ }
+ {
+ Type type;
+ BoxedCopyFunc dup_func;
+ DestroyNotify destroy_func;
+
+ bar.get ("g-type", out type, "g-dup-func", out dup_func, "g-destroy-func", out destroy_func);
+ assert (type == typeof(string));
+ assert (dup_func == (BoxedCopyFunc) string.dup);
+ assert (destroy_func == (DestroyNotify) free);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]