]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add `owned' type modifier and `(owned)' cast to replace `#', add `unowned'
authorJürg Billeter <j@bitron.ch>
Fri, 19 Dec 2008 10:47:17 +0000 (10:47 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 19 Dec 2008 10:47:17 +0000 (10:47 +0000)
2008-12-19  Jürg Billeter  <j@bitron.ch>

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

Add `owned' type modifier and `(owned)' cast to replace `#',
add `unowned' type modifier to complement `weak' for non-reference
counted objects.

`#' will be deprecated in Vala 0.5.5

svn path=/trunk/; revision=2214

ChangeLog
vala/valaparser.vala
vala/valascanner.vala
vala/valatokentype.vala

index ff35f5a266e94a94fe62ae898720fc8400060a02..1a2e9e10e85cf6d436fe165bdc87c617927fb95a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-12-19  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valaparser.vala:
+       * vala/valascanner.vala:
+       * vala/valatokentype.vala:
+
+       Add `owned' type modifier and `(owned)' cast to replace `#',
+       add `unowned' type modifier to complement `weak' for non-reference
+       counted objects.
+
+       `#' will be deprecated in Vala 0.5.5
+
 2008-12-18  Jürg Billeter  <j@bitron.ch>
 
        * gobject/valaccodememberaccessmodule.vala:
index 9352ddcacacd15cf719d6ccd676630218ef2c97a..f0188fc896a671eb13d52839ab6d146a77f8294d 100644 (file)
@@ -207,6 +207,7 @@ public class Vala.Parser : CodeVisitor {
                case TokenType.NULL:
                case TokenType.OUT:
                case TokenType.OVERRIDE:
+               case TokenType.OWNED:
                case TokenType.PARAMS:
                case TokenType.PRIVATE:
                case TokenType.PROTECTED:
@@ -226,6 +227,7 @@ public class Vala.Parser : CodeVisitor {
                case TokenType.TRUE:
                case TokenType.TRY:
                case TokenType.TYPEOF:
+               case TokenType.UNOWNED:
                case TokenType.USING:
                case TokenType.VAR:
                case TokenType.VIRTUAL:
@@ -336,6 +338,8 @@ public class Vala.Parser : CodeVisitor {
                        return;
                }
                accept (TokenType.DYNAMIC);
+               accept (TokenType.OWNED);
+               accept (TokenType.UNOWNED);
                accept (TokenType.WEAK);
                skip_symbol_name ();
                skip_type_argument_list ();
@@ -369,8 +373,14 @@ public class Vala.Parser : CodeVisitor {
                bool is_dynamic = accept (TokenType.DYNAMIC);
 
                bool value_owned = owned_by_default;
+
                if (owned_by_default) {
-                       value_owned = !accept (TokenType.WEAK);
+                       if (accept (TokenType.UNOWNED)
+                           || accept (TokenType.WEAK)) {
+                               value_owned = false;
+                       }
+               } else {
+                       value_owned = accept (TokenType.OWNED);
                }
 
                var sym = parse_symbol_name ();
@@ -419,7 +429,11 @@ public class Vala.Parser : CodeVisitor {
                }
 
                if (!owned_by_default) {
-                       value_owned = accept (TokenType.HASH);
+                       if (accept (TokenType.HASH)) {
+                               // TODO enable warning after releasing Vala 0.5.4
+                               // Report.warning (get_last_src (), "deprecated syntax, use `owned` modifier");
+                               value_owned = true;
+                       }
                }
 
                type.is_dynamic = is_dynamic;
@@ -776,15 +790,24 @@ public class Vala.Parser : CodeVisitor {
                }
                switch (current ()) {
                case TokenType.HASH:
+                       // TODO enable warning after releasing Vala 0.5.4
+                       // Report.warning (get_last_src (), "deprecated syntax, use `(owned)` cast");
                        next ();
                        var op = parse_unary_expression ();
                        return new ReferenceTransferExpression (op, get_src (begin));
                case TokenType.OPEN_PARENS:
                        next ();
                        switch (current ()) {
+                       case TokenType.OWNED:
+                               // (owned) foo
+                               next ();
+                               if (accept (TokenType.CLOSE_PARENS)) {
+                                       var op = parse_unary_expression ();
+                                       return new ReferenceTransferExpression (op, get_src (begin));
+                               }
+                               break;
                        case TokenType.VOID:
                        case TokenType.DYNAMIC:
-                       case TokenType.WEAK:
                        case TokenType.IDENTIFIER:
                                var type = parse_type ();
                                if (accept (TokenType.CLOSE_PARENS)) {
@@ -807,9 +830,6 @@ public class Vala.Parser : CodeVisitor {
                                        case TokenType.SIZEOF:
                                        case TokenType.TYPEOF:
                                        case TokenType.IDENTIFIER:
-                                               if (!(type is PointerType) && !type.value_owned) {
-                                                       Report.warning (get_src (begin), "obsolete syntax, weak type modifier unused in cast expressions");
-                                               }
                                                var inner = parse_unary_expression ();
                                                return new CastExpression (inner, type, get_src (begin), false);
                                        default:
@@ -2179,7 +2199,7 @@ public class Vala.Parser : CodeVisitor {
                var begin = get_location ();
                var access = parse_access_modifier ();
                var flags = parse_member_declaration_modifiers ();
-               bool is_weak = accept (TokenType.WEAK);
+               bool is_weak = accept (TokenType.UNOWNED) || accept (TokenType.WEAK);
                var type = parse_type (false);
                string id = parse_identifier ();
                var prop = new Property (id, type, null, null, get_src_com (begin));
@@ -2818,6 +2838,7 @@ public class Vala.Parser : CodeVisitor {
                                switch (current ()) {
                                case TokenType.VOID:
                                case TokenType.DYNAMIC:
+                               case TokenType.UNOWNED:
                                case TokenType.WEAK:
                                case TokenType.IDENTIFIER:
                                        var type = parse_type ();
index daa7f44efba6e586490db2fd14cbbe839fc871a2..390f8161298514d32346a83dbb2717fbd07b869b 100644 (file)
@@ -166,6 +166,9 @@ public class Vala.Scanner {
                        case 'f':
                                if (matches (begin, "false")) return TokenType.FALSE;
                                break;
+                       case 'o':
+                               if (matches (begin, "owned")) return TokenType.OWNED;
+                               break;
                        case 't':
                                if (matches (begin, "throw")) return TokenType.THROW;
                                break;
@@ -274,6 +277,9 @@ public class Vala.Scanner {
                        case 'p':
                                if (matches (begin, "private")) return TokenType.PRIVATE;
                                break;
+                       case 'u':
+                               if (matches (begin, "unowned")) return TokenType.UNOWNED;
+                               break;
                        case 'v':
                                if (matches (begin, "virtual")) return TokenType.VIRTUAL;
                                break;
index ff59df3f6e3e7aec9462645dee63df34e421fe6c..0b80e4694885846834b2046ac703f708abe320f3 100644 (file)
@@ -107,6 +107,7 @@ public enum Vala.TokenType {
        OPEN_BRACKET,
        OPEN_PARENS,
        OVERRIDE,
+       OWNED,
        PARAMS,
        PERCENT,
        PLUS,
@@ -133,6 +134,7 @@ public enum Vala.TokenType {
        TRUE,
        TRY,
        TYPEOF,
+       UNOWNED,
        USING,
        VAR,
        VERBATIM_STRING_LITERAL,
@@ -226,6 +228,7 @@ public enum Vala.TokenType {
                case OPEN_BRACKET: return "`['";
                case OPEN_PARENS: return "`('";
                case OVERRIDE: return "`override'";
+               case OWNED: return "`owned'";
                case PARAMS: return "`params'";
                case PERCENT: return "`%'";
                case PLUS: return "`+'";
@@ -252,6 +255,7 @@ public enum Vala.TokenType {
                case TRUE: return "`true'";
                case TRY: return "`try'";
                case TYPEOF: return "`typeof'";
+               case UNOWNED: return "`unowned'";
                case USING: return "`using'";
                case VAR: return "`var'";
                case VIRTUAL: return "`virtual'";