public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Use spans instead of locations for compiler diagnostics
@ 2021-04-28  9:41 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-04-28  9:41 UTC (permalink / raw)
  To: gcc-patches; +Cc: Yannick Moy

[-- 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 --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-28  9:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-28  9:41 [Ada] Use spans instead of locations for compiler diagnostics Pierre-Marie de Rodat

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).