]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Add CCode.type_get_function and get_ccode_type_get_function()
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 30 Jan 2021 20:17:25 +0000 (21:17 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 30 Jan 2021 20:17:25 +0000 (21:17 +0100)
Allow to overide the macro name, and join get_ccode_class_get_function ()
and get_ccode_interface_get_function().

codegen/valaccode.vala
codegen/valaccodebasemodule.vala
codegen/valaccodememberaccessmodule.vala
codegen/valaccodemethodmodule.vala
codegen/valagtypemodule.vala
libvaladoc/api/class.vala
libvaladoc/api/interface.vala
vala/valausedattr.vala

index d89d7219e9faf3ee1b591f90a4db9ce8cfd0658e..3284647c35004404b117faacefbe96624779c0a2 100644 (file)
@@ -54,13 +54,20 @@ namespace Vala {
                return get_ccode_upper_case_name (sym);
        }
 
-       public static string get_ccode_interface_get_function (Interface iface) {
-               return "%s_GET_INTERFACE".printf (get_ccode_upper_case_name (iface));
-       }
-
-       public static string get_ccode_class_get_function (Class cl) {
-               assert (!cl.is_compact);
-               return "%s_GET_CLASS".printf (get_ccode_upper_case_name (cl));
+       public static string get_ccode_type_get_function (ObjectTypeSymbol sym) {
+               var func_name = sym.get_attribute_string ("CCode", "type_get_function");
+               if (func_name != null) {
+                       return func_name;
+               }
+               if (sym is Class) {
+                       assert (!((Class) sym).is_compact);
+                       return "%s_GET_CLASS".printf (get_ccode_upper_case_name (sym));
+               } else if (sym is Interface) {
+                       return "%s_GET_INTERFACE".printf (get_ccode_upper_case_name (sym));
+               } else {
+                       Report.error (sym.source_reference, "`CCode.type_get_function' not supported");
+                       return "";
+               }
        }
 
        public static string get_ccode_class_get_private_function (Class cl) {
index 9f570049b7afef64ed997dbc613e7fbba1c953c5..515851525e01aef9189e104482b1061570ee46c6 100644 (file)
@@ -1780,7 +1780,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                var iface = (Interface) prop.parent_symbol;
 
                                vcast = new CCodeIdentifier ("_iface_");
-                               var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_interface_get_function (iface)));
+                               var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (iface)));
                                ((CCodeFunctionCall) vcastcall).add_argument (new CCodeIdentifier ("self"));
                                ccode.add_declaration ("%s*".printf (get_ccode_type_name (iface)), new CCodeVariableDeclarator ("_iface_"));
                                ccode.add_assignment (vcast, vcastcall);
@@ -1788,7 +1788,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                var cl = (Class) prop.parent_symbol;
                                if (!cl.is_compact) {
                                        vcast = new CCodeIdentifier ("_klass_");
-                                       var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_get_function (cl)));
+                                       var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (cl)));
                                        ((CCodeFunctionCall) vcastcall).add_argument (new CCodeIdentifier ("self"));
                                        ccode.add_declaration ("%sClass*".printf (get_ccode_name (cl)), new CCodeVariableDeclarator ("_klass_"));
                                        ccode.add_assignment (vcast, vcastcall);
@@ -2860,7 +2860,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                require_generic_accessors (iface);
 
                                string method_name = "get_%s_type".printf (type_parameter.name.ascii_down ());
-                               var cast_self = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_interface_get_function (iface)));
+                               var cast_self = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (iface)));
                                cast_self.add_argument (new CCodeIdentifier ("self"));
                                var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name));
                                function_call.add_argument (new CCodeIdentifier ("self"));
@@ -2930,7 +2930,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                require_generic_accessors (iface);
 
                                string method_name = "get_%s_dup_func".printf (type_parameter.name.ascii_down ());
-                               var cast_self = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_interface_get_function (iface)));
+                               var cast_self = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (iface)));
                                cast_self.add_argument (new CCodeIdentifier ("self"));
                                var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name));
                                function_call.add_argument (new CCodeIdentifier ("self"));
@@ -3486,7 +3486,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                require_generic_accessors (iface);
 
                                string method_name = "get_%s_destroy_func".printf (type_parameter.name.ascii_down ());
-                               var cast_self = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_interface_get_function (iface)));
+                               var cast_self = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (iface)));
                                cast_self.add_argument (new CCodeIdentifier ("self"));
                                var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name));
                                function_call.add_argument (new CCodeIdentifier ("self"));
index 4b353a09e64e560edd6845730d1d72668c4d107e..0a85a058d12eb459bb6daccc523574860b3c8b45 100644 (file)
@@ -68,7 +68,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                                if (m.base_method.get_attribute ("NoWrapper") != null) {
                                        var base_class = (Class) m.base_method.parent_symbol;
                                        if (!base_class.is_compact) {
-                                               var vclass = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_get_function (base_class)));
+                                               var vclass = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (base_class)));
                                                vclass.add_argument (pub_inst);
                                                set_cvalue (expr, new CCodeMemberAccess.pointer (vclass, get_ccode_vfunc_name (m)));
                                        } else {
@@ -80,7 +80,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                        } else if (m.base_interface_method != null) {
                                if (m.base_interface_method.get_attribute ("NoWrapper") != null) {
                                        var base_iface = (Interface) m.base_interface_method.parent_symbol;
-                                       var vclass = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_interface_get_function (base_iface)));
+                                       var vclass = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (base_iface)));
                                        vclass.add_argument (pub_inst);
                                        set_cvalue (expr, new CCodeMemberAccess.pointer (vclass, get_ccode_vfunc_name (m)));
                                } else {
index 4672735478be88ca96be696c1264db887de0ef8d..9402ad6ab9d8461bcc659b989cb770b09fd34b61 100644 (file)
@@ -1117,14 +1117,14 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                if (m.parent_symbol is Interface) {
                        var iface = (Interface) m.parent_symbol;
 
-                       var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_interface_get_function (iface)));
+                       var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (iface)));
                        ((CCodeFunctionCall) vcastcall).add_argument (new CCodeIdentifier ("self"));
                        ccode.add_declaration ("%s*".printf (get_ccode_type_name (iface)), new CCodeVariableDeclarator ("_iface_"));
                        ccode.add_assignment (vcast, vcastcall);
                } else {
                        var cl = (Class) m.parent_symbol;
                        if (!cl.is_compact) {
-                               var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_get_function (cl)));
+                               var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (cl)));
                                ((CCodeFunctionCall) vcastcall).add_argument (new CCodeIdentifier ("self"));
                                ccode.add_declaration ("%sClass*".printf (get_ccode_name (cl)), new CCodeVariableDeclarator ("_klass_"));
                                ccode.add_assignment (vcast, vcastcall);
index cc51849e137e1f80b5e2413a8b71656a8b385541..8ba9155576aaa8e308923fb51cf1ccc592273d5d 100644 (file)
@@ -85,7 +85,7 @@ public class Vala.GTypeModule : GErrorModule {
                        decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(klass)".printf (get_ccode_class_type_check_function (cl)), macro));
 
                        macro = "(G_TYPE_INSTANCE_GET_CLASS ((obj), %s, %sClass))".printf (get_ccode_type_id (cl), get_ccode_name (cl));
-                       decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_ccode_class_get_function (cl)), macro));
+                       decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_ccode_type_get_function (cl)), macro));
                        decl_space.add_type_declaration (new CCodeNewline ());
                }
 
@@ -762,11 +762,11 @@ public class Vala.GTypeModule : GErrorModule {
                                ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ref_count));
                                ccode.open_if (ccall);
 
-                               var get_class = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_get_function (cl)));
+                               var get_class = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (cl)));
                                get_class.add_argument (new CCodeIdentifier ("self"));
 
                                // finalize class
-                               var ccast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_get_function (cl)));
+                               var ccast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (cl)));
                                ccast.add_argument (new CCodeIdentifier ("self"));
                                ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (ccast, "finalize"));
                                ccall.add_argument (new CCodeIdentifier ("self"));
@@ -2072,7 +2072,7 @@ public class Vala.GTypeModule : GErrorModule {
                decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_ccode_type_check_function (iface)), macro));
 
                macro = "(G_TYPE_INSTANCE_GET_INTERFACE ((obj), %s, %s))".printf (get_ccode_type_id (iface), get_ccode_type_name (iface));
-               decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_ccode_interface_get_function (iface)), macro));
+               decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_ccode_type_get_function (iface)), macro));
                decl_space.add_type_declaration (new CCodeNewline ());
 
                decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (get_ccode_name (iface)), new CCodeVariableDeclarator (get_ccode_name (iface))));
index 667565bbc15736fadd7042c910a3eac43ae2c426..da22a5645124bf6f1495c90d9026a691c52d2ded 100644 (file)
@@ -57,7 +57,7 @@ public class Valadoc.Api.Class : TypeSymbol {
                if (!data.is_compact) {
                        this.is_class_type_macro_name = Vala.get_ccode_class_type_check_function (data);
                        this.class_type_macro_name = Vala.get_ccode_class_type_function (data);
-                       this.class_macro_name = Vala.get_ccode_class_get_function (data);
+                       this.class_macro_name = Vala.get_ccode_type_get_function (data);
                        this.private_cname = _get_private_cname (data);
                }
                this.dbus_name = Vala.GDBusModule.get_dbus_name (data);
index 3b336bdfc928559c3fc8b5f5eac59e93bcfb4732..bcc751196f98e73e0f6bfbc8f9087569de99b038 100644 (file)
@@ -38,7 +38,7 @@ public class Valadoc.Api.Interface : TypeSymbol {
        {
                base (parent, file, name, accessibility, comment, false, data);
 
-               this.interface_macro_name = Vala.get_ccode_interface_get_function (data);
+               this.interface_macro_name = Vala.get_ccode_type_get_function (data);
                this.dbus_name = Vala.GDBusModule.get_dbus_name (data);
                this.cname = Vala.get_ccode_name (data);
                this.type_id = Vala.get_ccode_type_id (data);
index c00d8e6a2f284b91a1a2beb05d56724cb2503397..b9d8ceb2233e95cf54abca63dbb8bf599f564cb4 100644 (file)
@@ -35,7 +35,7 @@ public class Vala.UsedAttr : CodeVisitor {
                "has_type_id", "instance_pos", "const_cname", "take_value_function", "copy_function", "free_function",
                "param_spec_function", "has_target", "has_typedef", "type_cname", "ref_function", "ref_function_void", "unref_function", "type",
                "has_construct_function", "returns_floating_reference", "gir_namespace", "gir_version", "construct_function",
-               "lower_case_cprefix", "simple_generics", "sentinel", "scope", "has_destroy_function", "ordering", "type_check_function",
+               "lower_case_cprefix", "simple_generics", "sentinel", "scope", "has_destroy_function", "ordering", "type_check_function", "type_get_function",
                "has_copy_function", "lower_case_csuffix", "ref_sink_function", "dup_function", "finish_function", "generic_type_pos",
                "array_length_type", "array_length", "array_length_cname", "array_length_cexpr", "array_null_terminated",
                "vfunc_name", "finish_vfunc_name", "finish_name", "free_function_address_of", "pos", "delegate_target", "delegate_target_cname",