[vala/wip/bug567269: 1192/1197] Allow multiple chain-up calls in the constructor



commit 85cdd0b5c22888db9dd0f1df3657286d5d226a65
Author: Simon Werbeck <simon werbeck gmail com>
Date:   Thu Nov 27 15:24:44 2014 +0100

    Allow multiple chain-up calls in the constructor
    
    This requires that the instance parameter is initialized at the end of
    the constructor.
    Another issue is the possibility of initializing 'this' more than once,
    so I added a warning when this is the case.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=567269

 vala/valaflowanalyzer.vala |   19 +++++++++++++++++--
 vala/valamethodcall.vala   |    4 ----
 2 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala
index ff0d9eb..618323c 100644
--- a/vala/valaflowanalyzer.vala
+++ b/vala/valaflowanalyzer.vala
@@ -207,6 +207,16 @@ public class Vala.FlowAnalyzer : CodeVisitor {
                                        m.return_block.add_node (param_ma);
                                }
                        }
+
+                       // ensure instance parameter is defined at end of creation method
+                       if (m is CreationMethod) {
+                               var cm = (CreationMethod) m;
+                               if (cm.chain_up) {
+                                       var this_ma = new MemberAccess.simple ("this");
+                                       this_ma.symbol_reference = cm.this_parameter;
+                                       m.return_block.add_node (this_ma);
+                               }
+                       }
                }
 
                current_block = new BasicBlock ();
@@ -474,7 +484,7 @@ public class Vala.FlowAnalyzer : CodeVisitor {
                        node.get_defined_variables (defined_variables);
 
                        foreach (Variable variable in defined_variables) {
-                               process_assignment (var_map, variable);
+                               process_assignment (var_map, variable, node);
                        }
                }
 
@@ -514,7 +524,7 @@ public class Vala.FlowAnalyzer : CodeVisitor {
                }
        }
 
-       Variable process_assignment (Map<Symbol, List<Variable>> var_map, Variable var_symbol) {
+       Variable process_assignment (Map<Symbol, List<Variable>> var_map, Variable var_symbol, CodeNode? 
node_reference = null) {
                var variable_stack = var_map.get (var_symbol);
                if (variable_stack == null) {
                        variable_stack = new ArrayList<Variable> ();
@@ -527,6 +537,11 @@ public class Vala.FlowAnalyzer : CodeVisitor {
                if (var_symbol is LocalVariable) {
                        versioned_var = new LocalVariable (var_symbol.variable_type.copy (), var_symbol.name, 
null, var_symbol.source_reference);
                } else {
+                       if (var_symbol.name == "this" && var_symbol.parent_symbol is CreationMethod && 
((CreationMethod)var_symbol.parent_symbol).chain_up) {
+                               if (variable_stack.size > 0) {
+                                       Report.warning (node_reference.source_reference, "possible 
reassignment of 'this'");
+                               }
+                       }
                        // parameter
                        versioned_var = new Parameter (var_symbol.name, var_symbol.variable_type.copy (), 
var_symbol.source_reference);
                }
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index b71b85f..5ed0465 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -238,10 +238,6 @@ public class Vala.MethodCall : Expression {
                                error = true;
                                Report.error (source_reference, "invocation not supported in this context");
                                return false;
-                       } else if (cm.chain_up) {
-                               error = true;
-                               Report.error (source_reference, "Multiple constructor calls in the same 
constructor are not permitted");
-                               return false;
                        }
                        cm.chain_up = true;
 


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