[vala/staging] vala: Rename Loop to LoopStatement and introduce a common base class
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Rename Loop to LoopStatement and introduce a common base class
- Date: Mon, 1 Feb 2021 09:18:12 +0000 (UTC)
commit b3ee5b0fffc7ab7f5d070bfde5bf8bb1d661b5e8
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Jan 9 16:21:06 2018 +0100
vala: Rename Loop to LoopStatement and introduce a common base class
codegen/valaccodebasemodule.vala | 4 +-
codegen/valaccodecontrolflowmodule.vala | 2 +-
vala/Makefile.am | 1 +
vala/valacodevisitor.vala | 2 +-
vala/valacodewriter.vala | 2 +-
vala/valadostatement.vala | 49 +++--------------------
vala/valaflowanalyzer.vala | 2 +-
vala/valaforstatement.vala | 44 +++------------------
vala/valagenieparser.vala | 2 +-
vala/valaloop.vala | 69 +++++++++++++--------------------
vala/valaloopstatement.vala | 68 ++++++++++++++++++++++++++++++++
vala/valaparser.vala | 2 +-
vala/valasymbolresolver.vala | 2 +-
vala/valatraversevisitor.vala | 2 +-
vala/valawhilestatement.vala | 43 ++------------------
15 files changed, 120 insertions(+), 174 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 0f501fc2e..c7ef8c9a3 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3950,13 +3950,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
append_scope_free (sym, stop_at);
if (jump_stmt is BreakStatement) {
- if (b.parent_node is Loop ||
+ if (b.parent_node is LoopStatement ||
b.parent_node is ForeachStatement ||
b.parent_node is SwitchStatement) {
return;
}
} else if (jump_stmt is ContinueStatement) {
- if (b.parent_node is Loop ||
+ if (b.parent_node is LoopStatement ||
b.parent_node is ForeachStatement) {
return;
}
diff --git a/codegen/valaccodecontrolflowmodule.vala b/codegen/valaccodecontrolflowmodule.vala
index dbf64b759..5cca19707 100644
--- a/codegen/valaccodecontrolflowmodule.vala
+++ b/codegen/valaccodecontrolflowmodule.vala
@@ -205,7 +205,7 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
}
}
- public override void visit_loop (Loop stmt) {
+ public override void visit_loop_statement (LoopStatement stmt) {
if (context.profile == Profile.GOBJECT) {
ccode.open_while (new CCodeConstant ("TRUE"));
} else {
diff --git a/vala/Makefile.am b/vala/Makefile.am
index 542c24f4d..09f3c0672 100644
--- a/vala/Makefile.am
+++ b/vala/Makefile.am
@@ -111,6 +111,7 @@ libvala_la_VALASOURCES = \
valalockable.vala \
valalockstatement.vala \
valaloop.vala \
+ valaloopstatement.vala \
valamarkupreader.vala \
valamemberaccess.vala \
valamemberinitializer.vala \
diff --git a/vala/valacodevisitor.vala b/vala/valacodevisitor.vala
index f47f96349..598d15c04 100644
--- a/vala/valacodevisitor.vala
+++ b/vala/valacodevisitor.vala
@@ -297,7 +297,7 @@ public abstract class Vala.CodeVisitor {
*
* @param stmt a loop
*/
- public virtual void visit_loop (Loop stmt) {
+ public virtual void visit_loop_statement (LoopStatement stmt) {
}
/**
diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index 0f624c010..944451e41 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -1081,7 +1081,7 @@ public class Vala.CodeWriter : CodeVisitor {
}
}
- public override void visit_loop (Loop stmt) {
+ public override void visit_loop_statement (LoopStatement stmt) {
write_indent ();
write_string ("loop");
stmt.body.accept (this);
diff --git a/vala/valadostatement.vala b/vala/valadostatement.vala
index 80df5849e..5605e1a01 100644
--- a/vala/valadostatement.vala
+++ b/vala/valadostatement.vala
@@ -25,48 +25,17 @@ using GLib;
/**
* Represents a do iteration statement in the source code.
*/
-public class Vala.DoStatement : CodeNode, Statement {
- /**
- * Specifies the loop body.
- */
- public Block body {
- get {
- return _body;
- }
- private set {
- _body = value;
- _body.parent_node = this;
- }
- }
-
- /**
- * Specifies the loop condition.
- */
- public Expression condition {
- get {
- return _condition;
- }
- private set {
- _condition = value;
- _condition.parent_node = this;
- }
- }
-
- private Expression _condition;
- private Block _body;
-
+public class Vala.DoStatement : Loop, Statement {
/**
* Creates a new do statement.
*
- * @param body loop body
* @param condition loop condition
+ * @param body loop body
* @param source_reference reference to source code
* @return newly created do statement
*/
- public DoStatement (Block body, Expression condition, SourceReference? source_reference = null) {
- this.condition = condition;
- this.source_reference = source_reference;
- this.body = body;
+ public DoStatement (Expression condition, Block body, SourceReference? source_reference = null) {
+ base (condition, body, source_reference);
}
public override void accept (CodeVisitor visitor) {
@@ -81,12 +50,6 @@ public class Vala.DoStatement : CodeNode, Statement {
visitor.visit_end_full_expression (condition);
}
- public override void replace_expression (Expression old_node, Expression new_node) {
- if (condition == old_node) {
- condition = new_node;
- }
- }
-
public override bool check (CodeContext context) {
if (checked) {
return !error;
@@ -98,7 +61,7 @@ public class Vala.DoStatement : CodeNode, Statement {
// do not generate variable and if block if condition is always true
if (condition.is_always_true ()) {
- var loop = new Loop (body, source_reference);
+ var loop = new LoopStatement (body, source_reference);
unowned Block parent_block = (Block) parent_node;
parent_block.replace_statement (this, loop);
@@ -127,7 +90,7 @@ public class Vala.DoStatement : CodeNode, Statement {
body.insert_statement (0, first_if);
body.insert_statement (1, new ExpressionStatement (new Assignment (new MemberAccess.simple
(first_local.name, source_reference), new BooleanLiteral (false, source_reference),
AssignmentOperator.SIMPLE, source_reference), source_reference));
- block.add_statement (new Loop (body, source_reference));
+ block.add_statement (new LoopStatement (body, source_reference));
unowned Block parent_block = (Block) parent_node;
parent_block.replace_statement (this, block);
diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala
index a859d7b8b..a86bda42a 100644
--- a/vala/valaflowanalyzer.vala
+++ b/vala/valaflowanalyzer.vala
@@ -752,7 +752,7 @@ public class Vala.FlowAnalyzer : CodeVisitor {
jump_stack.remove_at (jump_stack.size - 1);
}
- public override void visit_loop (Loop stmt) {
+ public override void visit_loop_statement (LoopStatement stmt) {
if (unreachable (stmt)) {
return;
}
diff --git a/vala/valaforstatement.vala b/vala/valaforstatement.vala
index dc721163c..cb494444f 100644
--- a/vala/valaforstatement.vala
+++ b/vala/valaforstatement.vala
@@ -25,41 +25,10 @@ using GLib;
/**
* Represents a for iteration statement in the source code.
*/
-public class Vala.ForStatement : CodeNode, Statement {
- /**
- * Specifies the loop condition.
- */
- public Expression? condition {
- get {
- return _condition;
- }
- private set {
- _condition = value;
- if (_condition != null) {
- _condition.parent_node = this;
- }
- }
- }
-
- /**
- * Specifies the loop body.
- */
- public Block body {
- get {
- return _body;
- }
- private set {
- _body = value;
- _body.parent_node = this;
- }
- }
-
+public class Vala.ForStatement : Loop, Statement {
private List<Expression> initializer = new ArrayList<Expression> ();
private List<Expression> iterator = new ArrayList<Expression> ();
- private Expression _condition;
- private Block _body;
-
/**
* Creates a new for statement.
*
@@ -69,9 +38,7 @@ public class Vala.ForStatement : CodeNode, Statement {
* @return newly created for statement
*/
public ForStatement (Expression? condition, Block body, SourceReference? source_reference = null) {
- this.condition = condition;
- this.body = body;
- this.source_reference = source_reference;
+ base (condition, body, source_reference);
}
/**
@@ -137,9 +104,8 @@ public class Vala.ForStatement : CodeNode, Statement {
}
public override void replace_expression (Expression old_node, Expression new_node) {
- if (condition == old_node) {
- condition = new_node;
- }
+ base.replace_expression (old_node, new_node);
+
for (int i=0; i < initializer.size; i++) {
if (initializer[i] == old_node) {
initializer[i] = new_node;
@@ -197,7 +163,7 @@ public class Vala.ForStatement : CodeNode, Statement {
body.insert_statement (0, first_if);
body.insert_statement (1, new ExpressionStatement (new Assignment (new MemberAccess.simple
(first_local.name, source_reference), new BooleanLiteral (false, source_reference),
AssignmentOperator.SIMPLE, source_reference), source_reference));
- block.add_statement (new Loop (body, source_reference));
+ block.add_statement (new LoopStatement (body, source_reference));
unowned Block parent_block = (Block) parent_node;
parent_block.replace_statement (this, block);
diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala
index 239a72542..2b3537cf6 100644
--- a/vala/valagenieparser.vala
+++ b/vala/valagenieparser.vala
@@ -2111,7 +2111,7 @@ public class Vala.Genie.Parser : CodeVisitor {
expect_terminator ();
- return new DoStatement (body, condition, get_src (begin));
+ return new DoStatement (condition, body, get_src (begin));
}
diff --git a/vala/valaloop.vala b/vala/valaloop.vala
index ce6894633..c9e16a21f 100644
--- a/vala/valaloop.vala
+++ b/vala/valaloop.vala
@@ -1,6 +1,6 @@
/* valaloop.vala
*
- * Copyright (C) 2009-2010 Jürg Billeter
+ * Copyright (C) 2021 Rico Tzschichholz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -17,15 +17,28 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
- * Jürg Billeter <j bitron ch>
+ * Rico Tzschichholz <ricotz ubuntu com>
*/
-using GLib;
-
/**
- * Represents an endless loop.
+ * Base class for all loop statements.
*/
-public class Vala.Loop : CodeNode, Statement {
+public abstract class Vala.Loop : CodeNode {
+ /**
+ * Specifies the loop condition.
+ */
+ public Expression? condition {
+ get {
+ return _condition;
+ }
+ private set {
+ _condition = value;
+ if (_condition != null) {
+ _condition.parent_node = this;
+ }
+ }
+ }
+
/**
* Specifies the loop body.
*/
@@ -33,52 +46,24 @@ public class Vala.Loop : CodeNode, Statement {
get {
return _body;
}
- set {
+ private set {
_body = value;
_body.parent_node = this;
}
}
- private Block _body;
+ Expression _condition;
+ Block _body;
- /**
- * Creates a new loop.
- *
- * @param body loop body
- * @param source_reference reference to source code
- * @return newly created while statement
- */
- public Loop (Block body, SourceReference? source_reference = null) {
+ protected Loop (Expression? condition, Block body, SourceReference? source_reference = null) {
+ this.condition = condition;
this.body = body;
this.source_reference = source_reference;
}
- public override void accept (CodeVisitor visitor) {
- visitor.visit_loop (this);
- }
-
- public override void accept_children (CodeVisitor visitor) {
- body.accept (visitor);
- }
-
- public override void get_error_types (Collection<DataType> collection, SourceReference?
source_reference = null) {
- body.get_error_types (collection, source_reference);
- }
-
- public override bool check (CodeContext context) {
- if (checked) {
- return !error;
+ public override void replace_expression (Expression old_node, Expression new_node) {
+ if (condition == old_node) {
+ condition = new_node;
}
-
- checked = true;
-
- body.check (context);
-
- return !error;
- }
-
- public override void emit (CodeGenerator codegen) {
- codegen.visit_loop (this);
}
}
-
diff --git a/vala/valaloopstatement.vala b/vala/valaloopstatement.vala
new file mode 100644
index 000000000..8348d300c
--- /dev/null
+++ b/vala/valaloopstatement.vala
@@ -0,0 +1,68 @@
+/* valaloopstatement.vala
+ *
+ * Copyright (C) 2009-2010 Jürg Billeter
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Jürg Billeter <j bitron ch>
+ */
+
+using GLib;
+
+/**
+ * Represents an endless loop.
+ */
+public class Vala.LoopStatement : Loop, Statement {
+ /**
+ * Creates a new loop.
+ *
+ * @param body loop body
+ * @param source_reference reference to source code
+ * @return newly created while statement
+ */
+ public LoopStatement (Block body, SourceReference? source_reference = null) {
+ base (null, body, source_reference);
+ }
+
+ public override void accept (CodeVisitor visitor) {
+ visitor.visit_loop_statement (this);
+ }
+
+ public override void accept_children (CodeVisitor visitor) {
+ body.accept (visitor);
+ }
+
+ public override void get_error_types (Collection<DataType> collection, SourceReference?
source_reference = null) {
+ body.get_error_types (collection, source_reference);
+ }
+
+ public override bool check (CodeContext context) {
+ if (checked) {
+ return !error;
+ }
+
+ checked = true;
+
+ body.check (context);
+
+ return !error;
+ }
+
+ public override void emit (CodeGenerator codegen) {
+ codegen.visit_loop_statement (this);
+ }
+}
+
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index f54de7832..2c2db2d3a 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -2124,7 +2124,7 @@ public class Vala.Parser : CodeVisitor {
var condition = parse_expression ();
expect (TokenType.CLOSE_PARENS);
expect (TokenType.SEMICOLON);
- return new DoStatement (body, condition, get_src (begin));
+ return new DoStatement (condition, body, get_src (begin));
}
Statement parse_for_statement () throws ParseError {
diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala
index 35d19d89d..b5594bfe0 100644
--- a/vala/valasymbolresolver.vala
+++ b/vala/valasymbolresolver.vala
@@ -562,7 +562,7 @@ public class Vala.SymbolResolver : CodeVisitor {
label.accept_children (this);
}
- public override void visit_loop (Loop stmt) {
+ public override void visit_loop_statement (LoopStatement stmt) {
if (stmt.checked) {
return;
}
diff --git a/vala/valatraversevisitor.vala b/vala/valatraversevisitor.vala
index c8e466481..34eb7a39a 100644
--- a/vala/valatraversevisitor.vala
+++ b/vala/valatraversevisitor.vala
@@ -198,7 +198,7 @@ public class Vala.TraverseVisitor : CodeVisitor {
}
}
- public override void visit_loop (Loop loop) {
+ public override void visit_loop_statement (LoopStatement loop) {
if (func (loop) == TraverseStatus.CONTINUE) {
loop.accept_children (this);
}
diff --git a/vala/valawhilestatement.vala b/vala/valawhilestatement.vala
index 161252219..be9237242 100644
--- a/vala/valawhilestatement.vala
+++ b/vala/valawhilestatement.vala
@@ -25,36 +25,7 @@ using GLib;
/**
* Represents a while iteration statement in the source code.
*/
-public class Vala.WhileStatement : CodeNode, Statement {
- /**
- * Specifies the loop condition.
- */
- public Expression condition {
- get {
- return _condition;
- }
- private set {
- _condition = value;
- _condition.parent_node = this;
- }
- }
-
- /**
- * Specifies the loop body.
- */
- public Block body {
- get {
- return _body;
- }
- private set {
- _body = value;
- _body.parent_node = this;
- }
- }
-
- private Expression _condition;
- private Block _body;
-
+public class Vala.WhileStatement : Loop, Statement {
/**
* Creates a new while statement.
*
@@ -64,9 +35,7 @@ public class Vala.WhileStatement : CodeNode, Statement {
* @return newly created while statement
*/
public WhileStatement (Expression condition, Block body, SourceReference? source_reference = null) {
- this.body = body;
- this.source_reference = source_reference;
- this.condition = condition;
+ base (condition, body, source_reference);
}
public override void accept (CodeVisitor visitor) {
@@ -81,12 +50,6 @@ public class Vala.WhileStatement : CodeNode, Statement {
body.accept (visitor);
}
- public override void replace_expression (Expression old_node, Expression new_node) {
- if (condition == old_node) {
- condition = new_node;
- }
- }
-
public override bool check (CodeContext context) {
if (checked) {
return !error;
@@ -109,7 +72,7 @@ public class Vala.WhileStatement : CodeNode, Statement {
body.insert_statement (0, if_stmt);
}
- var loop = new Loop (body, source_reference);
+ var loop = new LoopStatement (body, source_reference);
unowned Block parent_block = (Block) parent_node;
parent_block.replace_statement (this, loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]