public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Yannick Moy <moy@adacore.com>
Subject: [Ada] Use spans instead of locations for compiler diagnostics
Date: Wed, 28 Apr 2021 05:41:39 -0400	[thread overview]
Message-ID: <20210428094139.GA139913@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2490 bytes --]

Change the internal data structure that stores the compiler diagnostics
to store spans instead of locations, where a span is a triplet of a main
location, and a first-last pair of locations. Also change the main
procedures for reporting an error in Errout to use spans instead of
locations whenever possible.

As nodes in the AST are associated to a location and not a span, the
span is currently reconstructed when reporting an error on a node, by
retrieving the span covered by the node subtree.

Locations are still used whenever a span cannot be used because the
diagnostic is associated with a location (coming from a token during
parsing in many cases) rather than a node.

There are minimal changes to the compiler output for now, only as a
result of changes to First_Node that now applies to some declarations
and statements and not only expressions. This has a result to change the
location of some diagnostics. The effect of spans is visible when
compiling with debug flag -gnatdF to display spans inline with the
diagnstics in command-line usage, as used in GNATprove.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* errout.adb: (Error_Msg_Internal): Use span instead of
	location.
	(Error_Msg, Error_Msg_NEL): Add versions with span parameter.
	(Error_Msg_F, Error_Msg_FE, Error_Msg_N, Error_Msg_NE,
	Error_Msg_NW): Retrieve span from node.
	(First_Node): Use the new First_And_Last_Nodes.
	(First_And_Last_Nodes): Expand on previous First_Node. Apply to
	other nodes than expressions.
	(First_Sloc): Protect against inconsistent locations.
	(Last_Node): New function based on First_And_Last_Nodes.
	(Last_Sloc): New function similar to First_Sloc.
	(Output_Messages): Update output when -gnatdF is used. Use
	character ~ for making the span visible, similar to what is done
	in GCC and Clang.
	* errout.ads (Error_Msg, Error_Msg_NEL): Add versions with span
	parameter.
	(First_And_Last_Nodes, Last_Node, Last_Sloc): New subprograms.
	* erroutc.adb: Adapt to Sptr field being a span.
	* erroutc.ads (Error_Msg_Object): Change field Sptr from
	location to span.
	* errutil.adb: Adapt to Sptr field being a span.
	* freeze.adb: Use Errout reporting procedures for nodes to get
	spans.
	* par-ch3.adb: Likewise.
	* par-prag.adb: Likewise.
	* par-util.adb: Likewise.
	* sem_case.adb: Likewise.
	* sem_ch13.adb: Likewise.
	* sem_ch3.adb: Likewise.
	* sem_prag.adb: Likewise.
	* types.ads: (Source_Span): New type for spans.
	(To_Span): Basic constructors for spans.

[-- Attachment #2: patch.diff.gz --]
[-- Type: application/gzip, Size: 10335 bytes --]

                 reply	other threads:[~2021-04-28  9:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210428094139.GA139913@adacore.com \
    --to=derodat@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=moy@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).