[vala/wip/transform: 61/63] Make Method.yield_count be stateless
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 61/63] Make Method.yield_count be stateless
- Date: Sat, 27 Oct 2012 18:11:42 +0000 (UTC)
commit 22fe2c7e3494bdc4f7042bb30f80dd4320c75a00
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 238db83..1667978 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -283,6 +283,30 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
ccode.add_expression (register_call);
}
+ 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
@@ -463,7 +487,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 8713b9c..6a47542 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -172,8 +172,6 @@ public class Vala.Method : Subroutine {
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 32e346f..b9d78b6 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -608,7 +608,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 fbe870b..0efee81 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -342,7 +342,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]