[vala/wip/transform: 71/107] Make Method.yield_count be stateless
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 71/107] Make Method.yield_count be stateless
- Date: Fri, 21 Oct 2016 14:16:48 +0000 (UTC)
commit 34ecb3a7ff50637c91b7955fac85218da02b75dc
Author: Luca Bruno <lucabru src gnome org>
Date: Sat Oct 27 18:32:59 2012 +0200
Make Method.yield_count be stateless
codegen/valaccodemethodmodule.vala | 28 +++++++++++++++++++++++++++-
vala/valamethod.vala | 2 --
vala/valamethodcall.vala | 1 -
vala/valaobjectcreationexpression.vala | 1 -
vala/valayieldstatement.vala | 2 --
5 files changed, 27 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index e93a80f..9d2b7ae 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -286,6 +286,30 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
}
}
+ int get_yield_count (Method m) {
+ int yield_count = 0;
+ var traverse = new TraverseVisitor ((n) => {
+ if (n is Method && n != m) {
+ return TraverseStatus.STOP;
+ } else if (n is MethodCall) {
+ var expr = (MethodCall) n;
+ if (expr.is_yield_expression) {
+ yield_count++;
+ }
+ } else if (n is YieldStatement) {
+ yield_count++;
+ } else if (n is ObjectCreationExpression) {
+ var expr = (ObjectCreationExpression) n;
+ if (expr.is_yield_expression) {
+ yield_count++;
+ }
+ }
+ return TraverseStatus.CONTINUE;
+ });
+ m.accept (traverse);
+ return yield_count;
+ }
+
/**
* This function generates the code the given method. If the method is
* a constructor, _construct is generated, unless it's variadic, in which
@@ -460,7 +484,9 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
ccode.add_case (new CCodeConstant ("0"));
ccode.add_goto ("_state_0");
- for (int state = 1; state <= m.yield_count; state++) {
+ var yield_count = get_yield_count (m);
+
+ for (int state = 1; state <= yield_count; state++) {
ccode.add_case (new CCodeConstant (state.to_string ()));
ccode.add_goto ("_state_%d".printf (state));
}
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 994b4a3..2c724e7 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -183,8 +183,6 @@ public class Vala.Method : Subroutine, Callable {
public bool is_async_callback { get; set; }
- public int yield_count { get; set; }
-
private List<Parameter> parameters = new ArrayList<Parameter> ();
private List<Expression> preconditions;
private List<Expression> postconditions;
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 9fa8570..3ce66e0 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -516,7 +516,6 @@ public class Vala.MethodCall : Expression {
error = true;
Report.error (source_reference, "yield expression not available
outside async method");
}
- current_method.yield_count++;
}
if (m.returns_floating_reference) {
value_type.floating_reference = true;
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index 955a7fa..a26388a 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -366,7 +366,6 @@ public class Vala.ObjectCreationExpression : Expression {
error = true;
Report.error (source_reference, "yield expression not available
outside async method");
}
- current_method.yield_count++;
}
var args = get_argument_list ();
diff --git a/vala/valayieldstatement.vala b/vala/valayieldstatement.vala
index 18b49de..718f366 100644
--- a/vala/valayieldstatement.vala
+++ b/vala/valayieldstatement.vala
@@ -75,8 +75,6 @@ public class Vala.YieldStatement : BaseStatement {
error = yield_expression.error;
}
- context.analyzer.get_current_method (this).yield_count++;
-
return !error;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]