[vala/staging] girwriter: Add boolean GIR visible attribute to allow skipping symbols



commit d3f6389bdf41461fad6dbd2e778a86ce4ada823d
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Jul 5 16:03:19 2018 +0200

    girwriter: Add boolean GIR visible attribute to allow skipping symbols
    
    "visibility = false" will be transformed into introspectable="0" in the
    resulting GIR file.
    
    Attributed namespaces will be skipped altogether.

 codegen/valagirwriter.vala | 29 ++++++++++++++++++++++-------
 vala/valausedattr.vala     |  2 +-
 2 files changed, 23 insertions(+), 8 deletions(-)
---
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index ce0eb52d3..7c2ebc7f0 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -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);
+       }
 }
diff --git a/vala/valausedattr.vala b/vala/valausedattr.vala
index 78fdd0871..dab15a864 100644
--- a/vala/valausedattr.vala
+++ b/vala/valausedattr.vala
@@ -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", ""
 
        };
 


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