From: Bob Duff Date: Thu, 2 Jul 2020 22:16:57 +0000 (-0400) Subject: [Ada] Ada2020: matching parentheses and brackets X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8c8b92dcc8f0b45af96aecc9e83c52175d6f4ce5;p=gcc.git [Ada] Ada2020: matching parentheses and brackets gcc/ada/ * par-ch4.adb (P_Aggregate_Or_Paren_Expr): Require matching parens or brackets. * par.adb, par-tchk.adb (T_Right_Bracket): New procedure to give an error on missing ]. --- diff --git a/gcc/ada/par-ch4.adb b/gcc/ada/par-ch4.adb index cc5ed032bbb..649c88ec283 100644 --- a/gcc/ada/par-ch4.adb +++ b/gcc/ada/par-ch4.adb @@ -1391,6 +1391,9 @@ package body Ch4 is return Maybe; end Is_Quantified_Expression; + Start_Token : constant Token_Type := Token; + -- Used to prevent mismatches (...] and [...) + -- Start of processing for P_Aggregate_Or_Paren_Expr begin @@ -1697,23 +1700,26 @@ package body Ch4 is end if; end loop; - -- All component associations (positional and named) have been scanned + -- All component associations (positional and named) have been scanned. + -- Scan ] or ) based on Start_Token. - if Token = Tok_Right_Bracket and then Ada_Version >= Ada_2020 then - Set_Component_Associations (Aggregate_Node, Assoc_List); - Set_Is_Homogeneous_Aggregate (Aggregate_Node); - Scan; -- past right bracket + case Start_Token is + when Tok_Left_Bracket => + Set_Component_Associations (Aggregate_Node, Assoc_List); + Set_Is_Homogeneous_Aggregate (Aggregate_Node); + T_Right_Bracket; - if Token = Tok_Apostrophe then - Scan; + if Token = Tok_Apostrophe then + Scan; - if Token = Tok_Identifier then - return P_Reduction_Attribute_Reference (Aggregate_Node); + if Token = Tok_Identifier then + return P_Reduction_Attribute_Reference (Aggregate_Node); + end if; end if; - end if; - else - T_Right_Paren; - end if; + when Tok_Left_Paren => + T_Right_Paren; + when others => raise Program_Error; + end case; if Nkind (Aggregate_Node) /= N_Delta_Aggregate then Set_Expressions (Aggregate_Node, Expr_List); diff --git a/gcc/ada/par-tchk.adb b/gcc/ada/par-tchk.adb index 8eb705eeb45..65ff45aa0e6 100644 --- a/gcc/ada/par-tchk.adb +++ b/gcc/ada/par-tchk.adb @@ -402,6 +402,20 @@ package body Tchk is Check_Token (Tok_Record, AP); end T_Record; + --------------------- + -- T_Right_Bracket -- + --------------------- + + procedure T_Right_Bracket is + begin + if Token = Tok_Right_Bracket then + Scan; + else + Error_Msg_AP -- CODEFIX + ("|missing ""']'"""); + end if; + end T_Right_Bracket; + ------------------- -- T_Right_Paren -- ------------------- diff --git a/gcc/ada/par.adb b/gcc/ada/par.adb index 1dee1e7dfae..69da69d07be 100644 --- a/gcc/ada/par.adb +++ b/gcc/ada/par.adb @@ -1212,6 +1212,7 @@ function Par (Configuration_Pragmas : Boolean) return List_Id is procedure T_Private; procedure T_Range; procedure T_Record; + procedure T_Right_Bracket; procedure T_Right_Paren; procedure T_Semicolon; procedure T_Then;