In -gnatg mode, gnat complains "bad indentation" if a statement or
declaration does not start in a column divisible by 3. This patch fixes
a bug in which it complained similarly about a declare_expression, which
is not a statement or declaration.
Tested on x86_64-pc-linux-gnu, committed on trunk
2020-06-17 Bob Duff <d...@adacore.com>
gcc/ada/
* par.adb (P_Basic_Declarative_Items): Update comment about
Declare_Expression.
* par-ch3.adb (P_Declarative_Items): Pass in Declare_Expression
flag, and if True, skip the call to Style.Check_Indentation.
* par-ch4.adb (P_Declare_Expression): Fix incorrect comment.
--- gcc/ada/par-ch3.adb
+++ gcc/ada/par-ch3.adb
@@ -78,18 +78,24 @@ package body Ch3 is
-- it very unlikely that this will ever arise in practice.
procedure P_Declarative_Items
- (Decls : List_Id;
- Done : out Boolean;
- In_Spec : Boolean);
+ (Decls : List_Id;
+ Done : out Boolean;
+ Declare_Expression : Boolean;
+ In_Spec : Boolean);
-- Scans out a single declarative item, or, in the case of a declaration
-- with a list of identifiers, a list of declarations, one for each of the
-- identifiers in the list. The declaration or declarations scanned are
-- appended to the given list. Done indicates whether or not there may be
-- additional declarative items to scan. If Done is True, then a decision
-- has been made that there are no more items to scan. If Done is False,
- -- then there may be additional declarations to scan. In_Spec is true if
- -- we are scanning a package declaration, and is used to generate an
- -- appropriate message if a statement is encountered in such a context.
+ -- then there may be additional declarations to scan.
+ --
+ -- Declare_Expression is true if we are parsing a declare_expression, in
+ -- which case we want to suppress certain style checking.
+ --
+ -- In_Spec is true if we are scanning a package declaration, and is used to
+ -- generate an appropriate message if a statement is encountered in such a
+ -- context.
procedure P_Identifier_Declarations
(Decls : List_Id;
@@ -4310,7 +4316,8 @@ package body Ch3 is
-- Loop to scan out the declarations
loop
- P_Declarative_Items (Decls, Done, In_Spec => False);
+ P_Declarative_Items
+ (Decls, Done, Declare_Expression => False, In_Spec => False);
exit when Done;
end loop;
@@ -4337,16 +4344,20 @@ package body Ch3 is
-- then the scan is set past the next semicolon and Error is returned.
procedure P_Declarative_Items
- (Decls : List_Id;
- Done : out Boolean;
- In_Spec : Boolean)
+ (Decls : List_Id;
+ Done : out Boolean;
+ Declare_Expression : Boolean;
+ In_Spec : Boolean)
is
Scan_State : Saved_Scan_State;
begin
Done := False;
- if Style_Check then
+ -- In -gnatg mode, we don't want a "bad indentation" error inside a
+ -- declare_expression.
+
+ if Style_Check and not Declare_Expression then
Style.Check_Indentation;
end if;
@@ -4727,7 +4738,8 @@ package body Ch3 is
Decls := New_List;
loop
- P_Declarative_Items (Decls, Done, In_Spec => True);
+ P_Declarative_Items
+ (Decls, Done, Declare_Expression, In_Spec => True);
exit when Done;
end loop;
@@ -4827,7 +4839,8 @@ package body Ch3 is
Dummy_Done : Boolean;
pragma Warnings (Off, Dummy_Done);
begin
- P_Declarative_Items (S, Dummy_Done, False);
+ P_Declarative_Items
+ (S, Dummy_Done, Declare_Expression => False, In_Spec => False);
end Skip_Declaration;
-----------------------------------------
--- gcc/ada/par-ch4.adb
+++ gcc/ada/par-ch4.adb
@@ -3587,7 +3587,7 @@ package body Ch4 is
function P_Declare_Expression return Node_Id is
Loc : constant Source_Ptr := Token_Ptr;
begin
- Scan; -- past IF
+ Scan; -- past DECLARE
declare
Actions : constant List_Id := P_Basic_Declarative_Items
--- gcc/ada/par.adb
+++ gcc/ada/par.adb
@@ -699,7 +699,8 @@ function Par (Configuration_Pragmas : Boolean) return List_Id is
-- private part (in which case Declare_Expression is False), and
-- the declare_items of a declare_expression (in which case
-- Declare_Expression is True). Declare_Expression is used to
- -- affect the wording of error messages.
+ -- affect the wording of error messages, and to control style
+ -- checking.
function P_Access_Definition
(Null_Exclusion_Present : Boolean) return Node_Id;