Support qualified access to global symbols with `global::'
authorJuerg Billeter <j@bitron.ch>
Sun, 25 May 2008 11:40:01 +0000 (11:40 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sun, 25 May 2008 11:40:01 +0000 (11:40 +0000)
2008-05-25  Juerg Billeter  <j@bitron.ch>

* vala/valaparser.vala:
* vala/valascanner.vala:
* vala/valasymbolresolver.vala:
* vala/valatokentype.vala:
* vala/valaunresolvedsymbol.vala:

Support qualified access to global symbols with `global::'

svn path=/trunk/; revision=1424

ChangeLog
vala/valaparser.vala
vala/valascanner.vala
vala/valasymbolresolver.vala
vala/valatokentype.vala
vala/valaunresolvedsymbol.vala

index 861f517..d511c25 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2008-05-25  Jürg Billeter  <j@bitron.ch>
 
+       * vala/valaparser.vala:
+       * vala/valascanner.vala:
+       * vala/valasymbolresolver.vala:
+       * vala/valatokentype.vala:
+       * vala/valaunresolvedsymbol.vala:
+
+       Support qualified access to global symbols with `global::'
+
+2008-05-25  Jürg Billeter  <j@bitron.ch>
+
        * vapi/tiff.vapi: various binding fixes, patch by Christian Meyer
 
 2008-05-25  Jürg Billeter  <j@bitron.ch>
index c7a3d71..30c0b5e 100644 (file)
@@ -299,7 +299,7 @@ public class Vala.Parser : CodeVisitor {
        void skip_symbol_name () throws ParseError {
                do {
                        skip_identifier ();
-               } while (accept (TokenType.DOT));
+               } while (accept (TokenType.DOT) || accept (TokenType.DOUBLE_COLON));
        }
 
        UnresolvedSymbol parse_symbol_name () throws ParseError {
@@ -307,6 +307,14 @@ public class Vala.Parser : CodeVisitor {
                UnresolvedSymbol sym = null;
                do {
                        string name = parse_identifier ();
+                       if (name == "global" && accept (TokenType.DOUBLE_COLON)) {
+                               // global::Name
+                               // qualified access to global symbol
+                               name = parse_identifier ();
+                               sym = new UnresolvedSymbol (sym, name, get_src (begin));
+                               sym.qualified = true;
+                               continue;
+                       }
                        sym = new UnresolvedSymbol (sym, name, get_src (begin));
                } while (accept (TokenType.DOT));
                return sym;
index ba19754..38eaf90 100644 (file)
@@ -433,6 +433,10 @@ public class Vala.Scanner : Object {
                        case ':':
                                type = TokenType.COLON;
                                current++;
+                               if (current < end && current[0] == ':') {
+                                       type = TokenType.DOUBLE_COLON;
+                                       current++;
+                               }
                                break;
                        case ',':
                                type = TokenType.COMMA;
index 40f32c5..f574798 100644 (file)
@@ -189,7 +189,10 @@ public class Vala.SymbolResolver : CodeVisitor {
        }
 
        private Symbol? resolve_symbol (UnresolvedSymbol unresolved_symbol) {
-               if (unresolved_symbol.inner == null) {
+               if (unresolved_symbol.qualified) {
+                       // qualified access to global symbol
+                       return root_symbol.scope.lookup (unresolved_symbol.name);
+               } else if (unresolved_symbol.inner == null) {
                        Symbol sym = null;
                        Scope scope = current_scope;
                        while (sym == null && scope != null) {
index 1a7384d..94fc0a0 100644 (file)
@@ -58,6 +58,7 @@ public enum Vala.TokenType {
        DELETE,
        DIV,
        DO,
+       DOUBLE_COLON,
        DOT,
        DYNAMIC,
        ELLIPSIS,
index df8c30b..4ba4469 100644 (file)
@@ -36,6 +36,11 @@ public class Vala.UnresolvedSymbol : CodeNode {
         */
        public string name { get; set; }
 
+       /**
+        * Qualified access to global symbol.
+        */
+       public bool qualified { get; set; }
+
        public UnresolvedSymbol (UnresolvedSymbol? inner, string name, SourceReference? source_reference = null) {
                this.inner = inner;
                this.name = name;