diff options
author | Bob Duff <duff@adacore.com> | 2019-07-03 08:14:38 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2019-07-03 08:14:38 +0000 |
commit | c4487c3be84e0b892aeb61f30435638c6d94a8ab (patch) | |
tree | d92325f60a440a1745affa95115da988cb79db44 | |
parent | bf4f18bded58c7710276877ea8648b12ac3088be (diff) | |
download | gcc-c4487c3be84e0b892aeb61f30435638c6d94a8ab.zip gcc-c4487c3be84e0b892aeb61f30435638c6d94a8ab.tar.gz gcc-c4487c3be84e0b892aeb61f30435638c6d94a8ab.tar.bz2 |
[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
-rw-r--r-- | gcc/ada/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst | 10 | ||||
-rw-r--r-- | gcc/ada/gnat_ugn.texi | 14 | ||||
-rw-r--r-- | gcc/ada/par-ch3.adb | 6 | ||||
-rw-r--r-- | gcc/ada/style.ads | 4 | ||||
-rw-r--r-- | gcc/ada/styleg.adb | 21 | ||||
-rw-r--r-- | gcc/ada/styleg.ads | 5 | ||||
-rw-r--r-- | gcc/ada/stylesw.adb | 8 | ||||
-rw-r--r-- | gcc/ada/stylesw.ads | 4 |
9 files changed, 84 insertions, 1 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 6a4fcfd..750100e 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -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 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 9af50cc..57c3fe1 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 752c2ac..7371a76 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 75c17c3..aff14ed 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 b1684a7..0e75389 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 56526d8..fc2364b 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 d93121f..f176c02 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 549f826..929e2d7 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 d82fcb1..de1f92d 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. |