[vala/staging] parser: Add support for explicit "unlock" syntax
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] parser: Add support for explicit "unlock" syntax
- Date: Wed, 25 Apr 2018 17:23:20 +0000 (UTC)
commit 60ded4b69f0556520696b4b4d575743400d9baa1
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Wed Apr 25 16:08:06 2018 +0200
parser: Add support for explicit "unlock" syntax
By providing more control over the internal support for Mutex creation and
usage, this allows a more complex resource control while having an explicit
way to unlock a previously locked lockable.
lock (foo);
...
unlock (foo);
https://bugzilla.gnome.org/show_bug.cgi?id=795545
tests/Makefile.am | 1 +
tests/parser/lock-statement.vala | 19 +++++++++++++++++++
vala/valaparser.vala | 22 +++++++++++++++++++++-
vala/valascanner.vala | 3 +++
vala/valatokentype.vala | 2 ++
5 files changed, 46 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 64ce795..eb07352 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -419,6 +419,7 @@ TESTS = \
parser/function-syntax-error.test \
parser/inner-array-size.test \
parser/invalid-brace.test \
+ parser/lock-statement.vala \
parser/method-no-abstract-override.test \
parser/method-no-abstract-virtual-override.test \
parser/method-no-abstract-virtual.test \
diff --git a/tests/parser/lock-statement.vala b/tests/parser/lock-statement.vala
new file mode 100644
index 0000000..65d9d82
--- /dev/null
+++ b/tests/parser/lock-statement.vala
@@ -0,0 +1,19 @@
+class Foo {
+ int lockable;
+
+ public void explicit_unlocking () {
+ lock (lockable);
+ unlock (lockable);
+ }
+
+ public void implicit_unlocking () {
+ lock (lockable) {
+ }
+ }
+}
+
+void main () {
+ var foo = new Foo ();
+ foo.explicit_unlocking ();
+ foo.implicit_unlocking ();
+}
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 3df315d..eca5565 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -238,6 +238,7 @@ public class Vala.Parser : CodeVisitor {
case TokenType.TRUE:
case TokenType.TRY:
case TokenType.TYPEOF:
+ case TokenType.UNLOCK:
case TokenType.UNOWNED:
case TokenType.USING:
case TokenType.VAR:
@@ -1576,6 +1577,9 @@ public class Vala.Parser : CodeVisitor {
case TokenType.LOCK:
stmt = parse_lock_statement ();
break;
+ case TokenType.UNLOCK:
+ stmt = parse_unlock_statement ();
+ break;
case TokenType.DELETE:
stmt = parse_delete_statement ();
break;
@@ -1740,6 +1744,7 @@ public class Vala.Parser : CodeVisitor {
case TokenType.THROW: return parse_throw_statement ();
case TokenType.TRY: return parse_try_statement ();
case TokenType.LOCK: return parse_lock_statement ();
+ case TokenType.UNLOCK: return parse_unlock_statement ();
case TokenType.DELETE: return parse_delete_statement ();
case TokenType.VAR:
case TokenType.CONST:
@@ -2134,10 +2139,23 @@ public class Vala.Parser : CodeVisitor {
expect (TokenType.OPEN_PARENS);
var expr = parse_expression ();
expect (TokenType.CLOSE_PARENS);
- var stmt = parse_embedded_statement ("lock", false);
+ Block? stmt = null;
+ if (current () != TokenType.SEMICOLON) {
+ stmt = parse_embedded_statement ("lock", false);
+ }
return new LockStatement (expr, stmt, get_src (begin));
}
+ Statement parse_unlock_statement () throws ParseError {
+ var begin = get_location ();
+ expect (TokenType.UNLOCK);
+ expect (TokenType.OPEN_PARENS);
+ var expr = parse_expression ();
+ expect (TokenType.CLOSE_PARENS);
+ expect (TokenType.SEMICOLON);
+ return new UnlockStatement (expr, get_src (begin));
+ }
+
Statement parse_delete_statement () throws ParseError {
var begin = get_location ();
expect (TokenType.DELETE);
@@ -2265,6 +2283,7 @@ public class Vala.Parser : CodeVisitor {
case TokenType.THROW:
case TokenType.TRY:
case TokenType.LOCK:
+ case TokenType.UNLOCK:
case TokenType.DELETE:
case TokenType.VAR:
case TokenType.OP_INC:
@@ -2450,6 +2469,7 @@ public class Vala.Parser : CodeVisitor {
case TokenType.SWITCH:
case TokenType.THROW:
case TokenType.TRY:
+ case TokenType.UNLOCK:
case TokenType.VAR:
case TokenType.WHILE:
case TokenType.YIELD:
diff --git a/vala/valascanner.vala b/vala/valascanner.vala
index 8b50a59..2cb7050 100644
--- a/vala/valascanner.vala
+++ b/vala/valascanner.vala
@@ -473,6 +473,9 @@ public class Vala.Scanner {
break;
}
break;
+ case 'u':
+ if (matches (begin, "unlock")) return TokenType.UNLOCK;
+ break;
}
break;
case 7:
diff --git a/vala/valatokentype.vala b/vala/valatokentype.vala
index a3867f5..38be631 100644
--- a/vala/valatokentype.vala
+++ b/vala/valatokentype.vala
@@ -143,6 +143,7 @@ public enum Vala.TokenType {
TRUE,
TRY,
TYPEOF,
+ UNLOCK,
UNOWNED,
USING,
VAR,
@@ -275,6 +276,7 @@ public enum Vala.TokenType {
case TRUE: return "`true'";
case TRY: return "`try'";
case TYPEOF: return "`typeof'";
+ case UNLOCK: return "`unlock'";
case UNOWNED: return "`unowned'";
case USING: return "`using'";
case VAR: return "`var'";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]