]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix for statement and foreach on GList
authorLuca Bruno <lucabru@src.gnome.org>
Sat, 11 Feb 2012 22:22:58 +0000 (23:22 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 11 Mar 2019 12:52:38 +0000 (13:52 +0100)
codegen/valaccodetransformer.vala

index 92df673ec160db1cc64f0c9341921548ca524bb3..12c0a033b8bc6e7f4165514dedd8570d0c9520c5 100644 (file)
@@ -217,6 +217,15 @@ public class Vala.CCodeTransformer : CodeTransformer {
 
                if (stmt.condition == null || !always_false (stmt.condition)) {
                        b.open_loop ();
+                       var notfirst = b.add_temp_declaration (null, expression ("false"));
+                       b.open_if (expression (notfirst));
+                       foreach (var it_expr in stmt.get_iterator ()) {
+                               b.add_expression (it_expr);
+                       }
+                       b.add_else ();
+                       b.add_assignment (expression (notfirst), expression ("true"));
+                       b.close ();
+
                        if (stmt.condition != null && !always_true (stmt.condition)) {
                                b.open_if (new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, stmt.condition, stmt.source_reference));
                                b.add_break ();
@@ -224,9 +233,6 @@ public class Vala.CCodeTransformer : CodeTransformer {
                        }
                        b.add_statement (stmt.body);
 
-                       foreach (var it_expr in stmt.get_iterator ()) {
-                               b.add_expression (it_expr);
-                       }
                        b.close ();
                }
 
@@ -261,8 +267,11 @@ public class Vala.CCodeTransformer : CodeTransformer {
                        break;
                case ForeachIteration.GLIST:
                        // GList or GSList
-                       b.open_for (null, expression (@"$collection != null"), expression (@"$collection = $collection.next"));
-                       stmt.element_variable.initializer = expression (@"$collection.data");
+                       var iter_type = stmt.collection.value_type.copy ();
+                       iter_type.value_owned = false;
+                       var iter = b.add_temp_declaration (iter_type, expression (collection));
+                       b.open_for (null, expression (@"$iter != null"), expression (@"$iter = $iter.next"));
+                       stmt.element_variable.initializer = expression (@"$iter.data");
                        break;
                case ForeachIteration.INDEX:
                        // get()+size