[vala/0.48] codegen: Allow CCode.type_cname for classes and use get_ccode_type_name()



commit 814a3f9a037bc0bdcb978c7ba9e5bb11cc12d3d0
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Jan 30 21:17:25 2021 +0100

    codegen: Allow CCode.type_cname for classes and use get_ccode_type_name()

 codegen/valaccode.vala                 | 4 ++--
 codegen/valaccodeattribute.vala        | 9 ++++++++-
 codegen/valaccodebasemodule.vala       | 2 +-
 codegen/valaclassregisterfunction.vala | 2 +-
 codegen/valagsignalmodule.vala         | 9 ++-------
 codegen/valagtypemodule.vala           | 6 +++---
 6 files changed, 17 insertions(+), 15 deletions(-)
---
diff --git a/codegen/valaccode.vala b/codegen/valaccode.vala
index 3284647c3..175cd99ea 100644
--- a/codegen/valaccode.vala
+++ b/codegen/valaccode.vala
@@ -45,8 +45,8 @@ namespace Vala {
                return get_ccode_attribute(node).const_name;
        }
 
-       public static string get_ccode_type_name (Interface iface) {
-               return get_ccode_attribute(iface).type_name;
+       public static string get_ccode_type_name (ObjectTypeSymbol sym) {
+               return get_ccode_attribute (sym).type_name;
        }
 
        public static string get_ccode_type_cast_function (ObjectTypeSymbol sym) {
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index 935810d2a..dd5cb8a52 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -64,7 +64,14 @@ public class Vala.CCodeAttribute : AttributeCache {
                                        _type_name = ccode.get_string ("type_cname");
                                }
                                if (_type_name == null) {
-                                       _type_name = "%sIface".printf (get_ccode_name (sym));
+                                       if (sym is Class) {
+                                               _type_name = "%sClass".printf (get_ccode_name (sym));
+                                       } else if (sym is Interface) {
+                                               _type_name = "%sIface".printf (get_ccode_name (sym));
+                                       } else {
+                                               Report.error (sym.source_reference, "`CCode.type_cname' not 
supported");
+                                               _type_name = "";
+                                       }
                                }
                        }
                        return _type_name;
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 67d483d1d..04c722f6e 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -6550,7 +6550,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                return new CCodeInvalidExpression ();
        }
 
-       public virtual CCodeExpression get_signal_creation (Signal sig, TypeSymbol type) {
+       public virtual CCodeExpression get_signal_creation (Signal sig, ObjectTypeSymbol type) {
                return new CCodeInvalidExpression ();
        }
 
diff --git a/codegen/valaclassregisterfunction.vala b/codegen/valaclassregisterfunction.vala
index c3d0d57e3..5c9b3cfd4 100644
--- a/codegen/valaclassregisterfunction.vala
+++ b/codegen/valaclassregisterfunction.vala
@@ -46,7 +46,7 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
        }
 
        public override string get_type_struct_name () {
-               return "%sClass".printf (get_ccode_name (class_reference));
+               return get_ccode_type_name (class_reference);
        }
 
        public override string get_base_init_func_name () {
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index 108622815..24ebfd252 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -346,7 +346,7 @@ public class Vala.GSignalModule : GObjectModule {
                user_marshal_set.add (signature);
        }
 
-       public override CCodeExpression get_signal_creation (Signal sig, TypeSymbol type) {
+       public override CCodeExpression get_signal_creation (Signal sig, ObjectTypeSymbol type) {
                var csignew = new CCodeFunctionCall (new CCodeIdentifier ("g_signal_new"));
                csignew.add_argument (new CCodeConstant ("\"%s\"".printf (get_ccode_name (sig))));
                csignew.add_argument (new CCodeIdentifier (get_ccode_type_id (type)));
@@ -385,12 +385,7 @@ public class Vala.GSignalModule : GObjectModule {
                        csignew.add_argument (new CCodeConstant ("0"));
                } else {
                        var struct_offset = new CCodeFunctionCall (new CCodeIdentifier ("G_STRUCT_OFFSET"));
-                       if (type is Class) {
-                               struct_offset.add_argument (new CCodeIdentifier ("%sClass".printf 
(get_ccode_name (type))));
-                       } else {
-                               // interface
-                               struct_offset.add_argument (new CCodeIdentifier (get_ccode_type_name 
((Interface) type)));
-                       }
+                       struct_offset.add_argument (new CCodeIdentifier (get_ccode_type_name (type)));
                        struct_offset.add_argument (new CCodeIdentifier (get_ccode_vfunc_name 
(sig.default_handler)));
                        csignew.add_argument (struct_offset);
                }
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index a39dab353..55016a57b 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -184,7 +184,7 @@ public class Vala.GTypeModule : GErrorModule {
                }
 
                if (is_gtypeinstance) {
-                       decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%sClass".printf 
(get_ccode_name (cl)), new CCodeVariableDeclarator ("%sClass".printf (get_ccode_name (cl)))));
+                       decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf 
(get_ccode_type_name (cl)), new CCodeVariableDeclarator (get_ccode_type_name (cl))));
 
                        var type_fun = new ClassRegisterFunction (cl);
                        type_fun.init_from_type (context, in_plugin, true);
@@ -235,7 +235,7 @@ public class Vala.GTypeModule : GErrorModule {
                bool is_fundamental = is_gtypeinstance && cl.base_class == null;
 
                var instance_struct = new CCodeStruct ("_%s".printf (get_ccode_name (cl)));
-               var type_struct = new CCodeStruct ("_%sClass".printf (get_ccode_name (cl)));
+               var type_struct = new CCodeStruct ("_%s".printf (get_ccode_type_name (cl)));
 
                if (cl.base_class != null) {
                        instance_struct.add_field (get_ccode_name (cl.base_class), "parent_instance");
@@ -253,7 +253,7 @@ public class Vala.GTypeModule : GErrorModule {
                        if (is_fundamental) {
                                type_struct.add_field ("GTypeClass", "parent_class");
                        } else {
-                               type_struct.add_field ("%sClass".printf (get_ccode_name (cl.base_class)), 
"parent_class");
+                               type_struct.add_field (get_ccode_type_name (cl.base_class), "parent_class");
                        }
 
                        if (is_fundamental) {


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