* [Ada] Diagnose properly illegal uses of Target_Name
@ 2021-07-08 13:50 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-07-08 13:50 UTC (permalink / raw)
To: gcc-patches; +Cc: Ed Schonberg
[-- Attachment #1: Type: text/plain, Size: 472 bytes --]
Ada_2022 introduces the notion of Target_Name, written @, to be used in
assignment statements, where it denotes the value of the left-hand side
prior to the assignment. This patch diagnoses illegal uses of the target
name outside of its legal context.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_ch5.adb (Analyze_Target_Name): Properly reject a
Target_Name when it appears outside of an assignment statement,
or within the left-hand side of one.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1447 bytes --]
diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -4233,10 +4233,50 @@ package body Sem_Ch5 is
-------------------------
procedure Analyze_Target_Name (N : Node_Id) is
+ procedure Report_Error;
+
+ ------------------
+ -- Report_Error --
+ ------------------
+
+ procedure Report_Error is
+ begin
+ Error_Msg_N
+ ("must appear in the right-hand side of an assignment statement",
+ N);
+ Rewrite (N, New_Occurrence_Of (Any_Id, Sloc (N)));
+ end Report_Error;
+
begin
-- A target name has the type of the left-hand side of the enclosing
-- assignment.
+ -- First, verify that the context is the right-hand side of an
+ -- assignment statement.
+
+ if No (Current_Assignment) then
+ Report_Error;
+ return;
+
+ else
+ declare
+ P : Node_Id := N;
+ begin
+ while Present (P)
+ and then Nkind (Parent (P)) /= N_Assignment_Statement
+ loop
+ P := Parent (P);
+ end loop;
+
+ if No (P)
+ or else P /= Expression (Parent (P))
+ then
+ Report_Error;
+ return;
+ end if;
+ end;
+ end if;
+
Set_Etype (N, Etype (Name (Current_Assignment)));
end Analyze_Target_Name;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-07-08 13:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08 13:50 [Ada] Diagnose properly illegal uses of Target_Name 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).