]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girwriter: Add boolean GIR visible attribute to allow skipping symbols
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 5 Jul 2018 14:03:19 +0000 (16:03 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 5 Jul 2018 15:07:35 +0000 (17:07 +0200)
"visibility = false" will be transformed into introspectable="0" in the
resulting GIR file.

Attributed namespaces will be skipped altogether.

codegen/valagirwriter.vala
vala/valausedattr.vala

index ce0eb52d37b1c7f9a2ac19a45523433f38adf805..7c2ebc7f0cecd5559ef76aba01b3328097578451 100644 (file)
@@ -243,6 +243,10 @@ public class Vala.GIRWriter : CodeVisitor {
                        return;
                }
 
+               if (!is_visibility (ns)) {
+                       return;
+               }
+
                if (ns.name == null)  {
                        // global namespace
                        hierarchy.insert (0, ns);
@@ -283,6 +287,9 @@ public class Vala.GIRWriter : CodeVisitor {
        }
 
        private void write_symbol_attributes (Symbol symbol) {
+               if (!is_introspectable (symbol)) {
+                       buffer.append_printf (" introspectable=\"0\"");
+               }
                if (symbol.version.deprecated) {
                        buffer.append_printf (" deprecated=\"1\"");
                        if (symbol.version.deprecated_since != null) {
@@ -722,6 +729,7 @@ public class Vala.GIRWriter : CodeVisitor {
                buffer.append_printf ("<enumeration name=\"%s\"", edomain.name);
                write_ctype_attributes (edomain);
                buffer.append_printf (" glib:error-domain=\"%s\"", get_ccode_quark_name (edomain));
+               write_symbol_attributes (edomain);
                buffer.append_printf (">\n");
                indent++;
 
@@ -992,7 +1000,7 @@ public class Vala.GIRWriter : CodeVisitor {
                return true;
        }
 
-       bool is_introspectable (Method m) {
+       bool is_method_introspectable (Method m) {
                if (!is_type_introspectable (m.return_type)) {
                        return false;
                }
@@ -1004,6 +1012,14 @@ public class Vala.GIRWriter : CodeVisitor {
                return true;
        }
 
+       bool is_introspectable (Symbol sym) {
+               if (sym is Method && !is_method_introspectable ((Method) sym)) {
+                       return false;
+               }
+
+               return is_visibility (sym);
+       }
+
        private void write_signature (Method m, string tag_name, bool write_doc, bool instance = false) {
                var parent = this.hierarchy.get (0);
                string name;
@@ -1046,9 +1062,6 @@ public class Vala.GIRWriter : CodeVisitor {
                        buffer.append_printf (" throws=\"1\"");
                }
                write_symbol_attributes (m);
-               if (!is_introspectable (m)) {
-                       buffer.append_printf (" introspectable=\"0\"");
-               }
                buffer.append_printf (">\n");
                indent++;
 
@@ -1100,9 +1113,7 @@ public class Vala.GIRWriter : CodeVisitor {
                if (m.tree_can_fail) {
                        buffer.append_printf (" throws=\"1\"");
                }
-               if (!is_introspectable (m)) {
-                       buffer.append_printf (" introspectable=\"0\"");
-               }
+               write_symbol_attributes (m);
                buffer.append_printf (">\n");
                indent++;
 
@@ -1450,4 +1461,8 @@ public class Vala.GIRWriter : CodeVisitor {
 
                return false;
        }
+
+       private bool is_visibility (Symbol sym) {
+               return sym.get_attribute_bool ("GIR", "visible", true);
+       }
 }
index 78fdd0871e95311042419950390c55ec7a4dd14b..dab15a864a08ad554d24e7f6dea7e68667ae8db4 100644 (file)
@@ -83,7 +83,7 @@ public class Vala.UsedAttr : CodeVisitor {
 
                "DBus", "name", "no_reply", "result", "use_string_marshalling", "value", "signature", "visible", "timeout", "",
 
-               "GIR", "fullname", "name", ""
+               "GIR", "fullname", "name", "visible", ""
 
        };