public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Issue better error message for out-of-order keywords in record def
@ 2022-06-01  8:44 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-06-01  8:44 UTC (permalink / raw)
  To: gcc-patches; +Cc: Yannick Moy

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

Various cases of out-of-order keywords in the definition of a record
were already detected. This adds a similar detection after NULL and
RECORD keywords.

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

gcc/ada/

	* par-ch3.adb (P_Known_Discriminant_Part_Opt): Reword error
	message to benefit from existing codefix.
	(P_Record_Definition): Detect out-of-order keywords in record
	definition and issue appropriate messages. Other cases are
	already caught at appropriate places.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2544 bytes --]

diff --git a/gcc/ada/par-ch3.adb b/gcc/ada/par-ch3.adb
--- a/gcc/ada/par-ch3.adb
+++ b/gcc/ada/par-ch3.adb
@@ -3180,7 +3180,8 @@ package body Ch3 is
                   Scan;
 
                   if Token = Tok_Access then
-                     Error_Msg_SC ("CONSTANT must appear after ACCESS");
+                     Error_Msg_SC -- CODEFIX
+                       ("ACCESS must come before CONSTANT");
                      Set_Discriminant_Type
                        (Specification_Node,
                         P_Access_Definition (Not_Null_Present));
@@ -3462,8 +3463,42 @@ package body Ch3 is
    --  Error recovery: can raise Error_Resync
 
    function P_Record_Definition return Node_Id is
+
+      procedure Catch_Out_Of_Order_Keywords (Keyword : String);
+      --  Catch ouf-of-order keywords in a record definition
+
+      ---------------------------------
+      -- Catch_Out_Of_Order_Keywords --
+      ---------------------------------
+
+      procedure Catch_Out_Of_Order_Keywords (Keyword : String) is
+      begin
+         loop
+            if Token = Tok_Abstract then
+               Error_Msg_SC -- CODEFIX
+                 ("ABSTRACT must come before " & Keyword);
+               Scan; -- past ABSTRACT
+
+            elsif Token = Tok_Tagged then
+               Error_Msg_SC -- CODEFIX
+                 ("TAGGED must come before " & Keyword);
+               Scan; -- past TAGGED
+
+            elsif Token = Tok_Limited then
+               Error_Msg_SC -- CODEFIX
+                 ("LIMITED must come before " & Keyword);
+               Scan; -- past LIMITED
+
+            else
+               exit;
+            end if;
+         end loop;
+      end Catch_Out_Of_Order_Keywords;
+
       Rec_Node : Node_Id;
 
+   --  Start of processing for P_Record_Definition
+
    begin
       Inside_Record_Definition := True;
       Rec_Node := New_Node (N_Record_Definition, Token_Ptr);
@@ -3472,8 +3507,11 @@ package body Ch3 is
 
       if Token = Tok_Null then
          Scan; -- past NULL
+
+         Catch_Out_Of_Order_Keywords ("NULL");
          T_Record;
          Set_Null_Present (Rec_Node, True);
+         Catch_Out_Of_Order_Keywords ("RECORD");
 
       --  Catch incomplete declaration to prevent cascaded errors, see
       --  ACATS B393002 for an example.
@@ -3501,6 +3539,7 @@ package body Ch3 is
          Scopes (Scope.Last).Junk := (Token /= Tok_Record);
 
          T_Record;
+         Catch_Out_Of_Order_Keywords ("RECORD");
 
          Set_Component_List (Rec_Node, P_Component_List);
 



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

only message in thread, other threads:[~2022-06-01  8:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-01  8:44 [Ada] Issue better error message for out-of-order keywords in record def 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).