diff options
Diffstat (limited to 'gcc/ada/par-ch5.adb')
-rw-r--r-- | gcc/ada/par-ch5.adb | 128 |
1 files changed, 89 insertions, 39 deletions
diff --git a/gcc/ada/par-ch5.adb b/gcc/ada/par-ch5.adb index e201d02b29d..e8c6f3d65d6 100644 --- a/gcc/ada/par-ch5.adb +++ b/gcc/ada/par-ch5.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2001, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2003, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -172,6 +172,10 @@ package body Ch5 is procedure Test_Statement_Required; -- Flag error if Statement_Required flag set + ---------------------- + -- Junk_Declaration -- + ---------------------- + procedure Junk_Declaration is begin if (not Declaration_Found) or All_Errors_Mode then @@ -182,6 +186,10 @@ package body Ch5 is Skip_Declaration (Statement_List); end Junk_Declaration; + ----------------------------- + -- Test_Statement_Required -- + ----------------------------- + procedure Test_Statement_Required is begin if Statement_Required then @@ -899,8 +907,9 @@ package body Ch5 is if Nkind (Name_Node) = N_Indexed_Component then declare - Prefix_Node : Node_Id := Prefix (Name_Node); - Exprs_Node : List_Id := Expressions (Name_Node); + Prefix_Node : constant Node_Id := Prefix (Name_Node); + Exprs_Node : constant List_Id := Expressions (Name_Node); + begin Change_Node (Name_Node, N_Procedure_Call_Statement); Set_Name (Name_Node, Prefix_Node); @@ -912,8 +921,9 @@ package body Ch5 is elsif Nkind (Name_Node) = N_Function_Call then declare - Fname_Node : Node_Id := Name (Name_Node); - Params_List : List_Id := Parameter_Associations (Name_Node); + Fname_Node : constant Node_Id := Name (Name_Node); + Params_List : constant List_Id := + Parameter_Associations (Name_Node); begin Change_Node (Name_Node, N_Procedure_Call_Statement); @@ -979,7 +989,7 @@ package body Ch5 is -- LABEL ::= <<label_STATEMENT_IDENTIFIER>> - -- STATEMENT_IDENTIFIER ::= DIRECT_NAME + -- STATEMENT_INDENTIFIER ::= DIRECT_NAME -- The IDENTIFIER of a STATEMENT_IDENTIFIER shall be an identifier -- (not an OPERATOR_SYMBOL) @@ -1246,13 +1256,28 @@ package body Ch5 is -- to reconstruct the tree correctly in this case, but we do at least -- give an accurate error message. - while Token = Tok_Colon_Equal loop - Error_Msg_SC (""":="" should be ""="""); - Scan; -- past junk := - Discard_Junk_Node (P_Expression_No_Right_Paren); - end loop; + if Token = Tok_Colon_Equal then + while Token = Tok_Colon_Equal loop + Error_Msg_SC (""":="" should be ""="""); + Scan; -- past junk := + Discard_Junk_Node (P_Expression_No_Right_Paren); + end loop; + + return Cond; + + -- Otherwise check for redundant parens + + else + if Warn_On_Redundant_Constructs + and then Paren_Count (Cond) > 0 + then + Error_Msg_F ("redundant parentheses?", Cond); + end if; + + -- And return the result - return Cond; + return Cond; + end if; end P_Condition; ------------------------- @@ -1410,7 +1435,8 @@ package body Ch5 is -- Error recovery : cannot raise Error_Resync function P_Loop_Statement (Loop_Name : Node_Id := Empty) return Node_Id is - Loop_Node : Node_Id; + Loop_Node : Node_Id; + Created_Name : Node_Id; begin Push_Scope_Stack; @@ -1423,15 +1449,18 @@ package body Ch5 is TF_Loop; if No (Loop_Name) then + Created_Name := + Make_Identifier (Sloc (Loop_Node), + Chars => Set_Loop_Block_Name ('L')); + Set_Comes_From_Source (Created_Name, False); Set_Has_Created_Identifier (Loop_Node, True); - Set_Identifier (Loop_Node, - Make_Identifier (Sloc (Loop_Node), Set_Loop_Block_Name ('L'))); + Set_Identifier (Loop_Node, Created_Name); + Scope.Table (Scope.Last).Labl := Created_Name; else Set_Identifier (Loop_Node, Loop_Name); end if; Append_Elmt (Loop_Node, Label_List); - Set_Statements (Loop_Node, P_Sequence_Of_Statements (SS_Sreq)); End_Statements (Loop_Node); return Loop_Node; @@ -1453,6 +1482,7 @@ package body Ch5 is Loop_Node : Node_Id; Iter_Scheme_Node : Node_Id; Loop_For_Flag : Boolean; + Created_Name : Node_Id; begin Push_Scope_Stack; @@ -1483,24 +1513,26 @@ package body Ch5 is else Loop_Node := New_Node (N_Loop_Statement, Token_Ptr); - TF_Loop; - Set_Statements (Loop_Node, P_Sequence_Of_Statements (SS_Sreq)); - End_Statements (Loop_Node); - Set_Iteration_Scheme (Loop_Node, Iter_Scheme_Node); if No (Loop_Name) then + Created_Name := + Make_Identifier (Sloc (Loop_Node), + Chars => Set_Loop_Block_Name ('L')); + Set_Comes_From_Source (Created_Name, False); Set_Has_Created_Identifier (Loop_Node, True); - Set_Identifier (Loop_Node, - Make_Identifier (Sloc (Loop_Node), Set_Loop_Block_Name ('L'))); + Set_Identifier (Loop_Node, Created_Name); + Scope.Table (Scope.Last).Labl := Created_Name; else Set_Identifier (Loop_Node, Loop_Name); end if; + TF_Loop; + Set_Statements (Loop_Node, P_Sequence_Of_Statements (SS_Sreq)); + End_Statements (Loop_Node); + Set_Iteration_Scheme (Loop_Node, Iter_Scheme_Node); Append_Elmt (Loop_Node, Label_List); - return Loop_Node; end if; - end P_For_Statement; -- P_While_Statement @@ -1517,6 +1549,7 @@ package body Ch5 is Loop_Node : Node_Id; Iter_Scheme_Node : Node_Id; Loop_While_Flag : Boolean; + Created_Name : Node_Id; begin Push_Scope_Stack; @@ -1547,23 +1580,25 @@ package body Ch5 is else Loop_Node := New_Node (N_Loop_Statement, Token_Ptr); TF_Loop; - Set_Statements (Loop_Node, P_Sequence_Of_Statements (SS_Sreq)); - End_Statements (Loop_Node); - Set_Iteration_Scheme (Loop_Node, Iter_Scheme_Node); if No (Loop_Name) then + Created_Name := + Make_Identifier (Sloc (Loop_Node), + Chars => Set_Loop_Block_Name ('L')); + Set_Comes_From_Source (Created_Name, False); Set_Has_Created_Identifier (Loop_Node, True); - Set_Identifier (Loop_Node, - Make_Identifier (Sloc (Loop_Node), Set_Loop_Block_Name ('L'))); + Set_Identifier (Loop_Node, Created_Name); + Scope.Table (Scope.Last).Labl := Created_Name; else Set_Identifier (Loop_Node, Loop_Name); end if; + Set_Statements (Loop_Node, P_Sequence_Of_Statements (SS_Sreq)); + End_Statements (Loop_Node); + Set_Iteration_Scheme (Loop_Node, Iter_Scheme_Node); Append_Elmt (Loop_Node, Label_List); - return Loop_Node; end if; - end P_While_Statement; --------------------------------------- @@ -1644,7 +1679,8 @@ package body Ch5 is (Block_Name : Node_Id := Empty) return Node_Id is - Block_Node : Node_Id; + Block_Node : Node_Id; + Created_Name : Node_Id; begin Block_Node := New_Node (N_Block_Statement, Token_Ptr); @@ -1659,9 +1695,13 @@ package body Ch5 is Scan; -- past DECLARE if No (Block_Name) then + Created_Name := + Make_Identifier (Sloc (Block_Node), + Chars => Set_Loop_Block_Name ('B')); + Set_Comes_From_Source (Created_Name, False); Set_Has_Created_Identifier (Block_Node, True); - Set_Identifier (Block_Node, - Make_Identifier (Sloc (Block_Node), Set_Loop_Block_Name ('B'))); + Set_Identifier (Block_Node, Created_Name); + Scope.Table (Scope.Last).Labl := Created_Name; else Set_Identifier (Block_Node, Block_Name); end if; @@ -1683,7 +1723,8 @@ package body Ch5 is (Block_Name : Node_Id := Empty) return Node_Id is - Block_Node : Node_Id; + Block_Node : Node_Id; + Created_Name : Node_Id; begin Block_Node := New_Node (N_Block_Statement, Token_Ptr); @@ -1696,9 +1737,13 @@ package body Ch5 is Scope.Table (Scope.Last).Sloc := Token_Ptr; if No (Block_Name) then + Created_Name := + Make_Identifier (Sloc (Block_Node), + Chars => Set_Loop_Block_Name ('B')); + Set_Comes_From_Source (Created_Name, False); Set_Has_Created_Identifier (Block_Node, True); - Set_Identifier (Block_Node, - Make_Identifier (Sloc (Block_Node), Set_Loop_Block_Name ('B'))); + Set_Identifier (Block_Node, Created_Name); + Scope.Table (Scope.Last).Labl := Created_Name; else Set_Identifier (Block_Node, Block_Name); end if; @@ -1740,6 +1785,10 @@ package body Ch5 is -- WHEN token, and returns True if a semicolon is missing before -- the WHEN as in the above example. + ------------------------------- + -- Missing_Semicolon_On_Exit -- + ------------------------------- + function Missing_Semicolon_On_Exit return Boolean is State : Saved_Scan_State; @@ -1781,8 +1830,9 @@ package body Ch5 is Check_No_Exit_Name : for J in reverse 1 .. Scope.Last loop if Scope.Table (J).Etyp = E_Loop then - if Present (Scope.Table (J).Labl) then - + if Present (Scope.Table (J).Labl) + and then Comes_From_Source (Scope.Table (J).Labl) + then -- Innermost loop in fact had a name, style check fails Style.No_Exit_Name (Scope.Table (J).Labl); |