[vala/wip/transform: 104/179] Add more to_string() methods to expressions
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 104/179] Add more to_string() methods to expressions
- Date: Tue, 27 Mar 2018 11:49:44 +0000 (UTC)
commit c1919a7cd675afc6d45b9ba146db7c674a1853b8
Author: Luca Bruno <lucabru src gnome org>
Date: Tue Jan 3 13:03:53 2012 +0100
Add more to_string() methods to expressions
vala/valaaddressofexpression.vala | 8 +++++-
vala/valaarraycreationexpression.vala | 28 ++++++++++++++++++++----
vala/valaassignment.vala | 21 ++++++++++++++++++
vala/valacastexpression.vala | 10 ++++++++
vala/valaconditionalexpression.vala | 4 +++
vala/valaelementaccess.vala | 14 ++++++++++++
vala/valainitializerlist.vala | 26 +++++++++++++++++-----
vala/valanamespace.vala | 38 ++++++++++++++++++++-------------
vala/valasymbol.vala | 18 +++++++++------
9 files changed, 132 insertions(+), 35 deletions(-)
---
diff --git a/vala/valaaddressofexpression.vala b/vala/valaaddressofexpression.vala
index 0293252..8d0f026 100644
--- a/vala/valaaddressofexpression.vala
+++ b/vala/valaaddressofexpression.vala
@@ -38,7 +38,7 @@ public class Vala.AddressofExpression : Expression {
_inner.parent_node = this;
}
}
-
+
private Expression _inner;
/**
@@ -51,7 +51,7 @@ public class Vala.AddressofExpression : Expression {
this.source_reference = source_reference;
this.inner = inner;
}
-
+
public override void accept (CodeVisitor visitor) {
visitor.visit_addressof_expression (this);
@@ -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 2282d6f..fd0b75f 100644
--- a/vala/valaarraycreationexpression.vala
+++ b/vala/valaarraycreationexpression.vala
@@ -38,17 +38,17 @@ public class Vala.ArrayCreationExpression : Expression {
_element_type.parent_node = this;
}
}
-
+
/**
* The rank of the array.
*/
public int rank { get; set; }
-
+
/**
* The size for each dimension ascending from left to right.
*/
private List<Expression> sizes = new ArrayList<Expression> ();
-
+
/**
* The root array initializer list.
*/
@@ -74,14 +74,14 @@ public class Vala.ArrayCreationExpression : Expression {
size.parent_node = this;
}
}
-
+
/**
* Get the sizes for all dimensions ascending from left to right.
*/
public List<Expression> get_sizes () {
return sizes;
}
-
+
public ArrayCreationExpression (DataType element_type, int rank, InitializerList? initializer_list,
SourceReference source_reference) {
this.element_type = element_type;
this.rank = rank;
@@ -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 83c36fe..050d991 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -84,6 +84,27 @@ public class Vala.Assignment : Expression {
right.accept (visitor);
}
+ public 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 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/valacastexpression.vala b/vala/valacastexpression.vala
index ba3ee5b..478af5b 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 "(!)"+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 480d37c..9bc1639 100644
--- a/vala/valaconditionalexpression.vala
+++ b/vala/valaconditionalexpression.vala
@@ -122,6 +122,10 @@ public class Vala.ConditionalExpression : Expression {
false_expression.get_used_variables (collection);
}
+ 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 0bd5ca3..8343d98 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[";
+ 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 8a60187..99eb81e 100644
--- a/vala/valainitializerlist.vala
+++ b/vala/valainitializerlist.vala
@@ -29,9 +29,9 @@ using GLib;
*/
public class Vala.InitializerList : Expression {
private List<Expression> initializers = new ArrayList<Expression> ();
-
+
/**
- * Appends the specified expression to this initializer
+ * Appends the specified expression to this initializer
*
* @param expr an expression
*/
@@ -39,9 +39,9 @@ public class Vala.InitializerList : Expression {
initializers.add (expr);
expr.parent_node = this;
}
-
+
/**
- * Returns a copy of the expression
+ * Returns a copy of the expression
*
* @return expression list
*/
@@ -50,14 +50,14 @@ public class Vala.InitializerList : Expression {
}
/**
- * Returns the initializer count in this initializer
+ * Returns the initializer count in this initializer
*/
public int size {
get { return initializers.size; }
}
/**
- * Creates a new initializer
+ * Creates a new initializer
*
* @param source_reference reference to source code
* @return newly created initializer list
@@ -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/valanamespace.vala b/vala/valanamespace.vala
index af062f8..c253205 100644
--- a/vala/valanamespace.vala
+++ b/vala/valanamespace.vala
@@ -139,7 +139,7 @@ public class Vala.Namespace : Symbol {
scope.add (ns.name, ns);
}
}
-
+
/**
* Returns a copy of the list of namespaces.
*
@@ -148,7 +148,7 @@ public class Vala.Namespace : Symbol {
public List<Namespace> get_namespaces () {
return namespaces;
}
-
+
/**
* Adds the specified class to this namespace.
*
@@ -187,7 +187,7 @@ public class Vala.Namespace : Symbol {
scope.add (iface.name, iface);
}
-
+
/**
* Adds the specified struct to this namespace.
*
@@ -206,7 +206,7 @@ public class Vala.Namespace : Symbol {
structs.add (st);
scope.add (st.name, st);
}
-
+
/**
* Removes the specified struct from this namespace.
*
@@ -216,7 +216,7 @@ public class Vala.Namespace : Symbol {
structs.remove (st);
scope.remove (st.name);
}
-
+
/**
* Adds the specified enum to this namespace.
*
@@ -291,7 +291,7 @@ public class Vala.Namespace : Symbol {
public List<Class> get_classes () {
return classes;
}
-
+
/**
* Returns a copy of the list of interfaces.
*
@@ -300,7 +300,7 @@ public class Vala.Namespace : Symbol {
public List<Interface> get_interfaces () {
return interfaces;
}
-
+
/**
* Returns a copy of the list of enums.
*
@@ -309,7 +309,7 @@ public class Vala.Namespace : Symbol {
public List<Enum> get_enums () {
return enums;
}
-
+
/**
* Returns a copy of the list of error domains.
*
@@ -318,7 +318,7 @@ public class Vala.Namespace : Symbol {
public List<ErrorDomain> get_error_domains () {
return error_domains;
}
-
+
/**
* Returns a copy of the list of fields.
*
@@ -327,7 +327,7 @@ public class Vala.Namespace : Symbol {
public List<Field> get_fields () {
return fields;
}
-
+
/**
* Returns a copy of the list of constants.
*
@@ -336,7 +336,7 @@ public class Vala.Namespace : Symbol {
public List<Constant> get_constants () {
return constants;
}
-
+
/**
* Returns a copy of the list of delegates.
*
@@ -345,7 +345,7 @@ public class Vala.Namespace : Symbol {
public List<Delegate> get_delegates () {
return delegates;
}
-
+
/**
* Returns a copy of the list of methods.
*
@@ -354,7 +354,7 @@ public class Vala.Namespace : Symbol {
public List<Method> get_methods () {
return methods;
}
-
+
/**
* Adds the specified constant to this namespace.
*
@@ -373,7 +373,7 @@ public class Vala.Namespace : Symbol {
constants.add (constant);
scope.add (constant.name, constant);
}
-
+
/**
* Adds the specified field to this namespace.
*
@@ -407,7 +407,7 @@ public class Vala.Namespace : Symbol {
fields.add (f);
scope.add (f.name, f);
}
-
+
/**
* Adds the specified method to this namespace.
*
@@ -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/valasymbol.vala b/vala/valasymbol.vala
index ed1ad83..a6ef1aa 100644
--- a/vala/valasymbol.vala
+++ b/vala/valasymbol.vala
@@ -105,7 +105,7 @@ public abstract class Vala.Symbol : CodeNode {
public bool hides { get; set; }
/**
- * Check if this symbol is just internal API (and therefore doesn't need
+ * Check if this symbol is just internal API (and therefore doesn't need
* to be listed in header files for instance) by traversing parent symbols
* and checking their accessibility.
*/
@@ -209,7 +209,7 @@ public abstract class Vala.Symbol : CodeNode {
if (parent_symbol == null) {
return name;
}
-
+
if (name == null) {
return parent_symbol.get_full_name ();
}
@@ -224,7 +224,7 @@ public abstract class Vala.Symbol : CodeNode {
return "%s.%s".printf (parent_symbol.get_full_name (), name);
}
}
-
+
/**
* Converts a string from CamelCase to lower_case.
*
@@ -261,13 +261,13 @@ public abstract class Vala.Symbol : CodeNode {
}
}
}
-
+
result_builder.append_unichar (c.tolower ());
-
+
first = false;
i = i.next_char ();
}
-
+
return result_builder.str;
}
@@ -296,7 +296,7 @@ public abstract class Vala.Symbol : CodeNode {
} else {
result_builder.append_unichar (c);
}
-
+
i = i.next_char ();
}
@@ -467,6 +467,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 {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]