[vala/wip/array-helper: 3/3] codegen: Create only one vala-array helper function per array-type



commit 93f5b6e9eb4cf69787274c0565cd38bc9f466a2e
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Feb 4 23:38:48 2016 +0100

    codegen: Create only one vala-array helper function per array-type

 codegen/valaccodearraymodule.vala |   31 +++++++++++++++++++++++++------
 1 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 8922464..45b49d4 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -24,9 +24,6 @@
 
 
 public class Vala.CCodeArrayModule : CCodeMethodCallModule {
-       int next_array_dup_id = 0;
-       int next_array_add_id = 0;
-
        void append_initializer_list (CCodeExpression name_cnode, InitializerList initializer_list, int rank, 
ref int i) {
                foreach (Expression e in initializer_list.get_initializers ()) {
                        if (rank > 1) {
@@ -461,8 +458,28 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                }
        }
 
+       static uint get_attributes_flag (DataType type) {
+               uint result = 0U;
+
+               if (type.value_owned)
+                       result += 1 << 0;
+               if (type.nullable)
+                       result += 1 << 1;
+               if (type.floating_reference)
+                       result += 1 << 2;
+               if (type.is_dynamic)
+                       result += 1 << 3;
+               if (type.is_real_struct_type ())
+                       result += 1 << 10;
+               if (type.is_reference_type_or_type_parameter ())
+                       result += 1 << 11;
+
+               return result;
+       }
+
        string generate_array_dup_wrapper (ArrayType array_type) {
-               string dup_func = "_vala_array_dup%d".printf (++next_array_dup_id);
+               string dup_func = "_vala_%s_%x_array_dup".printf (get_ccode_lower_case_name 
(array_type.element_type),
+                       get_attributes_flag (array_type.element_type));
 
                if (!add_wrapper (dup_func)) {
                        // wrapper already defined
@@ -535,7 +552,8 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
        }
 
        string generate_array_copy_wrapper (ArrayType array_type) {
-               string dup_func = "_vala_array_copy%d".printf (++next_array_dup_id);
+               string dup_func = "_vala_%s_%x_array_copy".printf (get_ccode_lower_case_name 
(array_type.element_type),
+                       get_attributes_flag (array_type.element_type));
 
                if (!add_wrapper (dup_func)) {
                        // wrapper already defined
@@ -589,7 +607,8 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
        }
 
        string generate_array_add_wrapper (ArrayType array_type) {
-               string add_func = "_vala_array_add%d".printf (++next_array_add_id);
+               string add_func = "_vala_%s_%x_array_add".printf (get_ccode_lower_case_name 
(array_type.element_type),
+                       get_attributes_flag (array_type.element_type));
 
                if (!add_wrapper (add_func)) {
                        // wrapper already defined


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