From patchwork Sat Aug 24 22:32:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Dos Reis X-Patchwork-Id: 269673 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 820382C00A1 for ; Sun, 25 Aug 2013 08:32:58 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=jhY+suMG6y+PIURTyDb8J30MdzeTpJDCcYVoPP/7HQ3mxqnceS6a/ K5LnlvHp1qfbSV0u/BEfu924AcouGwJ2PDLBAYsRoket7aCOk3oeeLgSOyhPeX/L x771+fkL2/j7UrcxF8aawlz4uo7DvkP9xGhWIhCgn//xpmVp6fBygg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=5eGg/XRALIs9YxiQVC+hK3u9pwc=; b=WboiFwnSbIl547iVnaaq DanAqlUB4Hq3caB9OQofOqBXAWpYX8/1QLL4yu1HQ7/hf844PFk1f3IT4Cbru0nn EQMfxX3xH11xzFa4wZP2ePjsNGVfP6pFLEwZp1qK00uZD8mo04cti5tS480XYFXt OJ0i62jwIuvuIzLtMSFiSnM= Received: (qmail 9754 invoked by alias); 24 Aug 2013 22:32:50 -0000 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 Received: (qmail 9739 invoked by uid 89); 24 Aug 2013 22:32:50 -0000 X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 Received: from www.axiomatics.org (HELO mail.axiomatics.org) (66.228.53.191) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sat, 24 Aug 2013 22:32:49 +0000 Received: by mail.axiomatics.org (Postfix, from userid 1000) id 1ECB3ECB0; Sat, 24 Aug 2013 17:32:47 -0500 (CDT) From: Gabriel Dos Reis To: gcc-patches@gcc.gnu.org Subject: Clean up pretty printers [13/n] Date: Sat, 24 Aug 2013 17:32:46 -0500 Message-ID: <87ioyuoh2p.fsf@euclid.axiomatics.org> Lines: 247 MIME-Version: 1.0 Most of the specialized pretty printing functions from the C-family languages are really virtual functions. This patchlet makes the first explicitly so. Tested on an x86_64-suse-linux. Applied to trunk. -- Gaby c-family/ 2013-08-24 Gabriel Dos Reis * c-pretty-print.h (c_pretty_printer::constant): Now a virtual member function. (pp_constant): Adjust. (pp_c_constant): Remove. * c-pretty-print.c (c_pretty_printer::constant): Rename from pp_c_constant. Adjust. (pp_c_constant) (pp_c_primary_expression): Call pp_constant in lieu of pp_c_constant. (c_pretty_printer::c_pretty_printer): Remove assignment to constant. cp/ * cxx-pretty-print.h (cxx_pretty_printer::constant): Now a member function, overriding c_pretty_printer::constant. * cxx-pretty-print.c (cxx_pretty_printer::constant): Rename from pp_cxx_constant. Adjust. (cxx_pretty_printer::cxx_pretty_printer): Do not assign to constant. Index: c-family/c-pretty-print.c =================================================================== --- c-family/c-pretty-print.c (revision 201968) +++ c-family/c-pretty-print.c (working copy) @@ -1130,7 +1130,7 @@ character-constant */ void -pp_c_constant (c_pretty_printer *pp, tree e) +c_pretty_printer::constant (tree e) { const enum tree_code code = TREE_CODE (e); @@ -1140,38 +1140,38 @@ { tree type = TREE_TYPE (e); if (type == boolean_type_node) - pp_c_bool_constant (pp, e); + pp_c_bool_constant (this, e); else if (type == char_type_node) - pp_c_character_constant (pp, e); + pp_c_character_constant (this, e); else if (TREE_CODE (type) == ENUMERAL_TYPE - && pp_c_enumeration_constant (pp, e)) + && pp_c_enumeration_constant (this, e)) ; else - pp_c_integer_constant (pp, e); + pp_c_integer_constant (this, e); } break; case REAL_CST: - pp_c_floating_constant (pp, e); + pp_c_floating_constant (this, e); break; case FIXED_CST: - pp_c_fixed_constant (pp, e); + pp_c_fixed_constant (this, e); break; case STRING_CST: - pp_c_string_literal (pp, e); + pp_c_string_literal (this, e); break; case COMPLEX_CST: /* Sometimes, we are confused and we think a complex literal is a constant. Such thing is a compound literal which grammatically belongs to postfix-expr production. */ - pp_c_compound_literal (pp, e); + pp_c_compound_literal (this, e); break; default: - pp_unsupported_tree (pp, e); + pp_unsupported_tree (this, e); break; } } @@ -1236,7 +1236,7 @@ case REAL_CST: case FIXED_CST: case STRING_CST: - pp_c_constant (pp, e); + pp_constant (pp, e); break; case TARGET_EXPR: @@ -1357,7 +1357,7 @@ { pp_c_left_bracket (pp); if (TREE_PURPOSE (init)) - pp_c_constant (pp, TREE_PURPOSE (init)); + pp_constant (pp, TREE_PURPOSE (init)); pp_c_right_bracket (pp); } pp_c_whitespace (pp); @@ -2339,7 +2339,6 @@ statement = pp_c_statement; - constant = pp_c_constant; id_expression = pp_c_id_expression; primary_expression = pp_c_primary_expression; postfix_expression = pp_c_postfix_expression; Index: c-family/c-pretty-print.h =================================================================== --- c-family/c-pretty-print.h (revision 201968) +++ c-family/c-pretty-print.h (working copy) @@ -51,6 +51,7 @@ { c_pretty_printer (); + virtual void constant (tree); /* Points to the first element of an array of offset-list. Not used yet. */ int *offset_list; @@ -76,7 +77,6 @@ c_pretty_print_fn statement; - c_pretty_print_fn constant; c_pretty_print_fn id_expression; c_pretty_print_fn primary_expression; c_pretty_print_fn postfix_expression; @@ -109,7 +109,7 @@ #define pp_statement(PP, S) (PP)->statement (PP, S) -#define pp_constant(PP, E) (PP)->constant (PP, E) +#define pp_constant(PP, E) (PP)->constant (E) #define pp_id_expression(PP, E) (PP)->id_expression (PP, E) #define pp_primary_expression(PP, E) (PP)->primary_expression (PP, E) #define pp_postfix_expression(PP, E) (PP)->postfix_expression (PP, E) @@ -169,7 +169,6 @@ void pp_c_postfix_expression (c_pretty_printer *, tree); void pp_c_primary_expression (c_pretty_printer *, tree); void pp_c_init_declarator (c_pretty_printer *, tree); -void pp_c_constant (c_pretty_printer *, tree); void pp_c_id_expression (c_pretty_printer *, tree); void pp_c_ws_string (c_pretty_printer *, const char *); void pp_c_identifier (c_pretty_printer *, const char *); Index: cp/cxx-pretty-print.c =================================================================== --- cp/cxx-pretty-print.c (revision 201968) +++ cp/cxx-pretty-print.c (working copy) @@ -321,8 +321,8 @@ } -static void -pp_cxx_constant (cxx_pretty_printer *pp, tree t) +void +cxx_pretty_printer::constant (tree t) { switch (TREE_CODE (t)) { @@ -330,23 +330,23 @@ { const bool in_parens = PAREN_STRING_LITERAL_P (t); if (in_parens) - pp_cxx_left_paren (pp); - pp_c_constant (pp, t); + pp_cxx_left_paren (this); + c_pretty_printer::constant (t); if (in_parens) - pp_cxx_right_paren (pp); + pp_cxx_right_paren (this); } break; case INTEGER_CST: if (NULLPTR_TYPE_P (TREE_TYPE (t))) { - pp_string (pp, "nullptr"); + pp_string (this, "nullptr"); break; } /* else fall through. */ default: - pp_c_constant (pp, t); + c_pretty_printer::constant (t); break; } } @@ -372,7 +372,7 @@ void pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t) { - pp_cxx_constant (pp, USERDEF_LITERAL_VALUE (t)); + pp_constant (pp, USERDEF_LITERAL_VALUE (t)); pp_cxx_id_expression (pp, USERDEF_LITERAL_SUFFIX_ID (t)); } @@ -420,7 +420,7 @@ case REAL_CST: case COMPLEX_CST: case STRING_CST: - pp_cxx_constant (pp, t); + pp_constant (pp, t); break; case USERDEF_LITERAL: @@ -1041,7 +1041,7 @@ case INTEGER_CST: case REAL_CST: case COMPLEX_CST: - pp_cxx_constant (pp, t); + pp_constant (pp, t); break; case USERDEF_LITERAL: @@ -2452,7 +2452,6 @@ /* pp->statement = (pp_fun) pp_cxx_statement; */ - constant = (pp_fun) pp_cxx_constant; id_expression = (pp_fun) pp_cxx_id_expression; primary_expression = (pp_fun) pp_cxx_primary_expression; postfix_expression = (pp_fun) pp_cxx_postfix_expression; Index: cp/cxx-pretty-print.h =================================================================== --- cp/cxx-pretty-print.h (revision 201968) +++ cp/cxx-pretty-print.h (working copy) @@ -32,6 +32,8 @@ struct cxx_pretty_printer : c_pretty_printer { cxx_pretty_printer (); + + virtual void constant (tree); /* This is the enclosing scope of the entity being pretty-printed. */ tree enclosing_scope; };