Re: [Vala] [PATCH] Implement alias functionality for 'using' directive

2011-04-04 Thread Treviño
Il giorno dom, 03/04/2011 alle 18.11 -0500, Jim Peters ha scritto:
 Required to disambiguate symbol references in case of matches from
 multiple 'using' statements.

Great! ;)


___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] [PATCH] Implement alias functionality for 'using' directive

2011-04-04 Thread Jürg Billeter
On Sun, 2011-04-03 at 18:16 -0500, Jim Peters wrote:
 Jim Peters wrote:
  Required to disambiguate symbol references in case of matches from
  multiple 'using' statements.
 
 I've implemented the alias functionality missing from 'using'.  It
 took 3 tries before I found a way that worked and didn't upset the
 existing code too much.
 
 As Vala tries to follow C#, I've done it the C# way.  According to the
 C# language spec 9.3.2, an alias can be used to disambiguate the case
 which at the moment gives an ambiguous reference error.
 
 I've added error messages that suggest the using directives that the
 user can insert to resolve the issue.

This sounds great. I'll review the patch as soon as possible, but it
might make sense to attach it to a bug report in Bugzilla so that it
doesn't get lost in the mail. Hopefully, I'll soon have some time for
patch review in general.

Thanks,
Jürg

___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] [PATCH] Implement alias functionality for 'using' directive

2011-04-04 Thread Jim Peters
Jürg Billeter wrote:
 This sounds great. I'll review the patch as soon as possible, but it
 might make sense to attach it to a bug report in Bugzilla so that it
 doesn't get lost in the mail. Hopefully, I'll soon have some time for
 patch review in general.

Thanks.  It is bug #646713.

Jim

-- 
 Jim Peters  (_)/=\~/_(_) j...@uazu.net
  (_)  /=\  ~/_  (_)
 Uazú  (_)/=\~/_(_)http://
 in Peru(_)  /=\  ~/_  (_)uazu.net
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] [PATCH] Implement alias functionality for 'using' directive

2011-04-03 Thread Jim Peters
Required to disambiguate symbol references in case of matches from
multiple 'using' statements.
---
 tests/namespaces/aliases.vala |   30 
 vala/valacodewriter.vala  |6 ++-
 vala/valamemberaccess.vala|   26 +++
 vala/valaparser.vala  |   17 ++-
 vala/valasymbolresolver.vala  |   51 ---
 vala/valausingdirective.vala  |  105 ++--
 6 files changed, 197 insertions(+), 38 deletions(-)
 create mode 100644 tests/namespaces/aliases.vala

diff --git a/tests/namespaces/aliases.vala b/tests/namespaces/aliases.vala
new file mode 100644
index 000..277ae6e
--- /dev/null
+++ b/tests/namespaces/aliases.vala
@@ -0,0 +1,30 @@
+// Based on example of ambuiguity resolution from C# language
+// reference 9.3.2
+
+namespace N1 {
+   public class A {
+   public A() {}
+   public int test() { return 1234; }
+   }
+}
+namespace N2 {
+   public class A {
+   public A() {}
+   public int test() { return 5678; }
+   }
+}
+
+namespace N3 {
+   using N1;
+   using N2;
+   using A = N1.A;
+   public class B : A {  // A means N1.A
+   public B() { base(); }
+   }
+}
+
+public static void main() {
+   assert(new N1.A().test() == 1234);
+   assert(new N2.A().test() == 5678);
+   assert(new N3.B().test() == 1234);
+}
diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index b6e31c2..8cecbe8 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -124,7 +124,11 @@ public class Vala.CodeWriter : CodeVisitor {
 
public override void visit_using_directive (UsingDirective ns) {
if (type == CodeWriterType.FAST) {
-   write_string (using %s;\n.printf 
(ns.namespace_symbol.name));
+   if (ns.alias != null) {
+   write_string (using %s = %s;\n.printf 
(ns.alias, ns.symbol.name));
+   } else {
+   write_string (using %s;\n.printf 
(ns.symbol.name));
+   }
}
}
 
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index dfb0eb6..9026bb3 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -277,17 +277,25 @@ public class Vala.MemberAccess : Expression {
}
 
if (symbol_reference == null  source_reference != 
null) {
-   foreach (UsingDirective ns in 
source_reference.using_directives) {
-   var local_sym = 
ns.namespace_symbol.scope.lookup (member_name);
-   if (local_sym != null) {
-   if (symbol_reference != null  
symbol_reference != local_sym) {
-   error = true;
-   Report.error 
(source_reference, `%s' is an ambiguous reference between `%s' and 
`%s'.printf (member_name, symbol_reference.get_full_name (), 
local_sym.get_full_name ()));
-   return false;
-   }
-   symbol_reference = local_sym;
+   var scanner = new UsingDirective.Scanner 
(member_name, false);
+   foreach (UsingDirective ud in 
source_reference.using_directives) {
+   scanner.try_match (ud);
+   }
+   if (scanner.ambiguous) {
+   // Rescan to pick up errors
+   scanner = new UsingDirective.Scanner 
(member_name, true);
+   foreach (UsingDirective ud in 
source_reference.using_directives) {
+   scanner.try_match (ud);
+   }
+   if (scanner.alias_match) {
+   Report.error (source_reference, 
`%s' is an ambiguous reference to duplicate aliases:%s.printf (member_name, 
scanner.error_string.str));
+   } else {
+   Report.error (source_reference, 
`%s' is an ambiguous reference; add one of these aliases to resolve:%s.printf 
(member_name, scanner.error_string.str));
}
+   error = true;
+   return false;
}
+   symbol_reference = scanner.match;
}
} else {
if 

Re: [Vala] [PATCH] Implement alias functionality for 'using' directive

2011-04-03 Thread Jim Peters
Jim Peters wrote:
 Required to disambiguate symbol references in case of matches from
 multiple 'using' statements.

I've implemented the alias functionality missing from 'using'.  It
took 3 tries before I found a way that worked and didn't upset the
existing code too much.

As Vala tries to follow C#, I've done it the C# way.  According to the
C# language spec 9.3.2, an alias can be used to disambiguate the case
which at the moment gives an ambiguous reference error.

I've added error messages that suggest the using directives that the
user can insert to resolve the issue.

For example, compiling the following code with this patch:

  using Gee;

  public void main() {
 Queue queue = new LinkedListObject();
  }

gives the following error message:

  bug.vala:4.2-4.6: error: `Queue' is an ambiguous reference; add one of these 
aliases to resolve:
using Queue = GLib.Queue;
using Queue = Gee.Queue;
 Queue queue = new LinkedListObject();
 ^

Adding in 'using Queue = Gee.Queue;' fixes the problem.  This code
builds now:

  using Gee;
  using Queue = Gee.Queue;

  public void main() {
 Queue queue = new LinkedListObject();
  }

I've tried to follow the existing style.  I checked all the code
related to existing 'using' functionality -- I hope I got it right.
I've added a new test case, and the existing test cases pass.

If this patch isn't okay, I can make changes and reissue.

Jim

-- 
 Jim Peters  (_)/=\~/_(_) j...@uazu.net
  (_)  /=\  ~/_  (_)
 Uazú  (_)/=\~/_(_)http://
 in Peru(_)  /=\  ~/_  (_)uazu.net
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list