From: Rico Tzschichholz Date: Thu, 5 Jul 2018 14:03:19 +0000 (+0200) Subject: girwriter: Add boolean GIR visible attribute to allow skipping symbols X-Git-Tag: 0.41.90~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3f6389bdf41461fad6dbd2e778a86ce4ada823d;p=thirdparty%2Fvala.git 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. --- 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 ("\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", "" };