[vala/wip/transform: 63/104] Make Method.yield_count be stateless



commit 34058a639ff15170fcfeb8d2d4b43e2662360b01
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 0a7804c..aeb39d0 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -282,6 +282,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
@@ -458,7 +482,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 41b82cb..82cf6dc 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 b6b0ce4..52fe2c5 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -615,7 +615,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]