[vala/bug736774: 1/3] Bring back floating local variables



commit 08963b1f69a69594e1e0fdf842c9c302b0523946
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 f1b6f82..ac0192e 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2169,7 +2169,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));
                        }
                }
@@ -3489,7 +3489,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 8ccddba..965d4d9 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 17732ad..9f4ff59 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 efce548..1707880 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -633,6 +633,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 daf3113..b882cb8 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 20600d3..65eb7db 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]