[vala/staging] vala: Fix and add more to_string() methods to expressions
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Fix and add more to_string() methods to expressions
- Date: Tue, 23 Oct 2018 14:47:42 +0000 (UTC)
commit b4a644adac29a97c53b68fbcf26d1cd45a8082be
Author: Luca Bruno <lucabru src gnome org>
Date: Tue Jan 3 13:03:53 2012 +0100
vala: Fix and add more to_string() methods to expressions
vala/valaaddressofexpression.vala | 4 ++++
vala/valaarraycreationexpression.vala | 18 ++++++++++++++++++
vala/valaassignment.vala | 21 +++++++++++++++++++++
vala/valabinaryexpression.vala | 2 +-
vala/valacastexpression.vala | 10 ++++++++++
vala/valaconditionalexpression.vala | 4 ++++
vala/valaelementaccess.vala | 14 ++++++++++++++
vala/valainitializerlist.vala | 14 ++++++++++++++
vala/valamemberaccess.vala | 2 +-
vala/valamethodcall.vala | 22 ++++++++++++++++++++++
vala/valanamespace.vala | 8 ++++++++
vala/valapointerindirection.vala | 4 ++++
vala/valapostfixexpression.vala | 4 ++++
vala/valareferencetransferexpression.vala | 4 ++++
vala/valasymbol.vala | 4 ++++
vala/valatypecheck.vala | 4 ++++
16 files changed, 137 insertions(+), 2 deletions(-)
---
diff --git a/vala/valaaddressofexpression.vala b/vala/valaaddressofexpression.vala
index 029325264..4948a46c2 100644
--- a/vala/valaaddressofexpression.vala
+++ b/vala/valaaddressofexpression.vala
@@ -62,6 +62,10 @@ public class Vala.AddressofExpression : Expression {
inner.accept (visitor);
}
+ public override string to_string () {
+ return "&" + inner.to_string ();
+ }
+
public override void replace_expression (Expression old_node, Expression new_node) {
if (inner == old_node) {
inner = new_node;
diff --git a/vala/valaarraycreationexpression.vala b/vala/valaarraycreationexpression.vala
index 0969ff0e6..d3aebc9dc 100644
--- a/vala/valaarraycreationexpression.vala
+++ b/vala/valaarraycreationexpression.vala
@@ -127,6 +127,24 @@ public class Vala.ArrayCreationExpression : Expression {
return true;
}
+ public override string to_string () {
+ var builder = new StringBuilder ("new ");
+ builder.append_printf ("%s[", element_type.to_string ());
+ bool first = true;
+ foreach (var size in sizes) {
+ if (first) {
+ builder.append (size.to_string ());
+ first = false;
+ } else {
+ builder.append_printf (", %s", size.to_string ());
+ }
+ }
+ if (initializer_list != null) {
+ builder.append (initializer_list.to_string ());
+ }
+ return builder.str;
+ }
+
public override void replace_expression (Expression old_node, Expression new_node) {
for (int i = 0; i < sizes.size; i++) {
if (sizes[i] == old_node) {
diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala
index 0ee11aa5a..e4e707adb 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -84,6 +84,27 @@ public class Vala.Assignment : Expression {
right.accept (visitor);
}
+ private unowned string get_operator_string () {
+ switch (_operator) {
+ case AssignmentOperator.SIMPLE: return "=";
+ case AssignmentOperator.BITWISE_OR: return "|=";
+ case AssignmentOperator.BITWISE_AND: return "&=";
+ case AssignmentOperator.BITWISE_XOR: return "^=";
+ case AssignmentOperator.ADD: return "+=";
+ case AssignmentOperator.SUB: return "-=";
+ case AssignmentOperator.MUL: return "*=";
+ case AssignmentOperator.DIV: return "/=";
+ case AssignmentOperator.PERCENT: return "%=";
+ case AssignmentOperator.SHIFT_LEFT: return "<<=";
+ case AssignmentOperator.SHIFT_RIGHT: return ">>=";
+ default: assert_not_reached ();
+ }
+ }
+
+ public override string to_string () {
+ return "(%s %s %s)".printf (_left.to_string (), get_operator_string (), _right.to_string ());
+ }
+
public override void replace_expression (Expression old_node, Expression new_node) {
if (left == old_node) {
left = new_node;
diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala
index 1e24968aa..62c1014e8 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -135,7 +135,7 @@ public class Vala.BinaryExpression : Expression {
}
public override string to_string () {
- return _left.to_string () + get_operator_string () + _right.to_string ();
+ return "(%s %s %s)".printf (_left.to_string (), get_operator_string (), _right.to_string ());
}
public override bool is_constant () {
diff --git a/vala/valacastexpression.vala b/vala/valacastexpression.vala
index 18ed153b8..86bdad1d1 100644
--- a/vala/valacastexpression.vala
+++ b/vala/valacastexpression.vala
@@ -102,6 +102,16 @@ public class Vala.CastExpression : Expression {
}
}
+ public override string to_string () {
+ if (is_non_null_cast) {
+ return "(!) %s".printf (inner.to_string ());
+ } else if (is_silent_cast) {
+ return "%s as %s".printf (inner.to_string (), type_reference.to_string ());
+ } else {
+ return "(%s) %s".printf (type_reference.to_string (), inner.to_string ());
+ }
+ }
+
public override void replace_expression (Expression old_node, Expression new_node) {
if (inner == old_node) {
inner = new_node;
diff --git a/vala/valaconditionalexpression.vala b/vala/valaconditionalexpression.vala
index 30336289d..a0f0dbba7 100644
--- a/vala/valaconditionalexpression.vala
+++ b/vala/valaconditionalexpression.vala
@@ -110,6 +110,10 @@ public class Vala.ConditionalExpression : Expression {
false_expression.get_error_types (collection, source_reference);
}
+ public override string to_string () {
+ return "(%s ? %s : %s)".printf (condition.to_string (), true_expression.to_string (),
false_expression.to_string ());
+ }
+
public override void replace_expression (Expression old_node, Expression new_node) {
if (condition == old_node) {
condition = new_node;
diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala
index c7c783490..bc1072901 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -75,6 +75,20 @@ public class Vala.ElementAccess : Expression {
}
}
+ public override string to_string () {
+ var s = "%s[".printf (container.to_string ());
+ bool first = true;
+ foreach (var index in indices) {
+ if (first) {
+ s += index.to_string ();
+ first = false;
+ } else {
+ s += ", %s".printf (index.to_string ());
+ }
+ }
+ return s + "]";
+ }
+
public override void replace_expression (Expression old_node, Expression new_node) {
if (container == old_node) {
container = new_node;
diff --git a/vala/valainitializerlist.vala b/vala/valainitializerlist.vala
index aba79290f..ec4315e0b 100644
--- a/vala/valainitializerlist.vala
+++ b/vala/valainitializerlist.vala
@@ -106,6 +106,20 @@ public class Vala.InitializerList : Expression {
return true;
}
+ public override string to_string () {
+ var builder = new StringBuilder ("{");
+ bool first = true;
+ foreach (var initializer in initializers) {
+ if (first) {
+ builder.append (initializer.to_string ());
+ first = false;
+ } else {
+ builder.append_printf (", %s", initializer.to_string ());
+ }
+ }
+ return builder.str;
+ }
+
public override void replace_expression (Expression old_node, Expression new_node) {
for (int i = 0; i < initializers.size; i++) {
if (initializers[i] == old_node) {
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 805b168f3..d2005f688 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -136,7 +136,7 @@ public class Vala.MemberAccess : Expression {
if (inner == null) {
return member_name;
} else {
- return "%s.%s".printf (inner.to_string (), member_name);
+ return "%s%s%s".printf (inner.to_string (), pointer_member_access ? "->" :
".", member_name);
}
} else {
// ensure to always use fully-qualified name
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 86014c280..7fca36e39 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -697,4 +697,26 @@ public class Vala.MethodCall : Expression {
return null;
}
+
+ public override string to_string () {
+ var b = new StringBuilder ();
+ b.append_c ('(');
+ if (is_yield_expression) {
+ b.append ("yield ");
+ }
+ b.append (call.to_string ());
+ b.append_c ('(');
+
+ bool first = true;
+ foreach (var expr in argument_list) {
+ if (!first) {
+ b.append (", ");
+ }
+ b.append (expr.to_string ());
+ first = false;
+ }
+ b.append ("))");
+
+ return b.str;
+ }
}
diff --git a/vala/valanamespace.vala b/vala/valanamespace.vala
index af062f85c..c53fda830 100644
--- a/vala/valanamespace.vala
+++ b/vala/valanamespace.vala
@@ -523,4 +523,12 @@ public class Vala.Namespace : Symbol {
return !error;
}
+
+ public override string to_string () {
+ if (name == null) {
+ return "(root namespace)";
+ } else {
+ return "namespace %s".printf (name);
+ }
+ }
}
diff --git a/vala/valapointerindirection.vala b/vala/valapointerindirection.vala
index 20dbcbfde..5e99b9dc0 100644
--- a/vala/valapointerindirection.vala
+++ b/vala/valapointerindirection.vala
@@ -124,4 +124,8 @@ public class Vala.PointerIndirection : Expression {
public override void get_used_variables (Collection<Variable> collection) {
inner.get_used_variables (collection);
}
+
+ public override string to_string () {
+ return "(*%s)".printf (inner.to_string ());
+ }
}
diff --git a/vala/valapostfixexpression.vala b/vala/valapostfixexpression.vala
index 156ffecf0..1dd646625 100644
--- a/vala/valapostfixexpression.vala
+++ b/vala/valapostfixexpression.vala
@@ -169,4 +169,8 @@ public class Vala.PostfixExpression : Expression {
codegen.visit_expression (this);
}
+
+ public override string to_string () {
+ return "(%s%s)".printf (inner.to_string (), increment ? "++" : "--");
+ }
}
diff --git a/vala/valareferencetransferexpression.vala b/vala/valareferencetransferexpression.vala
index 9362bbd1c..6a06b1d65 100644
--- a/vala/valareferencetransferexpression.vala
+++ b/vala/valareferencetransferexpression.vala
@@ -142,4 +142,8 @@ public class Vala.ReferenceTransferExpression : Expression {
collection.add (param);
}
}
+
+ public override string to_string () {
+ return "(owned) %s".printf (inner.to_string ());
+ }
}
diff --git a/vala/valasymbol.vala b/vala/valasymbol.vala
index 131969afb..59e75a577 100644
--- a/vala/valasymbol.vala
+++ b/vala/valasymbol.vala
@@ -472,6 +472,10 @@ public abstract class Vala.Symbol : CodeNode {
public virtual void add_destructor (Destructor d) {
Report.error (d.source_reference, "unexpected declaration");
}
+
+ public override string to_string () {
+ return get_full_name ();
+ }
}
public enum Vala.SymbolAccessibility {
diff --git a/vala/valatypecheck.vala b/vala/valatypecheck.vala
index 5b22d75d4..cb0469a6f 100644
--- a/vala/valatypecheck.vala
+++ b/vala/valatypecheck.vala
@@ -132,4 +132,8 @@ public class Vala.TypeCheck : Expression {
codegen.visit_expression (this);
}
+
+ public override string to_string () {
+ return "(%s is %s)".printf (expression.to_string (), type_reference.to_string ());
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]