]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Replace NamespaceReference by UsingDirective and UnresolvedSymbol, fixes
authorJürg Billeter <j@bitron.ch>
Fri, 26 Sep 2008 19:09:30 +0000 (19:09 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 26 Sep 2008 19:09:30 +0000 (19:09 +0000)
2008-09-26  Jürg Billeter  <j@bitron.ch>

* vala/Makefile.am:
* vala/valacodevisitor.vala:
* vala/valagenieparser.vala:
* vala/valaparser.vala:
* vala/valasemanticanalyzer.vala:
* vala/valasourcefile.vala:
* vala/valasymbolresolver.vala:
* vala/valaunresolvedsymbol.vala:
* vala/valausingdirective.vala:
* compiler/valacompiler.vala:

Replace NamespaceReference by UsingDirective and UnresolvedSymbol,
fixes bug 537510

* tests/namespaces.vala:

Test using directive with nested namespaces

svn path=/trunk/; revision=1783

12 files changed:
ChangeLog
compiler/valacompiler.vala
tests/namespaces.vala
vala/Makefile.am
vala/valacodevisitor.vala
vala/valagenieparser.vala
vala/valaparser.vala
vala/valasemanticanalyzer.vala
vala/valasourcefile.vala
vala/valasymbolresolver.vala
vala/valaunresolvedsymbol.vala
vala/valausingdirective.vala [moved from vala/valanamespacereference.vala with 60% similarity]

index 3f5dcf5facc007a77b88eb493d4db8c464d17881..e1619e18f05823c3ee09443fcd9483f71f3cdee6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2008-09-26  Jürg Billeter  <j@bitron.ch>
+
+       * vala/Makefile.am:
+       * vala/valacodevisitor.vala:
+       * vala/valagenieparser.vala:
+       * vala/valaparser.vala:
+       * vala/valasemanticanalyzer.vala:
+       * vala/valasourcefile.vala:
+       * vala/valasymbolresolver.vala:
+       * vala/valaunresolvedsymbol.vala:
+       * vala/valausingdirective.vala:
+       * compiler/valacompiler.vala:
+
+       Replace NamespaceReference by UsingDirective and UnresolvedSymbol,
+       fixes bug 537510
+
+       * tests/namespaces.vala:
+
+       Test using directive with nested namespaces
+
 2008-09-26  Jürg Billeter  <j@bitron.ch>
 
        * vala/valarealliteral.vala:
index b614fdd23211579fc96da05a4fa9a518f74130a5..21428112f51f3425e715346ddc7fc24422f56619 100644 (file)
@@ -215,7 +215,7 @@ class Vala.Compiler {
                                        var source_file = new SourceFile (context, rpath);
 
                                        // import the GLib namespace by default (namespace of backend-specific standard library)
-                                       source_file.add_using_directive (new NamespaceReference ("GLib"));
+                                       source_file.add_using_directive (new UsingDirective (new UnresolvedSymbol (null, "GLib", null)));
 
                                        context.add_source_file (source_file);
                                } else if (source.has_suffix (".vapi")) {
index 67b42a7b2959decda203666c05c062eee7017efe..1469ec894f3fa5674e2fe1e25dda25154a409e88 100644 (file)
@@ -1,4 +1,4 @@
-using GLib;
+using Foo.Sub;
 
 public class GlobalTestClass {
        public GlobalTestClass() {
@@ -19,6 +19,8 @@ namespace Maman {
 
                new global::GlobalTestClass();
 
+               var obj = new ClassInNestedNamespace ();
+
                return 0;
        }
 
@@ -29,3 +31,6 @@ namespace Maman {
        }
 }
 
+public class Foo.Sub.ClassInNestedNamespace {
+}
+
index a8ba6dd7aa030fb00a70db52839b6e4366940409..0215a8c85502ba5614d6dcc338a860f0ea07d72f 100644 (file)
@@ -94,7 +94,6 @@ libvalacore_la_VALASOURCES = \
        valamethodtype.vala \
        valanamedargument.vala \
        valanamespace.vala \
-       valanamespacereference.vala \
        valanullchecker.vala \
        valanullliteral.vala \
        valanulltype.vala \
@@ -143,6 +142,7 @@ libvalacore_la_VALASOURCES = \
        valaunaryexpression.vala \
        valaunresolvedsymbol.vala \
        valaunresolvedtype.vala \
+       valausingdirective.vala \
        valavaluetype.vala \
        valavoidtype.vala \
        valawhilestatement.vala \
index a485adf9ab3dc5f76653722b560bb333c7f2f22a..bdaca54aa24c3021f7473dc62574d8a0bbf591ce 100644 (file)
@@ -212,11 +212,11 @@ public abstract class Vala.CodeVisitor {
        }
 
        /**
-        * Visit operation called for namespace references.
+        * Visit operation called for using directives.
         *
-        * @param ns a namespace reference
+        * @param ns a using directive
         */
-       public virtual void visit_namespace_reference (NamespaceReference ns) {
+       public virtual void visit_using_directive (UsingDirective ns) {
        }
 
        /**
index b0ed3804b5423e3604afd96a7db96c60395a10ac..71786d5ce0075021cf2011a372321933ba502b83 100644 (file)
@@ -2337,7 +2337,7 @@ public class Vala.Genie.Parser : CodeVisitor {
        void add_uses_clause () throws ParseError {
                var begin = get_location ();
                var sym = parse_symbol_name ();
-               var ns_ref = new NamespaceReference (sym.name, get_src (begin));
+               var ns_ref = new UsingDirective (sym, get_src (begin));
 
                scanner.source_file.add_using_directive (ns_ref);
        }
index bde388452bc9d4b886782f5fe95845db211874ee..74fcb25c92e8a462def0f20df78b93c93d117497 100644 (file)
@@ -1916,7 +1916,7 @@ public class Vala.Parser : CodeVisitor {
                        do {
                                var begin = get_location ();
                                var sym = parse_symbol_name ();
-                               var ns_ref = new NamespaceReference (sym.name, get_src (begin));
+                               var ns_ref = new UsingDirective (sym, get_src (begin));
                                scanner.source_file.add_using_directive (ns_ref);
                        } while (accept (TokenType.COMMA));
                        expect (TokenType.SEMICOLON);
index 1d99fd445c0dce3027c02bf6d78fa03a790a40cb..3473a19868c4bcfe678fd0f2d115d5c2f99b8adf 100644 (file)
@@ -37,7 +37,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        Class current_class;
        Struct current_struct;
 
-       Gee.List<NamespaceReference> current_using_directives;
+       Gee.List<UsingDirective> current_using_directives;
 
        DataType bool_type;
        DataType string_type;
@@ -1601,7 +1601,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                        }
 
                        if (expr.symbol_reference == null) {
-                               foreach (NamespaceReference ns in current_using_directives) {
+                               foreach (UsingDirective ns in current_using_directives) {
                                        var local_sym = ns.namespace_symbol.scope.lookup (expr.member_name);
                                        if (local_sym != null) {
                                                if (expr.symbol_reference != null) {
index 3d75105e6f6f910c540de113bf9966f5a13ec44b..bc8a69260e22d35e2cb23c59616a61557307a998 100644 (file)
@@ -69,7 +69,7 @@ public class Vala.SourceFile {
         */
        public weak CodeContext context { get; set; }
 
-       private Gee.List<NamespaceReference> using_directives = new ArrayList<NamespaceReference> ();
+       private Gee.List<UsingDirective> using_directives = new ArrayList<UsingDirective> ();
 
        private Gee.List<CodeNode> nodes = new ArrayList<CodeNode> ();
        
@@ -109,23 +109,39 @@ public class Vala.SourceFile {
         *
         * @param ns reference to namespace
         */
-       public void add_using_directive (NamespaceReference ns) {
-               foreach (NamespaceReference using_directive in using_directives) {
-                       if (using_directive.name == ns.name) {
+       public void add_using_directive (UsingDirective ns) {
+               foreach (UsingDirective using_directive in using_directives) {
+                       if (same_symbol (using_directive.namespace_symbol, ns.namespace_symbol)) {
                                // ignore duplicates
                                return;
                        }
                }
                using_directives.add (ns);
        }
-       
+
+       bool same_symbol (Symbol? sym1, Symbol? sym2) {
+               if (sym1 == sym2) {
+                       return true;
+               }
+
+               var unresolved_symbol1 = sym1 as UnresolvedSymbol;
+               var unresolved_symbol2 = sym2 as UnresolvedSymbol;
+               if (unresolved_symbol1 != null && unresolved_symbol2 != null) {
+                       if (same_symbol (unresolved_symbol1.inner, unresolved_symbol2.inner)) {
+                               return (unresolved_symbol1.name == unresolved_symbol2.name);
+                       }
+               }
+
+               return false;
+       }
+
        /**
         * Returns a copy of the list of using directives.
         *
         * @return using directive list
         */
-       public Gee.List<NamespaceReference> get_using_directives () {
-               return new ReadOnlyList<NamespaceReference> (using_directives);
+       public Gee.List<UsingDirective> get_using_directives () {
+               return new ReadOnlyList<UsingDirective> (using_directives);
        }
        
        /**
@@ -155,7 +171,7 @@ public class Vala.SourceFile {
        }
 
        public void accept_children (CodeVisitor visitor) {
-               foreach (NamespaceReference ns_ref in using_directives) {
+               foreach (UsingDirective ns_ref in using_directives) {
                        ns_ref.accept (visitor);
                }
                
index 84a417efee42c3e53a2cf0f80907d395604498e6..58a8e0733aa4b462f80b393999bd05882bae9f78 100644 (file)
@@ -30,7 +30,7 @@ using Gee;
 public class Vala.SymbolResolver : CodeVisitor {
        Symbol root_symbol;
        Scope current_scope;
-       Gee.List<NamespaceReference> current_using_directives;
+       Gee.List<UsingDirective> current_using_directives;
        
        /**
         * Resolve symbol names in the specified code context.
@@ -179,12 +179,15 @@ public class Vala.SymbolResolver : CodeVisitor {
                b.accept_children (this);
        }
 
-       public override void visit_namespace_reference (NamespaceReference ns) {
-               ns.namespace_symbol = current_scope.lookup (ns.name);
-               if (ns.namespace_symbol == null) {
-                       ns.error = true;
-                       Report.error (ns.source_reference, "The namespace name `%s' could not be found".printf (ns.name));
-                       return;
+       public override void visit_using_directive (UsingDirective ns) {
+               var unresolved_symbol = ns.namespace_symbol as UnresolvedSymbol;
+               if (unresolved_symbol != null) {
+                       ns.namespace_symbol = resolve_symbol (unresolved_symbol);
+                       if (ns.namespace_symbol == null) {
+                               ns.error = true;
+                               Report.error (ns.source_reference, "The namespace name `%s' could not be found".printf (unresolved_symbol.to_string ()));
+                               return;
+                       }
                }
        }
 
@@ -200,7 +203,7 @@ public class Vala.SymbolResolver : CodeVisitor {
                                scope = scope.parent_scope;
                        }
                        if (sym == null) {
-                               foreach (NamespaceReference ns in current_using_directives) {
+                               foreach (UsingDirective ns in current_using_directives) {
                                        if (ns.error) {
                                                continue;
                                        }
index 4ba4469e088d8513803fae5b6c397f63fd4aabfb..fcfaa3c3742c7e788a935e279a96f6cec1d47c00 100644 (file)
  *     Jürg Billeter <j@bitron.ch>
  */
 
-using GLib;
-
 /**
  * An unresolved reference to a symbol.
  */
-public class Vala.UnresolvedSymbol : CodeNode {
+public class Vala.UnresolvedSymbol : Symbol {
        /**
         * The parent of the symbol or null.
         */
        public UnresolvedSymbol? inner { get; set; }
 
-       /**
-        * The symbol name.
-        */
-       public string name { get; set; }
-
        /**
         * Qualified access to global symbol.
         */
similarity index 60%
rename from vala/valanamespacereference.vala
rename to vala/valausingdirective.vala
index 2f1885472b1df94bf83095646b93679bbdace541..9fb0766aff7050728084d7d2de9778cf9a3e17ad 100644 (file)
@@ -1,4 +1,4 @@
-/* valanamespacereference.vala
+/* valausingdirective.vala
  *
  * Copyright (C) 2006-2008  Jürg Billeter
  *
@@ -25,30 +25,24 @@ using GLib;
 /**
  * A reference to a namespace symbol.
  */
-public class Vala.NamespaceReference : CodeNode {
+public class Vala.UsingDirective : CodeNode {
        /**
-        * The name of the namespace this reference is referring to.
+        * The symbol of the namespace this using directive is referring to.
         */
-       public string name { get; set; }
-       
-       /**
-        * The resolved symbol of the namespace this reference is referring to.
-        */
-       public weak Symbol namespace_symbol { get; set; }
+       public Symbol namespace_symbol { get; set; }
 
        /**
-        * Creates a new namespace reference.
+        * Creates a new using directive.
         *
-        * @param name             namespace name
-        * @param source_reference reference to source code
-        * @return                 newly created namespace reference
+        * @param namespace_symbol namespace symbol
+        * @return                 newly created using directive
         */
-       public NamespaceReference (string name, SourceReference? source_reference = null) {
-               this.name = name;
+       public UsingDirective (Symbol namespace_symbol, SourceReference? source_reference = null) {
+               this.namespace_symbol = namespace_symbol;
                this.source_reference = source_reference;
        }
        
        public override void accept (CodeVisitor visitor) {
-               visitor.visit_namespace_reference (this);
+               visitor.visit_using_directive (this);
        }
 }