Here, second try. You may or may not like the new style; I think it
improves the overall readability (and mutability) quite a lot.

08:59 < penberg_home> vegard: cool.
08:59 < penberg_home> vegard: but doesn't that make debugging too easy?

Signed-off-by: Vegard Nossum <vegard.nos...@gmail.com>
---
 jit/tree-printer.c           |   14 +-
 test/jit/tree-printer-test.c |  447 +++++++++++++++++++++++-------------------
 2 files changed, 248 insertions(+), 213 deletions(-)

diff --git a/jit/tree-printer.c b/jit/tree-printer.c
index b2944bd..78b902e 100644
--- a/jit/tree-printer.c
+++ b/jit/tree-printer.c
@@ -246,7 +246,7 @@ static int print_checkcast_stmt(int lvl, struct string *str,
        if (err)
                goto out;
 
-       err = append_simple_attr(lvl + 1, str, "checkcast_type", "%p", 
stmt->checkcast_class);
+       err = append_simple_attr(lvl + 1, str, "checkcast_type", "%p '%s'", 
stmt->checkcast_class, stmt->checkcast_class->name);
        if (err)
                goto out;
 
@@ -498,7 +498,7 @@ static int print_conversion_expr(int lvl, struct string 
*str,
 
 static int print_class_field_expr(int lvl, struct string *str, struct 
expression *expr)
 {
-       return str_append(str, "[class_field %s %p]", 
type_names[expr->vm_type], expr->class_field);
+       return str_append(str, "[class_field %s %p '%s.%s']", 
type_names[expr->vm_type], expr->class_field, expr->class_field->class->name, 
expr->class_field->name);
 }
 
 static int print_instance_field_expr(int lvl, struct string *str, struct 
expression *expr)
@@ -513,7 +513,7 @@ static int print_instance_field_expr(int lvl, struct string 
*str, struct express
        if (err)
                goto out;
 
-       err = append_simple_attr(lvl + 1, str, "instance_field", "%p", 
expr->instance_field);
+       err = append_simple_attr(lvl + 1, str, "instance_field", "%p '%s.%s'", 
expr->instance_field, expr->instance_field->class->name, 
expr->instance_field->name);
        if (err)
                goto out;
 
@@ -630,7 +630,7 @@ static int print_new_expr(int lvl, struct string *str,
        if (err)
                goto out;
 
-       err = append_simple_attr(lvl + 1, str, "class", "%p", expr->class);
+       err = append_simple_attr(lvl + 1, str, "class", "%p '%s'", expr->class, 
expr->class->name);
 
       out:
        return err;
@@ -674,7 +674,7 @@ static int print_anewarray_expr(int lvl, struct string 
*str, struct expression *
        if (err)
                goto out;
 
-       err = append_simple_attr(lvl + 1, str, "anewarray_ref_type", "%p", 
expr->anewarray_ref_type);
+       err = append_simple_attr(lvl + 1, str, "anewarray_ref_type", "%p '%s'", 
expr->anewarray_ref_type, expr->anewarray_ref_type->name);
 
       out:
        return err;
@@ -692,7 +692,7 @@ static int print_multianewarray_expr(int lvl, struct string 
*str, struct express
        if (err)
                goto out;
 
-       err = append_simple_attr(lvl + 1, str, "multianewarray_ref_type", "%p", 
expr->multianewarray_ref_type);
+       err = append_simple_attr(lvl + 1, str, "multianewarray_ref_type", "%p 
'%s'", expr->multianewarray_ref_type, expr->multianewarray_ref_type->name);
        if (err)
                goto out;
 
@@ -732,7 +732,7 @@ static int print_instanceof_expr(int lvl, struct string 
*str, struct expression
        if (err)
                goto out;
 
-       err = append_simple_attr(lvl + 1, str, "instanceof_class", "%p", 
expr->instanceof_class);
+       err = append_simple_attr(lvl + 1, str, "instanceof_class", "%p '%s'", 
expr->instanceof_class, expr->instanceof_class->name);
        if (err)
                goto out;
 
diff --git a/test/jit/tree-printer-test.c b/test/jit/tree-printer-test.c
index 62b3915..734adbe 100644
--- a/test/jit/tree-printer-test.c
+++ b/test/jit/tree-printer-test.c
@@ -4,6 +4,9 @@
 
 #include <jit/tree-printer.h>
 #include <jit/statement.h>
+#include <vm/class.h>
+#include <vm/field.h>
+#include <vm/method.h>
 #include <vm/string.h>
 #include <vm/types.h>
 
@@ -12,17 +15,49 @@
 
 #include <test/vm.h>
 
-static void assert_tree_print(const char *expected, struct tree_node *root)
+static struct vm_class vmc = {
+       .name = "Class",
+};
+
+static struct vm_field vmf = {
+       .class = &vmc,
+       .name = "field",
+       .type = "I",
+};
+
+static struct vm_method vmm = {
+       .class = &vmc,
+       .virtual_index = 255,
+       .name = "method",
+       .type ="()I",
+};
+
+struct string *str_aprintf(const char *fmt, ...)
+{
+       va_list ap;
+       struct string *str;
+
+       str = alloc_str();
+
+       va_start(ap, fmt);
+       str_vappend(str, fmt, ap);
+       va_end(ap);
+
+       return str;
+}
+
+static void assert_tree_print(struct string *expected, struct tree_node *root)
 {
        struct string *str = alloc_str();
 
        tree_print(root, str);
-       assert_str_equals(expected, str->value);
+       assert_str_equals(expected->value, str->value);
 
        free_str(str);
+       free_str(expected);
 }
 
-static void assert_print_stmt(const char *expected, struct statement *stmt)
+static void assert_print_stmt(struct string *expected, struct statement *stmt)
 {
        assert_tree_print(expected, &stmt->node);
        free_statement(stmt);
@@ -40,12 +75,13 @@ void test_should_print_store_statement(void)
        stmt->store_dest = &dest->node;
        stmt->store_src = &src->node;
 
-       assert_print_stmt("STORE:\n  store_dest: [local int 0]\n  store_src: 
[value int 0x1]\n", stmt);
+       assert_print_stmt(str_aprintf(
+               "STORE:\n  store_dest: [local int 0]\n"
+               "  store_src: [value int 0x1]\n"), stmt);
 }
 
 void test_should_print_if_statement(void)
 {
-       struct string *expected;
        struct expression *if_conditional;
        struct statement *stmt;
        struct basic_block *if_true = (void *) 0xdeadbeef;
@@ -56,27 +92,23 @@ void test_should_print_if_statement(void)
        stmt->if_conditional = &if_conditional->node;
        stmt->if_true = if_true;
 
-       expected = alloc_str();
-       str_append(expected, "IF:\n  if_conditional: [local boolean 0]\n  
if_true: [bb %p]\n", if_true);
-       assert_print_stmt(expected->value, stmt);
-
-       free_str(expected);
+       assert_print_stmt(str_aprintf(
+               "IF:\n"
+               "  if_conditional: [local boolean 0]\n"
+               "  if_true: [bb %p]\n", if_true), stmt);
 }
 
 void test_should_print_goto_statement(void)
 {
-       struct string *expected;
        struct statement *stmt;
        struct basic_block *goto_target = (void *) 0xdeadbeef;
 
        stmt = alloc_statement(STMT_GOTO);
        stmt->goto_target = goto_target;
 
-       expected = alloc_str();
-       str_append(expected, "GOTO:\n  goto_target: [bb %p]\n", goto_target);
-       assert_print_stmt(expected->value, stmt);
-
-       free_str(expected);
+       assert_print_stmt(str_aprintf(
+               "GOTO:\n"
+               "  goto_target: [bb %p]\n", goto_target), stmt);
 }
 
 void test_should_print_return_statement(void)
@@ -89,7 +121,9 @@ void test_should_print_return_statement(void)
        stmt = alloc_statement(STMT_RETURN);
        stmt->return_value = &return_value->node;
 
-       assert_print_stmt("RETURN:\n  return_value: [local int 0]\n", stmt);
+       assert_print_stmt(str_aprintf(
+               "RETURN:\n"
+               "  return_value: [local int 0]\n"), stmt);
 }
 
 void test_should_print_void_return_statement(void)
@@ -98,7 +132,7 @@ void test_should_print_void_return_statement(void)
 
        stmt = alloc_statement(STMT_VOID_RETURN);
 
-       assert_print_stmt("VOID_RETURN\n", stmt);
+       assert_print_stmt(str_aprintf("VOID_RETURN\n"), stmt);
 }
 
 void test_should_print_expression_statement(void)
@@ -111,7 +145,9 @@ void test_should_print_expression_statement(void)
        stmt = alloc_statement(STMT_EXPRESSION);
        stmt->expression = &expression->node;
 
-       assert_print_stmt("EXPRESSION:\n  expression: [local int 0]\n", stmt);
+       assert_print_stmt(str_aprintf(
+               "EXPRESSION:\n"
+               "  expression: [local int 0]\n"), stmt);
 }
 
 void test_should_print_arraycheck_statement(void)
@@ -124,7 +160,9 @@ void test_should_print_arraycheck_statement(void)
        stmt = alloc_statement(STMT_ARRAY_CHECK);
        stmt->expression = &expression->node;
 
-       assert_print_stmt("ARRAY_CHECK:\n  expression: [local int 0]\n", stmt);
+       assert_print_stmt(str_aprintf(
+               "ARRAY_CHECK:\n"
+               "  expression: [local int 0]\n"), stmt);
 }
 
 void test_should_print_monitorenter_statement(void)
@@ -137,7 +175,9 @@ void test_should_print_monitorenter_statement(void)
        stmt = alloc_statement(STMT_MONITOR_ENTER);
        stmt->expression = &expr->node;
 
-       assert_print_stmt("MONITOR_ENTER:\n  expression: [local int 0]\n", 
stmt);
+       assert_print_stmt(str_aprintf(
+               "MONITOR_ENTER:\n"
+               "  expression: [local int 0]\n"), stmt);
 }
 
 void test_should_print_monitorexit_statement(void)
@@ -150,7 +190,9 @@ void test_should_print_monitorexit_statement(void)
        stmt = alloc_statement(STMT_MONITOR_EXIT);
        stmt->expression = &expr->node;
 
-       assert_print_stmt("MONITOR_EXIT:\n  expression: [local int 0]\n", stmt);
+       assert_print_stmt(str_aprintf(
+               "MONITOR_EXIT:\n"
+               "  expression: [local int 0]\n"), stmt);
 }
 
 void test_should_print_checkcast_statement(void)
@@ -162,20 +204,21 @@ void test_should_print_checkcast_statement(void)
 
        stmt = alloc_statement(STMT_CHECKCAST);
        stmt->checkcast_ref = &expr->node;
-       stmt->checkcast_class = (void *)0xcafebabe;
+       stmt->checkcast_class = &vmc;
 
-       assert_print_stmt("CHECKCAST:\n"
-                         "  checkcast_type: [0xcafebabe]\n"
-                         "  checkcast_ref: [local int 0]\n", stmt);
+       assert_print_stmt(str_aprintf(
+               "CHECKCAST:\n"
+               "  checkcast_type: [%p '%s']\n"
+               "  checkcast_ref: [local int 0]\n", &vmc, vmc.name), stmt);
 }
 
-static void assert_print_expr(const char *expected, struct expression *expr)
+static void assert_print_expr(struct string *expected, struct expression *expr)
 {
        assert_tree_print(expected, &expr->node);
        expr_put(expr);
 }
 
-void assert_printed_value_expr(const char *expected, enum vm_type type,
+void assert_printed_value_expr(struct string *expected, enum vm_type type,
                               unsigned long long value)
 {
        struct expression *expr;
@@ -186,11 +229,11 @@ void assert_printed_value_expr(const char *expected, enum 
vm_type type,
 
 void test_should_print_value_expression(void)
 {
-       assert_printed_value_expr("[value int 0x0]", J_INT, 0);
-       assert_printed_value_expr("[value boolean 0x1]", J_BOOLEAN, 1);
+       assert_printed_value_expr(str_aprintf("[value int 0x0]"), J_INT, 0);
+       assert_printed_value_expr(str_aprintf("[value boolean 0x1]"), 
J_BOOLEAN, 1);
 }
 
-void assert_printed_fvalue_expr(const char *expected, enum vm_type type,
+void assert_printed_fvalue_expr(struct string *expected, enum vm_type type,
                                double fvalue)
 {
        struct expression *expr;
@@ -201,11 +244,11 @@ void assert_printed_fvalue_expr(const char *expected, 
enum vm_type type,
 
 void test_should_print_fvalue_expression(void)
 {
-       assert_printed_fvalue_expr("[fvalue float 0.000000]", J_FLOAT, 0.0);
-       assert_printed_fvalue_expr("[fvalue double 1.100000]", J_DOUBLE, 1.1);
+       assert_printed_fvalue_expr(str_aprintf("[fvalue float 0.000000]"), 
J_FLOAT, 0.0);
+       assert_printed_fvalue_expr(str_aprintf("[fvalue double 1.100000]"), 
J_DOUBLE, 1.1);
 }
 
-void assert_printed_local_expr(const char *expected, enum vm_type type,
+void assert_printed_local_expr(struct string *expected, enum vm_type type,
                               unsigned long local_index)
 {
        struct expression *expr;
@@ -216,11 +259,11 @@ void assert_printed_local_expr(const char *expected, enum 
vm_type type,
 
 void test_should_print_local_expression(void)
 {
-       assert_printed_local_expr("[local int 0]", J_INT, 0);
-       assert_printed_local_expr("[local boolean 1]", J_BOOLEAN, 1);
+       assert_printed_local_expr(str_aprintf("[local int 0]"), J_INT, 0);
+       assert_printed_local_expr(str_aprintf("[local boolean 1]"), J_BOOLEAN, 
1);
 }
 
-void assert_printed_temporary_expr(const char *expected, enum vm_type type, 
struct var_info *var, struct var_info *var2)
+void assert_printed_temporary_expr(struct string *expected, enum vm_type type, 
struct var_info *var, struct var_info *var2)
 {
        struct expression *expr;
 
@@ -230,11 +273,16 @@ void assert_printed_temporary_expr(const char *expected, 
enum vm_type type, stru
 
 void test_should_print_temporary_expression(void)
 {
-       assert_printed_temporary_expr("[temporary int 0x0 (high), 0x12345678 
(low)]", J_INT, NULL, (struct var_info *)0x12345678);
-       assert_printed_temporary_expr("[temporary boolean 0x85215975 (high), 
0x87654321 (low)]", J_BOOLEAN, (struct var_info *)0x85215975, (struct var_info 
*)0x87654321);
+       assert_printed_temporary_expr(str_aprintf(
+               "[temporary int 0x0 (high), 0x12345678 (low)]"),
+               J_INT, NULL, (struct var_info *)0x12345678);
+       assert_printed_temporary_expr(str_aprintf(
+               "[temporary boolean 0x85215975 (high), 0x87654321 (low)]"),
+               J_BOOLEAN,
+               (struct var_info *)0x85215975, (struct var_info *)0x87654321);
 }
 
-void assert_printed_array_deref_expr(const char *expected, enum vm_type type,
+void assert_printed_array_deref_expr(struct string *expected, enum vm_type 
type,
                                     unsigned long arrayref, unsigned long 
array_index)
 {
        struct expression *expr;
@@ -247,11 +295,19 @@ void assert_printed_array_deref_expr(const char 
*expected, enum vm_type type,
 
 void test_should_print_array_deref_expression(void)
 {
-       assert_printed_array_deref_expr("ARRAY_DEREF:\n  vm_type: [float]\n  
arrayref: [value reference 0x0]\n  array_index: [value int 0x1]\n", J_FLOAT, 0, 
1);
-       assert_printed_array_deref_expr("ARRAY_DEREF:\n  vm_type: [double]\n  
arrayref: [value reference 0x1]\n  array_index: [value int 0x2]\n", J_DOUBLE, 
1, 2);
+       assert_printed_array_deref_expr(str_aprintf(
+               "ARRAY_DEREF:\n"
+               "  vm_type: [float]\n"
+               "  arrayref: [value reference 0x0]\n"
+               "  array_index: [value int 0x1]\n"), J_FLOAT, 0, 1);
+       assert_printed_array_deref_expr(str_aprintf(
+               "ARRAY_DEREF:\n"
+               "  vm_type: [double]\n"
+               "  arrayref: [value reference 0x1]\n"
+               "  array_index: [value int 0x2]\n"), J_DOUBLE, 1, 2);
 }
 
-void assert_printed_binop_expr(const char *expected, enum vm_type type,
+void assert_printed_binop_expr(struct string *expected, enum vm_type type,
                               enum binary_operator op,
                               struct expression *binary_left,
                               struct expression *binary_right)
@@ -264,33 +320,31 @@ void assert_printed_binop_expr(const char *expected, enum 
vm_type type,
 
 void test_should_print_binop_expression(void)
 {
-       assert_printed_binop_expr("BINOP:\n"
-                                 "  vm_type: [int]\n"
-                                 "  binary_operator: [add]\n"
-                                 "  binary_left: [value int 0x0]\n"
-                                 "  binary_right: [value int 0x1]\n",
-                                 J_INT, OP_ADD,
-                                 value_expr(J_INT, 0), value_expr(J_INT, 1));
-
-       assert_printed_binop_expr("BINOP:\n"
-                                 "  vm_type: [long]\n"
-                                 "  binary_operator: [add]\n"
-                                 "  binary_left: [value long 0x1]\n"
-                                 "  binary_right:\n"
-                                 "    BINOP:\n"
-                                 "      vm_type: [long]\n"
-                                 "      binary_operator: [sub]\n"
-                                 "      binary_left: [value long 0x2]\n"
-                                 "      binary_right: [value long 0x3]\n",
-                                 J_LONG, OP_ADD,
-                                 value_expr(J_LONG, 1),
-                                 binop_expr(J_LONG, OP_SUB,
-                                         value_expr(J_LONG, 2),
-                                         value_expr(J_LONG, 3))
-                                 );
-}
-
-void assert_printed_unary_op_expr(const char *expected, enum vm_type type,
+       assert_printed_binop_expr(str_aprintf(
+               "BINOP:\n"
+               "  vm_type: [int]\n"
+               "  binary_operator: [add]\n"
+               "  binary_left: [value int 0x0]\n"
+               "  binary_right: [value int 0x1]\n"),
+               J_INT, OP_ADD, value_expr(J_INT, 0), value_expr(J_INT, 1));
+
+       assert_printed_binop_expr(str_aprintf(
+               "BINOP:\n"
+               "  vm_type: [long]\n"
+               "  binary_operator: [add]\n"
+               "  binary_left: [value long 0x1]\n"
+               "  binary_right:\n"
+               "    BINOP:\n"
+               "      vm_type: [long]\n"
+               "      binary_operator: [sub]\n"
+               "      binary_left: [value long 0x2]\n"
+               "      binary_right: [value long 0x3]\n"),
+               J_LONG, OP_ADD,
+               value_expr(J_LONG, 1), binop_expr(J_LONG, OP_SUB,
+               value_expr(J_LONG, 2), value_expr(J_LONG, 3)));
+}
+
+void assert_printed_unary_op_expr(struct string *expected, enum vm_type type,
                                  enum unary_operator op,
                                  struct expression *unary_expr)
 {
@@ -302,20 +356,22 @@ void assert_printed_unary_op_expr(const char *expected, 
enum vm_type type,
 
 void test_should_print_unary_op_expression(void)
 {
-       assert_printed_unary_op_expr("UNARY_OP:\n"
-                                    "  vm_type: [int]\n"
-                                    "  unary_operator: [neg]\n"
-                                    "  unary_expression: [value int 0x0]\n",
-                                    J_INT, OP_NEG, value_expr(J_INT, 0));
+       assert_printed_unary_op_expr(str_aprintf(
+               "UNARY_OP:\n"
+               "  vm_type: [int]\n"
+               "  unary_operator: [neg]\n"
+               "  unary_expression: [value int 0x0]\n"),
+               J_INT, OP_NEG, value_expr(J_INT, 0));
 
-       assert_printed_unary_op_expr("UNARY_OP:\n"
-                                    "  vm_type: [boolean]\n"
-                                    "  unary_operator: [neg]\n"
-                                    "  unary_expression: [value boolean 
0x1]\n",
-                                    J_BOOLEAN, OP_NEG, value_expr(J_BOOLEAN, 
1));
+       assert_printed_unary_op_expr(str_aprintf(
+               "UNARY_OP:\n"
+               "  vm_type: [boolean]\n"
+               "  unary_operator: [neg]\n"
+               "  unary_expression: [value boolean 0x1]\n"),
+               J_BOOLEAN, OP_NEG, value_expr(J_BOOLEAN, 1));
 }
 
-void assert_printed_conversion_expr(const char *expected, enum vm_type type,
+void assert_printed_conversion_expr(struct string *expected, enum vm_type type,
                                    struct expression *from_expr)
 {
        struct expression *expr;
@@ -326,18 +382,20 @@ void assert_printed_conversion_expr(const char *expected, 
enum vm_type type,
 
 void test_should_print_conversion_expression(void)
 {
-       assert_printed_conversion_expr("CONVERSION:\n"
-                                    "  vm_type: [long]\n"
-                                    "  from_expression: [value int 0x0]\n",
-                                    J_LONG, value_expr(J_INT, 0));
+       assert_printed_conversion_expr(str_aprintf(
+               "CONVERSION:\n"
+               "  vm_type: [long]\n"
+               "  from_expression: [value int 0x0]\n"),
+               J_LONG, value_expr(J_INT, 0));
 
-       assert_printed_conversion_expr("CONVERSION:\n"
-                                    "  vm_type: [int]\n"
-                                    "  from_expression: [value boolean 0x1]\n",
-                                    J_INT, value_expr(J_BOOLEAN, 1));
+       assert_printed_conversion_expr(str_aprintf(
+               "CONVERSION:\n"
+               "  vm_type: [int]\n"
+               "  from_expression: [value boolean 0x1]\n"),
+               J_INT, value_expr(J_BOOLEAN, 1));
 }
 
-void assert_printed_class_field_expr(const char *expected, enum vm_type type,
+void assert_printed_class_field_expr(struct string *expected, enum vm_type 
type,
                                     struct vm_field *field)
 {
        struct expression *expr;
@@ -348,17 +406,12 @@ void assert_printed_class_field_expr(const char 
*expected, enum vm_type type,
 
 void test_should_print_class_field_expression(void)
 {
-       struct string *expected;
-       struct vm_field fb;
-
-       expected = alloc_str();
-       str_append(expected, "[class_field int %p]", &fb);
-
-       assert_printed_class_field_expr(expected->value, J_INT, &fb);
-       free_str(expected);
+       assert_printed_class_field_expr(str_aprintf(
+               "[class_field int %p '%s.%s']",
+               &vmf, vmf.class->name, vmf.name, vmf.type), J_INT, &vmf);
 }
 
-void assert_printed_instance_field_expr(const char *expected, enum vm_type 
type,
+void assert_printed_instance_field_expr(struct string *expected, enum vm_type 
type,
                                        struct vm_field *field,
                                        struct expression *objectref)
 {
@@ -371,22 +424,18 @@ void assert_printed_instance_field_expr(const char 
*expected, enum vm_type type,
 void test_should_print_instance_field_expression(void)
 {
        struct expression *objectref;
-       struct string *expected;
-       struct vm_field fb;
 
        objectref = value_expr(J_REFERENCE, 0xdeadbeef);
-       expected = alloc_str();
-       str_append(expected, "INSTANCE_FIELD:\n"
-                            "  vm_type: [int]\n"
-                            "  instance_field: [%p]\n"
-                            "  objectref_expression: [value reference 
0xdeadbeef]\n",
-                            &fb);
-
-       assert_printed_instance_field_expr(expected->value, J_INT, &fb, 
objectref);
-       free_str(expected);
+
+       assert_printed_instance_field_expr(str_aprintf(
+               "INSTANCE_FIELD:\n"
+               "  vm_type: [int]\n"
+               "  instance_field: [%p '%s.%s']\n"
+               "  objectref_expression: [value reference 0xdeadbeef]\n",
+               &vmf, vmf.class->name, vmf.name), J_INT, &vmf, objectref);
 }
 
-void assert_printed_invoke_expr(const char *expected,
+void assert_printed_invoke_expr(struct string *expected,
                                struct vm_method *method,
                                struct expression *args_list)
 {
@@ -399,27 +448,15 @@ void assert_printed_invoke_expr(const char *expected,
 
 void test_should_print_invoke_expression(void)
 {      
-       struct vm_class class = {
-               .name = "Foo",
-       };
-       struct vm_method method = {
-               .class = &class,
-               .name = "getId",
-               .type = "()I",
-       };
-       struct string *expected;
-
-       expected = alloc_str();
-       str_append(expected, "INVOKE:\n"
-                            "  target_method: [%p 'Foo.getId()I']\n"
-                            "  args_list: [no args]\n",
-                            &method);
-
-       assert_printed_invoke_expr(expected->value, &method, no_args_expr());
-       free_str(expected);
+       assert_printed_invoke_expr(str_aprintf(
+               "INVOKE:\n"
+               "  target_method: [%p '%s.%s%s']\n"
+               "  args_list: [no args]\n",
+               &vmm, vmm.class->name, vmm.name, vmm.type),
+               &vmm, no_args_expr());
 }
 
-void assert_printed_invokevirtual_expr(const char *expected,
+void assert_printed_invokevirtual_expr(struct string *expected,
                                       struct vm_method *target,
                                       struct expression *args_list)
 {
@@ -432,28 +469,15 @@ void assert_printed_invokevirtual_expr(const char 
*expected,
 
 void test_should_print_invokevirtual_expression(void)
 {
-       struct vm_class class = {
-               .name = "Foo",
-       };
-       struct vm_method method = {
-               .class = &class,
-               .method_index = 0xff,
-               .name = "bar",
-               .type = "(I)V",
-       };
-       struct string *expected;
-
-       expected = alloc_str();
-       str_append(expected, "INVOKEVIRTUAL:\n"
-                            "  target_method: [%p 'Foo.bar(I)V' (%lu)]\n"
-                            "  args_list: [no args]\n",
-                            &method, 0xff);
-
-       assert_printed_invokevirtual_expr(expected->value, &method, 
no_args_expr());
-       free_str(expected);
+       assert_printed_invokevirtual_expr(str_aprintf(
+               "INVOKEVIRTUAL:\n"
+               "  target_method: [%p '%s.%s%s' (%lu)]\n"
+               "  args_list: [no args]\n",
+               &vmm, vmm.class->name, vmm.name, vmm.type, vmm.virtual_index),
+               &vmm, no_args_expr());
 }
 
-void assert_printed_args_list_expr(const char *expected,
+void assert_printed_args_list_expr(struct string *expected,
                                   struct expression *args_left,
                                   struct expression *args_right)
 {
@@ -465,18 +489,18 @@ void assert_printed_args_list_expr(const char *expected,
 
 void test_should_print_args_list_expression(void)
 {
-       assert_printed_args_list_expr("ARGS_LIST:\n"
-                                    "  args_left:\n"
-                                    "    ARG:\n"
-                                    "      arg_expression: [value int 0x0]\n"
-                                    "  args_right:\n"
-                                    "    ARG:\n"
-                                    "      arg_expression: [value boolean 
0x1]\n",
-                                    value_expr(J_INT, 0),
-                                    value_expr(J_BOOLEAN, 1));
+       assert_printed_args_list_expr(str_aprintf(
+               "ARGS_LIST:\n"
+               "  args_left:\n"
+               "    ARG:\n"
+               "      arg_expression: [value int 0x0]\n"
+               "  args_right:\n"
+               "    ARG:\n"
+               "      arg_expression: [value boolean 0x1]\n"),
+               value_expr(J_INT, 0), value_expr(J_BOOLEAN, 1));
 }
 
-void assert_printed_arg_expr(const char *expected,
+void assert_printed_arg_expr(struct string *expected,
                             struct expression *arg_expression)
 {
        struct expression *expr;
@@ -487,21 +511,23 @@ void assert_printed_arg_expr(const char *expected,
 
 void test_should_print_arg_expression(void)
 {
-       assert_printed_arg_expr("ARG:\n"
-                                    "  arg_expression: [value int 0x0]\n",
-                                    value_expr(J_INT, 0));
+       assert_printed_arg_expr(str_aprintf(
+               "ARG:\n"
+               "  arg_expression: [value int 0x0]\n"),
+               value_expr(J_INT, 0));
 
-       assert_printed_arg_expr("ARG:\n"
-                                    "  arg_expression: [value boolean 0x1]\n",
-                                    value_expr(J_BOOLEAN, 1));
+       assert_printed_arg_expr(str_aprintf(
+               "ARG:\n"
+               "  arg_expression: [value boolean 0x1]\n"),
+               value_expr(J_BOOLEAN, 1));
 }
 
 void test_should_print_no_args_expression(void)
 {
-       assert_print_expr("[no args]", no_args_expr());
+       assert_print_expr(str_aprintf("[no args]"), no_args_expr());
 }
 
-void assert_printed_new_expr(const char *expected, struct vm_class *class)
+void assert_printed_new_expr(struct string *expected, struct vm_class *class)
 {
        struct expression *expr;
 
@@ -511,68 +537,75 @@ void assert_printed_new_expr(const char *expected, struct 
vm_class *class)
 
 void test_should_print_new_expression(void)
 {
-       assert_printed_new_expr("NEW:\n"
-                            "  vm_type: [reference]\n"
-                            "  class: [0xcafe]\n",
-                            (void *) 0xcafe);
+       assert_printed_new_expr(str_aprintf(
+               "NEW:\n"
+               "  vm_type: [reference]\n"
+               "  class: [%p '%s']\n", &vmc, vmc.name), &vmc);
 }
 
 void test_print_newarray_expression(void)
 {
-       assert_print_expr("NEWARRAY:\n"
-                         "  vm_type: [reference]\n"
-                         "  array_size: [value int 0xff]\n"
-                         "  array_type: [10]\n",
-                         newarray_expr(T_INT, value_expr(J_INT, 0xff)));
+       assert_print_expr(str_aprintf(
+               "NEWARRAY:\n"
+               "  vm_type: [reference]\n"
+               "  array_size: [value int 0xff]\n"
+               "  array_type: [10]\n"),
+               newarray_expr(T_INT, value_expr(J_INT, 0xff)));
 }
 
 void test_print_anewarray_expression(void)
 {
-       assert_print_expr("ANEWARRAY:\n"
-                         "  vm_type: [reference]\n"
-                         "  anewarray_size: [value int 0xff]\n"
-                         "  anewarray_ref_type: [0x55]\n",
-                         anewarray_expr((void *) 0x55, value_expr(J_INT, 
0xff)));
+       assert_print_expr(str_aprintf(
+               "ANEWARRAY:\n"
+               "  vm_type: [reference]\n"
+               "  anewarray_size: [value int 0xff]\n"
+               "  anewarray_ref_type: [%p '%s']\n",
+               &vmc, vmc.name),
+               anewarray_expr(&vmc, value_expr(J_INT, 0xff)));
 }
 
 void test_print_multianewarray_expression(void)
 {
        struct expression *expr, *args_list;
        args_list = args_list_expr(arg_expr(value_expr(J_INT, 0x02)),
-                                  arg_expr(value_expr(J_INT, 0xff)));
+               arg_expr(value_expr(J_INT, 0xff)));
 
-       expr = multianewarray_expr((void *) 0xff);
+       expr = multianewarray_expr(&vmc);
        expr->multianewarray_dimensions = &args_list->node;
 
-       assert_print_expr("MULTIANEWARRAY:\n"
-                         "  vm_type: [reference]\n"
-                         "  multianewarray_ref_type: [0xff]\n"
-                         "  dimension list:\n"
-                         "    ARGS_LIST:\n"
-                         "      args_left:\n"
-                         "        ARG:\n"
-                         "          arg_expression: [value int 0x2]\n"
-                         "      args_right:\n"
-                         "        ARG:\n"
-                         "          arg_expression: [value int 0xff]\n",
-                         expr);
+       assert_print_expr(str_aprintf(
+               "MULTIANEWARRAY:\n"
+               "  vm_type: [reference]\n"
+               "  multianewarray_ref_type: [%p '%s']\n"
+               "  dimension list:\n"
+               "    ARGS_LIST:\n"
+               "      args_left:\n"
+               "        ARG:\n"
+               "          arg_expression: [value int 0x2]\n"
+               "      args_right:\n"
+               "        ARG:\n"
+               "          arg_expression: [value int 0xff]\n",
+               &vmc, vmc.name), expr);
 }
 
 void test_print_arraylength_expression(void)
 {
-       assert_print_expr("ARRAYLENGTH:\n"
-                         "  vm_type: [reference]\n"
-                         "  arraylength_ref: [value reference 0xcafe]\n",
-                         arraylength_expr(value_expr(J_REFERENCE, 0xcafe)));
+       assert_print_expr(str_aprintf(
+               "ARRAYLENGTH:\n"
+               "  vm_type: [reference]\n"
+               "  arraylength_ref: [value reference 0xcafe]\n"),
+               arraylength_expr(value_expr(J_REFERENCE, 0xcafe)));
 }
 
 void test_print_instanceof_expression(void)
 {
-       assert_print_expr("INSTANCEOF:\n"
-                         "  vm_type: [reference]\n"
-                         "  instanceof_class: [0x55]\n"
-                         "  instanceof_ref: [value reference 0x55]\n",
-                         instanceof_expr(value_expr(J_REFERENCE, 0x55), (void 
*)0x55));
+       assert_print_expr(str_aprintf(
+               "INSTANCEOF:\n"
+               "  vm_type: [reference]\n"
+               "  instanceof_class: [%p '%s']\n"
+               "  instanceof_ref: [value reference 0x55]\n",
+               &vmc, vmc.name),
+               instanceof_expr(value_expr(J_REFERENCE, 0x55), &vmc));
 }
 
 void test_should_print_nullcheck_expression(void)
@@ -584,5 +617,7 @@ void test_should_print_nullcheck_expression(void)
 
        expr = null_check_expr(expression);
 
-       assert_print_expr("NULL_CHECK:\n  ref: [local reference 0]\n", expr);
+       assert_print_expr(str_aprintf(
+               "NULL_CHECK:\n"
+               "  ref: [local reference 0]\n"), expr);
 }
-- 
1.6.0.4


------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to