[vala] parser: Warn on if/else/lock without body
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] parser: Warn on if/else/lock without body
- Date: Tue, 23 Sep 2014 09:42:35 +0000 (UTC)
commit 071b7c87283a2bd8096d0d3f81265287880e716f
Author: Florian Brosch <flo brosch gmail com>
Date: Sun Sep 14 19:32:20 2014 +0200
parser: Warn on if/else/lock without body
Fixes bug 682906.
vala/valaparser.vala | 26 +++++++++++++++-----------
1 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 512909f..1f08f52 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -1672,7 +1672,7 @@ public class Vala.Parser : CodeVisitor {
return false;
}
- Block parse_embedded_statement () throws ParseError {
+ Block parse_embedded_statement (string statement_name, bool accept_empty_body = true) throws
ParseError {
if (current () == TokenType.OPEN_BRACE) {
var block = parse_block ();
return block;
@@ -1682,16 +1682,20 @@ public class Vala.Parser : CodeVisitor {
var block = new Block (get_src (get_location ()));
- var stmt = parse_embedded_statement_without_block ();
+ var stmt = parse_embedded_statement_without_block (statement_name, accept_empty_body);
block.add_statement (stmt);
return block;
}
- Statement parse_embedded_statement_without_block () throws ParseError {
+ Statement parse_embedded_statement_without_block (string statement_name, bool accept_empty_body)
throws ParseError {
switch (current ()) {
- case TokenType.SEMICOLON: return parse_empty_statement ();
+ case TokenType.SEMICOLON:
+ if (!accept_empty_body) {
+ Report.warning (get_current_src (), "%s-statement without body".printf
(statement_name));
+ }
+ return parse_empty_statement ();
case TokenType.IF: return parse_if_statement ();
case TokenType.SWITCH: return parse_switch_statement ();
case TokenType.WHILE: return parse_while_statement ();
@@ -1859,10 +1863,10 @@ public class Vala.Parser : CodeVisitor {
var condition = parse_expression ();
expect (TokenType.CLOSE_PARENS);
var src = get_src (begin);
- var true_stmt = parse_embedded_statement ();
+ var true_stmt = parse_embedded_statement ("if", false);
Block false_stmt = null;
if (accept (TokenType.ELSE)) {
- false_stmt = parse_embedded_statement ();
+ false_stmt = parse_embedded_statement ("else", false);
}
return new IfStatement (condition, true_stmt, false_stmt, src);
}
@@ -1900,14 +1904,14 @@ public class Vala.Parser : CodeVisitor {
expect (TokenType.OPEN_PARENS);
var condition = parse_expression ();
expect (TokenType.CLOSE_PARENS);
- var body = parse_embedded_statement ();
+ var body = parse_embedded_statement ("while");
return new WhileStatement (condition, body, get_src (begin));
}
Statement parse_do_statement () throws ParseError {
var begin = get_location ();
expect (TokenType.DO);
- var body = parse_embedded_statement ();
+ var body = parse_embedded_statement ("do");
expect (TokenType.WHILE);
expect (TokenType.OPEN_PARENS);
var condition = parse_expression ();
@@ -1961,7 +1965,7 @@ public class Vala.Parser : CodeVisitor {
}
expect (TokenType.CLOSE_PARENS);
var src = get_src (begin);
- var body = parse_embedded_statement ();
+ var body = parse_embedded_statement ("for");
var stmt = new ForStatement (condition, body, src);
foreach (Expression init in initializer_list) {
stmt.add_initializer (init);
@@ -1994,7 +1998,7 @@ public class Vala.Parser : CodeVisitor {
var collection = parse_expression ();
expect (TokenType.CLOSE_PARENS);
var src = get_src (begin);
- var body = parse_embedded_statement ();
+ var body = parse_embedded_statement ("foreach");
return new ForeachStatement (type, id, collection, body, src);
}
@@ -2095,7 +2099,7 @@ public class Vala.Parser : CodeVisitor {
expect (TokenType.OPEN_PARENS);
var expr = parse_expression ();
expect (TokenType.CLOSE_PARENS);
- var stmt = parse_embedded_statement ();
+ var stmt = parse_embedded_statement ("lock", false);
return new LockStatement (expr, stmt, get_src (begin));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]