]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Always include base_struct declaration if available
authorAlistair Thomas <astavale@yahoo.co.uk>
Tue, 27 Oct 2015 18:23:09 +0000 (18:23 +0000)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 5 Sep 2020 14:42:41 +0000 (16:42 +0200)
This fixes inheritance of structs across source files while not using
a header file.

Fixes https://gitlab.gnome.org/GNOME/vala/issues/464

codegen/valaccodestructmodule.vala

index 620a07e3f8b869ea545527d2221c6f1b70a69ad6..315bdc7cee40a68037c5aa4aa5fa5d71e3bc7ef2 100644 (file)
@@ -30,27 +30,30 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
                        return;
                }
 
+               if (st.base_struct != null) {
+                       generate_struct_declaration (st.base_struct, decl_space);
+               }
+
                if (st.is_boolean_type () || st.is_integer_type () || st.is_floating_type ()) {
+                       string typename;
                        // See GTypeModule.visit_struct()
                        if (st.base_struct != null) {
-                               generate_struct_declaration (st.base_struct, decl_space);
-                               decl_space.add_type_declaration (new CCodeTypeDefinition (get_ccode_name (st.base_struct), new CCodeVariableDeclarator (get_ccode_name (st))));
+                               typename = get_ccode_name (st.base_struct);
+                       } else if (st.is_boolean_type ()) {
+                               // typedef for boolean types
+                               decl_space.add_include ("stdbool.h");
+                               typename = "bool";
+                       } else if (st.is_integer_type ()) {
+                               // typedef for integral types
+                               decl_space.add_include ("stdint.h");
+                               typename = "%sint%d_t".printf (st.signed ? "" : "u", st.width);
+                       } else if (st.is_floating_type ()) {
+                               // typedef for floating types
+                               typename = (st.width == 64 ? "double" : "float");
                        } else {
-                               string typename = null;
-                               if (st.is_boolean_type ()) {
-                                       // typedef for boolean types
-                                       decl_space.add_include ("stdbool.h");
-                                       typename = "bool";
-                               } else if (st.is_integer_type ()) {
-                                       // typedef for integral types
-                                       decl_space.add_include ("stdint.h");
-                                       typename = "%sint%d_t".printf (st.signed ? "" : "u", st.width);
-                               } else if (st.is_floating_type ()) {
-                                       // typedef for floating types
-                                       typename = (st.width == 64 ? "double" : "float");
-                               }
-                               decl_space.add_type_declaration (new CCodeTypeDefinition (typename, new CCodeVariableDeclarator (get_ccode_name (st))));
+                               assert_not_reached ();
                        }
+                       decl_space.add_type_declaration (new CCodeTypeDefinition (typename, new CCodeVariableDeclarator (get_ccode_name (st))));
                        return;
                }