Commit aaa70e51 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Replace NamespaceReference by UsingDirective and UnresolvedSymbol, fixes

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
parent 5aeac6a9
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:
......
......@@ -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")) {
......
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 {
}
......@@ -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 \
......
......@@ -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) {
}
/**
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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) {
......
......@@ -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);
}
......
......@@ -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;
}
......
......@@ -20,22 +20,15 @@
* 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
*
......@@ -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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment