From patchwork Sat Aug 16 01:00:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWFudWVsIEzDs3Blei1JYsOhw7Fleg==?= X-Patchwork-Id: 380449 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C2F5140120 for ; Sat, 16 Aug 2014 11:01:25 +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 :mime-version:from:date:message-id:subject:to:cc:content-type; q=dns; s=default; b=sI7pBMmaaPlZQIJyA5cEgUcJk+F6qyXiaWr4UJJR80M 6Nt7cNJiol7RKiF+4s+tCOY4Ye3ZiD9lOmALg/iNqiGSuRGrRMikHuDmtL6U5TWO HZsWjEIoOqzeqfR1EvpHoxplv9cInMjb/djsIF2fZL9VsygAqypkUUW9NYs9xAYA = 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 :mime-version:from:date:message-id:subject:to:cc:content-type; s=default; bh=fDp2uvQgoXkc+zYUlMohsCMK3jA=; b=jTBm1lchchv2idRan o8HoLbRJmGuRcPEjtW6SsK6/wmXlQ/8ILn0P7LIoK6eXE4A0n1jGNtu0T1TUkwPg u4Hp6s88gQZWS8nDqAq0QK/QDEDvq8sUf2w2HUUH7LRtQV/8JNugdeZKaylyyj4n Tw2osGpZL2Ac3mGlN7ZH8g8vFQ= Received: (qmail 3955 invoked by alias); 16 Aug 2014 01:01:17 -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 3928 invoked by uid 89); 16 Aug 2014 01:01:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f47.google.com Received: from mail-wg0-f47.google.com (HELO mail-wg0-f47.google.com) (74.125.82.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 16 Aug 2014 01:01:07 +0000 Received: by mail-wg0-f47.google.com with SMTP id b13so2919421wgh.30 for ; Fri, 15 Aug 2014 18:01:03 -0700 (PDT) X-Received: by 10.194.184.166 with SMTP id ev6mr24131361wjc.61.1408150863738; Fri, 15 Aug 2014 18:01:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.217.80.73 with HTTP; Fri, 15 Aug 2014 18:00:43 -0700 (PDT) From: =?ISO-8859-1?Q?Manuel_L=F3pez=2DIb=E1=F1ez?= Date: Sat, 16 Aug 2014 03:00:43 +0200 Message-ID: Subject: [PATCH] Move caret printing to diagnostics_finalizer To: Gcc Patch List Cc: Dodji Seketeli X-IsSubscribed: yes Hi Dodji, This patch is in preparation for further patches moving the Fortran FE to use the common diagnostics machinery. Fortran has its own way of printing the caret information, so we need a way to override the default in the diagnostics machinery. A simple way is to move the printing of the caret (plus the destruction of the prefix and printing a newline at the end) to the diagnostic_finalizer, so Fortran can override the whole thing with its own finalizer. This means that the c-family finalizer needs to invoke the caret explicitly. The C++ finalizer was destroying the prefix even thought this was done by the common code anyway. Thus now there is only one finalizer for both C and C++. Bootstrapped and regression tested on x86-64-linux. OK? gcc/ChangeLog: 2014-08-16 Manuel López-Ibáñez * diagnostic.c (default_diagnostic_finalizer): Move caret printing to here ... (diagnostic_report_diagnostic): ... from here. * toplev.c (general_init): Move code to c-family. gcc/cp/ChangeLog: 2014-08-16 Manuel López-Ibáñez * error.c (cp_diagnostic_finalizer): Delete. (init_error): Do not set diagnostic_finalizer here. gcc/c-family/ChangeLog: 2014-08-16 Manuel López-Ibáñez * c-opts.c: Include tree-diagnostics.h. (c_diagnostic_finalizer): New. (c_common_initialize_diagnostics): Use it. Index: gcc/c-family/c-opts.c =================================================================== --- gcc/c-family/c-opts.c (revision 214024) +++ gcc/c-family/c-opts.c (working copy) @@ -26,10 +26,11 @@ along with GCC; see the file COPYING3. #include "c-pragma.h" #include "flags.h" #include "toplev.h" #include "langhooks.h" #include "diagnostic.h" +#include "tree-diagnostic.h" /* for virt_loc_aware_diagnostic_finalizer */ #include "intl.h" #include "cppdefault.h" #include "incpath.h" #include "debug.h" /* For debug_hooks. */ #include "opts.h" @@ -162,10 +163,23 @@ c_common_option_lang_mask (void) static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX}; return lang_flags[c_language]; } +/* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */ +static void +c_diagnostic_finalizer (diagnostic_context *context, + diagnostic_info *diagnostic) +{ + diagnostic_show_locus (context, diagnostic); + /* By default print macro expansion contexts in the diagnostic + finalizer -- for tokens resulting from macro expansion. */ + virt_loc_aware_diagnostic_finalizer (context, diagnostic); + pp_destroy_prefix (context->printer); + pp_newline_and_flush (context->printer); +} + /* Common diagnostics initialization. */ void c_common_initialize_diagnostics (diagnostic_context *context) { /* This is conditionalized only because that is the way the front @@ -176,12 +190,12 @@ c_common_initialize_diagnostics (diagnos ("COLUMNS") preferable? */ diagnostic_line_cutoff (context) = 80; /* By default, emit location information once for every diagnostic message. */ diagnostic_prefixing_rule (context) = DIAGNOSTICS_SHOW_PREFIX_ONCE; - } - + } + diagnostic_finalizer (context) = c_diagnostic_finalizer; context->opt_permissive = OPT_fpermissive; } /* Whether options from all C-family languages should be accepted quietly. */ Index: gcc/diagnostic.c =================================================================== --- gcc/diagnostic.c (revision 214024) +++ gcc/diagnostic.c (working copy) @@ -551,13 +551,16 @@ default_diagnostic_starter (diagnostic_c pp_set_prefix (context->printer, diagnostic_build_prefix (context, diagnostic)); } void -default_diagnostic_finalizer (diagnostic_context *context ATTRIBUTE_UNUSED, - diagnostic_info *diagnostic ATTRIBUTE_UNUSED) +default_diagnostic_finalizer (diagnostic_context *context, + diagnostic_info *diagnostic) { + diagnostic_show_locus (context, diagnostic); + pp_destroy_prefix (context->printer); + pp_newline_and_flush (context->printer); } /* Interface to specify diagnostic kind overrides. Returns the previous setting, or DK_UNSPECIFIED if the parameters are out of range. If OPTION_INDEX is zero, the new setting is for all the @@ -793,14 +796,11 @@ diagnostic_report_diagnostic (diagnostic diagnostic->message.x_data = &diagnostic->x_data; diagnostic->x_data = NULL; pp_format (context->printer, &diagnostic->message); (*diagnostic_starter (context)) (context, diagnostic); pp_output_formatted_text (context->printer); - diagnostic_show_locus (context, diagnostic); (*diagnostic_finalizer (context)) (context, diagnostic); - pp_destroy_prefix (context->printer); - pp_newline_and_flush (context->printer); diagnostic_action_after_output (context, diagnostic); diagnostic->message.format_spec = saved_format_spec; diagnostic->x_data = NULL; context->lock--; Index: gcc/toplev.c =================================================================== --- gcc/toplev.c (revision 214024) +++ gcc/toplev.c (working copy) @@ -1113,15 +1113,10 @@ general_init (const char *argv0) can give warnings and errors. */ diagnostic_initialize (global_dc, N_OPTS); /* Set a default printer. Language specific initializations will override it later. */ tree_diagnostics_defaults (global_dc); - /* FIXME: This should probably be moved to C-family - language-specific initializations. */ - /* By default print macro expansion contexts in the diagnostic - finalizer -- for tokens resulting from macro expansion. */ - diagnostic_finalizer (global_dc) = virt_loc_aware_diagnostic_finalizer; global_dc->show_caret = global_options_init.x_flag_diagnostics_show_caret; global_dc->show_option_requested = global_options_init.x_flag_diagnostics_show_option; Index: gcc/cp/error.c =================================================================== --- gcc/cp/error.c (revision 214024) +++ gcc/cp/error.c (working copy) @@ -97,21 +97,20 @@ static void maybe_print_instantiation_co static void print_instantiation_full_context (diagnostic_context *); static void print_instantiation_partial_context (diagnostic_context *, struct tinst_level *, location_t); static void cp_diagnostic_starter (diagnostic_context *, diagnostic_info *); -static void cp_diagnostic_finalizer (diagnostic_context *, diagnostic_info *); static void cp_print_error_function (diagnostic_context *, diagnostic_info *); static bool cp_printer (pretty_printer *, text_info *, const char *, int, bool, bool, bool); void init_error (void) { diagnostic_starter (global_dc) = cp_diagnostic_starter; - diagnostic_finalizer (global_dc) = cp_diagnostic_finalizer; + /* diagnostic_finalizer is already c_diagnostic_finalizer. */ diagnostic_format_decoder (global_dc) = cp_printer; new (cxx_pp) cxx_pretty_printer (); } @@ -3039,18 +3038,10 @@ cp_diagnostic_starter (diagnostic_contex maybe_print_constexpr_context (context); pp_set_prefix (context->printer, diagnostic_build_prefix (context, diagnostic)); } -static void -cp_diagnostic_finalizer (diagnostic_context *context, - diagnostic_info *diagnostic) -{ - virt_loc_aware_diagnostic_finalizer (context, diagnostic); - pp_destroy_prefix (context->printer); -} - /* Print current function onto BUFFER, in the process of reporting a diagnostic message. Called from cp_diagnostic_starter. */ static void cp_print_error_function (diagnostic_context *context, diagnostic_info *diagnostic)