1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2024, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This version of the Style package implements the standard GNAT style
27 -- checking rules. For documentation of these rules, see comments on the
28 -- individual procedures.
30 with Atree
; use Atree
;
31 with Casing
; use Casing
;
32 with Csets
; use Csets
;
33 with Err_Vars
; use Err_Vars
;
36 with Scans
; use Scans
;
37 with Sinfo
; use Sinfo
;
38 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
39 with Sinput
; use Sinput
;
40 with Stylesw
; use Stylesw
;
41 with Uintp
; use Uintp
;
43 package body Styleg
is
47 Blank_Lines
: Nat
:= 0;
48 -- Counts number of empty lines seen. Reset to zero if a non-empty line
49 -- is encountered. Used to check for trailing blank lines in Check_EOF,
50 -- and for multiple blank lines.
52 Blank_Line_Location
: Source_Ptr
;
53 -- Remembers location of first blank line in a series. Used to issue an
54 -- appropriate diagnostic if subsequent blank lines or the end of file
57 -----------------------
58 -- Local Subprograms --
59 -----------------------
61 procedure Check_No_Space_After
;
62 -- Checks that there is a non-white space character after the current
63 -- token, or white space followed by a comment, or the end of line.
64 -- Issue error message if not.
66 procedure Check_No_Space_Before
;
67 -- Check that token is first token on line, or else is not preceded
68 -- by white space. Signal error of space not allowed if not.
70 procedure Check_Separate_Stmt_Lines_Cont
;
71 -- Non-inlined continuation of Check_Separate_Stmt_Lines
73 function Determine_Token_Casing
return Casing_Type
;
74 -- Determine casing of current token
76 procedure Error_Space_Not_Allowed
(S
: Source_Ptr
);
77 -- Posts an error message indicating that a space is not allowed
78 -- at the given source location.
80 procedure Error_Space_Required
(S
: Source_Ptr
);
81 -- Posts an error message indicating that a space is required at
82 -- the given source location.
84 function Is_White_Space
(C
: Character) return Boolean;
85 pragma Inline
(Is_White_Space
);
86 -- Returns True for space or HT, False otherwise
88 procedure Require_Following_Space
;
89 pragma Inline
(Require_Following_Space
);
90 -- Require token to be followed by white space. Used only if in GNAT
91 -- style checking mode.
93 procedure Require_Preceding_Space
;
94 pragma Inline
(Require_Preceding_Space
);
95 -- Require token to be preceded by white space. Used only if in GNAT
96 -- style checking mode.
98 ----------------------
99 -- Check_Abs_Or_Not --
100 ----------------------
102 -- In check token mode (-gnatyt), ABS/NOT must be followed by a space or
105 procedure Check_Abs_Not
is
107 if Style_Check_Tokens
then
108 if Source
(Scan_Ptr
) not in ' ' | ASCII
.CR | ASCII
.LF
then
109 Error_Space_Required
(Scan_Ptr
);
114 ----------------------
115 -- Check_Apostrophe --
116 ----------------------
118 -- Do not allow space after apostrophe
120 procedure Check_Apostrophe
is
122 if Style_Check_Tokens
then
123 Check_No_Space_After
;
125 end Check_Apostrophe
;
131 -- In check tokens mode (-gnatys), arrow must be surrounded by spaces,
132 -- except that within the argument of a Depends or Refined_Depends aspect
133 -- or pragma the required format is "=>+ " rather than "=> +").
135 procedure Check_Arrow
(Inside_Depends
: Boolean := False) is
137 if Style_Check_Tokens
then
138 Require_Preceding_Space
;
140 -- Special handling for Depends and Refined_Depends
142 if Inside_Depends
then
143 if Source
(Scan_Ptr
) = ' '
144 and then Source
(Scan_Ptr
+ 1) = '+'
146 Error_Space_Not_Allowed
(Scan_Ptr
);
148 elsif Source
(Scan_Ptr
) /= ' '
149 and then Source
(Scan_Ptr
) /= '+'
151 Require_Following_Space
;
157 Require_Following_Space
;
162 --------------------------
163 -- Check_Attribute_Name --
164 --------------------------
166 -- In check attribute casing mode (-gnatya), attribute names must be
167 -- mixed case, i.e. start with an upper case letter, and otherwise
168 -- lower case, except after an underline character.
170 procedure Check_Attribute_Name
(Reserved
: Boolean) is
171 pragma Warnings
(Off
, Reserved
);
173 if Style_Check_Attribute_Casing
then
174 if Determine_Token_Casing
/= Mixed_Case
then
175 Error_Msg_SC
-- CODEFIX
176 ("(style) bad capitalization, mixed case required?a?");
179 end Check_Attribute_Name
;
181 ---------------------------
182 -- Check_Binary_Operator --
183 ---------------------------
185 -- In check token mode (-gnatyt), binary operators other than the special
186 -- case of exponentiation require surrounding space characters.
188 procedure Check_Binary_Operator
is
190 if Style_Check_Tokens
then
191 Require_Preceding_Space
;
192 Require_Following_Space
;
194 end Check_Binary_Operator
;
200 -- In check token mode (-gnatyt), box must be preceded by a space or by
201 -- a left parenthesis. Spacing checking on the surrounding tokens takes
202 -- care of the remaining checks.
204 procedure Check_Box
is
206 if Style_Check_Tokens
then
207 if Prev_Token
/= Tok_Left_Paren
then
208 Require_Preceding_Space
;
217 -- In check token mode (-gnatyt), colon must be surrounded by spaces
219 procedure Check_Colon
is
221 if Style_Check_Tokens
then
222 Require_Preceding_Space
;
223 Require_Following_Space
;
227 -----------------------
228 -- Check_Colon_Equal --
229 -----------------------
231 -- In check token mode (-gnatyt), := must be surrounded by spaces
233 procedure Check_Colon_Equal
is
235 if Style_Check_Tokens
then
236 Require_Preceding_Space
;
237 Require_Following_Space
;
239 end Check_Colon_Equal
;
245 -- In check token mode (-gnatyt), comma must be either the first
246 -- token on a line, or be preceded by a non-blank character.
247 -- It must also always be followed by a blank.
249 procedure Check_Comma
is
251 if Style_Check_Tokens
then
252 Check_No_Space_Before
;
254 if Source
(Scan_Ptr
) > ' ' then
255 Error_Space_Required
(Scan_Ptr
);
264 -- In check comment mode (-gnatyc) there are several requirements on the
265 -- format of comments. The following are permissible comment formats:
267 -- 1. Any comment that is not at the start of a line, i.e. where the
268 -- initial minuses are not the first non-blank characters on the
269 -- line must have at least one blank after the second minus or a
270 -- special character as defined in rule 5.
272 -- 2. A row of all minuses of any length is permitted (see procedure
273 -- box above in the source of this routine).
275 -- 3. A comment line starting with two minuses and a space, and ending
276 -- with a space and two minuses. Again see the procedure title box
277 -- immediately above in the source.
279 -- 4. A full line comment where two spaces follow the two minus signs.
280 -- This is the normal comment format in GNAT style, as typified by
281 -- the comments you are reading now.
283 -- 5. A full line comment where the first character after the second
284 -- minus is a special character, i.e. a character in the ASCII
285 -- range 16#21#..16#2F# or 16#3A#..16#3F#. This allows special
286 -- comments, such as those generated by gnatprep, or those that
287 -- appear in the SPARK annotation language to be accepted.
289 -- Note: for GNAT internal files (-gnatg switch set on for the
290 -- compilation), the only special sequence recognized and allowed
291 -- is --! as generated by gnatprep.
293 -- 6. In addition, the comment must be properly indented if comment
294 -- indentation checking is active (Style_Check_Indentation non-zero).
295 -- Either the start column must be a multiple of this indentation,
296 -- or the indentation must match that of the next non-blank line,
297 -- or must match the indentation of the immediately preciding line
298 -- if it is non-blank.
300 procedure Check_Comment
is
304 function Is_Box_Comment
return Boolean;
305 -- Returns True if the last two characters on the line are -- which
306 -- characterizes a box comment (as for example follows this spec).
308 function Is_Special_Character
(C
: Character) return Boolean;
309 -- Determines if C is a special character (see rule 5 above)
311 function Same_Column_As_Next_Non_Blank_Line
return Boolean;
312 -- Called for a full line comment. If the indentation of this comment
313 -- matches that of the next non-blank line in the source, then True is
314 -- returned, otherwise False.
316 function Same_Column_As_Previous_Line
return Boolean;
317 -- Called for a full line comment. If the previous line is blank, then
318 -- returns False. Otherwise, if the indentation of this comment matches
319 -- that of the previous line in the source, then True is returned,
326 function Is_Box_Comment
return Boolean is
330 -- Do we need to worry about UTF_32 line terminators here ???
333 while Source
(S
) not in Line_Terminator
loop
337 return Source
(S
- 1) = '-' and then Source
(S
- 2) = '-';
340 --------------------------
341 -- Is_Special_Character --
342 --------------------------
344 function Is_Special_Character
(C
: Character) return Boolean is
350 Character'Pos (C
) in 16#
21#
.. 16#
2F#
352 Character'Pos (C
) in 16#
3A#
.. 16#
3F#
;
354 end Is_Special_Character
;
356 ----------------------------------------
357 -- Same_Column_As_Next_Non_Blank_Line --
358 ----------------------------------------
360 function Same_Column_As_Next_Non_Blank_Line
return Boolean is
364 -- Step to end of line
367 while Source
(P
) not in Line_Terminator
loop
371 -- Step past blanks, and line terminators (UTF_32 case???)
373 while Source
(P
) <= ' ' and then Source
(P
) /= EOF
loop
379 return Get_Column_Number
(Scan_Ptr
) = Get_Column_Number
(P
);
380 end Same_Column_As_Next_Non_Blank_Line
;
382 ----------------------------------
383 -- Same_Column_As_Previous_Line --
384 ----------------------------------
386 function Same_Column_As_Previous_Line
return Boolean is
390 -- Point S to start of this line, and P to start of previous line
392 S
:= Line_Start
(Scan_Ptr
);
396 -- Step P to first non-blank character on line
399 -- If we get back to start of current line, then the previous line
400 -- was blank, and we always return False in that situation.
406 exit when Source
(P
) /= ' ' and then Source
(P
) /= ASCII
.HT
;
412 return Get_Column_Number
(Scan_Ptr
) = Get_Column_Number
(P
);
413 end Same_Column_As_Previous_Line
;
415 -- Start of processing for Check_Comment
418 -- Can never have a non-blank character preceding the first minus.
419 -- The "+ 3" is to leave room for a possible byte order mark (BOM);
420 -- we want to avoid a warning for a comment at the start of the
421 -- file just after the BOM.
423 if Style_Check_Comments
then
424 if Scan_Ptr
> Source_First
(Current_Source_File
) + 3
425 and then Source
(Scan_Ptr
- 1) > ' '
427 Error_Msg_S
-- CODEFIX
428 ("(style) space required?c?");
432 -- For a comment that is not at the start of the line, the only
433 -- requirement is that we cannot have a non-blank character after
434 -- the second minus sign or a special character.
436 if Scan_Ptr
/= First_Non_Blank_Location
then
437 if Style_Check_Comments
then
438 if Source
(Scan_Ptr
+ 2) > ' '
439 and then not Is_Special_Character
(Source
(Scan_Ptr
+ 2))
442 ("(style) space required?c?", Scan_Ptr
+ 2);
448 -- Case of a comment that is at the start of a line
451 -- First check, must be in appropriately indented column
453 if Style_Check_Indentation
/= 0 then
454 if Start_Column
rem Style_Check_Indentation
/= 0 then
455 if not Same_Column_As_Next_Non_Blank_Line
456 and then not Same_Column_As_Previous_Line
458 Error_Msg_S
-- CODEFIX
459 ("(style) bad column?0?");
466 -- If we are not checking comments, nothing more to do
468 if not Style_Check_Comments
then
472 -- Case of not followed by a blank. Usually wrong, but there are
473 -- some exceptions that we permit.
475 if Source
(Scan_Ptr
+ 2) /= ' ' then
476 C
:= Source
(Scan_Ptr
+ 2);
478 -- Case of -- all on its own on a line is OK
484 -- Case of --x, x special character is OK (gnatprep/SPARK/etc.)
485 -- This is not permitted in internal GNAT implementation units
486 -- except for the case of --! as used by gnatprep output.
488 if Is_Special_Character
(C
) then
492 -- The only other case in which we allow a character after
493 -- the -- other than a space is when we have a row of minus
494 -- signs (case of header lines for a box comment for example).
497 while Source
(S
) >= ' ' loop
498 if Source
(S
) /= '-' then
500 or else Style_Check_Comments_Spacing
= 1
502 Error_Space_Required
(Scan_Ptr
+ 2);
505 ("(style) two spaces required?c?", Scan_Ptr
+ 2);
514 -- If we are followed by a blank, then the comment is OK if the
515 -- character following this blank is another blank or a format
516 -- effector, or if the required comment spacing is 1.
518 elsif Source
(Scan_Ptr
+ 3) <= ' '
519 or else Style_Check_Comments_Spacing
= 1
523 -- Here is the case where we only have one blank after the two minus
524 -- signs, with Style_Check_Comments_Spacing set to 2, which is an
525 -- error unless the line ends with two minus signs, the case of a
528 elsif not Is_Box_Comment
then
529 Error_Space_Required
(Scan_Ptr
+ 3);
534 --------------------------------------
535 -- Check_Defining_Identifier_Casing --
536 --------------------------------------
538 procedure Check_Defining_Identifier_Casing
is
540 if Style_Check_Mixed_Case_Decls
then
541 case Determine_Token_Casing
is
545 Error_Msg_SC
-- CODEFIX
546 ("(style) bad capitalization, mixed case required?D?");
548 -- The Unknown case is something like A_B_C, which is both all
549 -- caps and mixed case.
557 end Check_Defining_Identifier_Casing
;
563 -- In check token mode (-gnatyt), ".." must be surrounded by spaces
565 procedure Check_Dot_Dot
is
567 if Style_Check_Tokens
then
568 Require_Preceding_Space
;
569 Require_Following_Space
;
577 -- In check blanks at end mode, check no blank lines precede the EOF
579 procedure Check_EOF
is
581 if Style_Check_Blank_Lines
then
583 -- We expect one blank line, from the EOF, but no more than one
585 if Blank_Lines
= 2 then
587 ("(style) blank line not allowed at end of file?u?",
588 Blank_Line_Location
);
590 elsif Blank_Lines
>= 3 then
592 ("(style) blank lines not allowed at end of file?u?",
593 Blank_Line_Location
);
598 -----------------------------------
599 -- Check_Exponentiation_Operator --
600 -----------------------------------
602 -- No spaces are required for the ** operator in GNAT style check mode
604 procedure Check_Exponentiation_Operator
is
607 end Check_Exponentiation_Operator
;
613 -- In check horizontal tab mode (-gnatyh), tab characters are not allowed
615 procedure Check_HT
is
617 if Style_Check_Horizontal_Tabs
then
618 Error_Msg_S
-- CODEFIX
619 ("(style) horizontal tab not allowed?h?");
623 -----------------------
624 -- Check_Indentation --
625 -----------------------
627 -- In check indentation mode (-gnaty? for ? a digit), a new statement or
628 -- declaration is required to start in a column that is a multiple of the
629 -- indentation amount.
631 procedure Check_Indentation
is
633 if Style_Check_Indentation
/= 0 then
634 if Token_Ptr
= First_Non_Blank_Location
635 and then Start_Column
rem Style_Check_Indentation
/= 0
637 Error_Msg_SC
-- CODEFIX
638 ("(style) bad indentation?0?");
641 end Check_Indentation
;
643 -------------------------------------
644 -- Check_Left_Paren_Square_Bracket --
645 -------------------------------------
647 -- In check token mode (-gnatyt), left paren must not be preceded by an
648 -- identifier character or digit (a separating space is required) and may
649 -- never be followed by a space.
650 -- Same applies for the left square bracket starting from Ada version 2022.
652 procedure Check_Left_Paren_Square_Bracket
is
654 if Style_Check_Tokens
then
655 if Token_Ptr
> Source_First
(Current_Source_File
)
656 and then Identifier_Char
(Source
(Token_Ptr
- 1))
658 Error_Space_Required
(Token_Ptr
);
661 Check_No_Space_After
;
663 end Check_Left_Paren_Square_Bracket
;
665 ---------------------------
666 -- Check_Line_Max_Length --
667 ---------------------------
669 -- In check max line length mode (-gnatym), the line length must
670 -- not exceed the permitted maximum value.
672 procedure Check_Line_Max_Length
(Len
: Nat
) is
674 if Style_Check_Max_Line_Length
then
675 if Len
> Style_Max_Line_Length
then
676 Error_Msg_Uint_1
:= UI_From_Int
(Len
);
678 ("(style) this line is too long: ^?M?",
679 Current_Line_Start
+ Source_Ptr
(Style_Max_Line_Length
));
682 end Check_Line_Max_Length
;
684 ---------------------------
685 -- Check_Line_Terminator --
686 ---------------------------
688 -- In check blanks at end mode (-gnatyb), lines may not end with a
691 -- In check form feeds mode (-gnatyf), the line terminator may not
692 -- be either of the characters FF or VT.
694 -- In check DOS line terminators node (-gnatyd), the line terminator
695 -- must be a single LF, without a following CR.
697 procedure Check_Line_Terminator
(Len
: Nat
) is
701 -- Length of line (adjusted down for blanks at end of line)
704 -- Reset count of blank lines if first line
706 if Get_Logical_Line_Number
(Scan_Ptr
) = 1 then
710 -- Check FF/VT terminators
712 if Style_Check_Form_Feeds
then
713 if Source
(Scan_Ptr
) = ASCII
.FF
then
714 Error_Msg_S
-- CODEFIX
715 ("(style) form feed not allowed?f?");
716 elsif Source
(Scan_Ptr
) = ASCII
.VT
then
717 Error_Msg_S
-- CODEFIX
718 ("(style) vertical tab not allowed?f?");
722 -- Check DOS line terminator
724 if Style_Check_DOS_Line_Terminator
then
726 -- Ignore EOF, since we only get called with an EOF if it is the last
727 -- character in the buffer (and was therefore not in the source
728 -- file), since the terminating EOF is added to stop the scan.
730 if Source
(Scan_Ptr
) = EOF
then
733 -- Bad terminator if we don't have an LF
735 elsif Source
(Scan_Ptr
) /= LF
then
736 Error_Msg_S
("(style) incorrect line terminator?d?");
740 -- Remove trailing spaces
743 while L
> 0 and then Is_White_Space
(Source
(S
- 1)) loop
748 -- Issue message for blanks at end of line if option enabled
750 if Style_Check_Blanks_At_End
and then L
< Len
then
752 ("(style) trailing spaces not permitted?b?", S
);
755 -- Deal with empty (blank) line
759 -- Increment blank line count
761 Blank_Lines
:= Blank_Lines
+ 1;
763 -- If first blank line, record location for later error message
765 if Blank_Lines
= 1 then
766 Blank_Line_Location
:= Scan_Ptr
;
769 -- Non-blank line, check for previous multiple blank lines
772 if Style_Check_Blank_Lines
and then Blank_Lines
> 1 then
774 ("(style) multiple blank lines?u?", Blank_Line_Location
);
777 -- And reset blank line count
781 end Check_Line_Terminator
;
787 -- In check tokens mode, only one space between NOT and IN
789 procedure Check_Not_In
is
791 if Style_Check_Tokens
then
792 if Source
(Token_Ptr
- 1) /= ' '
793 or else Token_Ptr
- Prev_Token_Ptr
/= 4
796 ("(style) single space must separate NOT and IN?t?",
802 --------------------------
803 -- Check_No_Space_After --
804 --------------------------
806 procedure Check_No_Space_After
is
810 if Is_White_Space
(Source
(Scan_Ptr
)) then
812 -- Allow one or more spaces if followed by comment
816 if Source
(S
) = '-' and then Source
(S
+ 1) = '-' then
819 elsif Is_White_Space
(Source
(S
)) then
827 Error_Space_Not_Allowed
(Scan_Ptr
);
829 end Check_No_Space_After
;
831 ---------------------------
832 -- Check_No_Space_Before --
833 ---------------------------
835 procedure Check_No_Space_Before
is
837 if Token_Ptr
> First_Non_Blank_Location
838 and then Source
(Token_Ptr
- 1) <= ' '
840 Error_Space_Not_Allowed
(Token_Ptr
- 1);
842 end Check_No_Space_Before
;
844 -----------------------
845 -- Check_Pragma_Name --
846 -----------------------
848 -- In check pragma casing mode (-gnatyp), pragma names must be mixed
849 -- case, i.e. start with an upper case letter, and otherwise lower case,
850 -- except after an underline character.
852 procedure Check_Pragma_Name
is
854 if Style_Check_Pragma_Casing
then
855 if Determine_Token_Casing
/= Mixed_Case
then
856 Error_Msg_SC
-- CODEFIX
857 ("(style) bad capitalization, mixed case required?p?");
860 end Check_Pragma_Name
;
862 -----------------------
863 -- Check_Right_Paren --
864 -----------------------
866 -- In check token mode (-gnatyt), right paren must not be immediately
867 -- followed by an identifier character, and must never be preceded by
868 -- a space unless it is the initial non-blank character on the line.
870 procedure Check_Right_Paren
is
872 if Style_Check_Tokens
then
873 if Identifier_Char
(Source
(Token_Ptr
+ 1)) then
874 Error_Space_Required
(Token_Ptr
+ 1);
877 Check_No_Space_Before
;
879 end Check_Right_Paren
;
881 ---------------------
882 -- Check_Semicolon --
883 ---------------------
885 -- In check token mode (-gnatyt), semicolon does not permit a preceding
886 -- space and a following space is required.
888 procedure Check_Semicolon
is
890 if Style_Check_Tokens
then
891 Check_No_Space_Before
;
893 if Source
(Scan_Ptr
) > ' ' then
894 Error_Space_Required
(Scan_Ptr
);
899 -------------------------------
900 -- Check_Separate_Stmt_Lines --
901 -------------------------------
903 procedure Check_Separate_Stmt_Lines
is
905 if Style_Check_Separate_Stmt_Lines
then
906 Check_Separate_Stmt_Lines_Cont
;
908 end Check_Separate_Stmt_Lines
;
910 ------------------------------------
911 -- Check_Separate_Stmt_Lines_Cont --
912 ------------------------------------
914 procedure Check_Separate_Stmt_Lines_Cont
is
918 -- Skip past white space
921 while Is_White_Space
(Source
(S
)) loop
925 -- Line terminator is OK
927 if Source
(S
) in Line_Terminator
then
932 elsif Source
(S
) = '-' and then Source
(S
+ 1) = '-' then
935 -- ABORT keyword is OK after THEN (THEN ABORT case)
937 elsif Token
= Tok_Then
938 and then (Source
(S
+ 0) = 'a' or else Source
(S
+ 0) = 'A')
939 and then (Source
(S
+ 1) = 'b' or else Source
(S
+ 1) = 'B')
940 and then (Source
(S
+ 2) = 'o' or else Source
(S
+ 2) = 'O')
941 and then (Source
(S
+ 3) = 'r' or else Source
(S
+ 3) = 'R')
942 and then (Source
(S
+ 4) = 't' or else Source
(S
+ 4) = 'T')
943 and then (Source
(S
+ 5) in Line_Terminator
944 or else Is_White_Space
(Source
(S
+ 5)))
948 -- PRAGMA keyword is OK after ELSE
950 elsif Token
= Tok_Else
951 and then (Source
(S
+ 0) = 'p' or else Source
(S
+ 0) = 'P')
952 and then (Source
(S
+ 1) = 'r' or else Source
(S
+ 1) = 'R')
953 and then (Source
(S
+ 2) = 'a' or else Source
(S
+ 2) = 'A')
954 and then (Source
(S
+ 3) = 'g' or else Source
(S
+ 3) = 'G')
955 and then (Source
(S
+ 4) = 'm' or else Source
(S
+ 4) = 'M')
956 and then (Source
(S
+ 5) = 'a' or else Source
(S
+ 5) = 'A')
957 and then (Source
(S
+ 6) in Line_Terminator
958 or else Is_White_Space
(Source
(S
+ 6)))
962 -- Otherwise we have the style violation we are looking for
965 if Token
= Tok_Then
then
967 ("(style) no statements may follow THEN on same line?S?", S
);
970 ("(style) no statements may follow ELSE on same line?S?", S
);
973 end Check_Separate_Stmt_Lines_Cont
;
979 -- In check if then layout mode (-gnatyi), we expect a THEN keyword to
980 -- appear either on the same line as the IF, or on a separate line if
981 -- the IF statement extends for more than one line.
983 procedure Check_Then
(If_Loc
: Source_Ptr
) is
985 if Style_Check_If_Then_Layout
then
987 If_Line
: constant Physical_Line_Number
:=
988 Get_Physical_Line_Number
(If_Loc
);
989 Then_Line
: constant Physical_Line_Number
:=
990 Get_Physical_Line_Number
(Token_Ptr
);
992 if If_Line
= Then_Line
then
994 elsif Token_Ptr
/= First_Non_Blank_Location
then
995 Error_Msg_SC
("(style) misplaced THEN?i?");
1001 -------------------------------
1002 -- Check_Unary_Plus_Or_Minus --
1003 -------------------------------
1005 -- In check token mode (-gnatyt), unary plus or minus must not be
1006 -- followed by a space.
1008 -- Annoying exception: if we have the sequence =>+ within a Depends or
1009 -- Refined_Depends pragma or aspect, then we insist on a space rather
1010 -- than forbidding it.
1012 procedure Check_Unary_Plus_Or_Minus
(Inside_Depends
: Boolean := False) is
1014 if Style_Check_Tokens
then
1015 if Inside_Depends
then
1016 Require_Following_Space
;
1018 Check_No_Space_After
;
1021 end Check_Unary_Plus_Or_Minus
;
1023 ------------------------
1024 -- Check_Vertical_Bar --
1025 ------------------------
1027 -- In check token mode (-gnatyt), vertical bar must be surrounded by spaces
1029 procedure Check_Vertical_Bar
is
1031 if Style_Check_Tokens
then
1032 Require_Preceding_Space
;
1033 Require_Following_Space
;
1035 end Check_Vertical_Bar
;
1037 -----------------------
1038 -- Check_Xtra_Parens --
1039 -----------------------
1041 procedure Check_Xtra_Parens
(N
: Node_Id
) is
1043 if Style_Check_Xtra_Parens
1046 (if Nkind
(N
) in N_Case_Expression
1047 | N_Expression_With_Actions
1049 | N_Quantified_Expression
1050 | N_Raise_Expression
1054 Error_Msg
-- CODEFIX
1055 ("(style) redundant parentheses?x?", Errout
.First_Sloc
(N
));
1057 end Check_Xtra_Parens
;
1059 ----------------------------
1060 -- Determine_Token_Casing --
1061 ----------------------------
1063 function Determine_Token_Casing
return Casing_Type
is
1065 return Determine_Casing
(Source
(Token_Ptr
.. Scan_Ptr
- 1));
1066 end Determine_Token_Casing
;
1068 -----------------------------
1069 -- Error_Space_Not_Allowed --
1070 -----------------------------
1072 procedure Error_Space_Not_Allowed
(S
: Source_Ptr
) is
1074 Error_Msg
-- CODEFIX
1075 ("(style) space not allowed?t?", S
);
1076 end Error_Space_Not_Allowed
;
1078 --------------------------
1079 -- Error_Space_Required --
1080 --------------------------
1082 procedure Error_Space_Required
(S
: Source_Ptr
) is
1084 Error_Msg
-- CODEFIX
1085 ("(style) space required?t?", S
);
1086 end Error_Space_Required
;
1088 --------------------
1089 -- Is_White_Space --
1090 --------------------
1092 function Is_White_Space
(C
: Character) return Boolean is
1094 return C
= ' ' or else C
= HT
;
1101 function Mode_In_Check
return Boolean is
1103 return Style_Check
and Style_Check_Mode_In
;
1110 -- In check end/exit labels mode (-gnatye), always require the name of
1111 -- a subprogram or package to be present on the END, so this is an error.
1113 procedure No_End_Name
(Name
: Node_Id
) is
1115 if Style_Check_End_Labels
then
1116 Error_Msg_Node_1
:= Name
;
1117 Error_Msg_SP
-- CODEFIX
1118 ("(style) `END &` required?e?");
1126 -- In check end/exit labels mode (-gnatye), always require the name of
1127 -- the loop to be present on the EXIT when exiting a named loop.
1129 procedure No_Exit_Name
(Name
: Node_Id
) is
1131 if Style_Check_End_Labels
then
1132 Error_Msg_Node_1
:= Name
;
1133 Error_Msg_SP
-- CODEFIX
1134 ("(style) `EXIT &` required?e?");
1138 ----------------------------
1139 -- Non_Lower_Case_Keyword --
1140 ----------------------------
1142 -- In check casing mode (-gnatyk), reserved keywords must be spelled
1143 -- in all lower case (excluding keywords range, access, delta and digits
1144 -- used as attribute designators).
1146 procedure Non_Lower_Case_Keyword
is
1148 if Style_Check_Keyword_Casing
then
1149 Error_Msg_SC
-- CODEFIX
1150 ("(style) reserved words must be all lower case?k?");
1152 end Non_Lower_Case_Keyword
;
1154 -----------------------------
1155 -- Require_Following_Space --
1156 -----------------------------
1158 procedure Require_Following_Space
is
1160 if Source
(Scan_Ptr
) > ' ' then
1161 Error_Space_Required
(Scan_Ptr
);
1163 end Require_Following_Space
;
1165 -----------------------------
1166 -- Require_Preceding_Space --
1167 -----------------------------
1169 procedure Require_Preceding_Space
is
1171 if Token_Ptr
> Source_First
(Current_Source_File
)
1172 and then Source
(Token_Ptr
- 1) > ' '
1174 Error_Space_Required
(Token_Ptr
);
1176 end Require_Preceding_Space
;