[Ada] Style check for mixed-case identifiers
This patch implements a new switch, -gnatyD, enables a style check that requires defining identifiers to be in mixed case. 2019-07-03 Bob Duff <duff@adacore.com> gcc/ada/ * par-ch3.adb (P_Defining_Identifier): Call Check_Defining_Identifier_Casing. * style.ads, styleg.ads, styleg.adb (Check_Defining_Identifier_Casing): New procedure to check for mixed-case defining identifiers. * stylesw.ads, stylesw.adb (Style_Check_Mixed_Case_Decls): New flag for checking for mixed-case defining identifiers. * doc/gnat_ugn/building_executable_programs_with_gnat.rst: Document new feature. * gnat_ugn.texi: Regenerate. From-SVN: r272972
This commit is contained in:
parent
bf4f18bded
commit
c4487c3be8
|
@ -1,3 +1,16 @@
|
|||
2019-07-03 Bob Duff <duff@adacore.com>
|
||||
|
||||
* par-ch3.adb (P_Defining_Identifier): Call
|
||||
Check_Defining_Identifier_Casing.
|
||||
* style.ads, styleg.ads, styleg.adb
|
||||
(Check_Defining_Identifier_Casing): New procedure to check for
|
||||
mixed-case defining identifiers.
|
||||
* stylesw.ads, stylesw.adb (Style_Check_Mixed_Case_Decls): New
|
||||
flag for checking for mixed-case defining identifiers.
|
||||
* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
|
||||
Document new feature.
|
||||
* gnat_ugn.texi: Regenerate.
|
||||
|
||||
2019-07-03 Eric Botcazou <ebotcazou@adacore.com>
|
||||
|
||||
* doc/gnat_ugn/building_executable_programs_with_gnat.rst
|
||||
|
|
|
@ -4690,6 +4690,16 @@ checks to be performed. The following checks are defined:
|
|||
allowed).
|
||||
|
||||
|
||||
.. index:: -gnatyD (gcc)
|
||||
|
||||
:switch:`-gnatyD`
|
||||
*Check declared identifiers in mixed case.*
|
||||
|
||||
Declared identifiers must be in mixed case, as in
|
||||
This_Is_An_Identifier. Use -gnatyr in addition to ensure
|
||||
that references match declarations.
|
||||
|
||||
|
||||
.. index:: -gnatye (gcc)
|
||||
|
||||
:switch:`-gnatye`
|
||||
|
|
|
@ -13515,6 +13515,20 @@ character (in particular the DOS line terminator sequence CR/LF is not
|
|||
allowed).
|
||||
@end table
|
||||
|
||||
@geindex -gnatyD (gcc)
|
||||
|
||||
|
||||
@table @asis
|
||||
|
||||
@item @code{-gnatyD}
|
||||
|
||||
@emph{Check declared identifiers in mixed case.}
|
||||
|
||||
Declared identifiers must be in mixed case, as in
|
||||
This_Is_An_Identifier. Use -gnatyr in addition to ensure
|
||||
that references match declarations.
|
||||
@end table
|
||||
|
||||
@geindex -gnatye (gcc)
|
||||
|
||||
|
||||
|
|
|
@ -228,8 +228,12 @@ package body Ch3 is
|
|||
raise Error_Resync;
|
||||
end if;
|
||||
|
||||
if Style_Check then
|
||||
Style.Check_Defining_Identifier_Casing;
|
||||
end if;
|
||||
|
||||
Ident_Node := Token_Node;
|
||||
Scan; -- past the reserved identifier
|
||||
Scan; -- past the identifier
|
||||
|
||||
-- If we already have a defining identifier, clean it out and make
|
||||
-- a new clean identifier. This situation arises in some error cases
|
||||
|
|
|
@ -125,6 +125,9 @@ package Style is
|
|||
-- Called with Scan_Ptr pointing to the first minus sign of a comment.
|
||||
-- Intended for checking any specific rules for comment placement/format.
|
||||
|
||||
procedure Check_Defining_Identifier_Casing
|
||||
renames Style_Inst.Check_Defining_Identifier_Casing;
|
||||
|
||||
procedure Check_Dot_Dot
|
||||
renames Style_Inst.Check_Dot_Dot;
|
||||
-- Called after scanning out dot dot to check spacing
|
||||
|
@ -219,4 +222,5 @@ package Style is
|
|||
-- lower case letters. On entry Token_Ptr points to the keyword token.
|
||||
-- This is not used for keywords appearing as attribute designators,
|
||||
-- where instead Check_Attribute_Name (True) is called.
|
||||
|
||||
end Style;
|
||||
|
|
|
@ -610,6 +610,27 @@ package body Styleg is
|
|||
end if;
|
||||
end Check_Comment;
|
||||
|
||||
--------------------------------------
|
||||
-- Check_Defining_Identifier_Casing --
|
||||
--------------------------------------
|
||||
|
||||
procedure Check_Defining_Identifier_Casing is
|
||||
begin
|
||||
if Style_Check_Mixed_Case_Decls then
|
||||
case Determine_Token_Casing is
|
||||
when All_Upper_Case | All_Lower_Case =>
|
||||
Error_Msg_SC -- CODEFIX
|
||||
("(style) bad capitalization, mixed case required");
|
||||
|
||||
-- The Unknown case is something like A_B_C, which is both all
|
||||
-- caps and mixed case.
|
||||
|
||||
when Mixed_Case | Unknown =>
|
||||
null; -- OK
|
||||
end case;
|
||||
end if;
|
||||
end Check_Defining_Identifier_Casing;
|
||||
|
||||
-------------------
|
||||
-- Check_Dot_Dot --
|
||||
-------------------
|
||||
|
|
|
@ -91,6 +91,11 @@ package Styleg is
|
|||
-- Called with Scan_Ptr pointing to the first minus sign of a comment.
|
||||
-- Intended for checking any specific rules for comment placement/format.
|
||||
|
||||
procedure Check_Defining_Identifier_Casing;
|
||||
-- The current token is an identifier that will be a defining
|
||||
-- identifier. Check that it is mixed case, if the appropriate
|
||||
-- switch is set.
|
||||
|
||||
procedure Check_Dot_Dot;
|
||||
-- Called after scanning out dot dot to check spacing
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ package body Stylesw is
|
|||
Style_Check_Boolean_And_Or := False;
|
||||
Style_Check_Comments := False;
|
||||
Style_Check_DOS_Line_Terminator := False;
|
||||
Style_Check_Mixed_Case_Decls := False;
|
||||
Style_Check_End_Labels := False;
|
||||
Style_Check_Form_Feeds := False;
|
||||
Style_Check_Horizontal_Tabs := False;
|
||||
|
@ -168,6 +169,7 @@ package body Stylesw is
|
|||
end if;
|
||||
|
||||
Add ('d', Style_Check_DOS_Line_Terminator);
|
||||
Add ('D', Style_Check_Mixed_Case_Decls);
|
||||
Add ('e', Style_Check_End_Labels);
|
||||
Add ('f', Style_Check_Form_Feeds);
|
||||
Add ('h', Style_Check_Horizontal_Tabs);
|
||||
|
@ -336,6 +338,9 @@ package body Stylesw is
|
|||
when 'd' =>
|
||||
Style_Check_DOS_Line_Terminator := True;
|
||||
|
||||
when 'D' =>
|
||||
Style_Check_Mixed_Case_Decls := True;
|
||||
|
||||
when 'e' =>
|
||||
Style_Check_End_Labels := True;
|
||||
|
||||
|
@ -503,6 +508,9 @@ package body Stylesw is
|
|||
when 'd' =>
|
||||
Style_Check_DOS_Line_Terminator := False;
|
||||
|
||||
when 'D' =>
|
||||
Style_Check_Mixed_Case_Decls := False;
|
||||
|
||||
when 'e' =>
|
||||
Style_Check_End_Labels := False;
|
||||
|
||||
|
|
|
@ -113,6 +113,10 @@ package Stylesw is
|
|||
-- the line terminator must be a single LF, without an associated CR (e.g.
|
||||
-- DOS line terminator sequence CR/LF not allowed).
|
||||
|
||||
Style_Check_Mixed_Case_Decls : Boolean := False;
|
||||
-- This can be set True by using the -gnatyD switch. If it is True, then
|
||||
-- declared identifiers must be in Mixed_Case.
|
||||
|
||||
Style_Check_End_Labels : Boolean := False;
|
||||
-- This can be set True by using the -gnatye switch. If it is True, then
|
||||
-- optional END labels must always be present.
|
||||
|
|
Loading…
Reference in New Issue