avx10_2-comibf-2.c: Require AVX10.2 support
[official-gcc.git] / gcc / ada / styleg.adb
blob74b629c34b3352b4488e25f27ca644cff6e46069
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S T Y L E G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2024, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
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;
34 with Errout;
35 with Opt; use Opt;
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
45 use ASCII;
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
55 -- is encountered.
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
103 -- a line feed.
105 procedure Check_Abs_Not is
106 begin
107 if Style_Check_Tokens then
108 if Source (Scan_Ptr) not in ' ' | ASCII.CR | ASCII.LF then
109 Error_Space_Required (Scan_Ptr);
110 end if;
111 end if;
112 end Check_Abs_Not;
114 ----------------------
115 -- Check_Apostrophe --
116 ----------------------
118 -- Do not allow space after apostrophe
120 procedure Check_Apostrophe is
121 begin
122 if Style_Check_Tokens then
123 Check_No_Space_After;
124 end if;
125 end Check_Apostrophe;
127 -----------------
128 -- Check_Arrow --
129 -----------------
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
136 begin
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) = '+'
145 then
146 Error_Space_Not_Allowed (Scan_Ptr);
148 elsif Source (Scan_Ptr) /= ' '
149 and then Source (Scan_Ptr) /= '+'
150 then
151 Require_Following_Space;
152 end if;
154 -- Normal case
156 else
157 Require_Following_Space;
158 end if;
159 end if;
160 end Check_Arrow;
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);
172 begin
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?");
177 end if;
178 end if;
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
189 begin
190 if Style_Check_Tokens then
191 Require_Preceding_Space;
192 Require_Following_Space;
193 end if;
194 end Check_Binary_Operator;
196 ---------------
197 -- Check_Box --
198 ---------------
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
205 begin
206 if Style_Check_Tokens then
207 if Prev_Token /= Tok_Left_Paren then
208 Require_Preceding_Space;
209 end if;
210 end if;
211 end Check_Box;
213 -----------------
214 -- Check_Colon --
215 -----------------
217 -- In check token mode (-gnatyt), colon must be surrounded by spaces
219 procedure Check_Colon is
220 begin
221 if Style_Check_Tokens then
222 Require_Preceding_Space;
223 Require_Following_Space;
224 end if;
225 end Check_Colon;
227 -----------------------
228 -- Check_Colon_Equal --
229 -----------------------
231 -- In check token mode (-gnatyt), := must be surrounded by spaces
233 procedure Check_Colon_Equal is
234 begin
235 if Style_Check_Tokens then
236 Require_Preceding_Space;
237 Require_Following_Space;
238 end if;
239 end Check_Colon_Equal;
241 -----------------
242 -- Check_Comma --
243 -----------------
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
250 begin
251 if Style_Check_Tokens then
252 Check_No_Space_Before;
254 if Source (Scan_Ptr) > ' ' then
255 Error_Space_Required (Scan_Ptr);
256 end if;
257 end if;
258 end Check_Comma;
260 -------------------
261 -- Check_Comment --
262 -------------------
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
301 S : Source_Ptr;
302 C : Character;
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,
320 -- otherwise False.
322 --------------------
323 -- Is_Box_Comment --
324 --------------------
326 function Is_Box_Comment return Boolean is
327 S : Source_Ptr;
329 begin
330 -- Do we need to worry about UTF_32 line terminators here ???
332 S := Scan_Ptr + 3;
333 while Source (S) not in Line_Terminator loop
334 S := S + 1;
335 end loop;
337 return Source (S - 1) = '-' and then Source (S - 2) = '-';
338 end Is_Box_Comment;
340 --------------------------
341 -- Is_Special_Character --
342 --------------------------
344 function Is_Special_Character (C : Character) return Boolean is
345 begin
346 if GNAT_Mode then
347 return C = '!';
348 else
349 return
350 Character'Pos (C) in 16#21# .. 16#2F#
351 or else
352 Character'Pos (C) in 16#3A# .. 16#3F#;
353 end if;
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
361 P : Source_Ptr;
363 begin
364 -- Step to end of line
366 P := Scan_Ptr + 2;
367 while Source (P) not in Line_Terminator loop
368 P := P + 1;
369 end loop;
371 -- Step past blanks, and line terminators (UTF_32 case???)
373 while Source (P) <= ' ' and then Source (P) /= EOF loop
374 P := P + 1;
375 end loop;
377 -- Compare columns
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
387 S, P : Source_Ptr;
389 begin
390 -- Point S to start of this line, and P to start of previous line
392 S := Line_Start (Scan_Ptr);
393 P := S;
394 Backup_Line (P);
396 -- Step P to first non-blank character on line
398 loop
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.
402 if P = S then
403 return False;
404 end if;
406 exit when Source (P) /= ' ' and then Source (P) /= ASCII.HT;
407 P := P + 1;
408 end loop;
410 -- Compare columns
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
417 begin
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) > ' '
426 then
427 Error_Msg_S -- CODEFIX
428 ("(style) space required?c?");
429 end if;
430 end if;
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))
440 then
441 Error_Msg -- CODEFIX
442 ("(style) space required?c?", Scan_Ptr + 2);
443 end if;
444 end if;
446 return;
448 -- Case of a comment that is at the start of a line
450 else
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
457 then
458 Error_Msg_S -- CODEFIX
459 ("(style) bad column?0?");
460 end if;
462 return;
463 end if;
464 end if;
466 -- If we are not checking comments, nothing more to do
468 if not Style_Check_Comments then
469 return;
470 end if;
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
480 if C < ' ' then
481 return;
482 end if;
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
489 return;
490 end if;
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).
496 S := Scan_Ptr + 2;
497 while Source (S) >= ' ' loop
498 if Source (S) /= '-' then
499 if Is_Box_Comment
500 or else Style_Check_Comments_Spacing = 1
501 then
502 Error_Space_Required (Scan_Ptr + 2);
503 else
504 Error_Msg -- CODEFIX
505 ("(style) two spaces required?c?", Scan_Ptr + 2);
506 end if;
508 return;
509 end if;
511 S := S + 1;
512 end loop;
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
520 then
521 return;
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
526 -- box comment.
528 elsif not Is_Box_Comment then
529 Error_Space_Required (Scan_Ptr + 3);
530 end if;
531 end if;
532 end Check_Comment;
534 --------------------------------------
535 -- Check_Defining_Identifier_Casing --
536 --------------------------------------
538 procedure Check_Defining_Identifier_Casing is
539 begin
540 if Style_Check_Mixed_Case_Decls then
541 case Determine_Token_Casing is
542 when All_Lower_Case
543 | All_Upper_Case
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.
551 when Mixed_Case
552 | Unknown
554 null; -- OK
555 end case;
556 end if;
557 end Check_Defining_Identifier_Casing;
559 -------------------
560 -- Check_Dot_Dot --
561 -------------------
563 -- In check token mode (-gnatyt), ".." must be surrounded by spaces
565 procedure Check_Dot_Dot is
566 begin
567 if Style_Check_Tokens then
568 Require_Preceding_Space;
569 Require_Following_Space;
570 end if;
571 end Check_Dot_Dot;
573 ---------------
574 -- Check_EOF --
575 ---------------
577 -- In check blanks at end mode, check no blank lines precede the EOF
579 procedure Check_EOF is
580 begin
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
586 Error_Msg -- CODEFIX
587 ("(style) blank line not allowed at end of file?u?",
588 Blank_Line_Location);
590 elsif Blank_Lines >= 3 then
591 Error_Msg -- CODEFIX
592 ("(style) blank lines not allowed at end of file?u?",
593 Blank_Line_Location);
594 end if;
595 end if;
596 end Check_EOF;
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
605 begin
606 null;
607 end Check_Exponentiation_Operator;
609 --------------
610 -- Check_HT --
611 --------------
613 -- In check horizontal tab mode (-gnatyh), tab characters are not allowed
615 procedure Check_HT is
616 begin
617 if Style_Check_Horizontal_Tabs then
618 Error_Msg_S -- CODEFIX
619 ("(style) horizontal tab not allowed?h?");
620 end if;
621 end Check_HT;
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
632 begin
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
636 then
637 Error_Msg_SC -- CODEFIX
638 ("(style) bad indentation?0?");
639 end if;
640 end if;
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
653 begin
654 if Style_Check_Tokens then
655 if Token_Ptr > Source_First (Current_Source_File)
656 and then Identifier_Char (Source (Token_Ptr - 1))
657 then
658 Error_Space_Required (Token_Ptr);
659 end if;
661 Check_No_Space_After;
662 end if;
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
673 begin
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);
677 Error_Msg
678 ("(style) this line is too long: ^?M?",
679 Current_Line_Start + Source_Ptr (Style_Max_Line_Length));
680 end if;
681 end if;
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
689 -- trailing space.
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
698 S : Source_Ptr;
700 L : Nat := Len;
701 -- Length of line (adjusted down for blanks at end of line)
703 begin
704 -- Reset count of blank lines if first line
706 if Get_Logical_Line_Number (Scan_Ptr) = 1 then
707 Blank_Lines := 0;
708 end if;
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?");
719 end if;
720 end if;
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
731 null;
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?");
737 end if;
738 end if;
740 -- Remove trailing spaces
742 S := Scan_Ptr;
743 while L > 0 and then Is_White_Space (Source (S - 1)) loop
744 S := S - 1;
745 L := L - 1;
746 end 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
751 Error_Msg -- CODEFIX
752 ("(style) trailing spaces not permitted?b?", S);
753 end if;
755 -- Deal with empty (blank) line
757 if L = 0 then
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;
767 end if;
769 -- Non-blank line, check for previous multiple blank lines
771 else
772 if Style_Check_Blank_Lines and then Blank_Lines > 1 then
773 Error_Msg -- CODEFIX
774 ("(style) multiple blank lines?u?", Blank_Line_Location);
775 end if;
777 -- And reset blank line count
779 Blank_Lines := 0;
780 end if;
781 end Check_Line_Terminator;
783 ------------------
784 -- Check_Not_In --
785 ------------------
787 -- In check tokens mode, only one space between NOT and IN
789 procedure Check_Not_In is
790 begin
791 if Style_Check_Tokens then
792 if Source (Token_Ptr - 1) /= ' '
793 or else Token_Ptr - Prev_Token_Ptr /= 4
794 then -- CODEFIX?
795 Error_Msg
796 ("(style) single space must separate NOT and IN?t?",
797 Token_Ptr - 1);
798 end if;
799 end if;
800 end Check_Not_In;
802 --------------------------
803 -- Check_No_Space_After --
804 --------------------------
806 procedure Check_No_Space_After is
807 S : Source_Ptr;
809 begin
810 if Is_White_Space (Source (Scan_Ptr)) then
812 -- Allow one or more spaces if followed by comment
814 S := Scan_Ptr + 1;
815 loop
816 if Source (S) = '-' and then Source (S + 1) = '-' then
817 return;
819 elsif Is_White_Space (Source (S)) then
820 S := S + 1;
822 else
823 exit;
824 end if;
825 end loop;
827 Error_Space_Not_Allowed (Scan_Ptr);
828 end if;
829 end Check_No_Space_After;
831 ---------------------------
832 -- Check_No_Space_Before --
833 ---------------------------
835 procedure Check_No_Space_Before is
836 begin
837 if Token_Ptr > First_Non_Blank_Location
838 and then Source (Token_Ptr - 1) <= ' '
839 then
840 Error_Space_Not_Allowed (Token_Ptr - 1);
841 end if;
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
853 begin
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?");
858 end if;
859 end if;
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
871 begin
872 if Style_Check_Tokens then
873 if Identifier_Char (Source (Token_Ptr + 1)) then
874 Error_Space_Required (Token_Ptr + 1);
875 end if;
877 Check_No_Space_Before;
878 end if;
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
889 begin
890 if Style_Check_Tokens then
891 Check_No_Space_Before;
893 if Source (Scan_Ptr) > ' ' then
894 Error_Space_Required (Scan_Ptr);
895 end if;
896 end if;
897 end Check_Semicolon;
899 -------------------------------
900 -- Check_Separate_Stmt_Lines --
901 -------------------------------
903 procedure Check_Separate_Stmt_Lines is
904 begin
905 if Style_Check_Separate_Stmt_Lines then
906 Check_Separate_Stmt_Lines_Cont;
907 end if;
908 end Check_Separate_Stmt_Lines;
910 ------------------------------------
911 -- Check_Separate_Stmt_Lines_Cont --
912 ------------------------------------
914 procedure Check_Separate_Stmt_Lines_Cont is
915 S : Source_Ptr;
917 begin
918 -- Skip past white space
920 S := Scan_Ptr;
921 while Is_White_Space (Source (S)) loop
922 S := S + 1;
923 end loop;
925 -- Line terminator is OK
927 if Source (S) in Line_Terminator then
928 return;
930 -- Comment is OK
932 elsif Source (S) = '-' and then Source (S + 1) = '-' then
933 return;
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)))
945 then
946 return;
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)))
959 then
960 return;
962 -- Otherwise we have the style violation we are looking for
964 else
965 if Token = Tok_Then then
966 Error_Msg -- CODEFIX
967 ("(style) no statements may follow THEN on same line?S?", S);
968 else
969 Error_Msg
970 ("(style) no statements may follow ELSE on same line?S?", S);
971 end if;
972 end if;
973 end Check_Separate_Stmt_Lines_Cont;
975 ----------------
976 -- Check_Then --
977 ----------------
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
984 begin
985 if Style_Check_If_Then_Layout then
986 declare
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);
991 begin
992 if If_Line = Then_Line then
993 null;
994 elsif Token_Ptr /= First_Non_Blank_Location then
995 Error_Msg_SC ("(style) misplaced THEN?i?");
996 end if;
997 end;
998 end if;
999 end Check_Then;
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
1013 begin
1014 if Style_Check_Tokens then
1015 if Inside_Depends then
1016 Require_Following_Space;
1017 else
1018 Check_No_Space_After;
1019 end if;
1020 end if;
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
1030 begin
1031 if Style_Check_Tokens then
1032 Require_Preceding_Space;
1033 Require_Following_Space;
1034 end if;
1035 end Check_Vertical_Bar;
1037 -----------------------
1038 -- Check_Xtra_Parens --
1039 -----------------------
1041 procedure Check_Xtra_Parens (N : Node_Id) is
1042 begin
1043 if Style_Check_Xtra_Parens
1044 and then
1045 Paren_Count (N) >
1046 (if Nkind (N) in N_Case_Expression
1047 | N_Expression_With_Actions
1048 | N_If_Expression
1049 | N_Quantified_Expression
1050 | N_Raise_Expression
1051 then 1
1052 else 0)
1053 then
1054 Error_Msg -- CODEFIX
1055 ("(style) redundant parentheses?x?", Errout.First_Sloc (N));
1056 end if;
1057 end Check_Xtra_Parens;
1059 ----------------------------
1060 -- Determine_Token_Casing --
1061 ----------------------------
1063 function Determine_Token_Casing return Casing_Type is
1064 begin
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
1073 begin
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
1083 begin
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
1093 begin
1094 return C = ' ' or else C = HT;
1095 end Is_White_Space;
1097 -------------------
1098 -- Mode_In_Check --
1099 -------------------
1101 function Mode_In_Check return Boolean is
1102 begin
1103 return Style_Check and Style_Check_Mode_In;
1104 end Mode_In_Check;
1106 -----------------
1107 -- No_End_Name --
1108 -----------------
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
1114 begin
1115 if Style_Check_End_Labels then
1116 Error_Msg_Node_1 := Name;
1117 Error_Msg_SP -- CODEFIX
1118 ("(style) `END &` required?e?");
1119 end if;
1120 end No_End_Name;
1122 ------------------
1123 -- No_Exit_Name --
1124 ------------------
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
1130 begin
1131 if Style_Check_End_Labels then
1132 Error_Msg_Node_1 := Name;
1133 Error_Msg_SP -- CODEFIX
1134 ("(style) `EXIT &` required?e?");
1135 end if;
1136 end No_Exit_Name;
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
1147 begin
1148 if Style_Check_Keyword_Casing then
1149 Error_Msg_SC -- CODEFIX
1150 ("(style) reserved words must be all lower case?k?");
1151 end if;
1152 end Non_Lower_Case_Keyword;
1154 -----------------------------
1155 -- Require_Following_Space --
1156 -----------------------------
1158 procedure Require_Following_Space is
1159 begin
1160 if Source (Scan_Ptr) > ' ' then
1161 Error_Space_Required (Scan_Ptr);
1162 end if;
1163 end Require_Following_Space;
1165 -----------------------------
1166 -- Require_Preceding_Space --
1167 -----------------------------
1169 procedure Require_Preceding_Space is
1170 begin
1171 if Token_Ptr > Source_First (Current_Source_File)
1172 and then Source (Token_Ptr - 1) > ' '
1173 then
1174 Error_Space_Required (Token_Ptr);
1175 end if;
1176 end Require_Preceding_Space;
1178 end Styleg;