From patchwork Thu Jun 30 18:42:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 102803 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 282BBB6EDF for ; Fri, 1 Jul 2011 04:42:56 +1000 (EST) Received: (qmail 11372 invoked by alias); 30 Jun 2011 18:42:55 -0000 Received: (qmail 11363 invoked by uid 22791); 30 Jun 2011 18:42:54 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 30 Jun 2011 18:42:35 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5UIgZYZ017242 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 30 Jun 2011 14:42:35 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p5UIgYv9025957 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 30 Jun 2011 14:42:34 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p5UIgXwM003260 for ; Thu, 30 Jun 2011 20:42:33 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p5UIgXRq003258 for gcc-patches@gcc.gnu.org; Thu, 30 Jun 2011 20:42:33 +0200 Date: Thu, 30 Jun 2011 20:42:33 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Improve CONSTRUCTOR printing in tree-pretty-print.c Message-ID: <20110630184233.GC16443@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 * tree-pretty-print.c (dump_generic_code) : Print [idx]= and [idx1 ... idx2]= before initializers if needed for array initializers. Jakub --- 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);