From: Jürg Billeter Date: Fri, 26 Sep 2008 19:09:30 +0000 (+0000) Subject: Replace NamespaceReference by UsingDirective and UnresolvedSymbol, fixes X-Git-Tag: VALA_0_4_0~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aaa70e51776a4fb842f982fcddcd032a543fe12b;p=thirdparty%2Fvala.git Replace NamespaceReference by UsingDirective and UnresolvedSymbol, fixes 2008-09-26 Jürg Billeter * 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 --- diff --git a/ChangeLog b/ChangeLog index 3f5dcf5fa..e1619e18f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2008-09-26 Jürg Billeter + + * 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 * vala/valarealliteral.vala: diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala index b614fdd23..21428112f 100644 --- a/compiler/valacompiler.vala +++ b/compiler/valacompiler.vala @@ -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")) { diff --git a/tests/namespaces.vala b/tests/namespaces.vala index 67b42a7b2..1469ec894 100644 --- a/tests/namespaces.vala +++ b/tests/namespaces.vala @@ -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 { +} + diff --git a/vala/Makefile.am b/vala/Makefile.am index a8ba6dd7a..0215a8c85 100644 --- a/vala/Makefile.am +++ b/vala/Makefile.am @@ -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 \ diff --git a/vala/valacodevisitor.vala b/vala/valacodevisitor.vala index a485adf9a..bdaca54aa 100644 --- a/vala/valacodevisitor.vala +++ b/vala/valacodevisitor.vala @@ -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) { } /** diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala index b0ed3804b..71786d5ce 100644 --- a/vala/valagenieparser.vala +++ b/vala/valagenieparser.vala @@ -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); } diff --git a/vala/valaparser.vala b/vala/valaparser.vala index bde388452..74fcb25c9 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -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); diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 1d99fd445..3473a1986 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -37,7 +37,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { Class current_class; Struct current_struct; - Gee.List current_using_directives; + Gee.List 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) { diff --git a/vala/valasourcefile.vala b/vala/valasourcefile.vala index 3d75105e6..bc8a69260 100644 --- a/vala/valasourcefile.vala +++ b/vala/valasourcefile.vala @@ -69,7 +69,7 @@ public class Vala.SourceFile { */ public weak CodeContext context { get; set; } - private Gee.List using_directives = new ArrayList (); + private Gee.List using_directives = new ArrayList (); private Gee.List nodes = new ArrayList (); @@ -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 get_using_directives () { - return new ReadOnlyList (using_directives); + public Gee.List get_using_directives () { + return new ReadOnlyList (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); } diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala index 84a417efe..58a8e0733 100644 --- a/vala/valasymbolresolver.vala +++ b/vala/valasymbolresolver.vala @@ -30,7 +30,7 @@ using Gee; public class Vala.SymbolResolver : CodeVisitor { Symbol root_symbol; Scope current_scope; - Gee.List current_using_directives; + Gee.List 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; } diff --git a/vala/valaunresolvedsymbol.vala b/vala/valaunresolvedsymbol.vala index 4ba4469e0..fcfaa3c37 100644 --- a/vala/valaunresolvedsymbol.vala +++ b/vala/valaunresolvedsymbol.vala @@ -20,22 +20,15 @@ * Jürg Billeter */ -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. */ diff --git a/vala/valanamespacereference.vala b/vala/valausingdirective.vala similarity index 60% rename from vala/valanamespacereference.vala rename to vala/valausingdirective.vala index 2f1885472..9fb0766af 100644 --- a/vala/valanamespacereference.vala +++ b/vala/valausingdirective.vala @@ -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); } }