[vala/staging: 4/9] vala: Add missing replace_expression() implementations



commit 508d5d07ad6938e806d36eb085890944361b56aa
Author: Luca Bruno <lucabru src gnome org>
Date:   Thu Dec 29 12:39:15 2011 +0100

    vala: Add missing replace_expression() implementations

 vala/valaconditionalexpression.vala | 12 ++++++++++++
 vala/valadeletestatement.vala       |  6 ++++++
 vala/valadostatement.vala           |  6 ++++++
 vala/valaforstatement.vala          | 16 ++++++++++++++++
 vala/valalockstatement.vala         |  6 ++++++
 vala/valapostfixexpression.vala     |  6 ++++++
 vala/valatemplate.vala              |  8 ++++++++
 vala/valaunlockstatement.vala       |  6 ++++++
 vala/valawhilestatement.vala        |  6 ++++++
 9 files changed, 72 insertions(+)
---
diff --git a/vala/valaconditionalexpression.vala b/vala/valaconditionalexpression.vala
index 27f7d8618..30336289d 100644
--- a/vala/valaconditionalexpression.vala
+++ b/vala/valaconditionalexpression.vala
@@ -110,6 +110,18 @@ public class Vala.ConditionalExpression : Expression {
                false_expression.get_error_types (collection, source_reference);
        }
 
+       public override void replace_expression (Expression old_node, Expression new_node) {
+               if (condition == old_node) {
+                       condition = new_node;
+               }
+               if (true_expression == old_node) {
+                       true_expression = new_node;
+               }
+               if (false_expression == old_node) {
+                       false_expression = new_node;
+               }
+       }
+
        public override bool check (CodeContext context) {
                if (checked) {
                        return !error;
diff --git a/vala/valadeletestatement.vala b/vala/valadeletestatement.vala
index e12b5c4e1..ff3ff6891 100644
--- a/vala/valadeletestatement.vala
+++ b/vala/valadeletestatement.vala
@@ -50,6 +50,12 @@ public class Vala.DeleteStatement : CodeNode, Statement {
                expression.accept (visitor);
        }
 
+       public override void replace_expression (Expression old_node, Expression new_node) {
+               if (expression == old_node) {
+                       expression = new_node;
+               }
+       }
+
        public override bool check (CodeContext context) {
                if (checked) {
                        return !error;
diff --git a/vala/valadostatement.vala b/vala/valadostatement.vala
index b7fa03660..987facc90 100644
--- a/vala/valadostatement.vala
+++ b/vala/valadostatement.vala
@@ -86,6 +86,12 @@ public class Vala.DoStatement : CodeNode, Statement {
                return (literal != null && literal.value);
        }
 
+       public override void replace_expression (Expression old_node, Expression new_node) {
+               if (condition == old_node) {
+                       condition = new_node;
+               }
+       }
+
        public override bool check (CodeContext context) {
                // convert to simple loop
 
diff --git a/vala/valaforstatement.vala b/vala/valaforstatement.vala
index 80ff8dbeb..79bd063f7 100644
--- a/vala/valaforstatement.vala
+++ b/vala/valaforstatement.vala
@@ -136,6 +136,22 @@ public class Vala.ForStatement : CodeNode, Statement {
                body.accept (visitor);
        }
 
+       public override void replace_expression (Expression old_node, Expression new_node) {
+               if (condition == old_node) {
+                       condition = new_node;
+               }
+               for (int i=0; i < initializer.size; i++) {
+                       if (initializer[i] == old_node) {
+                               initializer[i] = new_node;
+                       }
+               }
+               for (int i=0; i < iterator.size; i++) {
+                       if (iterator[i] == old_node) {
+                               iterator[i] = new_node;
+                       }
+               }
+       }
+
        bool always_true (Expression condition) {
                var literal = condition as BooleanLiteral;
                return (literal != null && literal.value);
diff --git a/vala/valalockstatement.vala b/vala/valalockstatement.vala
index 38fac07b5..65d8ff09e 100644
--- a/vala/valalockstatement.vala
+++ b/vala/valalockstatement.vala
@@ -57,6 +57,12 @@ public class Vala.LockStatement : CodeNode, Statement {
                visitor.visit_lock_statement (this);
        }
 
+       public override void replace_expression (Expression old_node, Expression new_node) {
+               if (resource == old_node) {
+                       resource = new_node;
+               }
+       }
+
        public override bool check (CodeContext context) {
                if (body != null) {
                        // if the statement isn't empty, it is converted into a try statement
diff --git a/vala/valapostfixexpression.vala b/vala/valapostfixexpression.vala
index eed39a39a..156ffecf0 100644
--- a/vala/valapostfixexpression.vala
+++ b/vala/valapostfixexpression.vala
@@ -91,6 +91,12 @@ public class Vala.PostfixExpression : Expression {
                inner.get_used_variables (collection);
        }
 
+       public override void replace_expression (Expression old_node, Expression new_node) {
+               if (inner == old_node) {
+                       inner = new_node;
+               }
+       }
+
        public override bool check (CodeContext context) {
                if (checked) {
                        return !error;
diff --git a/vala/valatemplate.vala b/vala/valatemplate.vala
index 5e27a7b8e..dd66c3d4c 100644
--- a/vala/valatemplate.vala
+++ b/vala/valatemplate.vala
@@ -58,6 +58,14 @@ public class Vala.Template : Expression {
                }
        }
 
+       public override void replace_expression (Expression old_node, Expression new_node) {
+               int index = expression_list.index_of (old_node);
+               if (index >= 0) {
+                       expression_list[index] = new_node;
+                       new_node.parent_node = this;
+               }
+       }
+
        public override bool check (CodeContext context) {
                if (checked) {
                        return !error;
diff --git a/vala/valaunlockstatement.vala b/vala/valaunlockstatement.vala
index 283b782a5..69f9eb022 100644
--- a/vala/valaunlockstatement.vala
+++ b/vala/valaunlockstatement.vala
@@ -40,6 +40,12 @@ public class Vala.UnlockStatement : CodeNode, Statement {
                visitor.visit_unlock_statement (this);
        }
 
+       public override void replace_expression (Expression old_node, Expression new_node) {
+               if (resource == old_node) {
+                       resource = new_node;
+               }
+       }
+
        public override bool check (CodeContext context) {
                if (checked) {
                        return !error;
diff --git a/vala/valawhilestatement.vala b/vala/valawhilestatement.vala
index 9c4e65e6c..0b0a1b1bb 100644
--- a/vala/valawhilestatement.vala
+++ b/vala/valawhilestatement.vala
@@ -91,6 +91,12 @@ public class Vala.WhileStatement : CodeNode, Statement {
                return (literal != null && !literal.value);
        }
 
+       public override void replace_expression (Expression old_node, Expression new_node) {
+               if (condition == old_node) {
+                       condition = new_node;
+               }
+       }
+
        public override bool check (CodeContext context) {
                // convert to simple loop
 


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