diff options
author | Yannick Moy <moy@adacore.com> | 2022-04-27 09:52:55 +0200 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2022-06-01 08:43:16 +0000 |
commit | 94e416d23b8cb2824d395230f23fac300ee6d496 (patch) | |
tree | 046aa4f552274cafbee7da98167ac98b6b0fe9f5 /gcc | |
parent | 73514ab714d651795c10e0790217a67eb6b41b48 (diff) | |
download | gcc-94e416d23b8cb2824d395230f23fac300ee6d496.zip gcc-94e416d23b8cb2824d395230f23fac300ee6d496.tar.gz gcc-94e416d23b8cb2824d395230f23fac300ee6d496.tar.bz2 |
[Ada] Issue better error message for out-of-order keywords in record def
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.
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/par-ch3.adb | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/gcc/ada/par-ch3.adb b/gcc/ada/par-ch3.adb index 2359b8c..557a9cb 100644 --- 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); |