[vala/0.40] girwriter: Write c:symbol-prefix on supported elements



commit 7f34f607c19f64717c49521d84b1cdd49940ce76
Author: Jean Pierre Dudey <me jeandudey tech>
Date:   Sun Jul 19 16:48:12 2020 -0500

    girwriter: Write c:symbol-prefix on supported elements
    
    This specifies the symbol prefix, e.g.: window in gtk_window_new
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1038

 codegen/valagirwriter.vala | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 28063d248..7ea4a39a7 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -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));
        }


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