[vala/staging] codegen: Add get_variable_array_length_cname() and use as possible



commit 48f26fa2e995a90efaca4abe28dfc21733f918d7
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Feb 24 21:39:47 2019 +0100

    codegen: Add get_variable_array_length_cname() and use as possible
    
    This also replaces get_parameter_array_length_cname()

 codegen/valaccodearraymodule.vala        | 12 ++++++------
 codegen/valaccodebasemodule.vala         |  9 +++++----
 codegen/valaccodedelegatemodule.vala     |  2 +-
 codegen/valaccodememberaccessmodule.vala | 20 ++++----------------
 codegen/valaccodestructmodule.vala       |  7 +------
 codegen/valagasyncmodule.vala            |  2 +-
 codegen/valagdbusclientmodule.vala       |  2 +-
 codegen/valagdbusservermodule.vala       | 10 +++++-----
 codegen/valagtypemodule.vala             | 14 ++------------
 9 files changed, 26 insertions(+), 52 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 66cf9f402..07a9a5399 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -114,12 +114,12 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                return "%s_length%d".printf (array_cname, dim);
        }
 
-       public override string get_parameter_array_length_cname (Parameter param, int dim) {
-               if (get_ccode_array_length_name (param) != null) {
-                       return get_ccode_array_length_name (param);
-               } else {
-                       return get_array_length_cname (get_ccode_name (param), dim);
+       public override string get_variable_array_length_cname (Variable variable, int dim) {
+               string? length_cname = get_ccode_array_length_name (variable);
+               if (length_cname == null) {
+                       length_cname = get_array_length_cname (get_ccode_name (variable), dim);
                }
+               return (!) length_cname;
        }
 
        public override CCodeExpression get_array_length_cexpression (Expression array_expr, int dim = -1) {
@@ -750,7 +750,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                        }
 
                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                               var cparam = new CCodeParameter (get_parameter_array_length_cname (param, 
dim), length_ctype);
+                               var cparam = new CCodeParameter (get_variable_array_length_cname (param, 
dim), length_ctype);
                                cparam_map.set (get_param_pos (get_ccode_array_length_pos (param) + 0.01 * 
dim), cparam);
                                if (carg_map != null) {
                                        carg_map.set (get_param_pos (get_ccode_array_length_pos (param) + 
0.01 * dim), get_cexpression (cparam.name));
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 10be7e44f..533d230fd 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1977,7 +1977,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                if (array_type != null && get_ccode_array_length (param)) {
                        var length_ctype = get_ccode_array_length_type (array_type);
                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                               data.add_field (length_ctype, get_parameter_array_length_cname (param, dim));
+                               data.add_field (length_ctype, get_variable_array_length_cname (param, dim));
                        }
                } else if (deleg_type != null && deleg_type.delegate_symbol.has_target) {
                        data.add_field (get_ccode_name (delegate_target_type), get_ccode_delegate_target_name 
(param));
@@ -3851,8 +3851,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                var array_type = param.variable_type as ArrayType;
                if (array_type != null && !array_type.fixed_length && get_ccode_array_length (param)) {
                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                               ccode.open_if (get_cexpression (get_parameter_array_length_cname (param, 
dim)));
-                               ccode.add_assignment (new CCodeUnaryExpression 
(CCodeUnaryOperator.POINTER_INDIRECTION, get_cexpression (get_parameter_array_length_cname (param, dim))), 
get_array_length_cvalue (value, dim));
+                               string length_cname = get_variable_array_length_cname (param, dim);
+                               ccode.open_if (get_cexpression (length_cname));
+                               ccode.add_assignment (new CCodeUnaryExpression 
(CCodeUnaryOperator.POINTER_INDIRECTION, get_cexpression (length_cname)), get_array_length_cvalue (value, 
dim));
                                ccode.close ();
                        }
                }
@@ -6662,7 +6663,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                return "";
        }
 
-       public virtual string get_parameter_array_length_cname (Parameter param, int dim) {
+       public virtual string get_variable_array_length_cname (Variable variable, int dim) {
                return "";
        }
 
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index c82364699..ef2bd1179 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -335,7 +335,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                                        } else if (!get_ccode_array_length (d_params.get (i))) {
                                                clength = new CCodeConstant ("-1");
                                        } else {
-                                               clength = new CCodeIdentifier 
(get_parameter_array_length_cname (d_params.get (i), dim));
+                                               clength = new CCodeIdentifier 
(get_variable_array_length_cname (d_params.get (i), dim));
                                        }
                                        carg_map.set (get_param_pos (get_ccode_array_length_pos (param) + 
0.01 * dim), clength);
                                }
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index f49d93b1a..5ef5f4eb9 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -471,7 +471,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                                result.cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression 
("_data%d_".printf (get_block_id (block))), get_ccode_name (param));
                                if (array_type != null && get_ccode_array_length (param)) {
                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                               result.append_array_length_cvalue (new 
CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), 
get_parameter_array_length_cname (param, dim)));
+                                               result.append_array_length_cvalue (new 
CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), 
get_variable_array_length_cname (param, dim)));
                                        }
                                } else if (delegate_type != null && delegate_type.delegate_symbol.has_target) 
{
                                        result.delegate_target_cvalue = new CCodeMemberAccess.pointer 
(get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_ccode_delegate_target_name (param));
@@ -535,7 +535,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                        if (!param.captured && array_type != null) {
                                if (get_ccode_array_length (param) && !get_ccode_array_null_terminated 
(param)) {
                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                               CCodeExpression length_expr = get_cexpression 
(get_parameter_array_length_cname (param, dim));
+                                               CCodeExpression length_expr = get_cexpression 
(get_variable_array_length_cname (param, dim));
                                                if (param.direction == ParameterDirection.OUT) {
                                                        length_expr = get_cexpression (get_array_length_cname 
(name, dim));
                                                } else if (param.direction == ParameterDirection.REF) {
@@ -605,13 +605,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                        if (array_type != null && get_ccode_array_length (field)) {
                                for (int dim = 1; dim <= array_type.rank; dim++) {
                                        CCodeExpression length_expr = null;
-
-                                       string length_cname;
-                                       if (get_ccode_array_length_name (field) != null) {
-                                               length_cname = get_ccode_array_length_name (field);
-                                       } else {
-                                               length_cname = get_array_length_cname (get_ccode_name 
(field), dim);
-                                       }
+                                       string length_cname = get_variable_array_length_cname (field, dim);
 
                                        if (((TypeSymbol) field.parent_symbol).is_reference_type ()) {
                                                length_expr = new CCodeMemberAccess.pointer (inst, 
length_cname);
@@ -684,13 +678,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 
                        if (array_type != null && get_ccode_array_length (field)) {
                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                       string length_cname;
-                                       if (get_ccode_array_length_name (field) != null) {
-                                               length_cname = get_ccode_array_length_name (field);
-                                       } else {
-                                               length_cname = get_array_length_cname (get_ccode_name 
(field), dim);
-                                       }
-
+                                       string length_cname = get_variable_array_length_cname (field, dim);
                                        result.append_array_length_cvalue (new CCodeIdentifier 
(length_cname));
                                }
                                if (array_type.rank == 1 && field.is_internal_symbol ()) {
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 0baa75233..048cbb790 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -88,12 +88,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
                                                var length_ctype = get_ccode_array_length_type (array_type);
 
                                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                       string length_cname;
-                                                       if (get_ccode_array_length_name (f) != null) {
-                                                               length_cname = get_ccode_array_length_name 
(f);
-                                                       } else {
-                                                               length_cname = get_array_length_cname 
(get_ccode_name (f), dim);
-                                                       }
+                                                       string length_cname = get_variable_array_length_cname 
(f, dim);
                                                        instance_struct.add_field (length_ctype, 
length_cname);
                                                }
 
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index 459cdca46..65ba99ff5 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -60,7 +60,7 @@ public class Vala.GAsyncModule : GtkModule {
                                if (get_ccode_array_length (param)) {
                                        var length_ctype = get_ccode_array_length_type (array_type);
                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                               data.add_field (length_ctype, 
get_parameter_array_length_cname (param, dim));
+                                               data.add_field (length_ctype, get_variable_array_length_cname 
(param, dim));
                                        }
                                }
                        } else if (param.variable_type is DelegateType) {
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index 8961af672..5303975ea 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -475,7 +475,7 @@ public class Vala.GDBusClientModule : GDBusModule {
                                var length_ctype = get_ccode_array_length_type (array_type);
 
                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                       string length_cname = get_parameter_array_length_cname (param, dim);
+                                       string length_cname = get_variable_array_length_cname (param, dim);
 
                                        ccode.add_declaration (length_ctype, new CCodeVariableDeclarator 
(length_cname, new CCodeConstant ("0")));
                                        ccall.add_argument (new CCodeIdentifier (length_cname));
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index 0d5a323a4..01fbef616 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -152,7 +152,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                                if (array_type != null) {
                                        var length_ctype = get_ccode_array_length_type (array_type);
                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                               string length_cname = get_parameter_array_length_cname 
(param, dim);
+                                               string length_cname = get_variable_array_length_cname (param, 
dim);
 
                                                if (ready_data_struct != null) {
                                                        ready_data_struct.add_field (length_ctype, 
length_cname);
@@ -234,7 +234,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                        var array_type = param.variable_type as ArrayType;
                        if (array_type != null) {
                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                       string length_cname = get_parameter_array_length_cname (param, dim);
+                                       string length_cname = get_variable_array_length_cname (param, dim);
 
                                        CCodeExpression length_expr;
                                        if (ready_data_expr != null && param.direction == 
ParameterDirection.IN)
@@ -343,7 +343,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                                if (array_type != null) {
                                        var length_ctype = get_ccode_array_length_type (array_type);
                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                               string length_cname = get_parameter_array_length_cname 
(param, dim);
+                                               string length_cname = get_variable_array_length_cname (param, 
dim);
 
                                                ccode.add_declaration (length_ctype, new 
CCodeVariableDeclarator.zero (length_cname, new CCodeConstant ("0")));
                                        }
@@ -454,7 +454,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                                                var array_type = owned_type as ArrayType;
                                                if (array_type != null) {
                                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                               string length_cname = 
get_parameter_array_length_cname (param, dim);
+                                                               string length_cname = 
get_variable_array_length_cname (param, dim);
 
                                                                target.append_array_length_cvalue (new 
CCodeMemberAccess.pointer (ready_data_expr, length_cname));
                                                        }
@@ -509,7 +509,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                                var array_type = (ArrayType) param.variable_type;
                                var length_ctype = get_ccode_array_length_type (array_type);
                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                       function.add_parameter (new CCodeParameter 
(get_parameter_array_length_cname (param, dim), length_ctype));
+                                       function.add_parameter (new CCodeParameter 
(get_variable_array_length_cname (param, dim), length_ctype));
                                }
                        }
                }
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index af53b8370..77838f792 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -419,12 +419,7 @@ public class Vala.GTypeModule : GErrorModule {
                                        var length_ctype = get_ccode_array_length_type (array_type);
 
                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                               string length_cname;
-                                               if (get_ccode_array_length_name (f) != null) {
-                                                       length_cname = get_ccode_array_length_name (f);
-                                               } else {
-                                                       length_cname = get_array_length_cname (get_ccode_name 
(f), dim);
-                                               }
+                                               string length_cname = get_variable_array_length_cname (f, 
dim);
                                                instance_struct.add_field (length_ctype, length_cname);
                                        }
 
@@ -521,12 +516,7 @@ public class Vala.GTypeModule : GErrorModule {
                                                        var length_ctype = get_ccode_array_length_type 
(array_type);
 
                                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                               string length_cname;
-                                                               if (get_ccode_array_length_name (f) != null) {
-                                                                       length_cname = 
get_ccode_array_length_name (f);
-                                                               } else {
-                                                                       length_cname = get_array_length_cname 
(get_ccode_name (f), dim);
-                                                               }
+                                                               string length_cname = 
get_variable_array_length_cname (f, dim);
                                                                instance_priv_struct.add_field (length_ctype, 
length_cname);
                                                        }
 


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