+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:
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")) {
-using GLib;
+using Foo.Sub;
public class GlobalTestClass {
public GlobalTestClass() {
new global::GlobalTestClass();
+ var obj = new ClassInNestedNamespace ();
+
return 0;
}
}
}
+public class Foo.Sub.ClassInNestedNamespace {
+}
+
valamethodtype.vala \
valanamedargument.vala \
valanamespace.vala \
- valanamespacereference.vala \
valanullchecker.vala \
valanullliteral.vala \
valanulltype.vala \
valaunaryexpression.vala \
valaunresolvedsymbol.vala \
valaunresolvedtype.vala \
+ valausingdirective.vala \
valavaluetype.vala \
valavoidtype.vala \
valawhilestatement.vala \
}
/**
- * 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) {
}
/**
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);
}
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);
Class current_class;
Struct current_struct;
- Gee.List<NamespaceReference> current_using_directives;
+ Gee.List<UsingDirective> current_using_directives;
DataType bool_type;
DataType string_type;
}
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) {
*/
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> ();
*
* @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);
}
/**
}
public void accept_children (CodeVisitor visitor) {
- foreach (NamespaceReference ns_ref in using_directives) {
+ foreach (UsingDirective ns_ref in using_directives) {
ns_ref.accept (visitor);
}
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.
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;
+ }
}
}
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;
}
* 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.
*/
-/* valanamespacereference.vala
+/* valausingdirective.vala
*
* Copyright (C) 2006-2008 Jürg Billeter
*
/**
* 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);
}
}