]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Unify handling of GenericType arguments/parameters
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 18 Apr 2021 19:02:21 +0000 (21:02 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 19 Apr 2021 06:56:10 +0000 (08:56 +0200)
codegen/valaccodearraymodule.vala
codegen/valaccodebasemodule.vala
codegen/valaccodemethodcallmodule.vala
codegen/valaccodemethodmodule.vala
codegen/valagasyncmodule.vala
codegen/valagirwriter.vala
codegen/valagobjectmodule.vala
codegen/valagtypemodule.vala

index 100dca58e2059e3b4b165567a3f893a5a14976fe..cb1568d77033796dc0f07c72a0bfd866509d6b9d 100644 (file)
@@ -559,8 +559,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                function.add_parameter (new CCodeParameter ("length", get_ccode_name (ssize_t_type)));
                if (array_type.element_type is GenericType) {
                        // dup function array elements
-                       string func_name = "%s_dup_func".printf (((GenericType) array_type.element_type).type_parameter.name.ascii_down ());
-                       function.add_parameter (new CCodeParameter (func_name, "GBoxedCopyFunc"));
+                       function.add_parameter (new CCodeParameter (get_ccode_copy_function (((GenericType) array_type.element_type).type_parameter), "GBoxedCopyFunc"));
                }
 
                // definition
index 0dfaacf67d4f9e056cf49ddedee2a8fb6e89991a..759a8499ca15b8f9a84a9d1010280f2017421c06 100644 (file)
@@ -2180,16 +2180,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                if (current_method != null) {
                                        // allow capturing generic type parameters
                                        foreach (var type_param in current_method.get_type_parameters ()) {
-                                               string func_name;
-
-                                               func_name = "%s_type".printf (type_param.name.ascii_down ());
-                                               data.add_field ("GType", func_name);
-
-                                               func_name = "%s_dup_func".printf (type_param.name.ascii_down ());
-                                               data.add_field ("GBoxedCopyFunc", func_name);
-
-                                               func_name = "%s_destroy_func".printf (type_param.name.ascii_down ());
-                                               data.add_field ("GDestroyNotify", func_name);
+                                               data.add_field ("GType", get_ccode_type_id (type_param));
+                                               data.add_field ("GBoxedCopyFunc", get_ccode_copy_function (type_param));
+                                               data.add_field ("GDestroyNotify", get_ccode_destroy_function (type_param));
                                        }
                                }
                        }
@@ -2256,12 +2249,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                                if (current_method != null) {
                                        // allow capturing generic type parameters
-                                       var suffices = new string[] {"type", "dup_func", "destroy_func"};
+                                       var data_var = get_variable_cexpression ("_data%d_".printf (block_id));
                                        foreach (var type_param in current_method.get_type_parameters ()) {
-                                               foreach (string suffix in suffices) {
-                                                       string func_name = "%s_%s".printf (type_param.name.ascii_down (), suffix);
-                                                       ccode.add_assignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name), get_variable_cexpression (func_name));
-                                               }
+                                               var type = get_ccode_type_id (type_param);
+                                               var dup_func = get_ccode_copy_function (type_param);
+                                               var destroy_func = get_ccode_destroy_function (type_param);
+                                               ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, type), get_variable_cexpression (type));
+                                               ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, dup_func), get_variable_cexpression (dup_func));
+                                               ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, destroy_func), get_variable_cexpression (destroy_func));
                                        }
                                }
                        }
@@ -2355,19 +2350,15 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        if (current_method != null) {
                                // assign captured generic type parameters
                                foreach (var type_param in current_method.get_type_parameters ()) {
-                                       string func_name;
-
-                                       func_name = "%s_type".printf (type_param.name.ascii_down ());
-                                       ccode.add_declaration ("GType", new CCodeVariableDeclarator (func_name));
-                                       ccode.add_assignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (outer_block, func_name));
-
-                                       func_name = "%s_dup_func".printf (type_param.name.ascii_down ());
-                                       ccode.add_declaration ("GBoxedCopyFunc", new CCodeVariableDeclarator (func_name));
-                                       ccode.add_assignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (outer_block, func_name));
-
-                                       func_name = "%s_destroy_func".printf (type_param.name.ascii_down ());
-                                       ccode.add_declaration ("GDestroyNotify", new CCodeVariableDeclarator (func_name));
-                                       ccode.add_assignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (outer_block, func_name));
+                                       var type = get_ccode_type_id (type_param);
+                                       var dup_func = get_ccode_copy_function (type_param);
+                                       var destroy_func = get_ccode_destroy_function (type_param);
+                                       ccode.add_declaration ("GType", new CCodeVariableDeclarator (type));
+                                       ccode.add_declaration ("GBoxedCopyFunc", new CCodeVariableDeclarator (dup_func));
+                                       ccode.add_declaration ("GDestroyNotify", new CCodeVariableDeclarator (destroy_func));
+                                       ccode.add_assignment (new CCodeIdentifier (type), new CCodeMemberAccess.pointer (outer_block, type));
+                                       ccode.add_assignment (new CCodeIdentifier (dup_func), new CCodeMemberAccess.pointer (outer_block, dup_func));
+                                       ccode.add_assignment (new CCodeIdentifier (destroy_func), new CCodeMemberAccess.pointer (outer_block, destroy_func));
                                }
                        }
 
@@ -2928,7 +2919,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
        public CCodeExpression get_type_id_expression (DataType type, bool is_chainup = false) {
                if (type is GenericType) {
                        var type_parameter = ((GenericType) type).type_parameter;
-                       string identifier = "%s_type".printf (type_parameter.name.ascii_down ());
+                       string identifier = get_ccode_type_id (type_parameter);
                        return get_generic_type_expression (identifier, (GenericType) type, is_chainup);
                } else {
                        string type_id = get_ccode_type_id (type);
@@ -2946,7 +2937,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        return new CCodeIdentifier ("g_error_copy");
                } else if (type is GenericType) {
                        var type_parameter = ((GenericType) type).type_parameter;
-                       string identifier = "%s_dup_func".printf (type_parameter.name.ascii_down ());
+                       string identifier = get_ccode_copy_function (type_parameter);
                        return get_generic_type_expression (identifier, (GenericType) type, is_chainup);
                } else if (type.type_symbol != null) {
                        string dup_function;
@@ -3463,7 +3454,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        return new CCodeIdentifier ("g_error_free");
                } else if (type is GenericType) {
                        var type_parameter = ((GenericType) type).type_parameter;
-                       string identifier = "%s_destroy_func".printf (type_parameter.name.ascii_down ());
+                       string identifier = get_ccode_destroy_function (type_parameter);
                        return get_generic_type_expression (identifier, (GenericType) type, is_chainup);
                } else if (type.type_symbol != null) {
                        string unref_function;
index 4d6a9ff5a60684bbeac188167d223c810c225a68..c400dc2e9b450d16da37eeb9627ea8e51d619c64 100644 (file)
@@ -196,9 +196,9 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                        int type_param_index = 0;
                                        var cl = (Class) m.parent_symbol;
                                        foreach (TypeParameter type_param in cl.get_type_parameters ()) {
-                                               in_arg_map.set (get_param_pos (0.1 * type_param_index + 0.01), new CCodeIdentifier ("%s_type".printf (type_param.name.ascii_down ())));
-                                               in_arg_map.set (get_param_pos (0.1 * type_param_index + 0.02), new CCodeIdentifier ("%s_dup_func".printf (type_param.name.ascii_down ())));
-                                               in_arg_map.set (get_param_pos (0.1 * type_param_index + 0.03), new CCodeIdentifier ("%s_destroy_func".printf (type_param.name.ascii_down ())));
+                                               in_arg_map.set (get_param_pos (0.1 * type_param_index + 0.01), new CCodeIdentifier (get_ccode_type_id (type_param)));
+                                               in_arg_map.set (get_param_pos (0.1 * type_param_index + 0.02), new CCodeIdentifier (get_ccode_copy_function (type_param)));
+                                               in_arg_map.set (get_param_pos (0.1 * type_param_index + 0.03), new CCodeIdentifier (get_ccode_destroy_function (type_param)));
                                                type_param_index++;
                                        }
                                }
@@ -384,14 +384,14 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 
                        if (!current_class.is_compact && current_class.has_type_parameters ()) {
                                /* type, dup func, and destroy func fields for generic types */
-                               var suffices = new string[] {"type", "dup_func", "destroy_func"};
+                               var priv_access = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv");
                                foreach (TypeParameter type_param in current_class.get_type_parameters ()) {
-                                       var priv_access = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv");
-
-                                       foreach (string suffix in suffices) {
-                                               var param_name = new CCodeIdentifier ("%s_%s".printf (type_param.name.ascii_down (), suffix));
-                                               ccode.add_assignment (new CCodeMemberAccess.pointer (priv_access, param_name.name), param_name);
-                                       }
+                                       var type = get_ccode_type_id (type_param);
+                                       var dup_func = get_ccode_copy_function (type_param);
+                                       var destroy_func = get_ccode_destroy_function (type_param);
+                                       ccode.add_assignment (new CCodeMemberAccess.pointer (priv_access, type), new CCodeIdentifier (type));
+                                       ccode.add_assignment (new CCodeMemberAccess.pointer (priv_access, dup_func), new CCodeIdentifier (dup_func));
+                                       ccode.add_assignment (new CCodeMemberAccess.pointer (priv_access, destroy_func), new CCodeIdentifier (destroy_func));
                                }
                        }
                        // object chainup can't be used as expression
index 944d6a00a42049bfa7198ea491a60ce56109bddd..df3b8b274b4e45a74d9678de22069e323b1ac284 100644 (file)
@@ -504,20 +504,17 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                                        }
 
                                        // allow capturing generic type parameters
+                                       var data_var = get_variable_cexpression ("_data%d_".printf (block_id));
                                        foreach (var type_param in m.get_type_parameters ()) {
-                                               string func_name;
-
-                                               func_name = "%s_type".printf (type_param.name.ascii_down ());
-                                               ccode.add_declaration ("GType", new CCodeVariableDeclarator (func_name));
-                                               ccode.add_assignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name));
-
-                                               func_name = "%s_dup_func".printf (type_param.name.ascii_down ());
-                                               ccode.add_declaration ("GBoxedCopyFunc", new CCodeVariableDeclarator (func_name));
-                                               ccode.add_assignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name));
-
-                                               func_name = "%s_destroy_func".printf (type_param.name.ascii_down ());
-                                               ccode.add_declaration ("GDestroyNotify", new CCodeVariableDeclarator (func_name));
-                                               ccode.add_assignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name));
+                                               var type = get_ccode_type_id (type_param);
+                                               var dup_func = get_ccode_copy_function (type_param);
+                                               var destroy_func = get_ccode_destroy_function (type_param);
+                                               ccode.add_declaration ("GType", new CCodeVariableDeclarator (type));
+                                               ccode.add_declaration ("GBoxedCopyFunc", new CCodeVariableDeclarator (dup_func));
+                                               ccode.add_declaration ("GDestroyNotify", new CCodeVariableDeclarator (destroy_func));
+                                               ccode.add_assignment (new CCodeIdentifier (type), new CCodeMemberAccess.pointer (data_var, type));
+                                               ccode.add_assignment (new CCodeIdentifier (dup_func), new CCodeMemberAccess.pointer (data_var, dup_func));
+                                               ccode.add_assignment (new CCodeIdentifier (destroy_func), new CCodeMemberAccess.pointer (data_var, destroy_func));
                                        }
                                } else if (m.parent_symbol is Class && !m.coroutine) {
                                        var cl = (Class) m.parent_symbol;
@@ -607,23 +604,14 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                                                        ccode.add_assignment (get_this_cexpression (), new CCodeCastExpression (ccall, get_ccode_name (cl) + "*"));
 
                                                        /* type, dup func, and destroy func fields for generic types */
+                                                       var priv_access = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv");
                                                        foreach (TypeParameter type_param in current_class.get_type_parameters ()) {
-                                                               CCodeIdentifier param_name;
-                                                               CCodeAssignment assign;
-
-                                                               var priv_access = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv");
-
-                                                               param_name = new CCodeIdentifier ("%s_type".printf (type_param.name.ascii_down ()));
-                                                               assign = new CCodeAssignment (new CCodeMemberAccess.pointer (priv_access, param_name.name), param_name);
-                                                               ccode.add_expression (assign);
-
-                                                               param_name = new CCodeIdentifier ("%s_dup_func".printf (type_param.name.ascii_down ()));
-                                                               assign = new CCodeAssignment (new CCodeMemberAccess.pointer (priv_access, param_name.name), param_name);
-                                                               ccode.add_expression (assign);
-
-                                                               param_name = new CCodeIdentifier ("%s_destroy_func".printf (type_param.name.ascii_down ()));
-                                                               assign = new CCodeAssignment (new CCodeMemberAccess.pointer (priv_access, param_name.name), param_name);
-                                                               ccode.add_expression (assign);
+                                                               var type = get_ccode_type_id (type_param);
+                                                               var dup_func = get_ccode_copy_function (type_param);
+                                                               var destroy_func = get_ccode_destroy_function (type_param);
+                                                               ccode.add_assignment (new CCodeMemberAccess.pointer (priv_access, type), new CCodeIdentifier (type));
+                                                               ccode.add_assignment (new CCodeMemberAccess.pointer (priv_access, dup_func), new CCodeIdentifier (dup_func));
+                                                               ccode.add_assignment (new CCodeMemberAccess.pointer (priv_access, destroy_func), new CCodeIdentifier (destroy_func));
                                                        }
                                                }
                                        } else if (current_type_symbol is Class) {
@@ -988,13 +976,16 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                if (type_parameters != null) {
                        int type_param_index = 0;
                        foreach (var type_param in type_parameters) {
-                               cparam_map.set (get_param_pos (0.1 * type_param_index + 0.01), new CCodeParameter ("%s_type".printf (type_param.name.ascii_down ()), "GType"));
-                               cparam_map.set (get_param_pos (0.1 * type_param_index + 0.02), new CCodeParameter ("%s_dup_func".printf (type_param.name.ascii_down ()), "GBoxedCopyFunc"));
-                               cparam_map.set (get_param_pos (0.1 * type_param_index + 0.03), new CCodeParameter ("%s_destroy_func".printf (type_param.name.ascii_down ()), "GDestroyNotify"));
+                               var type = get_ccode_type_id (type_param);
+                               var dup_func = get_ccode_copy_function (type_param);
+                               var destroy_func = get_ccode_destroy_function (type_param);
+                               cparam_map.set (get_param_pos (0.1 * type_param_index + 0.01), new CCodeParameter (type, "GType"));
+                               cparam_map.set (get_param_pos (0.1 * type_param_index + 0.02), new CCodeParameter (dup_func, "GBoxedCopyFunc"));
+                               cparam_map.set (get_param_pos (0.1 * type_param_index + 0.03), new CCodeParameter (destroy_func, "GDestroyNotify"));
                                if (carg_map != null) {
-                                       carg_map.set (get_param_pos (0.1 * type_param_index + 0.01), new CCodeIdentifier ("%s_type".printf (type_param.name.ascii_down ())));
-                                       carg_map.set (get_param_pos (0.1 * type_param_index + 0.02), new CCodeIdentifier ("%s_dup_func".printf (type_param.name.ascii_down ())));
-                                       carg_map.set (get_param_pos (0.1 * type_param_index + 0.03), new CCodeIdentifier ("%s_destroy_func".printf (type_param.name.ascii_down ())));
+                                       carg_map.set (get_param_pos (0.1 * type_param_index + 0.01), new CCodeIdentifier (type));
+                                       carg_map.set (get_param_pos (0.1 * type_param_index + 0.02), new CCodeIdentifier (dup_func));
+                                       carg_map.set (get_param_pos (0.1 * type_param_index + 0.03), new CCodeIdentifier (destroy_func));
                                }
                                type_param_index++;
                        }
index 6c59c7fe479f82375ac03a7df1ebdae638549065..7019f8ee6d1c71b60c96972c500d9ac383d974d2 100644 (file)
@@ -70,9 +70,9 @@ public class Vala.GAsyncModule : GtkModule {
                }
 
                foreach (var type_param in m.get_type_parameters ()) {
-                       data.add_field ("GType", "%s_type".printf (type_param.name.ascii_down ()));
-                       data.add_field ("GBoxedCopyFunc", "%s_dup_func".printf (type_param.name.ascii_down ()));
-                       data.add_field ("GDestroyNotify", "%s_destroy_func".printf (type_param.name.ascii_down ()));
+                       data.add_field ("GType", get_ccode_type_id (type_param));
+                       data.add_field ("GBoxedCopyFunc", get_ccode_copy_function (type_param));
+                       data.add_field ("GDestroyNotify", get_ccode_destroy_function (type_param));
                }
 
                if (!(m.return_type is VoidType)) {
@@ -313,9 +313,9 @@ public class Vala.GAsyncModule : GtkModule {
                emit_context.pop_symbol ();
 
                foreach (var type_param in m.get_type_parameters ()) {
-                       var type = "%s_type".printf (type_param.name.ascii_down ());
-                       var dup_func = "%s_dup_func".printf (type_param.name.ascii_down ());
-                       var destroy_func = "%s_destroy_func".printf (type_param.name.ascii_down ());
+                       var type = get_ccode_type_id (type_param);
+                       var dup_func = get_ccode_copy_function (type_param);
+                       var destroy_func = get_ccode_destroy_function (type_param);
                        ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, type), new CCodeIdentifier (type));
                        ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, dup_func), new CCodeIdentifier (dup_func));
                        ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, destroy_func), new CCodeIdentifier (destroy_func));
index acb19c8db3654b3989c2339a571781126c77b47f..d60c3da3dc2780e4ea5c7f975874c6abdb5a5ba0 100644 (file)
@@ -1099,9 +1099,9 @@ public class Vala.GIRWriter : CodeVisitor {
        private void write_type_parameter (TypeParameter type_parameter, string tag_type) {
                write_indent ();
                if (tag_type == "property") {
-                       buffer.append_printf ("<%s name=\"%s-type\" writable=\"1\" construct-only=\"1\">\n", tag_type, type_parameter.name.ascii_down ());
+                       buffer.append_printf ("<%s name=\"%s\" writable=\"1\" construct-only=\"1\">\n", tag_type, get_ccode_type_id (type_parameter).replace ("_", "-"));
                } else {
-                       buffer.append_printf ("<%s name=\"%s_type\" transfer-ownership=\"none\">\n", tag_type, type_parameter.name.ascii_down ());
+                       buffer.append_printf ("<%s name=\"%s\" transfer-ownership=\"none\">\n", tag_type, get_ccode_type_id (type_parameter));
                }
                indent++;
                write_indent ();
@@ -1111,9 +1111,9 @@ public class Vala.GIRWriter : CodeVisitor {
                buffer.append_printf ("</%s>\n", tag_type);
                write_indent ();
                if (tag_type == "property") {
-                       buffer.append_printf ("<%s name=\"%s-dup-func\" writable=\"1\" construct-only=\"1\">\n", tag_type, type_parameter.name.ascii_down ());
+                       buffer.append_printf ("<%s name=\"%s\" writable=\"1\" construct-only=\"1\">\n", tag_type, get_ccode_copy_function (type_parameter).replace ("_", "-"));
                } else {
-                       buffer.append_printf ("<%s name=\"%s_dup_func\" transfer-ownership=\"none\">\n", tag_type, type_parameter.name.ascii_down ());
+                       buffer.append_printf ("<%s name=\"%s\" transfer-ownership=\"none\">\n", tag_type, get_ccode_copy_function (type_parameter));
                }
                indent++;
                write_indent ();
@@ -1123,9 +1123,9 @@ public class Vala.GIRWriter : CodeVisitor {
                buffer.append_printf ("</%s>\n", tag_type);
                write_indent ();
                if (tag_type == "property") {
-                       buffer.append_printf ("<%s name=\"%s-destroy-func\" writable=\"1\" construct-only=\"1\">\n", tag_type, type_parameter.name.ascii_down ());
+                       buffer.append_printf ("<%s name=\"%s\" writable=\"1\" construct-only=\"1\">\n", tag_type, get_ccode_destroy_function (type_parameter).replace ("_", "-"));
                } else {
-                       buffer.append_printf ("<%s name=\"%s_destroy_func\" transfer-ownership=\"none\">\n", tag_type, type_parameter.name.ascii_down ());
+                       buffer.append_printf ("<%s name=\"%s\" transfer-ownership=\"none\">\n", tag_type, get_ccode_destroy_function (type_parameter));
                }
                indent++;
                write_indent ();
index 30d7eace6e821771bafa8e610d1f22b9798251bd..238a67909890f35969e0fe99488da7c8e962530e 100644 (file)
@@ -79,11 +79,9 @@ public class Vala.GObjectModule : GTypeModule {
                        CCodeConstant func_name_constant;
                        CCodeFunctionCall cinst, cspec;
 
-                       var name_prefix = type_param.name.ascii_down ();
-                       var canonical_prefix = name_prefix.replace ("_", "-");
 
-                       func_name = "%s_type".printf (name_prefix);
-                       func_name_constant = new CCodeConstant ("\"%s-type\"".printf (canonical_prefix));
+                       func_name = get_ccode_type_id (type_param);
+                       func_name_constant = new CCodeConstant ("\"%s\"".printf (func_name.replace ("_", "-")));
                        enum_value = "%s_%s".printf (get_ccode_lower_case_name (cl, null), func_name).ascii_up ();
                        cinst = new CCodeFunctionCall (new CCodeIdentifier ("g_object_class_install_property"));
                        cinst.add_argument (ccall);
@@ -99,8 +97,8 @@ public class Vala.GObjectModule : GTypeModule {
                        prop_enum.add_value (new CCodeEnumValue (enum_value));
 
 
-                       func_name = "%s_dup_func".printf (name_prefix);
-                       func_name_constant = new CCodeConstant ("\"%s-dup-func\"".printf (canonical_prefix));
+                       func_name = get_ccode_copy_function (type_param);
+                       func_name_constant = new CCodeConstant ("\"%s\"".printf (func_name.replace ("_", "-")));
                        enum_value = "%s_%s".printf (get_ccode_lower_case_name (cl, null), func_name).ascii_up ();
                        cinst = new CCodeFunctionCall (new CCodeIdentifier ("g_object_class_install_property"));
                        cinst.add_argument (ccall);
@@ -115,8 +113,8 @@ public class Vala.GObjectModule : GTypeModule {
                        prop_enum.add_value (new CCodeEnumValue (enum_value));
 
 
-                       func_name = "%s_destroy_func".printf (name_prefix);
-                       func_name_constant = new CCodeConstant ("\"%s-destroy-func\"".printf (canonical_prefix));
+                       func_name = get_ccode_destroy_function (type_param);
+                       func_name_constant = new CCodeConstant ("\"%s\"".printf (func_name.replace ("_", "-")));
                        enum_value = "%s_%s".printf (get_ccode_lower_case_name (cl, null), func_name).ascii_up ();
                        cinst = new CCodeFunctionCall (new CCodeIdentifier ("g_object_class_install_property"));
                        cinst.add_argument (ccall);
@@ -291,7 +289,7 @@ public class Vala.GObjectModule : GTypeModule {
                        CCodeMemberAccess cfield;
                        CCodeFunctionCall csetcall;
 
-                       func_name = "%s_type".printf (type_param.name.ascii_down ());
+                       func_name = get_ccode_type_id (type_param);
                        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);
@@ -301,7 +299,7 @@ public class Vala.GObjectModule : GTypeModule {
                        ccode.add_expression (csetcall);
                        ccode.add_break ();
 
-                       func_name = "%s_dup_func".printf (type_param.name.ascii_down ());
+                       func_name = get_ccode_copy_function (type_param);
                        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);
@@ -311,7 +309,7 @@ public class Vala.GObjectModule : GTypeModule {
                        ccode.add_expression (csetcall);
                        ccode.add_break ();
 
-                       func_name = "%s_destroy_func".printf (type_param.name.ascii_down ());
+                       func_name = get_ccode_destroy_function (type_param);
                        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);
@@ -422,7 +420,7 @@ public class Vala.GObjectModule : GTypeModule {
                        CCodeMemberAccess cfield;
                        CCodeFunctionCall cgetcall;
 
-                       func_name = "%s_type".printf (type_param.name.ascii_down ());
+                       func_name = get_ccode_type_id (type_param);
                        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);
@@ -431,7 +429,7 @@ public class Vala.GObjectModule : GTypeModule {
                        ccode.add_assignment (cfield, cgetcall);
                        ccode.add_break ();
 
-                       func_name = "%s_dup_func".printf (type_param.name.ascii_down ());
+                       func_name = get_ccode_copy_function (type_param);
                        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);
@@ -440,7 +438,7 @@ public class Vala.GObjectModule : GTypeModule {
                        ccode.add_assignment (cfield, cgetcall);
                        ccode.add_break ();
 
-                       func_name = "%s_destroy_func".printf (type_param.name.ascii_down ());
+                       func_name = get_ccode_destroy_function (type_param);
                        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);
index 1a0e0d1b31f1994e8f6758c886808d4a3d3e76c6..138201008fa0a5ce12be0b76f524373ee0cb2501 100644 (file)
@@ -488,16 +488,9 @@ public class Vala.GTypeModule : GErrorModule {
                if (is_gtypeinstance) {
                        /* create type, dup_func, and destroy_func fields for generic types */
                        foreach (TypeParameter type_param in cl.get_type_parameters ()) {
-                               string func_name;
-
-                               func_name = "%s_type".printf (type_param.name.ascii_down ());
-                               instance_priv_struct.add_field ("GType", func_name);
-
-                               func_name = "%s_dup_func".printf (type_param.name.ascii_down ());
-                               instance_priv_struct.add_field ("GBoxedCopyFunc", func_name);
-
-                               func_name = "%s_destroy_func".printf (type_param.name.ascii_down ());
-                               instance_priv_struct.add_field ("GDestroyNotify", func_name);
+                               instance_priv_struct.add_field ("GType", get_ccode_type_id (type_param));
+                               instance_priv_struct.add_field ("GBoxedCopyFunc", get_ccode_copy_function (type_param));
+                               instance_priv_struct.add_field ("GDestroyNotify", get_ccode_destroy_function (type_param));
                        }
                }
 
@@ -1427,17 +1420,17 @@ public class Vala.GTypeModule : GErrorModule {
                                GenericType p_type = new GenericType (p);
                                DataType p_data_type = p_type.get_actual_type (SemanticAnalyzer.get_data_type_for_symbol (cl), null, cl);
 
-                               add_generic_accessor_function ("get_%s_type".printf (p.name.ascii_down ()),
+                               add_generic_accessor_function ("get_%s".printf (get_ccode_type_id (p)),
                                                               "GType",
                                                               get_type_id_expression (p_data_type),
                                                               p, cl, iface);
 
-                               add_generic_accessor_function ("get_%s_dup_func".printf (p.name.ascii_down ()),
+                               add_generic_accessor_function ("get_%s".printf (get_ccode_copy_function (p)),
                                                               "GBoxedCopyFunc",
                                                               get_dup_func_expression (p_data_type, null),
                                                               p, cl, iface);
 
-                               add_generic_accessor_function ("get_%s_destroy_func".printf (p.name.ascii_down ()),
+                               add_generic_accessor_function ("get_%s".printf (get_ccode_destroy_function (p)),
                                                               "GDestroyNotify",
                                                               get_destroy_func_expression (p_data_type),
                                                               p, cl, iface);
@@ -2091,8 +2084,7 @@ public class Vala.GTypeModule : GErrorModule {
 
                if (iface.get_attribute ("GenericAccessors") != null) {
                        foreach (TypeParameter p in iface.get_type_parameters ()) {
-                               string method_name = "get_%s_type".printf (p.name.ascii_down ());
-                               var vdeclarator = new CCodeFunctionDeclarator (method_name);
+                               var vdeclarator = new CCodeFunctionDeclarator ("get_%s".printf (get_ccode_type_id (p)));
                                var this_type = SemanticAnalyzer.get_data_type_for_symbol (iface);
                                vdeclarator.add_parameter (new CCodeParameter ("self", get_ccode_name (this_type)));
 
@@ -2100,8 +2092,7 @@ public class Vala.GTypeModule : GErrorModule {
                                vdecl.add_declarator (vdeclarator);
                                type_struct.add_declaration (vdecl);
 
-                               method_name = "get_%s_dup_func".printf (p.name.ascii_down ());
-                               vdeclarator = new CCodeFunctionDeclarator (method_name);
+                               vdeclarator = new CCodeFunctionDeclarator ("get_%s".printf (get_ccode_copy_function (p)));
                                this_type = SemanticAnalyzer.get_data_type_for_symbol (iface);
                                vdeclarator.add_parameter (new CCodeParameter ("self", get_ccode_name (this_type)));
 
@@ -2109,8 +2100,7 @@ public class Vala.GTypeModule : GErrorModule {
                                vdecl.add_declarator (vdeclarator);
                                type_struct.add_declaration (vdecl);
 
-                               method_name = "get_%s_destroy_func".printf (p.name.ascii_down ());
-                               vdeclarator = new CCodeFunctionDeclarator (method_name);
+                               vdeclarator = new CCodeFunctionDeclarator ("get_%s".printf (get_ccode_destroy_function (p)));
                                this_type = SemanticAnalyzer.get_data_type_for_symbol (iface);
                                vdeclarator.add_parameter (new CCodeParameter ("self", get_ccode_name (this_type)));