[vala/0.40] girwriter: Don't include symbols outside of a namespace



commit a1fee7d1aa0f57144dfe065875dc7bed33318487
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Jul 27 18:10:38 2020 +0200

    girwriter: Don't include symbols outside of a namespace
    
    Additionally report a warning for symbols which doesn't fulfill this rule.
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/241

 codegen/valaccodearraymodule.vala |  2 +-
 codegen/valagirwriter.vala        | 45 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 0c01facae..a25716acb 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -485,7 +485,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                unowned ArrayType? array_type = value.value_type as ArrayType;
 
                if (array_type != null && array_type.fixed_length) {
-                       unowned Struct? st = array_type.element_type.type_symbol as Struct;
+                       unowned Struct? st = array_type.element_type.data_type as Struct;
                        if (st != null && !array_type.element_type.nullable) {
                                var ccall = new CCodeFunctionCall (new CCodeIdentifier 
(append_struct_array_destroy (st)));
                                ccall.add_argument (get_cvalue_ (value));
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 7ea4a39a7..b3bae9660 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -387,6 +387,10 @@ public class Vala.GIRWriter : CodeVisitor {
                        return;
                }
 
+               if (!has_namespace (cl)) {
+                       return;
+               }
+
                if (!(hierarchy[0] is Namespace)) {
                        deferred.add (cl);
                        return;
@@ -586,6 +590,10 @@ public class Vala.GIRWriter : CodeVisitor {
                        return;
                }
 
+               if (!has_namespace (st)) {
+                       return;
+               }
+
                if (!(hierarchy[0] is Namespace)) {
                        deferred.add (st);
                        return;
@@ -624,6 +632,10 @@ public class Vala.GIRWriter : CodeVisitor {
                        return;
                }
 
+               if (!has_namespace (iface)) {
+                       return;
+               }
+
                if (!(hierarchy[0] is Namespace)) {
                        deferred.add (iface);
                        return;
@@ -789,6 +801,10 @@ public class Vala.GIRWriter : CodeVisitor {
                        return;
                }
 
+               if (!has_namespace (en)) {
+                       return;
+               }
+
                if (!(hierarchy[0] is Namespace)) {
                        deferred.add (en);
                        return;
@@ -863,6 +879,10 @@ public class Vala.GIRWriter : CodeVisitor {
                        return;
                }
 
+               if (!has_namespace (edomain)) {
+                       return;
+               }
+
                write_indent ();
                buffer.append_printf ("<enumeration name=\"%s\"", edomain.name);
                write_ctype_attributes (edomain);
@@ -920,6 +940,10 @@ public class Vala.GIRWriter : CodeVisitor {
                        return;
                }
 
+               if (!has_namespace (c)) {
+                       return;
+               }
+
                //TODO Add better constant evaluation
                var initializer = c.value;
                string value = literal_expression_to_value_string (initializer);
@@ -949,6 +973,10 @@ public class Vala.GIRWriter : CodeVisitor {
                        return;
                }
 
+               if (!has_namespace (f)) {
+                       return;
+               }
+
                write_indent ();
                buffer.append_printf ("<field name=\"%s\"", get_ccode_name (f));
                if (f.variable_type.nullable) {
@@ -1172,6 +1200,10 @@ public class Vala.GIRWriter : CodeVisitor {
                        return;
                }
 
+               if (!has_namespace (cb)) {
+                       return;
+               }
+
                write_indent ();
                buffer.append_printf ("<callback name=\"%s\"", cb.name);
                buffer.append_printf (" c:type=\"%s\"", get_ccode_name (cb));
@@ -1201,6 +1233,10 @@ public class Vala.GIRWriter : CodeVisitor {
                        return;
                }
 
+               if (!has_namespace (m)) {
+                       return;
+               }
+
                string tag_name = "method";
                var parent = this.hierarchy.get (0);
                if (parent is Enum) {
@@ -1708,4 +1744,13 @@ public class Vala.GIRWriter : CodeVisitor {
        private bool is_visibility (Symbol sym) {
                return sym.get_attribute_bool ("GIR", "visible", true);
        }
+
+       bool has_namespace (Symbol sym) {
+               if (!(sym.parent_symbol is Namespace) || sym.parent_symbol.name != null) {
+                       return true;
+               }
+
+               Report.warning (sym.source_reference, "`%s' must be part of namespace to be included in 
GIR".printf (sym.name));
+               return false;
+       }
 }


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