From ace0b643ac34b5aa68668614204f231fe0440207 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Tue, 23 Oct 2018 13:40:54 +0200 Subject: [PATCH] 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 | 14 ++++++- vala/valaswitchsection.vala | 2 +- vala/valatemplate.vala | 1 + vala/valatuple.vala | 2 + vala/valaunlockstatement.vala | 10 ++++- 14 files changed, 124 insertions(+), 17 deletions(-) diff --git a/vala/valaarraycreationexpression.vala b/vala/valaarraycreationexpression.vala index 41b0f351b..0969ff0e6 100644 --- a/vala/valaarraycreationexpression.vala +++ b/vala/valaarraycreationexpression.vala @@ -131,6 +131,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 4f5aa4b87..def794f17 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -119,17 +119,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. @@ -139,6 +163,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); } @@ -151,12 +176,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. @@ -167,7 +208,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 88c396ae1..c7c783490 100644 --- a/vala/valaelementaccess.vala +++ b/vala/valaelementaccess.vala @@ -81,7 +81,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 8a601874e..aba79290f 100644 --- a/vala/valainitializerlist.vala +++ b/vala/valainitializerlist.vala @@ -110,6 +110,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 9864abc0c..86014c280 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 4b609aee7..ff0e818e3 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 object_initializer = new ArrayList (); 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..d3df5a3ee 100644 --- a/vala/valaswitchlabel.vala +++ b/vala/valaswitchlabel.vala @@ -29,9 +29,19 @@ 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; } + } - 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 2b0da5837..2b6bc60ab 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 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 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; -- 2.47.2