[vala/wip/issue/606: 2/4] girwriter: Populate gir_namespace/version attributes of external namespaces



commit 96c0d9b19a4c153f960bb094f971c15e912e54be
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Apr 27 13:20:28 2019 +0200

    girwriter: Populate gir_namespace/version attributes of external namespaces

 codegen/valagirwriter.vala | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
---
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 355ef856b..441c7c587 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -162,6 +162,11 @@ public class Vala.GIRWriter : CodeVisitor {
 
                write_package (package);
 
+               // Make sure to initialize external files with their gir_namespace/version
+               foreach (var file in context.get_source_files ()) {
+                       file.accept (this);
+               }
+
                context.accept (this);
 
                indent--;
@@ -252,6 +257,26 @@ public class Vala.GIRWriter : CodeVisitor {
                buffer.append_printf ("<c:include name=\"%s\"/>\n", name);
        }
 
+       public override void visit_source_file (SourceFile source_file) {
+               if (source_file.file_type != SourceFileType.PACKAGE) {
+                       return;
+               }
+
+               // Populate gir_namespace/version of source-file like in Namespace.check()
+               foreach (var node in source_file.get_nodes ()) {
+                       if (node is Namespace && ((Namespace) node).parent_symbol == context.root) {
+                               var a = node.get_attribute ("CCode");
+                               if (a != null && a.has_argument ("gir_namespace")) {
+                                       source_file.gir_namespace = a.get_string ("gir_namespace");
+                               }
+                               if (a != null && a.has_argument ("gir_version")) {
+                                       source_file.gir_version = a.get_string ("gir_version");
+                               }
+                               break;
+                       }
+               }
+       }
+
        public override void visit_namespace (Namespace ns) {
                if (ns.external_package) {
                        return;


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