[vala/wip/transform: 105/142] Make Method.yield_count be stateless



commit 3affa2f3009ddb9de69a9f7f4deab7b769767210
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 1876702..2dcf027 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -330,6 +330,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
@@ -502,7 +526,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 d546a6e..16bb2ee 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 e6629aa..ebf3d62 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -498,7 +498,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 6d53880..405c287 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++;
                        }
 
                        // FIXME partial code duplication of MethodCall.check
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]