]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girwriter: Write c:symbol-prefix on supported elements
authorJean Pierre Dudey <me@jeandudey.tech>
Sun, 19 Jul 2020 21:48:12 +0000 (16:48 -0500)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 26 Jul 2020 10:29:50 +0000 (12:29 +0200)
This specifies the symbol prefix, e.g.: window in gtk_window_new

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

codegen/valagirwriter.vala

index 28063d24827d047db57def9a82b53b5aa32ddbbe..7ea4a39a7374a41baa9aabcf94a3753940cab50c 100644 (file)
@@ -344,6 +344,10 @@ public class Vala.GIRWriter : CodeVisitor {
                        buffer.append_printf (" c:prefix=\"%s\"", cprefix);
                        buffer.append_printf (" c:identifier-prefixes=\"%s\"", cprefix);
                }
+               string? csymbol_prefix = get_ccode_lower_case_suffix (ns);
+               if (csymbol_prefix != null) {
+                       buffer.append_printf (" c:symbol-prefix=\"%s\"", csymbol_prefix);
+               }
                buffer.append_printf (">\n");
                indent++;
 
@@ -393,7 +397,7 @@ public class Vala.GIRWriter : CodeVisitor {
 
                        write_indent ();
                        buffer.append_printf ("<class name=\"%s\"", get_gir_name (cl));
-                       write_gtype_attributes (cl);
+                       write_gtype_attributes (cl, true);
                        buffer.append_printf (" glib:type-struct=\"%s\"", gtype_struct_name);
                        if (cl.base_class == null) {
                                buffer.append_printf (" glib:fundamental=\"1\"");
@@ -590,9 +594,9 @@ public class Vala.GIRWriter : CodeVisitor {
                write_indent ();
                buffer.append_printf ("<record name=\"%s\"", get_gir_name (st));
                if (get_ccode_has_type_id (st)) {
-                       write_gtype_attributes (st);
+                       write_gtype_attributes (st, true);
                } else {
-                       write_ctype_attributes (st);
+                       write_ctype_attributes (st, "", true);
                }
                write_symbol_attributes (st);
                buffer.append_printf (">\n");
@@ -629,7 +633,7 @@ public class Vala.GIRWriter : CodeVisitor {
 
                write_indent ();
                buffer.append_printf ("<interface name=\"%s\"", get_gir_name (iface));
-               write_gtype_attributes (iface);
+               write_gtype_attributes (iface, true);
                buffer.append_printf (" glib:type-struct=\"%s\"", gtype_struct_name);
                write_symbol_attributes (iface);
                buffer.append_printf (">\n");
@@ -1525,12 +1529,15 @@ public class Vala.GIRWriter : CodeVisitor {
                index++;
        }
 
-       private void write_ctype_attributes (TypeSymbol symbol, string suffix = "") {
+       private void write_ctype_attributes (TypeSymbol symbol, string suffix = "", bool symbol_prefix = false) {
                buffer.append_printf (" c:type=\"%s%s\"", get_ccode_name (symbol), suffix);
+               if (symbol_prefix) {
+                       buffer.append_printf (" c:symbol-prefix=\"%s\"", get_ccode_lower_case_suffix (symbol));
+               }
        }
 
-       private void write_gtype_attributes (TypeSymbol symbol) {
-               write_ctype_attributes(symbol);
+       private void write_gtype_attributes (TypeSymbol symbol, bool symbol_prefix = false) {
+               write_ctype_attributes(symbol, "", symbol_prefix);
                buffer.append_printf (" glib:type-name=\"%s\"", get_ccode_name (symbol));
                buffer.append_printf (" glib:get-type=\"%sget_type\"", get_ccode_lower_case_prefix (symbol));
        }