* [PATCH] Improve CONSTRUCTOR printing in tree-pretty-print.c
@ 2011-06-30 20:17 Jakub Jelinek
2011-07-01 8:03 ` Richard Guenther
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2011-06-30 20:17 UTC (permalink / raw)
To: gcc-patches
Hi!
As reporteed by Tobias, when printing array ctors the pretty printer would
never print indexes or ranges, which means that e.g.
{[2 ... 71]=7}
ctor was printed as
{7}
and
{[3]=1, [7]=2}
ctor was printed as
{1, 2}
The following patch prints the index (if different from the last index + 1
resp. min value for the first element) or range (always).
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2011-06-30 Jakub Jelinek <jakub@redhat.com>
* tree-pretty-print.c (dump_generic_code) <case CONSTRUCTOR>: Print
[idx]= and [idx1 ... idx2]= before initializers if needed for
array initializers.
--- gcc/tree-pretty-print.c.jj 2011-06-06 19:07:08.000000000 +0200
+++ gcc/tree-pretty-print.c 2011-06-30 11:51:04.000000000 +0200
@@ -1250,19 +1250,58 @@ dump_generic_node (pretty_printer *buffe
{
unsigned HOST_WIDE_INT ix;
tree field, val;
- bool is_struct_init = FALSE;
+ bool is_struct_init = false;
+ bool is_array_init = false;
+ double_int curidx = double_int_zero;
pp_character (buffer, '{');
if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
|| TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
- is_struct_init = TRUE;
+ is_struct_init = true;
+ else if (TREE_CODE (TREE_TYPE (node)) == ARRAY_TYPE
+ && TYPE_DOMAIN (TREE_TYPE (node))
+ && TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node)))
+ && TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node))))
+ == INTEGER_CST)
+ {
+ tree minv = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node)));
+ is_array_init = true;
+ curidx = tree_to_double_int (minv);
+ }
FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node), ix, field, val)
{
- if (field && is_struct_init)
+ if (field)
{
- pp_character (buffer, '.');
- dump_generic_node (buffer, field, spc, flags, false);
- pp_string (buffer, "=");
+ if (is_struct_init)
+ {
+ pp_character (buffer, '.');
+ dump_generic_node (buffer, field, spc, flags, false);
+ pp_character (buffer, '=');
+ }
+ else if (is_array_init
+ && (TREE_CODE (field) != INTEGER_CST
+ || !double_int_equal_p (tree_to_double_int (field),
+ curidx)))
+ {
+ pp_character (buffer, '[');
+ if (TREE_CODE (field) == RANGE_EXPR)
+ {
+ dump_generic_node (buffer, TREE_OPERAND (field, 0), spc,
+ flags, false);
+ pp_string (buffer, " ... ");
+ dump_generic_node (buffer, TREE_OPERAND (field, 1), spc,
+ flags, false);
+ if (TREE_CODE (TREE_OPERAND (field, 1)) == INTEGER_CST)
+ curidx = tree_to_double_int (TREE_OPERAND (field, 1));
+ }
+ else
+ dump_generic_node (buffer, field, spc, flags, false);
+ if (TREE_CODE (field) == INTEGER_CST)
+ curidx = tree_to_double_int (field);
+ pp_string (buffer, "]=");
+ }
}
+ if (is_array_init)
+ curidx = double_int_add (curidx, double_int_one);
if (val && TREE_CODE (val) == ADDR_EXPR)
if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
val = TREE_OPERAND (val, 0);
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Improve CONSTRUCTOR printing in tree-pretty-print.c
2011-06-30 20:17 [PATCH] Improve CONSTRUCTOR printing in tree-pretty-print.c Jakub Jelinek
@ 2011-07-01 8:03 ` Richard Guenther
0 siblings, 0 replies; 2+ messages in thread
From: Richard Guenther @ 2011-07-01 8:03 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On Thu, Jun 30, 2011 at 8:42 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> As reporteed by Tobias, when printing array ctors the pretty printer would
> never print indexes or ranges, which means that e.g.
> {[2 ... 71]=7}
> ctor was printed as
> {7}
> and
> {[3]=1, [7]=2}
> ctor was printed as
> {1, 2}
> The following patch prints the index (if different from the last index + 1
> resp. min value for the first element) or range (always).
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
Ok.
Thanks,
Richard.
> 2011-06-30 Jakub Jelinek <jakub@redhat.com>
>
> * tree-pretty-print.c (dump_generic_code) <case CONSTRUCTOR>: Print
> [idx]= and [idx1 ... idx2]= before initializers if needed for
> array initializers.
>
> --- gcc/tree-pretty-print.c.jj 2011-06-06 19:07:08.000000000 +0200
> +++ gcc/tree-pretty-print.c 2011-06-30 11:51:04.000000000 +0200
> @@ -1250,19 +1250,58 @@ dump_generic_node (pretty_printer *buffe
> {
> unsigned HOST_WIDE_INT ix;
> tree field, val;
> - bool is_struct_init = FALSE;
> + bool is_struct_init = false;
> + bool is_array_init = false;
> + double_int curidx = double_int_zero;
> pp_character (buffer, '{');
> if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
> || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
> - is_struct_init = TRUE;
> + is_struct_init = true;
> + else if (TREE_CODE (TREE_TYPE (node)) == ARRAY_TYPE
> + && TYPE_DOMAIN (TREE_TYPE (node))
> + && TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node)))
> + && TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node))))
> + == INTEGER_CST)
> + {
> + tree minv = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node)));
> + is_array_init = true;
> + curidx = tree_to_double_int (minv);
> + }
> FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node), ix, field, val)
> {
> - if (field && is_struct_init)
> + if (field)
> {
> - pp_character (buffer, '.');
> - dump_generic_node (buffer, field, spc, flags, false);
> - pp_string (buffer, "=");
> + if (is_struct_init)
> + {
> + pp_character (buffer, '.');
> + dump_generic_node (buffer, field, spc, flags, false);
> + pp_character (buffer, '=');
> + }
> + else if (is_array_init
> + && (TREE_CODE (field) != INTEGER_CST
> + || !double_int_equal_p (tree_to_double_int (field),
> + curidx)))
> + {
> + pp_character (buffer, '[');
> + if (TREE_CODE (field) == RANGE_EXPR)
> + {
> + dump_generic_node (buffer, TREE_OPERAND (field, 0), spc,
> + flags, false);
> + pp_string (buffer, " ... ");
> + dump_generic_node (buffer, TREE_OPERAND (field, 1), spc,
> + flags, false);
> + if (TREE_CODE (TREE_OPERAND (field, 1)) == INTEGER_CST)
> + curidx = tree_to_double_int (TREE_OPERAND (field, 1));
> + }
> + else
> + dump_generic_node (buffer, field, spc, flags, false);
> + if (TREE_CODE (field) == INTEGER_CST)
> + curidx = tree_to_double_int (field);
> + pp_string (buffer, "]=");
> + }
> }
> + if (is_array_init)
> + curidx = double_int_add (curidx, double_int_one);
> if (val && TREE_CODE (val) == ADDR_EXPR)
> if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
> val = TREE_OPERAND (val, 0);
>
> Jakub
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-07-01 8:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-30 20:17 [PATCH] Improve CONSTRUCTOR printing in tree-pretty-print.c Jakub Jelinek
2011-07-01 8:03 ` Richard Guenther
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).