[vala/1270-remove-static-codecontext-access: 3/4] Namespace: set current context at construction time




commit 2a61375960efabb4dffdccd8fdbf04a07c6dcf52
Author: Daniel Espinosa <esodan gmail com>
Date:   Fri Dec 31 14:53:55 2021 -0600

    Namespace: set current context at construction time
    
    With this change any namespace will have access to
    current context, to allow access from its childs
    
    Related to issue #1270

 vala/valacodecontext.vala   |  3 ++-
 vala/valagenieparser.vala   | 16 ++++++++--------
 vala/valagirparser.vala     |  4 ++--
 vala/valanamespace.vala     |  3 ++-
 vala/valaparser.vala        | 16 ++++++++--------
 vapigen/valagidlparser.vala |  4 ++--
 6 files changed, 24 insertions(+), 22 deletions(-)
---
diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala
index 0b9022eb1..d3a11547d 100644
--- a/vala/valacodecontext.vala
+++ b/vala/valacodecontext.vala
@@ -206,7 +206,7 @@ public class Vala.CodeContext {
        private List<SourceFile> source_files = new ArrayList<SourceFile> ();
        private Map<string,unowned SourceFile> source_files_map = new HashMap<string,unowned SourceFile> 
(str_hash, str_equal);
        private List<string> c_source_files = new ArrayList<string> (str_equal);
-       private Namespace _root = new Namespace (null);
+       private Namespace _root;
 
        private List<string> packages = new ArrayList<string> (str_equal);
 
@@ -241,6 +241,7 @@ public class Vala.CodeContext {
        public UsedAttr used_attr { get; set; }
 
        public CodeContext () {
+               _root = new Namespace (null, this);
                add_default_defines ();
 
                resolver = new SymbolResolver ();
diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala
index 87a125f22..b581135cf 100644
--- a/vala/valagenieparser.vala
+++ b/vala/valagenieparser.vala
@@ -2575,7 +2575,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                var begin = get_location ();
                expect (TokenType.NAMESPACE);
                var sym = parse_symbol_name ();
-               var ns = new Namespace (sym.name, get_src (begin));
+               var ns = new Namespace (sym.name, context, get_src (begin));
                if (comment != null) {
                        ns.add_comment (comment);
                        comment = null;
@@ -2587,7 +2587,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                Namespace result = ns;
                while (sym.inner != null) {
                        sym = sym.inner;
-                       ns = new Namespace (sym.name, result.source_reference);
+                       ns = new Namespace (sym.name, context, result.source_reference);
                        ns.add_namespace ((Namespace) result);
                        result = ns;
                }
@@ -2722,7 +2722,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                Symbol result = cl;
                while (sym.inner != null) {
                        sym = sym.inner;
-                       var ns = new Namespace (sym.name, cl.source_reference);
+                       var ns = new Namespace (sym.name, context, cl.source_reference);
                        if (result is Namespace) {
                                ns.add_namespace ((Namespace) result);
                        } else {
@@ -3326,7 +3326,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                Symbol result = st;
                while (sym.inner != null) {
                        sym = sym.inner;
-                       var ns = new Namespace (sym.name, st.source_reference);
+                       var ns = new Namespace (sym.name, context, st.source_reference);
                        if (result is Namespace) {
                                ns.add_namespace ((Namespace) result);
                        } else {
@@ -3395,7 +3395,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                Symbol result = iface;
                while (sym.inner != null) {
                        sym = sym.inner;
-                       var ns = new Namespace (sym.name, iface.source_reference);
+                       var ns = new Namespace (sym.name, context, iface.source_reference);
                        if (result is Namespace) {
                                ns.add_namespace ((Namespace) result);
                        } else {
@@ -3482,7 +3482,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                Symbol result = en;
                while (sym.inner != null) {
                        sym = sym.inner;
-                       var ns = new Namespace (sym.name, en.source_reference);
+                       var ns = new Namespace (sym.name, context, en.source_reference);
                        if (result is Namespace) {
                                ns.add_namespace ((Namespace) result);
                        } else {
@@ -3538,7 +3538,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                Symbol result = ed;
                while (sym.inner != null) {
                        sym = sym.inner;
-                       var ns = new Namespace (sym.name, ed.source_reference);
+                       var ns = new Namespace (sym.name, context, ed.source_reference);
 
                        if (result is Namespace) {
                                ns.add_namespace ((Namespace) result);
@@ -3826,7 +3826,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                Symbol result = d;
                while (sym.inner != null) {
                        sym = sym.inner;
-                       var ns = new Namespace (sym.name, d.source_reference);
+                       var ns = new Namespace (sym.name, context,  d.source_reference);
 
                        if (result is Namespace) {
                                ns.add_namespace ((Namespace) result);
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index f99c64ceb..cf952d72c 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -2210,7 +2210,7 @@ public class Vala.GirParser : CodeVisitor {
                Namespace ns;
                push_node (vala_namespace, true);
                if (current.new_symbol) {
-                       ns = new Namespace (vala_namespace, current.source_reference);
+                       ns = new Namespace (vala_namespace, context, current.source_reference);
                        current.symbol = ns;
                } else {
                        ns = (Namespace) current.symbol;
@@ -3838,7 +3838,7 @@ public class Vala.GirParser : CodeVisitor {
        void create_new_namespaces () {
                foreach (var node in Node.new_namespaces) {
                        if (node.symbol == null) {
-                               node.symbol = new Namespace (node.name, node.source_reference);
+                               node.symbol = new Namespace (node.name, context, node.source_reference);
                        }
                }
        }
diff --git a/vala/valanamespace.vala b/vala/valanamespace.vala
index d62babb63..73b0d314e 100644
--- a/vala/valanamespace.vala
+++ b/vala/valanamespace.vala
@@ -49,9 +49,10 @@ public class Vala.Namespace : Symbol {
         * @param source_reference reference to source code
         * @return                 newly created namespace
         */
-       public Namespace (string? name, SourceReference? source_reference = null) {
+       public Namespace (string? name, CodeContext context, SourceReference? source_reference = null) {
                base (name, source_reference);
                access = SymbolAccessibility.PUBLIC;
+               this.context = context;
        }
 
        /**
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 5d12d1d68..3ad133ac9 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -2888,7 +2888,7 @@ public class Vala.Parser : CodeVisitor {
                var begin = get_location ();
                expect (TokenType.NAMESPACE);
                var sym = parse_symbol_name ();
-               var ns = new Namespace (sym.name, get_src (begin));
+               var ns = new Namespace (sym.name, context, get_src (begin));
                if (comment != null) {
                        ns.add_comment (comment);
                        comment = null;
@@ -2916,7 +2916,7 @@ public class Vala.Parser : CodeVisitor {
                while (sym != null) {
                        sym = sym.inner;
 
-                       Symbol next = (sym != null ? new Namespace (sym.name, ns.source_reference) : parent);
+                       Symbol next = (sym != null ? new Namespace (sym.name, context, ns.source_reference) : 
parent);
                        next.add_namespace ((Namespace) result);
                        result = next;
                }
@@ -3048,7 +3048,7 @@ public class Vala.Parser : CodeVisitor {
                while (sym != null) {
                        sym = sym.inner;
 
-                       Symbol next = (sym != null ? new Namespace (sym.name, cl.source_reference) : parent);
+                       Symbol next = (sym != null ? new Namespace (sym.name, context, cl.source_reference) : 
parent);
                        if (result is Namespace) {
                                next.add_namespace ((Namespace) result);
                        } else if (!partial_reparse && cl.is_partial) {
@@ -3497,7 +3497,7 @@ public class Vala.Parser : CodeVisitor {
                while (sym != null) {
                        sym = sym.inner;
 
-                       Symbol next = (sym != null ? new Namespace (sym.name, st.source_reference) : parent);
+                       Symbol next = (sym != null ? new Namespace (sym.name, context, st.source_reference) : 
parent);
                        if (result is Namespace) {
                                next.add_namespace ((Namespace) result);
                        } else {
@@ -3540,7 +3540,7 @@ public class Vala.Parser : CodeVisitor {
                while (sym != null) {
                        sym = sym.inner;
 
-                       Symbol next = (sym != null ? new Namespace (sym.name, iface.source_reference) : 
parent);
+                       Symbol next = (sym != null ? new Namespace (sym.name, context, 
iface.source_reference) : parent);
                        if (result is Namespace) {
                                next.add_namespace ((Namespace) result);
                        } else {
@@ -3607,7 +3607,7 @@ public class Vala.Parser : CodeVisitor {
                while (sym != null) {
                        sym = sym.inner;
 
-                       Symbol next = (sym != null ? new Namespace (sym.name, en.source_reference) : parent);
+                       Symbol next = (sym != null ? new Namespace (sym.name, context, en.source_reference) : 
parent);
                        if (result is Namespace) {
                                next.add_namespace ((Namespace) result);
                        } else {
@@ -3672,7 +3672,7 @@ public class Vala.Parser : CodeVisitor {
                while (sym != null) {
                        sym = sym.inner;
 
-                       Symbol next = (sym != null ? new Namespace (sym.name, ed.source_reference) : parent);
+                       Symbol next = (sym != null ? new Namespace (sym.name, context, ed.source_reference) : 
parent);
                        if (result is Namespace) {
                                next.add_namespace ((Namespace) result);
                        } else {
@@ -3927,7 +3927,7 @@ public class Vala.Parser : CodeVisitor {
                while (sym != null) {
                        sym = sym.inner;
 
-                       Symbol next = (sym != null ? new Namespace (sym.name, d.source_reference) : parent);
+                       Symbol next = (sym != null ? new Namespace (sym.name, context, d.source_reference) : 
parent);
                        if (result is Namespace) {
                                next.add_namespace ((Namespace) result);
                        } else {
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index 007896ec4..2b1005de7 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -475,7 +475,7 @@ public class Vala.GIdlParser : CodeVisitor {
                foreach ( unowned string tok in path ) {
                        cc = cp.scope.lookup (tok);
                        if ( cc == null ) {
-                               cc = new Namespace (tok, current_source_reference);
+                               cc = new Namespace (tok, context, current_source_reference);
                                add_symbol_to_container (cp, cc);
                        }
                        cp = cc;
@@ -494,7 +494,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                ns.source_reference = current_source_reference;
                        }
                } else {
-                       ns = new Namespace (module.name, current_source_reference);
+                       ns = new Namespace (module.name, context, current_source_reference);
                }
 
                current_namespace = ns;


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