[vala/0.36] codegen: Emit delegate/enum typedefs to type-declaration section



commit a55cfca706abf62c5f32ff78067983a3f1100ef5
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Dec 6 22:41:43 2018 +0100

    codegen: Emit delegate/enum typedefs to type-declaration section
    
    This fixes compilation of circular dependency of delegates with enums,
    structs, classes and interfaces.
    
    Resolve interface prerequisites after writing forward declarations to
    fix entagled delegate dependencies in them.
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/318

 codegen/valaccodebasemodule.vala     |  4 ++--
 codegen/valaccodedelegatemodule.vala |  2 +-
 codegen/valagtypemodule.vala         | 20 ++++++++++----------
 3 files changed, 13 insertions(+), 13 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 62de5bd7e..a05907b7e 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -823,8 +823,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                cfile = current_cfile;
 
-               decl_space.add_type_definition (cenum);
-               decl_space.add_type_definition (new CCodeNewline ());
+               decl_space.add_type_declaration (cenum);
+               decl_space.add_type_declaration (new CCodeNewline ());
 
                if (!get_ccode_has_type_id (en)) {
                        return true;
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index 4e402894a..d1ce03aa1 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -118,7 +118,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                var ctypedef = new CCodeTypeDefinition (return_type_cname, cfundecl);
                ctypedef.modifiers |= (d.version.deprecated ? CCodeModifiers.DEPRECATED : 0);
 
-               decl_space.add_type_definition (ctypedef);
+               decl_space.add_type_declaration (ctypedef);
        }
 
        public override void visit_delegate (Delegate d) {
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index f7a143eae..5b30d069a 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -1911,16 +1911,6 @@ public class Vala.GTypeModule : GErrorModule {
                        return;
                }
 
-               foreach (DataType prerequisite in iface.get_prerequisites ()) {
-                       var prereq_cl = prerequisite.data_type as Class;
-                       var prereq_iface = prerequisite.data_type as Interface;
-                       if (prereq_cl != null) {
-                               generate_class_declaration (prereq_cl, decl_space);
-                       } else if (prereq_iface != null) {
-                               generate_interface_declaration (prereq_iface, decl_space);
-                       }
-               }
-
                var type_struct = new CCodeStruct ("_%s".printf (get_ccode_type_name (iface)));
                
                decl_space.add_type_declaration (new CCodeNewline ());
@@ -1940,6 +1930,16 @@ public class Vala.GTypeModule : GErrorModule {
                decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (get_ccode_name 
(iface)), new CCodeVariableDeclarator (get_ccode_name (iface))));
                decl_space.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf 
(type_struct.name), new CCodeVariableDeclarator (get_ccode_type_name (iface))));
 
+               foreach (DataType prerequisite in iface.get_prerequisites ()) {
+                       var prereq_cl = prerequisite.data_type as Class;
+                       var prereq_iface = prerequisite.data_type as Interface;
+                       if (prereq_cl != null) {
+                               generate_class_declaration (prereq_cl, decl_space);
+                       } else if (prereq_iface != null) {
+                               generate_interface_declaration (prereq_iface, decl_space);
+                       }
+               }
+
                type_struct.add_field ("GTypeInterface", "parent_iface");
 
                if (iface.get_attribute ("GenericAccessors") != null) {


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