[vala/wip/array-length-type: 5/6] codegen: Support marshalling ArrayType.length_type in signals



commit 0df7e19ac58e9295ca7f821049eeb0186a083b14
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Oct 31 10:21:52 2018 +0100

    codegen: Support marshalling ArrayType.length_type in signals

 codegen/valaccodeattribute.vala | 10 ++++++----
 codegen/valagsignalmodule.vala  | 18 ++++++++++--------
 2 files changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index b6f60498c..dc1e87b49 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -1044,12 +1044,14 @@ public class Vala.CCodeAttribute : AttributeCache {
                } else if (node is ErrorType) {
                        return "POINTER";
                } else if (node is ArrayType) {
-                       if (((ArrayType) node).element_type.data_type.get_full_name () == "string") {
-                               return "BOXED,INT";
+                       unowned ArrayType array_type = (ArrayType) node;
+                       if (array_type.element_type.data_type.get_full_name () == "string") {
+                               return "BOXED,%s".printf (get_ccode_marshaller_type_name 
(array_type.length_type.data_type));
                        } else {
                                var ret = "POINTER";
-                               for (var i = 0; i < ((ArrayType) node).rank; i++) {
-                                       ret = "%s,INT".printf (ret);
+                               var length_marshaller_type_name = get_ccode_marshaller_type_name 
(array_type.length_type.data_type);
+                               for (var i = 0; i < array_type.rank; i++) {
+                                       ret = "%s,%s".printf (ret, length_marshaller_type_name);
                                }
                                return ret;
                        }
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index fc8a03bbe..966deef44 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -194,9 +194,7 @@ public class Vala.GSignalModule : GObjectModule {
                        n_params++;
                        if (p.variable_type is ArrayType) {
                                var array_type = (ArrayType) p.variable_type;
-                               //FIXME Only int length-type
-                               //var length_ctype = get_ccode_array_length_type (array_type);
-                               var length_ctype = get_ccode_name (int_type);
+                               var length_ctype = get_ccode_array_length_type (array_type);
                                for (var j = 0; j < array_type.rank; j++) {
                                        callback_decl.add_parameter (new CCodeParameter ("arg_%d".printf 
(n_params), length_ctype));
                                        n_params++;
@@ -270,9 +268,10 @@ public class Vala.GSignalModule : GObjectModule {
                        i++;
                        if (p.variable_type is ArrayType) {
                                var array_type = (ArrayType) p.variable_type;
+                               var length_value_function = get_ccode_get_value_function 
(array_type.length_type.data_type);
+                               assert (length_value_function != null && length_value_function != "");
                                for (var j = 0; j < array_type.rank; j++) {
-                                       //FIXME Only int length-type
-                                       inner_fc = new CCodeFunctionCall (new CCodeIdentifier 
("g_value_get_int"));
+                                       inner_fc = new CCodeFunctionCall (new CCodeIdentifier 
(length_value_function));
                                        inner_fc.add_argument (new CCodeBinaryExpression 
(CCodeBinaryOperator.PLUS, new CCodeIdentifier ("param_values"), new CCodeIdentifier (i.to_string ())));
                                        fc.add_argument (inner_fc);
                                        i++;
@@ -399,13 +398,16 @@ public class Vala.GSignalModule : GObjectModule {
                csignew.add_argument (new CCodeConstant ("%d".printf (params_len)));
                foreach (Parameter param in params) {
                        if (param.variable_type is ArrayType) {
-                               if (((ArrayType) param.variable_type).element_type.data_type == 
string_type.data_type) {
+                               var array_type = (ArrayType) param.variable_type;
+                               if (array_type.element_type.data_type == string_type.data_type) {
                                        csignew.add_argument (new CCodeConstant ("G_TYPE_STRV"));
                                } else {
                                        csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
                                }
-                               for (var i = 0; i < ((ArrayType) param.variable_type).rank; i++) {
-                                       csignew.add_argument (new CCodeConstant ("G_TYPE_INT"));
+                               assert (get_ccode_has_type_id (array_type.length_type.data_type));
+                               var length_type_id = get_ccode_type_id (array_type.length_type.data_type);
+                               for (var i = 0; i < array_type.rank; i++) {
+                                       csignew.add_argument (new CCodeConstant (length_type_id));
                                }
                        } else if (param.variable_type is PointerType || param.variable_type is GenericType 
|| param.direction != ParameterDirection.IN) {
                                csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));


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