1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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 Einfo
; use Einfo
;
34 with Err_Vars
; use Err_Vars
;
36 with Scans
; use Scans
;
37 with Sinfo
; use Sinfo
;
38 with Sinput
; use Sinput
;
39 with Stylesw
; use Stylesw
;
41 package body Styleg
is
45 Blank_Lines
: Nat
:= 0;
46 -- Counts number of empty lines seen. Reset to zero if a non-empty line
47 -- is encountered. Used to check for trailing blank lines in Check_EOF,
48 -- and for multiple blank lines.
50 Blank_Line_Location
: Source_Ptr
;
51 -- Remembers location of first blank line in a series. Used to issue an
52 -- appropriate diagnostic if subsequent blank lines or the end of file
55 -----------------------
56 -- Local Subprograms --
57 -----------------------
59 procedure Check_No_Space_After
;
60 -- Checks that there is a non-white space character after the current
61 -- token, or white space followed by a comment, or the end of line.
62 -- Issue error message if not.
64 procedure Check_No_Space_Before
;
65 -- Check that token is first token on line, or else is not preceded
66 -- by white space. Signal error of space not allowed if not.
68 procedure Check_Separate_Stmt_Lines_Cont
;
69 -- Non-inlined continuation of Check_Separate_Stmt_Lines
71 function Determine_Token_Casing
return Casing_Type
;
72 -- Determine casing of current token
74 procedure Error_Space_Not_Allowed
(S
: Source_Ptr
);
75 -- Posts an error message indicating that a space is not allowed
76 -- at the given source location.
78 procedure Error_Space_Required
(S
: Source_Ptr
);
79 -- Posts an error message indicating that a space is required at
80 -- the given source location.
82 function Is_White_Space
(C
: Character) return Boolean;
83 pragma Inline
(Is_White_Space
);
84 -- Returns True for space, HT, VT or FF, False otherwise
86 procedure Require_Following_Space
;
87 pragma Inline
(Require_Following_Space
);
88 -- Require token to be followed by white space. Used only if in GNAT
89 -- style checking mode.
91 procedure Require_Preceding_Space
;
92 pragma Inline
(Require_Preceding_Space
);
93 -- Require token to be preceded by white space. Used only if in GNAT
94 -- style checking mode.
96 ----------------------
97 -- Check_Abs_Or_Not --
98 ----------------------
100 -- In check tokens mode (-gnatyt), ABS/NOT must be followed by a space
102 procedure Check_Abs_Not
is
104 if Style_Check_Tokens
then
105 if Source
(Scan_Ptr
) > ' ' then
106 Error_Space_Required
(Scan_Ptr
);
111 ----------------------
112 -- Check_Apostrophe --
113 ----------------------
115 -- Do not allow space before or after apostrophe
117 procedure Check_Apostrophe
is
119 if Style_Check_Tokens
then
120 Check_No_Space_After
;
122 end Check_Apostrophe
;
128 -- In check tokens mode (-gnatys), arrow must be surrounded by spaces
130 procedure Check_Arrow
is
132 if Style_Check_Tokens
then
133 Require_Preceding_Space
;
134 Require_Following_Space
;
138 --------------------------
139 -- Check_Attribute_Name --
140 --------------------------
142 -- In check attribute casing mode (-gnatya), attribute names must be
143 -- mixed case, i.e. start with an upper case letter, and otherwise
144 -- lower case, except after an underline character.
146 procedure Check_Attribute_Name
(Reserved
: Boolean) is
147 pragma Warnings
(Off
, Reserved
);
149 if Style_Check_Attribute_Casing
then
150 if Determine_Token_Casing
/= Mixed_Case
then
151 Error_Msg_SC
-- CODEFIX
152 ("(style) bad capitalization, mixed case required");
155 end Check_Attribute_Name
;
157 ---------------------------
158 -- Check_Binary_Operator --
159 ---------------------------
161 -- In check token mode (-gnatyt), binary operators other than the special
162 -- case of exponentiation require surrounding space characters.
164 procedure Check_Binary_Operator
is
166 if Style_Check_Tokens
then
167 Require_Preceding_Space
;
168 Require_Following_Space
;
170 end Check_Binary_Operator
;
172 ----------------------------
173 -- Check_Boolean_Operator --
174 ----------------------------
176 procedure Check_Boolean_Operator
(Node
: Node_Id
) is
178 function OK_Boolean_Operand
(N
: Node_Id
) return Boolean;
179 -- Returns True for simple variable, or "not X1" or "X1 and X2" or
180 -- "X1 or X2" where X1, X2 are recursively OK_Boolean_Operand's.
182 ------------------------
183 -- OK_Boolean_Operand --
184 ------------------------
186 function OK_Boolean_Operand
(N
: Node_Id
) return Boolean is
188 if Nkind_In
(N
, N_Identifier
, N_Expanded_Name
) then
191 elsif Nkind
(N
) = N_Op_Not
then
192 return OK_Boolean_Operand
(Original_Node
(Right_Opnd
(N
)));
194 elsif Nkind_In
(N
, N_Op_And
, N_Op_Or
) then
195 return OK_Boolean_Operand
(Original_Node
(Left_Opnd
(N
)))
197 OK_Boolean_Operand
(Original_Node
(Right_Opnd
(N
)));
202 end OK_Boolean_Operand
;
204 -- Start of processig for Check_Boolean_Operator
206 if Style_Check_Boolean_And_Or
207 and then Comes_From_Source
(Node
)
210 Orig
: constant Node_Id
:= Original_Node
(Node
);
213 if Nkind_In
(Orig
, N_Op_And
, N_Op_Or
) then
215 L
: constant Node_Id
:= Original_Node
(Left_Opnd
(Orig
));
216 R
: constant Node_Id
:= Original_Node
(Right_Opnd
(Orig
));
219 -- First OK case, simple boolean constants/identifiers
221 if OK_Boolean_Operand
(L
)
223 OK_Boolean_Operand
(R
)
227 -- Second OK case, modular types
229 elsif Is_Modular_Integer_Type
(Etype
(Node
)) then
232 -- Third OK case, array types
234 elsif Is_Array_Type
(Etype
(Node
)) then
237 -- Otherwise we have an error
239 elsif Nkind
(Orig
) = N_Op_And
then
240 Error_Msg
("(style) `AND THEN` required", Sloc
(Orig
));
242 Error_Msg
("(style) `OR ELSE` required", Sloc
(Orig
));
248 end Check_Boolean_Operator
;
254 -- In check token mode (-gnatyt), box must be preceded by a space or by
255 -- a left parenthesis. Spacing checking on the surrounding tokens takes
256 -- care of the remaining checks.
258 procedure Check_Box
is
260 if Style_Check_Tokens
then
261 if Prev_Token
/= Tok_Left_Paren
then
262 Require_Preceding_Space
;
271 -- In check token mode (-gnatyt), colon must be surrounded by spaces
273 procedure Check_Colon
is
275 if Style_Check_Tokens
then
276 Require_Preceding_Space
;
277 Require_Following_Space
;
281 -----------------------
282 -- Check_Colon_Equal --
283 -----------------------
285 -- In check token mode (-gnatyt), := must be surrounded by spaces
287 procedure Check_Colon_Equal
is
289 if Style_Check_Tokens
then
290 Require_Preceding_Space
;
291 Require_Following_Space
;
293 end Check_Colon_Equal
;
299 -- In check token mode (-gnatyt), comma must be either the first
300 -- token on a line, or be preceded by a non-blank character.
301 -- It must also always be followed by a blank.
303 procedure Check_Comma
is
305 if Style_Check_Tokens
then
306 Check_No_Space_Before
;
308 if Source
(Scan_Ptr
) > ' ' then
309 Error_Space_Required
(Scan_Ptr
);
318 -- In check comment mode (-gnatyc) there are several requirements on the
319 -- format of comments. The following are permissible comment formats:
321 -- 1. Any comment that is not at the start of a line, i.e. where the
322 -- initial minuses are not the first non-blank characters on the
323 -- line must have at least one blank after the second minus or a
324 -- special character as defined in rule 5.
326 -- 2. A row of all minuses of any length is permitted (see procedure
327 -- box above in the source of this routine).
329 -- 3. A comment line starting with two minuses and a space, and ending
330 -- with a space and two minuses. Again see the procedure title box
331 -- immediately above in the source.
333 -- 4. A full line comment where two spaces follow the two minus signs.
334 -- This is the normal comment format in GNAT style, as typified by
335 -- the comments you are reading now.
337 -- 5. A full line comment where the first character after the second
338 -- minus is a special character, i.e. a character in the ASCII
339 -- range 16#21#..16#2F# or 16#3A#..16#3F#. This allows special
340 -- comments, such as those generated by gnatprep, or those that
341 -- appear in the SPARK annotation language to be accepted.
343 -- Note: for GNAT internal files (-gnatg switch set on for the
344 -- compilation), the only special sequence recognized and allowed
345 -- is --! as generated by gnatprep.
347 -- 6. In addition, the comment must be properly indented if comment
348 -- indentation checking is active (Style_Check_Indentation non-zero).
349 -- Either the start column must be a multiple of this indentation,
350 -- or the indentation must match that of the next non-blank line.
352 procedure Check_Comment
is
356 function Is_Box_Comment
return Boolean;
357 -- Returns True if the last two characters on the line are -- which
358 -- characterizes a box comment (as for example follows this spec).
360 function Is_Special_Character
(C
: Character) return Boolean;
361 -- Determines if C is a special character (see rule 5 above)
363 function Same_Column_As_Next_Non_Blank_Line
return Boolean;
364 -- Called for a full line comment. If the indentation of this comment
365 -- matches that of the next non-blank line in the source, then True is
366 -- returned, otherwise False.
372 function Is_Box_Comment
return Boolean is
376 -- Do we need to worry about UTF_32 line terminators here ???
379 while Source
(S
) not in Line_Terminator
loop
383 return Source
(S
- 1) = '-' and then Source
(S
- 2) = '-';
386 --------------------------
387 -- Is_Special_Character --
388 --------------------------
390 function Is_Special_Character
(C
: Character) return Boolean is
396 Character'Pos (C
) in 16#
21#
.. 16#
2F#
398 Character'Pos (C
) in 16#
3A#
.. 16#
3F#
;
400 end Is_Special_Character
;
402 ----------------------------------------
403 -- Same_Column_As_Next_Non_Blank_Line --
404 ----------------------------------------
406 function Same_Column_As_Next_Non_Blank_Line
return Boolean is
410 -- Step to end of line
413 while Source
(P
) not in Line_Terminator
loop
417 -- Step past blanks, and line terminators (UTF_32 case???)
419 while Source
(P
) <= ' ' and then Source
(P
) /= EOF
loop
425 return Get_Column_Number
(Scan_Ptr
) = Get_Column_Number
(P
);
426 end Same_Column_As_Next_Non_Blank_Line
;
428 -- Start of processing for Check_Comment
431 -- Can never have a non-blank character preceding the first minus
433 if Style_Check_Comments
then
434 if Scan_Ptr
> Source_First
(Current_Source_File
)
435 and then Source
(Scan_Ptr
- 1) > ' '
437 Error_Msg_S
("(style) space required");
441 -- For a comment that is not at the start of the line, the only
442 -- requirement is that we cannot have a non-blank character after
443 -- the second minus sign or a special character.
445 if Scan_Ptr
/= First_Non_Blank_Location
then
446 if Style_Check_Comments
then
447 if Source
(Scan_Ptr
+ 2) > ' '
448 and then not Is_Special_Character
(Source
(Scan_Ptr
+ 2))
450 Error_Msg
("(style) space required", Scan_Ptr
+ 2);
456 -- Case of a comment that is at the start of a line
459 -- First check, must be in appropriately indented column
461 if Style_Check_Indentation
/= 0 then
462 if Start_Column
rem Style_Check_Indentation
/= 0 then
463 if not Same_Column_As_Next_Non_Blank_Line
then
464 Error_Msg_S
-- CODEFIX
465 ("(style) bad column");
472 -- If we are not checking comments, nothing more to do
474 if not Style_Check_Comments
then
478 -- Case of not followed by a blank. Usually wrong, but there are
479 -- some exceptions that we permit.
481 if Source
(Scan_Ptr
+ 2) /= ' ' then
482 C
:= Source
(Scan_Ptr
+ 2);
484 -- Case of -- all on its own on a line is OK
490 -- Case of --x, x special character is OK (gnatprep/SPARK/etc.)
491 -- This is not permitted in internal GNAT implementation units
492 -- except for the case of --! as used by gnatprep output.
494 if Is_Special_Character
(C
) then
498 -- The only other case in which we allow a character after
499 -- the -- other than a space is when we have a row of minus
500 -- signs (case of header lines for a box comment for example).
503 while Source
(S
) >= ' ' loop
504 if Source
(S
) /= '-' then
505 if Is_Box_Comment
then
506 Error_Space_Required
(Scan_Ptr
+ 2);
508 Error_Msg
("(style) two spaces required", Scan_Ptr
+ 2);
517 -- If we are followed by a blank, then the comment is OK if the
518 -- character following this blank is another blank or a format
521 elsif Source
(Scan_Ptr
+ 3) <= ' ' then
524 -- Here is the case where we only have one blank after the two
525 -- minus signs, which is an error unless the line ends with two
526 -- minus signs, the case of a box comment.
528 elsif not Is_Box_Comment
then
529 Error_Space_Required
(Scan_Ptr
+ 3);
538 -- In check token mode (-gnatyt), colon must be surrounded by spaces
540 procedure Check_Dot_Dot
is
542 if Style_Check_Tokens
then
543 Require_Preceding_Space
;
544 Require_Following_Space
;
552 -- In check blanks at end mode, check no blank lines precede the EOF
554 procedure Check_EOF
is
556 if Style_Check_Blank_Lines
then
558 -- We expect one blank line, from the EOF, but no more than one
560 if Blank_Lines
= 2 then
562 ("(style) blank line not allowed at end of file",
563 Blank_Line_Location
);
565 elsif Blank_Lines
>= 3 then
567 ("(style) blank lines not allowed at end of file",
568 Blank_Line_Location
);
573 -----------------------------------
574 -- Check_Exponentiation_Operator --
575 -----------------------------------
577 -- No spaces are required for the ** operator in GNAT style check mode
579 procedure Check_Exponentiation_Operator
is
582 end Check_Exponentiation_Operator
;
588 -- In check horizontal tab mode (-gnatyh), tab characters are not allowed
590 procedure Check_HT
is
592 if Style_Check_Horizontal_Tabs
then
593 Error_Msg_S
("(style) horizontal tab not allowed");
597 -----------------------
598 -- Check_Indentation --
599 -----------------------
601 -- In check indentation mode (-gnatyn for n a digit), a new statement or
602 -- declaration is required to start in a column that is a multiple of the
603 -- indentation amount.
605 procedure Check_Indentation
is
607 if Style_Check_Indentation
/= 0 then
608 if Token_Ptr
= First_Non_Blank_Location
609 and then Start_Column
rem Style_Check_Indentation
/= 0
611 Error_Msg_SC
("(style) bad indentation");
614 end Check_Indentation
;
616 ----------------------
617 -- Check_Left_Paren --
618 ----------------------
620 -- In tone check mode (-gnatyt), left paren must not be preceded by an
621 -- identifier character or digit (a separating space is required) and
622 -- may never be followed by a space.
624 procedure Check_Left_Paren
is
626 if Style_Check_Tokens
then
627 if Token_Ptr
> Source_First
(Current_Source_File
)
628 and then Identifier_Char
(Source
(Token_Ptr
- 1))
630 Error_Space_Required
(Token_Ptr
);
633 Check_No_Space_After
;
635 end Check_Left_Paren
;
637 ---------------------------
638 -- Check_Line_Max_Length --
639 ---------------------------
641 -- In check max line length mode (-gnatym), the line length must
642 -- not exceed the permitted maximum value.
644 procedure Check_Line_Max_Length
(Len
: Int
) is
646 if Style_Check_Max_Line_Length
then
647 if Len
> Style_Max_Line_Length
then
649 ("(style) this line is too long",
650 Current_Line_Start
+ Source_Ptr
(Style_Max_Line_Length
));
653 end Check_Line_Max_Length
;
655 ---------------------------
656 -- Check_Line_Terminator --
657 ---------------------------
659 -- In check blanks at end mode (-gnatyb), lines may not end with a
662 -- In check form feeds mode (-gnatyf), the line terminator may not
663 -- be either of the characters FF or VT.
665 -- In check DOS line terminators node (-gnatyd), the line terminator
666 -- must be a single LF, without a following CR.
668 procedure Check_Line_Terminator
(Len
: Int
) is
672 -- Length of line (adjusted down for blanks at end of line)
675 -- Reset count of blank lines if first line
677 if Get_Logical_Line_Number
(Scan_Ptr
) = 1 then
681 -- Check FF/VT terminators
683 if Style_Check_Form_Feeds
then
684 if Source
(Scan_Ptr
) = ASCII
.FF
then
685 Error_Msg_S
("(style) form feed not allowed");
686 elsif Source
(Scan_Ptr
) = ASCII
.VT
then
687 Error_Msg_S
("(style) vertical tab not allowed");
691 -- Check DOS line terminator
693 if Style_Check_DOS_Line_Terminator
then
695 -- Ignore EOF, since we only get called with an EOF if it is the last
696 -- character in the buffer (and was therefore not in the source file),
697 -- since the terminating EOF is added to stop the scan.
699 if Source
(Scan_Ptr
) = EOF
then
702 -- Bad terminator if we don't have an LF
704 elsif Source
(Scan_Ptr
) /= LF
then
705 Error_Msg_S
("(style) incorrect line terminator");
709 -- Remove trailing spaces
712 while L
> 0 and then Is_White_Space
(Source
(S
- 1)) loop
717 -- Issue message for blanks at end of line if option enabled
719 if Style_Check_Blanks_At_End
and then L
< Len
then
721 ("(style) trailing spaces not permitted", S
);
724 -- Deal with empty (blank) line
728 -- Increment blank line count
730 Blank_Lines
:= Blank_Lines
+ 1;
732 -- If first blank line, record location for later error message
734 if Blank_Lines
= 1 then
735 Blank_Line_Location
:= Scan_Ptr
;
738 -- Non-blank line, check for previous multiple blank lines
741 if Style_Check_Blank_Lines
and then Blank_Lines
> 1 then
743 ("(style) multiple blank lines", Blank_Line_Location
);
746 -- And reset blank line count
750 end Check_Line_Terminator
;
752 --------------------------
753 -- Check_No_Space_After --
754 --------------------------
756 procedure Check_No_Space_After
is
760 if Is_White_Space
(Source
(Scan_Ptr
)) then
762 -- Allow one or more spaces if followed by comment
766 if Source
(S
) = '-' and then Source
(S
+ 1) = '-' then
769 elsif Is_White_Space
(Source
(S
)) then
777 Error_Space_Not_Allowed
(Scan_Ptr
);
779 end Check_No_Space_After
;
781 ---------------------------
782 -- Check_No_Space_Before --
783 ---------------------------
785 procedure Check_No_Space_Before
is
787 if Token_Ptr
> First_Non_Blank_Location
788 and then Source
(Token_Ptr
- 1) <= ' '
790 Error_Space_Not_Allowed
(Token_Ptr
- 1);
792 end Check_No_Space_Before
;
794 -----------------------
795 -- Check_Pragma_Name --
796 -----------------------
798 -- In check pragma casing mode (-gnatyp), pragma names must be mixed
799 -- case, i.e. start with an upper case letter, and otherwise lower case,
800 -- except after an underline character.
802 procedure Check_Pragma_Name
is
804 if Style_Check_Pragma_Casing
then
805 if Determine_Token_Casing
/= Mixed_Case
then
806 Error_Msg_SC
-- CODEFIX
807 ("(style) bad capitalization, mixed case required");
810 end Check_Pragma_Name
;
812 -----------------------
813 -- Check_Right_Paren --
814 -----------------------
816 -- In check tokens mode (-gnatyt), right paren must not be immediately
817 -- followed by an identifier character, and must never be preceded by
818 -- a space unless it is the initial non-blank character on the line.
820 procedure Check_Right_Paren
is
822 if Style_Check_Tokens
then
823 if Identifier_Char
(Source
(Token_Ptr
+ 1)) then
824 Error_Space_Required
(Token_Ptr
+ 1);
827 Check_No_Space_Before
;
829 end Check_Right_Paren
;
831 ---------------------
832 -- Check_Semicolon --
833 ---------------------
835 -- In check tokens mode (-gnatyt), semicolon does not permit a preceding
836 -- space and a following space is required.
838 procedure Check_Semicolon
is
840 if Style_Check_Tokens
then
841 Check_No_Space_Before
;
843 if Source
(Scan_Ptr
) > ' ' then
844 Error_Space_Required
(Scan_Ptr
);
849 -------------------------------
850 -- Check_Separate_Stmt_Lines --
851 -------------------------------
853 procedure Check_Separate_Stmt_Lines
is
855 if Style_Check_Separate_Stmt_Lines
then
856 Check_Separate_Stmt_Lines_Cont
;
858 end Check_Separate_Stmt_Lines
;
860 ------------------------------------
861 -- Check_Separate_Stmt_Lines_Cont --
862 ------------------------------------
864 procedure Check_Separate_Stmt_Lines_Cont
is
868 -- Skip past white space
871 while Is_White_Space
(Source
(S
)) loop
875 -- Line terminator is OK
877 if Source
(S
) in Line_Terminator
then
882 elsif Source
(S
) = '-' and then Source
(S
+ 1) = '-' then
885 -- ABORT keyword is OK after THEN (THEN ABORT case)
887 elsif Token
= Tok_Then
888 and then (Source
(S
+ 0) = 'a' or else Source
(S
+ 0) = 'A')
889 and then (Source
(S
+ 1) = 'b' or else Source
(S
+ 1) = 'B')
890 and then (Source
(S
+ 2) = 'o' or else Source
(S
+ 2) = 'O')
891 and then (Source
(S
+ 3) = 'r' or else Source
(S
+ 3) = 'R')
892 and then (Source
(S
+ 4) = 't' or else Source
(S
+ 4) = 'T')
893 and then (Source
(S
+ 5) in Line_Terminator
894 or else Is_White_Space
(Source
(S
+ 5)))
898 -- PRAGMA keyword is OK after ELSE
900 elsif Token
= Tok_Else
901 and then (Source
(S
+ 0) = 'p' or else Source
(S
+ 0) = 'P')
902 and then (Source
(S
+ 1) = 'r' or else Source
(S
+ 1) = 'R')
903 and then (Source
(S
+ 2) = 'a' or else Source
(S
+ 2) = 'A')
904 and then (Source
(S
+ 3) = 'g' or else Source
(S
+ 3) = 'G')
905 and then (Source
(S
+ 4) = 'm' or else Source
(S
+ 4) = 'M')
906 and then (Source
(S
+ 5) = 'a' or else Source
(S
+ 5) = 'A')
907 and then (Source
(S
+ 6) in Line_Terminator
908 or else Is_White_Space
(Source
(S
+ 6)))
912 -- Otherwise we have the style violation we are looking for
915 if Token
= Tok_Then
then
917 ("(style) no statements may follow THEN on same line", S
);
920 ("(style) no statements may follow ELSE on same line", S
);
923 end Check_Separate_Stmt_Lines_Cont
;
929 -- In check if then layout mode (-gnatyi), we expect a THEN keyword
930 -- to appear either on the same line as the IF, or on a separate line
931 -- after multiple conditions. In any case, it may not appear on the
932 -- line immediately following the line with the IF.
934 procedure Check_Then
(If_Loc
: Source_Ptr
) is
936 if Style_Check_If_Then_Layout
then
937 if Get_Physical_Line_Number
(Token_Ptr
) =
938 Get_Physical_Line_Number
(If_Loc
) + 1
940 Error_Msg_SC
("(style) misplaced THEN");
945 -------------------------------
946 -- Check_Unary_Plus_Or_Minus --
947 -------------------------------
949 -- In check token mode (-gnatyt), unary plus or minus must not be
950 -- followed by a space.
952 procedure Check_Unary_Plus_Or_Minus
is
954 if Style_Check_Tokens
then
955 Check_No_Space_After
;
957 end Check_Unary_Plus_Or_Minus
;
959 ------------------------
960 -- Check_Vertical_Bar --
961 ------------------------
963 -- In check token mode (-gnatyt), vertical bar must be surrounded by spaces
965 procedure Check_Vertical_Bar
is
967 if Style_Check_Tokens
then
968 Require_Preceding_Space
;
969 Require_Following_Space
;
971 end Check_Vertical_Bar
;
973 -----------------------
974 -- Check_Xtra_Parens --
975 -----------------------
977 procedure Check_Xtra_Parens
(Loc
: Source_Ptr
) is
979 if Style_Check_Xtra_Parens
then
980 Error_Msg
("redundant parentheses?", Loc
);
982 end Check_Xtra_Parens
;
984 ----------------------------
985 -- Determine_Token_Casing --
986 ----------------------------
988 function Determine_Token_Casing
return Casing_Type
is
990 return Determine_Casing
(Source
(Token_Ptr
.. Scan_Ptr
- 1));
991 end Determine_Token_Casing
;
993 -----------------------------
994 -- Error_Space_Not_Allowed --
995 -----------------------------
997 procedure Error_Space_Not_Allowed
(S
: Source_Ptr
) is
999 Error_Msg
("(style) space not allowed", S
);
1000 end Error_Space_Not_Allowed
;
1002 --------------------------
1003 -- Error_Space_Required --
1004 --------------------------
1006 procedure Error_Space_Required
(S
: Source_Ptr
) is
1008 Error_Msg
("(style) space required", S
);
1009 end Error_Space_Required
;
1011 --------------------
1012 -- Is_White_Space --
1013 --------------------
1015 function Is_White_Space
(C
: Character) return Boolean is
1017 return C
= ' ' or else C
= HT
;
1024 function Mode_In_Check
return Boolean is
1026 return Style_Check
and Style_Check_Mode_In
;
1033 -- In check end/exit labels mode (-gnatye), always require the name of
1034 -- a subprogram or package to be present on the END, so this is an error.
1036 procedure No_End_Name
(Name
: Node_Id
) is
1038 if Style_Check_End_Labels
then
1039 Error_Msg_Node_1
:= Name
;
1040 Error_Msg_SP
("(style) `END &` required");
1048 -- In check end/exit labels mode (-gnatye), always require the name of
1049 -- the loop to be present on the EXIT when exiting a named loop.
1051 procedure No_Exit_Name
(Name
: Node_Id
) is
1053 if Style_Check_End_Labels
then
1054 Error_Msg_Node_1
:= Name
;
1055 Error_Msg_SP
("(style) `EXIT &` required");
1059 ----------------------------
1060 -- Non_Lower_Case_Keyword --
1061 ----------------------------
1063 -- In check casing mode (-gnatyk), reserved keywords must be spelled
1064 -- in all lower case (excluding keywords range, access, delta and digits
1065 -- used as attribute designators).
1067 procedure Non_Lower_Case_Keyword
is
1069 if Style_Check_Keyword_Casing
then
1070 Error_Msg_SC
-- CODEIX
1071 ("(style) reserved words must be all lower case");
1073 end Non_Lower_Case_Keyword
;
1075 -----------------------------
1076 -- Require_Following_Space --
1077 -----------------------------
1079 procedure Require_Following_Space
is
1081 if Source
(Scan_Ptr
) > ' ' then
1082 Error_Space_Required
(Scan_Ptr
);
1084 end Require_Following_Space
;
1086 -----------------------------
1087 -- Require_Preceding_Space --
1088 -----------------------------
1090 procedure Require_Preceding_Space
is
1092 if Token_Ptr
> Source_First
(Current_Source_File
)
1093 and then Source
(Token_Ptr
- 1) > ' '
1095 Error_Space_Required
(Token_Ptr
);
1097 end Require_Preceding_Space
;