[vala/staging: 1/2] Bring back floating local variables



commit ec1f1f87607c94d3bc48ac40c1c63c1d929f33f7
Author: Luca Bruno <lucabru src gnome org>
Date:   Thu Sep 18 22:36:38 2014 +0200

    Bring back floating local variables

 codegen/valaccodebasemodule.vala       |    4 ++--
 vala/valabinaryexpression.vala         |    1 +
 vala/valalocalvariable.vala            |    5 +++++
 vala/valamethodcall.vala               |    1 +
 vala/valaobjectcreationexpression.vala |    1 +
 vala/valasemanticanalyzer.vala         |    2 +-
 6 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 78e52dc..9c31840 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2182,7 +2182,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                for (int i = local_vars.size - 1; i >= 0; i--) {
                        var local = local_vars[i];
                        local.active = false;
-                       if (!local.unreachable && !local.captured && requires_destroy (local.variable_type)) {
+                       if (!local.unreachable && !local.floating && !local.captured && requires_destroy 
(local.variable_type)) {
                                ccode.add_expression (destroy_local (local));
                        }
                }
@@ -3502,7 +3502,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                // free in reverse order
                for (int i = local_vars.size - 1; i >= 0; i--) {
                        var local = local_vars[i];
-                       if (!local.unreachable && local.active && !local.captured && requires_destroy 
(local.variable_type)) {
+                       if (!local.unreachable && local.active && !local.floating && !local.captured && 
requires_destroy (local.variable_type)) {
                                ccode.add_expression (destroy_local (local));
                        }
                }
diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala
index e57ebb4..9bb77d6 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -217,6 +217,7 @@ public class Vala.BinaryExpression : Expression {
                        }
                
                        var local = new LocalVariable (local_type, get_temp_name (), left, source_reference);
+                       local.floating = true;
                        var decl = new DeclarationStatement (local, source_reference);
 
                        var right_stmt = new ExpressionStatement (new Assignment (new MemberAccess.simple 
(local.name, right.source_reference), right, AssignmentOperator.SIMPLE, right.source_reference), 
right.source_reference);
diff --git a/vala/valalocalvariable.vala b/vala/valalocalvariable.vala
index a7979f7..16a5e80 100644
--- a/vala/valalocalvariable.vala
+++ b/vala/valalocalvariable.vala
@@ -28,6 +28,11 @@ using GLib;
 public class Vala.LocalVariable : Variable {
        public bool is_result { get; set; }
 
+       /**
+        * Floating variables may only be accessed exactly once.
+        */
+       public bool floating { get; set; }
+
        public bool captured { get; set; }
 
        /* Currently ignored due to GCC 4.8 being strict on possibly uninitialized variables */
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 0229e40..9c537f2 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -627,6 +627,7 @@ public class Vala.MethodCall : Expression {
                                var old_parent_node = parent_node;
 
                                var local = new LocalVariable (value_type.copy (), get_temp_name (), null, 
source_reference);
+                               local.floating = true;
                                var decl = new DeclarationStatement (local, source_reference);
 
                                insert_statement (context.analyzer.insert_block, decl);
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index 6b18efd..9f7c0f0 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -430,6 +430,7 @@ public class Vala.ObjectCreationExpression : Expression {
                                var old_parent_node = parent_node;
 
                                var local = new LocalVariable (value_type.copy (), get_temp_name (), null, 
source_reference);
+                               local.floating = true;
                                var decl = new DeclarationStatement (local, source_reference);
 
                                insert_statement (context.analyzer.insert_block, decl);
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index cb1a575..91f2769 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -271,7 +271,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                } else if (sym is LocalVariable) {
                        var local = (LocalVariable) sym;
                        var type = local.variable_type.copy ();
-                       if (!lvalue) {
+                       if (!lvalue && !local.floating) {
                                type.value_owned = false;
                        }
                        return type;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]