From c4487c3be84e0b892aeb61f30435638c6d94a8ab Mon Sep 17 00:00:00 2001 From: Bob Duff Date: Wed, 3 Jul 2019 08:14:38 +0000 Subject: [PATCH] [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 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 --- gcc/ada/ChangeLog | 13 ++++++++++++ ...building_executable_programs_with_gnat.rst | 10 +++++++++ gcc/ada/gnat_ugn.texi | 14 +++++++++++++ gcc/ada/par-ch3.adb | 6 +++++- gcc/ada/style.ads | 4 ++++ gcc/ada/styleg.adb | 21 +++++++++++++++++++ gcc/ada/styleg.ads | 5 +++++ gcc/ada/stylesw.adb | 8 +++++++ gcc/ada/stylesw.ads | 4 ++++ 9 files changed, 84 insertions(+), 1 deletion(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 6a4fcfd9249..750100e9062 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,16 @@ +2019-07-03 Bob Duff + + * 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 * doc/gnat_ugn/building_executable_programs_with_gnat.rst diff --git a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst index 9af50cc7b8d..57c3fe1573b 100644 --- a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst +++ b/gcc/ada/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` diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi index 752c2acbfee..7371a76ae31 100644 --- a/gcc/ada/gnat_ugn.texi +++ b/gcc/ada/gnat_ugn.texi @@ -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) diff --git a/gcc/ada/par-ch3.adb b/gcc/ada/par-ch3.adb index 75c17c38afd..aff14ed18b5 100644 --- a/gcc/ada/par-ch3.adb +++ b/gcc/ada/par-ch3.adb @@ -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 diff --git a/gcc/ada/style.ads b/gcc/ada/style.ads index b1684a71b03..0e75389e367 100644 --- a/gcc/ada/style.ads +++ b/gcc/ada/style.ads @@ -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; diff --git a/gcc/ada/styleg.adb b/gcc/ada/styleg.adb index 56526d83f20..fc2364b43f3 100644 --- a/gcc/ada/styleg.adb +++ b/gcc/ada/styleg.adb @@ -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 -- ------------------- diff --git a/gcc/ada/styleg.ads b/gcc/ada/styleg.ads index d93121f2923..f176c0282a1 100644 --- a/gcc/ada/styleg.ads +++ b/gcc/ada/styleg.ads @@ -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 diff --git a/gcc/ada/stylesw.adb b/gcc/ada/stylesw.adb index 549f826c61e..929e2d7d9bd 100644 --- a/gcc/ada/stylesw.adb +++ b/gcc/ada/stylesw.adb @@ -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; diff --git a/gcc/ada/stylesw.ads b/gcc/ada/stylesw.ads index d82fcb119ef..de1f92d1255 100644 --- a/gcc/ada/stylesw.ads +++ b/gcc/ada/stylesw.ads @@ -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. -- 2.30.2