From patchwork Wed Apr 25 15:31:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 154983 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 B960AB6F6E for ; Thu, 26 Apr 2012 01:31:39 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1335972700; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Cc:Subject:References:Date:In-Reply-To: Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=EuwSlFHX0GKqlWDua02RSRTUEe4=; b=qPPQpLCwjyXyw87P2YLXl7d+3P8iJJWFFmlZ/RDoLqektpuMf3daT5xjUdSpGe TsEtcAbptu0Ow68UyxhxvQnrby25T/FRbyEhlcCMOlQ15y19EevmF8Ub+ouwOZcp QNKPTpE39gWFtQc6N6Ua3nBEG8w3C7yQM2LbKeIYa7MzE= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:Cc:Subject:References:X-URL:Date:In-Reply-To:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=VZFGci+b+2Qd7bAFpiRyk65whNpFcteBsJv5vbo4EC1TL2ZcD2zcbvqQ8xq3pB 3HhhMvY/qZ0abXaENG2JoW7EKbCsya6QUYmJrjTbkx1B1+kpFKnhjb0hCYVDu7ss G3M0QAbQEEr8KSPJuOIqaHiI4BcvfJD2QoUzSeib6RO9A=; Received: (qmail 8641 invoked by alias); 25 Apr 2012 15:31:33 -0000 Received: (qmail 8553 invoked by uid 22791); 25 Apr 2012 15:31:30 -0000 X-SWARE-Spam-Status: No, hits=-5.9 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, 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; Wed, 25 Apr 2012 15:31:12 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3PFVCYD011003 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 25 Apr 2012 11:31:12 -0400 Received: from localhost (ovpn-116-18.ams2.redhat.com [10.36.116.18]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3PFV9BB011730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 25 Apr 2012 11:31:11 -0400 Received: by localhost (Postfix, from userid 500) id 4BC0529C046; Wed, 25 Apr 2012 17:31:07 +0200 (CEST) From: Dodji Seketeli To: Jason Merrill Cc: GCC Patches , Tom Tromey , Gabriel Dos Reis Subject: Re: [PATCH 05/11] Make expand_location resolve to locus in main source file References: <4F858BD2.7070200@redhat.com> X-URL: http://www.redhat.com Date: Wed, 25 Apr 2012 17:31:07 +0200 In-Reply-To: (Dodji Seketeli's message of "Wed, 25 Apr 2012 11:50:13 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 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 I have re-based my tree on top of a recent tree that incorporates the changes for caret diagnostics and I had to update this patch accordingly. Here is its new version on trunk of today. It basically updates the new diagnostic_show_locus function to point to spelling locations. The patch does pass bootstrap with -ftrack-macro-expansion turned off, and passes bootstrap with the full series with -ftrack-macro-expansion turned on. gcc/ * input.c (expand_location_1): New. Takes a parameter to choose whether to resolve the location to spelling or expansion point. Was factorized from ... (expand_location): ... here. (expand_location_to_spelling_point): New. Implemented in terms of expand_location_1. * diagnostic.c (diagnostic_build_prefix): Use the new expand_location_to_spelling_point instead of expand_location. --- gcc/diagnostic.c | 4 ++-- gcc/input.c | 40 +++++++++++++++++++++++++++++++++++----- gcc/input.h | 9 +++++++++ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index 4496803..729e865 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -214,7 +214,7 @@ diagnostic_build_prefix (diagnostic_context *context, "must-not-happen" }; const char *text = _(diagnostic_kind_text[diagnostic->kind]); - expanded_location s = expand_location (diagnostic->location); + expanded_location s = expand_location_to_spelling_point (diagnostic->location); if (diagnostic->override_column) s.column = diagnostic->override_column; gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND); @@ -266,7 +266,7 @@ diagnostic_show_locus (diagnostic_context * context, || diagnostic->location <= BUILTINS_LOCATION) return; - s = expand_location(diagnostic->location); + s = expand_location_to_spelling_point (diagnostic->location); line = location_get_source_line (s); if (line == NULL) return; diff --git a/gcc/input.c b/gcc/input.c index bf5fe48..e9ba301 100644 --- a/gcc/input.c +++ b/gcc/input.c @@ -32,16 +32,22 @@ struct line_maps *line_table; /* Expand the source location LOC into a human readable location. If LOC resolves to a builtin location, the file name of the readable - location is set to the string "". */ - -expanded_location -expand_location (source_location loc) + location is set to the string "". If EXPANSION_POINT_P is + TRUE and LOC is virtual, then it is resolved to the expansion + point of the involved macro. Otherwise, it is resolved to the + spelling location of the token. */ + +static expanded_location +expand_location_1 (source_location loc, + bool expansion_point_p) { expanded_location xloc; const struct line_map *map; loc = linemap_resolve_location (line_table, loc, - LRK_SPELLING_LOCATION, &map); + expansion_point_p + ? LRK_MACRO_EXPANSION_POINT + : LRK_SPELLING_LOCATION, &map); xloc = linemap_expand_location (line_table, map, loc); if (loc <= BUILTINS_LOCATION) @@ -109,6 +115,30 @@ location_get_source_line(expanded_location xloc) return buffer; } +/* Expand the source location LOC into a human readable location. If + LOC is virtual, it resolves to the expansion point of the involved + macro. If LOC resolves to a builtin location, the file name of the + readable location is set to the string "". */ + +expanded_location +expand_location (source_location loc) +{ + return expand_location_1 (loc, /*expansion_point_p=*/true); +} + +/* Expand the source location LOC into a human readable location. If + LOC is virtual, it resolves to the expansion location of the + relevant macro. If LOC resolves to a builtin location, the file + name of the readable location is set to the string + "". */ + +expanded_location +expand_location_to_spelling_point (source_location loc) +{ + return expand_location_1 (loc, /*expansion_piont_p=*/false); +} + + #define ONE_K 1024 #define ONE_M (ONE_K * ONE_K) diff --git a/gcc/input.h b/gcc/input.h index 4b15222..f755cdf 100644 --- a/gcc/input.h +++ b/gcc/input.h @@ -39,6 +39,7 @@ extern char builtins_location_check[(BUILTINS_LOCATION extern expanded_location expand_location (source_location); extern const char * location_get_source_line(expanded_location xloc); +extern expanded_location expand_location_to_spelling_point (source_location); /* Historically GCC used location_t, while cpp used source_location. This could be removed but it hardly seems worth the effort. */ @@ -50,6 +51,14 @@ extern location_t input_location; #define LOCATION_LINE(LOC) ((expand_location (LOC)).line) #define LOCATION_COLUMN(LOC)((expand_location (LOC)).column) +#define EXPANSION_POINT_LOCATION_FILE(LOC) \ + ((expand_location_to_expansion_point (LOC)).file) +#define EXPANSION_POINT_LOCATION_LINE(LOC) \ + ((expand_location_to_expansion_point (LOC)).line) +#define EXPANSION_POINT_LOCATION_COLUMN(LOC) \ + ((expand_location_to_expansion_point (LOC)).column) + + #define input_line LOCATION_LINE (input_location) #define input_filename LOCATION_FILE (input_location) #define in_system_header_at(LOC) \