[vala] Set parent_node and always copy datatype when assigned to code nodes.
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Set parent_node and always copy datatype when assigned to code nodes.
- Date: Sun, 6 Oct 2013 19:12:51 +0000 (UTC)
commit a09c9e93af0d64b9331c274de573465fe070b722
Author: Luca Bruno <lucabru src gnome org>
Date: Sun Oct 6 21:06:46 2013 +0200
Set parent_node and always copy datatype when assigned to code nodes.
This is a delicate patch that fixes subtle memory corruption bugs in
libvala users and the compiler itself.
It might break some application, so this commit is open for testing.
vala/valaarraycreationexpression.vala | 2 +-
vala/valaarraytype.vala | 2 +-
vala/valacastexpression.vala | 2 +-
vala/valacatchclause.vala | 5 ++-
vala/valaclass.vala | 8 +++--
vala/valaconstant.vala | 2 +-
vala/valadatatype.vala | 6 ++-
vala/valadelegate.vala | 2 +-
vala/valaexpression.vala | 61 +++++++++++++++++++++++++++++--
vala/valaforeachstatement.vala | 5 ++-
vala/valainterface.vala | 10 ++++--
vala/valamemberaccess.vala | 6 ++-
vala/valamethod.vala | 2 +-
vala/valaobjectcreationexpression.vala | 2 +-
vala/valapointertype.vala | 2 +-
vala/valaproperty.vala | 3 +-
vala/valapropertyaccessor.vala | 3 +-
vala/valasignal.vala | 2 +-
vala/valasizeofexpression.vala | 2 +-
vala/valatypeofexpression.vala | 2 +-
vala/valavariable.vala | 5 ++-
21 files changed, 101 insertions(+), 33 deletions(-)
---
diff --git a/vala/valaarraycreationexpression.vala b/vala/valaarraycreationexpression.vala
index 3b52748..c0f3830 100644
--- a/vala/valaarraycreationexpression.vala
+++ b/vala/valaarraycreationexpression.vala
@@ -34,7 +34,7 @@ public class Vala.ArrayCreationExpression : Expression {
public DataType element_type {
get { return _element_type; }
set {
- _element_type = value;
+ _element_type = value.copy ();
_element_type.parent_node = this;
}
}
diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala
index b376723..11bf1a7 100644
--- a/vala/valaarraytype.vala
+++ b/vala/valaarraytype.vala
@@ -32,7 +32,7 @@ public class Vala.ArrayType : ReferenceType {
public DataType element_type {
get { return _element_type; }
set {
- _element_type = value;
+ _element_type = value.copy ();
_element_type.parent_node = this;
}
}
diff --git a/vala/valacastexpression.vala b/vala/valacastexpression.vala
index c7a72b6..c09e8ab 100644
--- a/vala/valacastexpression.vala
+++ b/vala/valacastexpression.vala
@@ -44,7 +44,7 @@ public class Vala.CastExpression : Expression {
public DataType type_reference {
get { return _data_type; }
set {
- _data_type = value;
+ _data_type = value.copy ();
_data_type.parent_node = this;
}
}
diff --git a/vala/valacatchclause.vala b/vala/valacatchclause.vala
index b2f20a4..ef1f998 100644
--- a/vala/valacatchclause.vala
+++ b/vala/valacatchclause.vala
@@ -31,8 +31,9 @@ public class Vala.CatchClause : CodeNode {
public DataType? error_type {
get { return _data_type; }
set {
- _data_type = value;
- if (_data_type != null) {
+ _data_type = null;
+ if (value != null) {
+ _data_type = value.copy ();
_data_type.parent_node = this;
}
}
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index ba23a50..a88fb01 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -225,10 +225,11 @@ public class Vala.Class : ObjectTypeSymbol {
* @param type a class or interface reference
*/
public void add_base_type (DataType type) {
- base_types.add (type);
- type.parent_node = this;
+ var copy = type.copy ();
+ base_types.add (copy);
+ copy.parent_node = this;
}
-
+
/**
* Returns a copy of the base type list.
*
@@ -556,6 +557,7 @@ public class Vala.Class : ObjectTypeSymbol {
for (int i = 0; i < base_types.size; i++) {
if (base_types[i] == old_type) {
base_types[i] = new_type;
+ new_type.parent_node = this;
return;
}
}
diff --git a/vala/valaconstant.vala b/vala/valaconstant.vala
index 53b84c6..0c789bd 100644
--- a/vala/valaconstant.vala
+++ b/vala/valaconstant.vala
@@ -32,7 +32,7 @@ public class Vala.Constant : Symbol, Lockable {
public DataType type_reference {
get { return _data_type; }
set {
- _data_type = value;
+ _data_type = value.copy ();
_data_type.parent_node = this;
}
}
diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala
index 085d321..376e1f1 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -71,8 +71,9 @@ public abstract class Vala.DataType : CodeNode {
if (type_argument_list == null) {
type_argument_list = new ArrayList<DataType> ();
}
- type_argument_list.add (arg);
- arg.parent_node = this;
+ var copy = arg.copy ();
+ type_argument_list.add (copy);
+ copy.parent_node = this;
}
/**
@@ -251,6 +252,7 @@ public abstract class Vala.DataType : CodeNode {
for (int i = 0; i < type_argument_list.size; i++) {
if (type_argument_list[i] == old_type) {
type_argument_list[i] = new_type;
+ new_type.parent_node = this;
return;
}
}
diff --git a/vala/valadelegate.vala b/vala/valadelegate.vala
index d949c61..14f7ffa 100644
--- a/vala/valadelegate.vala
+++ b/vala/valadelegate.vala
@@ -32,7 +32,7 @@ public class Vala.Delegate : TypeSymbol {
public DataType return_type {
get { return _return_type; }
set {
- _return_type = value;
+ _return_type = value.copy ();
_return_type.parent_node = this;
}
}
diff --git a/vala/valaexpression.vala b/vala/valaexpression.vala
index 620086e..96e037d 100644
--- a/vala/valaexpression.vala
+++ b/vala/valaexpression.vala
@@ -31,18 +31,71 @@ public abstract class Vala.Expression : CodeNode {
*
* The semantic analyzer computes this value.
*/
- public DataType value_type { get; set; }
+ public DataType value_type {
+ get {
+ return _value_type;
+ }
+
+ set {
+ _value_type = null;
+ if (value != null) {
+ _value_type = value.copy ();
+ _value_type.parent_node = this;
+ }
+ }
+ }
+
+ private DataType _value_type;
+
+ public DataType? formal_value_type {
+ get {
+ return _formal_value_type;
+ }
+ set {
+ _formal_value_type = null;
+ if (value != null) {
+ _formal_value_type = value.copy ();
+ _formal_value_type.parent_node = this;
+ }
+ }
+ }
- public DataType? formal_value_type { get; set; }
+ private DataType _formal_value_type;
/*
* The static type this expression is expected to have.
*
* The semantic analyzer computes this value, lambda expressions use it.
*/
- public DataType target_type { get; set; }
+ public DataType target_type {
+ get {
+ return _target_type;
+ }
+ set {
+ _target_type = null;
+ if (value != null) {
+ _target_type = value.copy ();
+ _target_type.parent_node = this;
+ }
+ }
+ }
+
+ private DataType _target_type;
+
+ public DataType? formal_target_type {
+ get {
+ return _formal_target_type;
+ }
+ set {
+ _formal_target_type = null;
+ if (value != null) {
+ _formal_target_type = value.copy ();
+ _formal_target_type.parent_node = this;
+ }
+ }
+ }
- public DataType? formal_target_type { get; set; }
+ private DataType _formal_target_type;
/**
* The symbol this expression refers to.
diff --git a/vala/valaforeachstatement.vala b/vala/valaforeachstatement.vala
index 8c65222..e10192d 100644
--- a/vala/valaforeachstatement.vala
+++ b/vala/valaforeachstatement.vala
@@ -32,8 +32,9 @@ public class Vala.ForeachStatement : Block {
public DataType? type_reference {
get { return _data_type; }
set {
- _data_type = value;
- if (_data_type != null) {
+ _data_type = null;
+ if (value != null) {
+ _data_type = value.copy ();
_data_type.parent_node = this;
}
}
diff --git a/vala/valainterface.vala b/vala/valainterface.vala
index 49bc0ae..cc7ce13 100644
--- a/vala/valainterface.vala
+++ b/vala/valainterface.vala
@@ -95,8 +95,9 @@ public class Vala.Interface : ObjectTypeSymbol {
* @param type an interface or class reference
*/
public void add_prerequisite (DataType type) {
- prerequisites.add (type);
- type.parent_node = this;
+ var copy = type.copy ();
+ prerequisites.add (copy);
+ copy.parent_node = this;
}
/**
@@ -106,7 +107,9 @@ public class Vala.Interface : ObjectTypeSymbol {
* @param type an interface or class reference
*/
public void prepend_prerequisite (DataType type) {
- prerequisites.insert (0, type);
+ var copy = type.copy ();
+ prerequisites.insert (0, copy);
+ copy.parent_node = this;
}
/**
@@ -349,6 +352,7 @@ public class Vala.Interface : ObjectTypeSymbol {
for (int i = 0; i < prerequisites.size; i++) {
if (prerequisites[i] == old_type) {
prerequisites[i] = new_type;
+ new_type.parent_node = this;
return;
}
}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index af9f51f..156f9aa 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -102,8 +102,9 @@ public class Vala.MemberAccess : Expression {
* @param arg a type reference
*/
public void add_type_argument (DataType arg) {
- type_argument_list.add (arg);
- arg.parent_node = this;
+ var copy = arg.copy ();
+ type_argument_list.add (copy);
+ copy.parent_node = this;
}
/**
@@ -160,6 +161,7 @@ public class Vala.MemberAccess : Expression {
for (int i = 0; i < type_argument_list.size; i++) {
if (type_argument_list[i] == old_type) {
type_argument_list[i] = new_type;
+ new_type.parent_node = this;
return;
}
}
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 663ae6f..eef04ab 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -36,7 +36,7 @@ public class Vala.Method : Subroutine {
public DataType return_type {
get { return _return_type; }
set {
- _return_type = value;
+ _return_type = value.copy ();
_return_type.parent_node = this;
}
}
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index a4121f3..56fb3ae 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -32,7 +32,7 @@ public class Vala.ObjectCreationExpression : Expression {
public DataType type_reference {
get { return _data_type; }
set {
- _data_type = value;
+ _data_type = value.copy ();
_data_type.parent_node = this;
}
}
diff --git a/vala/valapointertype.vala b/vala/valapointertype.vala
index 4bfaf34..5ec9228 100644
--- a/vala/valapointertype.vala
+++ b/vala/valapointertype.vala
@@ -32,7 +32,7 @@ public class Vala.PointerType : DataType {
public DataType base_type {
get { return _base_type; }
set {
- _base_type = value;
+ _base_type = value.copy ();
_base_type.parent_node = this;
}
}
diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala
index 8a8ced4..300fb4d 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -33,8 +33,9 @@ public class Vala.Property : Symbol, Lockable {
public DataType? property_type {
get { return _data_type; }
set {
- _data_type = value;
+ _data_type = null;
if (value != null) {
+ _data_type = value.copy ();
_data_type.parent_node = this;
}
}
diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala
index 466fe6c..3903ae8 100644
--- a/vala/valapropertyaccessor.vala
+++ b/vala/valapropertyaccessor.vala
@@ -39,8 +39,9 @@ public class Vala.PropertyAccessor : Subroutine {
public DataType? value_type {
get { return _value_type; }
set {
- _value_type = value;
+ _value_type = null;
if (value != null) {
+ _value_type = value.copy ();
_value_type.parent_node = this;
}
}
diff --git a/vala/valasignal.vala b/vala/valasignal.vala
index 3ddc453..866760f 100644
--- a/vala/valasignal.vala
+++ b/vala/valasignal.vala
@@ -32,7 +32,7 @@ public class Vala.Signal : Symbol, Lockable {
public DataType return_type {
get { return _return_type; }
set {
- _return_type = value;
+ _return_type = value.copy ();
_return_type.parent_node = this;
}
}
diff --git a/vala/valasizeofexpression.vala b/vala/valasizeofexpression.vala
index 42c1ee5..1fd80c4 100644
--- a/vala/valasizeofexpression.vala
+++ b/vala/valasizeofexpression.vala
@@ -32,7 +32,7 @@ public class Vala.SizeofExpression : Expression {
public DataType type_reference {
get { return _data_type; }
set {
- _data_type = value;
+ _data_type = value.copy ();
_data_type.parent_node = this;
}
}
diff --git a/vala/valatypeofexpression.vala b/vala/valatypeofexpression.vala
index 9b0e02e..1e932f1 100644
--- a/vala/valatypeofexpression.vala
+++ b/vala/valatypeofexpression.vala
@@ -32,7 +32,7 @@ public class Vala.TypeofExpression : Expression {
public DataType type_reference {
get { return _data_type; }
set {
- _data_type = value;
+ _data_type = value.copy ();
_data_type.parent_node = this;
}
}
diff --git a/vala/valavariable.vala b/vala/valavariable.vala
index e625e66..a65fcbe 100644
--- a/vala/valavariable.vala
+++ b/vala/valavariable.vala
@@ -42,8 +42,9 @@ public class Vala.Variable : Symbol {
public DataType? variable_type {
get { return _variable_type; }
set {
- _variable_type = value;
- if (_variable_type != null) {
+ _variable_type = null;
+ if (value != null) {
+ _variable_type = value.copy ();
_variable_type.parent_node = this;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]