[vala/0.42] vala: Fix several AST construction/parenting issues



commit 07deb198878bf7ab9dfb7e915cccfaf4ef37173d
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Oct 23 13:40:54 2018 +0200

    vala: Fix several AST construction/parenting issues

 vala/valaarraycreationexpression.vala  |  1 +
 vala/valaclass.vala                    | 56 +++++++++++++++++++++++++++++++---
 vala/valaelementaccess.vala            |  2 +-
 vala/valaerrorcode.vala                | 12 +++++++-
 vala/valaforstatement.vala             |  2 ++
 vala/valainitializerlist.vala          |  1 +
 vala/valalockstatement.vala            | 21 +++++++++++--
 vala/valamethodcall.vala               |  2 +-
 vala/valaobjectcreationexpression.vala | 15 +++++++--
 vala/valaswitchlabel.vala              | 15 +++++++--
 vala/valaswitchsection.vala            |  2 +-
 vala/valatemplate.vala                 |  1 +
 vala/valatuple.vala                    |  2 ++
 vala/valaunlockstatement.vala          | 10 +++++-
 14 files changed, 125 insertions(+), 17 deletions(-)
---
diff --git a/vala/valaarraycreationexpression.vala b/vala/valaarraycreationexpression.vala
index 43cb1e6af..d3aebc9dc 100644
--- a/vala/valaarraycreationexpression.vala
+++ b/vala/valaarraycreationexpression.vala
@@ -149,6 +149,7 @@ public class Vala.ArrayCreationExpression : Expression {
                for (int i = 0; i < sizes.size; i++) {
                        if (sizes[i] == old_node) {
                                sizes[i] = new_node;
+                               new_node.parent_node = this;
                                return;
                        }
                }
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index 2167e4e4b..d54a67ff2 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -102,17 +102,41 @@ public class Vala.Class : ObjectTypeSymbol {
        /**
         * Specifies the instance constructor.
         */
-       public Constructor constructor { get; set; }
+       public Constructor constructor {
+               get { return _constructor; }
+               set {
+                       _constructor = value;
+                       if (_constructor != null) {
+                               _constructor.owner = scope;
+                       }
+               }
+       }
 
        /**
         * Specifies the class constructor.
         */
-       public Constructor class_constructor { get; set; }
+       public Constructor class_constructor {
+               get { return _class_constructor; }
+               set {
+                       _class_constructor = value;
+                       if (_class_constructor != null) {
+                               _class_constructor.owner = scope;
+                       }
+               }
+       }
 
        /**
         * Specifies the static class constructor.
         */
-       public Constructor static_constructor { get; set; }
+       public Constructor static_constructor {
+               get { return _static_constructor; }
+               set {
+                       _static_constructor = value;
+                       if (_static_constructor != null) {
+                               _static_constructor.owner = scope;
+                       }
+               }
+       }
 
        /**
         * Specifies the instance destructor.
@@ -122,6 +146,7 @@ public class Vala.Class : ObjectTypeSymbol {
                set {
                        _destructor = value;
                        if (_destructor != null) {
+                               _destructor.owner = scope;
                                if (_destructor.this_parameter != null) {
                                        _destructor.scope.remove (_destructor.this_parameter.name);
                                }
@@ -134,12 +159,28 @@ public class Vala.Class : ObjectTypeSymbol {
        /**
         * Specifies the class destructor.
         */
-       public Destructor? static_destructor { get; set; }
+       public Destructor? static_destructor {
+               get { return _static_destructor; }
+               set {
+                       _static_destructor = value;
+                       if (_static_destructor != null) {
+                               _static_destructor.owner = scope;
+                       }
+               }
+       }
 
        /**
         * Specifies the class destructor.
         */
-       public Destructor? class_destructor { get; set; }
+       public Destructor? class_destructor {
+               get { return _class_destructor; }
+               set {
+                       _class_destructor = value;
+                       if (_class_destructor != null) {
+                               _class_destructor.owner = scope;
+                       }
+               }
+       }
 
        /**
         * Specifies whether this class denotes an error base.
@@ -150,7 +191,12 @@ public class Vala.Class : ObjectTypeSymbol {
                }
        }
 
+       Constructor _constructor;
+       Constructor _class_constructor;
+       Constructor _static_constructor;
        Destructor? _destructor;
+       Destructor? _class_destructor;
+       Destructor? _static_destructor;
 
        /**
         * Creates a new class.
diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala
index 1725b1100..59e3604c5 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -95,7 +95,7 @@ public class Vala.ElementAccess : Expression {
                }
 
                int index = indices.index_of (old_node);
-               if (index >= 0 && new_node.parent_node == null) {
+               if (index >= 0) {
                        indices[index] = new_node;
                        new_node.parent_node = this;
                }
diff --git a/vala/valaerrorcode.vala b/vala/valaerrorcode.vala
index 93308aec2..ef5f36410 100644
--- a/vala/valaerrorcode.vala
+++ b/vala/valaerrorcode.vala
@@ -29,7 +29,17 @@ public class Vala.ErrorCode : TypeSymbol {
        /**
         * Specifies the numerical representation of this enum value.
         */
-       public Expression value { get; set; }
+       public Expression? value {
+               get { return _value; }
+               set {
+                       _value = value;
+                       if (_value != null) {
+                               _value.parent_node = this;
+                       }
+               }
+       }
+
+       private Expression _value;
 
        /**
         * Creates a new enum value.
diff --git a/vala/valaforstatement.vala b/vala/valaforstatement.vala
index 79bd063f7..bd3229ad5 100644
--- a/vala/valaforstatement.vala
+++ b/vala/valaforstatement.vala
@@ -143,11 +143,13 @@ public class Vala.ForStatement : CodeNode, Statement {
                for (int i=0; i < initializer.size; i++) {
                        if (initializer[i] == old_node) {
                                initializer[i] = new_node;
+                               new_node.parent_node = this;
                        }
                }
                for (int i=0; i < iterator.size; i++) {
                        if (iterator[i] == old_node) {
                                iterator[i] = new_node;
+                               new_node.parent_node = this;
                        }
                }
        }
diff --git a/vala/valainitializerlist.vala b/vala/valainitializerlist.vala
index a4f0f2486..ec4315e0b 100644
--- a/vala/valainitializerlist.vala
+++ b/vala/valainitializerlist.vala
@@ -124,6 +124,7 @@ public class Vala.InitializerList : Expression {
                for (int i = 0; i < initializers.size; i++) {
                        if (initializers[i] == old_node) {
                                initializers[i] = new_node;
+                               new_node.parent_node = this;
                        }
                }
        }
diff --git a/vala/valalockstatement.vala b/vala/valalockstatement.vala
index 65d8ff09e..7099383fa 100644
--- a/vala/valalockstatement.vala
+++ b/vala/valalockstatement.vala
@@ -36,12 +36,29 @@ public class Vala.LockStatement : CodeNode, Statement {
        /**
         * Expression representing the resource to be locked.
         */
-       public Expression resource { get; set; }
+       public Expression resource {
+               get { return _resource; }
+               set {
+                       _resource = value;
+                       _resource.parent_node = this;
+               }
+       }
 
        /**
         * The statement during its execution the resource is locked.
         */
-       public Block? body { get; set; }
+       public Block? body {
+               get { return _body; }
+               set {
+                       _body = value;
+                       if (_body != null) {
+                               _body.parent_node = this;
+                       }
+               }
+       }
+
+       private Expression _resource;
+       private Block _body;
 
        public LockStatement (Expression resource, Block? body, SourceReference? source_reference = null) {
                this.body = body;
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index ea8543588..b3fe08465 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -103,7 +103,7 @@ public class Vala.MethodCall : Expression {
                }
 
                int index = argument_list.index_of (old_node);
-               if (index >= 0 && new_node.parent_node == null) {
+               if (index >= 0) {
                        argument_list[index] = new_node;
                        new_node.parent_node = this;
                }
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index 8bef09b25..9c56227b0 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -41,7 +41,15 @@ public class Vala.ObjectCreationExpression : Expression {
         * The construction method to use or the data type to be created
         * with the default construction method.
         */
-       public MemberAccess member_name { get; set; }
+       public MemberAccess? member_name {
+               get { return _member_name; }
+               set {
+                       _member_name = value;
+                       if (_member_name != null) {
+                               _member_name.parent_node = this;
+                       }
+               }
+       }
 
        public bool is_yield_expression { get; set; }
 
@@ -52,6 +60,7 @@ public class Vala.ObjectCreationExpression : Expression {
        private List<MemberInitializer> object_initializer = new ArrayList<MemberInitializer> ();
 
        private DataType _data_type;
+       private MemberAccess? _member_name;
 
        /**
         * Creates a new object creation expression.
@@ -60,7 +69,7 @@ public class Vala.ObjectCreationExpression : Expression {
         * @param source_reference reference to source code
         * @return                 newly created object creation expression
         */
-       public ObjectCreationExpression (MemberAccess member_name, SourceReference source_reference) {
+       public ObjectCreationExpression (MemberAccess? member_name, SourceReference source_reference) {
                this.source_reference = source_reference;
                this.member_name = member_name;
        }
@@ -129,7 +138,7 @@ public class Vala.ObjectCreationExpression : Expression {
 
        public override void replace_expression (Expression old_node, Expression new_node) {
                int index = argument_list.index_of (old_node);
-               if (index >= 0 && new_node.parent_node == null) {
+               if (index >= 0) {
                        argument_list[index] = new_node;
                        new_node.parent_node = this;
                }
diff --git a/vala/valaswitchlabel.vala b/vala/valaswitchlabel.vala
index 70eb7e336..8d4444c7f 100644
--- a/vala/valaswitchlabel.vala
+++ b/vala/valaswitchlabel.vala
@@ -29,9 +29,20 @@ public class Vala.SwitchLabel : CodeNode {
        /**
         * Specifies the label expression.
         */
-       public Expression expression { get; set; }
+       public Expression expression {
+               get { return _expression; }
+               set {
+                       _expression = value;
+                       _expression.parent_node = this;
+               }
+       }
+
+       public weak SwitchSection section {
+               get { return (SwitchSection) parent_node; }
+               set { parent_node = value; }
+       }
 
-       public weak SwitchSection section { get; set; }
+       private Expression _expression;
 
        /**
         * Creates a new switch case label.
diff --git a/vala/valaswitchsection.vala b/vala/valaswitchsection.vala
index 156740f80..39ac75dd8 100644
--- a/vala/valaswitchsection.vala
+++ b/vala/valaswitchsection.vala
@@ -49,7 +49,7 @@ public class Vala.SwitchSection : Block {
                }
 
                labels.add (label);
-               label.section = this;
+               label.parent_node = this;
        }
 
        /**
diff --git a/vala/valatemplate.vala b/vala/valatemplate.vala
index dd66c3d4c..5def6781b 100644
--- a/vala/valatemplate.vala
+++ b/vala/valatemplate.vala
@@ -40,6 +40,7 @@ public class Vala.Template : Expression {
 
        public void add_expression (Expression expr) {
                expression_list.add (expr);
+               expr.parent_node = this;
        }
 
        public List<Expression> get_expressions () {
diff --git a/vala/valatuple.vala b/vala/valatuple.vala
index d35795a39..87a0a9c4e 100644
--- a/vala/valatuple.vala
+++ b/vala/valatuple.vala
@@ -46,6 +46,7 @@ public class Vala.Tuple : Expression {
 
        public void add_expression (Expression expr) {
                expression_list.add (expr);
+               expr.parent_node = this;
        }
 
        public List<Expression> get_expressions () {
@@ -60,6 +61,7 @@ public class Vala.Tuple : Expression {
                for (int i = 0; i < expression_list.size; i++) {
                        if (expression_list[i] == old_node) {
                                expression_list[i] = new_node;
+                               new_node.parent_node = this;
                        }
                }
        }
diff --git a/vala/valaunlockstatement.vala b/vala/valaunlockstatement.vala
index 69f9eb022..3e49671ee 100644
--- a/vala/valaunlockstatement.vala
+++ b/vala/valaunlockstatement.vala
@@ -28,7 +28,15 @@ public class Vala.UnlockStatement : CodeNode, Statement {
        /**
         * Expression representing the resource to be unlocked.
         */
-       public Expression resource { get; set; }
+       public Expression resource {
+               get { return _resource; }
+               set {
+                       _resource = value;
+                       _resource.parent_node = this;
+               }
+       }
+
+       private Expression _resource;
 
        public UnlockStatement (Expression resource, SourceReference? source_reference = null) {
                this.source_reference = source_reference;


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