* doc/install.texi (*-*-aix): Update explanation of XLC bootstrap.
[official-gcc.git] / gcc / ada / styleg.adb
blobc92231d60b3cd5498c9ce6660b5e1d946629969d
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-2009, 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 Casing; use Casing;
31 with Csets; use Csets;
32 with Err_Vars; use Err_Vars;
33 with Opt; use Opt;
34 with Scans; use Scans;
35 with Sinput; use Sinput;
36 with Stylesw; use Stylesw;
38 package body Styleg is
40 use ASCII;
42 Blank_Lines : Nat := 0;
43 -- Counts number of empty lines seen. Reset to zero if a non-empty line
44 -- is encountered. Used to check for trailing blank lines in Check_EOF,
45 -- and for multiple blank lines.
47 Blank_Line_Location : Source_Ptr;
48 -- Remembers location of first blank line in a series. Used to issue an
49 -- appropriate diagnostic if subsequent blank lines or the end of file
50 -- is encountered.
52 -----------------------
53 -- Local Subprograms --
54 -----------------------
56 procedure Check_No_Space_After;
57 -- Checks that there is a non-white space character after the current
58 -- token, or white space followed by a comment, or the end of line.
59 -- Issue error message if not.
61 procedure Check_No_Space_Before;
62 -- Check that token is first token on line, or else is not preceded
63 -- by white space. Signal error of space not allowed if not.
65 procedure Check_Separate_Stmt_Lines_Cont;
66 -- Non-inlined continuation of Check_Separate_Stmt_Lines
68 function Determine_Token_Casing return Casing_Type;
69 -- Determine casing of current token
71 procedure Error_Space_Not_Allowed (S : Source_Ptr);
72 -- Posts an error message indicating that a space is not allowed
73 -- at the given source location.
75 procedure Error_Space_Required (S : Source_Ptr);
76 -- Posts an error message indicating that a space is required at
77 -- the given source location.
79 function Is_White_Space (C : Character) return Boolean;
80 pragma Inline (Is_White_Space);
81 -- Returns True for space, HT, VT or FF, False otherwise
83 procedure Require_Following_Space;
84 pragma Inline (Require_Following_Space);
85 -- Require token to be followed by white space. Used only if in GNAT
86 -- style checking mode.
88 procedure Require_Preceding_Space;
89 pragma Inline (Require_Preceding_Space);
90 -- Require token to be preceded by white space. Used only if in GNAT
91 -- style checking mode.
93 ----------------------
94 -- Check_Abs_Or_Not --
95 ----------------------
97 -- In check tokens mode (-gnatyt), ABS/NOT must be followed by a space
99 procedure Check_Abs_Not is
100 begin
101 if Style_Check_Tokens then
102 if Source (Scan_Ptr) > ' ' then
103 Error_Space_Required (Scan_Ptr);
104 end if;
105 end if;
106 end Check_Abs_Not;
108 ----------------------
109 -- Check_Apostrophe --
110 ----------------------
112 -- Do not allow space before or after apostrophe
114 procedure Check_Apostrophe is
115 begin
116 if Style_Check_Tokens then
117 Check_No_Space_After;
118 end if;
119 end Check_Apostrophe;
121 -----------------
122 -- Check_Arrow --
123 -----------------
125 -- In check tokens mode (-gnatys), arrow must be surrounded by spaces
127 procedure Check_Arrow is
128 begin
129 if Style_Check_Tokens then
130 Require_Preceding_Space;
131 Require_Following_Space;
132 end if;
133 end Check_Arrow;
135 --------------------------
136 -- Check_Attribute_Name --
137 --------------------------
139 -- In check attribute casing mode (-gnatya), attribute names must be
140 -- mixed case, i.e. start with an upper case letter, and otherwise
141 -- lower case, except after an underline character.
143 procedure Check_Attribute_Name (Reserved : Boolean) is
144 pragma Warnings (Off, Reserved);
145 begin
146 if Style_Check_Attribute_Casing then
147 if Determine_Token_Casing /= Mixed_Case then
148 Error_Msg_SC -- CODEFIX
149 ("(style) bad capitalization, mixed case required");
150 end if;
151 end if;
152 end Check_Attribute_Name;
154 ---------------------------
155 -- Check_Binary_Operator --
156 ---------------------------
158 -- In check token mode (-gnatyt), binary operators other than the special
159 -- case of exponentiation require surrounding space characters.
161 procedure Check_Binary_Operator is
162 begin
163 if Style_Check_Tokens then
164 Require_Preceding_Space;
165 Require_Following_Space;
166 end if;
167 end Check_Binary_Operator;
169 ---------------
170 -- Check_Box --
171 ---------------
173 -- In check token mode (-gnatyt), box must be preceded by a space or by
174 -- a left parenthesis. Spacing checking on the surrounding tokens takes
175 -- care of the remaining checks.
177 procedure Check_Box is
178 begin
179 if Style_Check_Tokens then
180 if Prev_Token /= Tok_Left_Paren then
181 Require_Preceding_Space;
182 end if;
183 end if;
184 end Check_Box;
186 -----------------
187 -- Check_Colon --
188 -----------------
190 -- In check token mode (-gnatyt), colon must be surrounded by spaces
192 procedure Check_Colon is
193 begin
194 if Style_Check_Tokens then
195 Require_Preceding_Space;
196 Require_Following_Space;
197 end if;
198 end Check_Colon;
200 -----------------------
201 -- Check_Colon_Equal --
202 -----------------------
204 -- In check token mode (-gnatyt), := must be surrounded by spaces
206 procedure Check_Colon_Equal is
207 begin
208 if Style_Check_Tokens then
209 Require_Preceding_Space;
210 Require_Following_Space;
211 end if;
212 end Check_Colon_Equal;
214 -----------------
215 -- Check_Comma --
216 -----------------
218 -- In check token mode (-gnatyt), comma must be either the first
219 -- token on a line, or be preceded by a non-blank character.
220 -- It must also always be followed by a blank.
222 procedure Check_Comma is
223 begin
224 if Style_Check_Tokens then
225 Check_No_Space_Before;
227 if Source (Scan_Ptr) > ' ' then
228 Error_Space_Required (Scan_Ptr);
229 end if;
230 end if;
231 end Check_Comma;
233 -------------------
234 -- Check_Comment --
235 -------------------
237 -- In check comment mode (-gnatyc) there are several requirements on the
238 -- format of comments. The following are permissible comment formats:
240 -- 1. Any comment that is not at the start of a line, i.e. where the
241 -- initial minuses are not the first non-blank characters on the
242 -- line must have at least one blank after the second minus or a
243 -- special character as defined in rule 5.
245 -- 2. A row of all minuses of any length is permitted (see procedure
246 -- box above in the source of this routine).
248 -- 3. A comment line starting with two minuses and a space, and ending
249 -- with a space and two minuses. Again see the procedure title box
250 -- immediately above in the source.
252 -- 4. A full line comment where two spaces follow the two minus signs.
253 -- This is the normal comment format in GNAT style, as typified by
254 -- the comments you are reading now.
256 -- 5. A full line comment where the first character after the second
257 -- minus is a special character, i.e. a character in the ASCII
258 -- range 16#21#..16#2F# or 16#3A#..16#3F#. This allows special
259 -- comments, such as those generated by gnatprep, or those that
260 -- appear in the SPARK annotation language to be accepted.
262 -- Note: for GNAT internal files (-gnatg switch set on for the
263 -- compilation), the only special sequence recognized and allowed
264 -- is --! as generated by gnatprep.
266 -- 6. In addition, the comment must be properly indented if comment
267 -- indentation checking is active (Style_Check_Indentation non-zero).
268 -- Either the start column must be a multiple of this indentation,
269 -- or the indentation must match that of the next non-blank line.
271 procedure Check_Comment is
272 S : Source_Ptr;
273 C : Character;
275 function Is_Box_Comment return Boolean;
276 -- Returns True if the last two characters on the line are -- which
277 -- characterizes a box comment (as for example follows this spec).
279 function Is_Special_Character (C : Character) return Boolean;
280 -- Determines if C is a special character (see rule 5 above)
282 function Same_Column_As_Next_Non_Blank_Line return Boolean;
283 -- Called for a full line comment. If the indentation of this comment
284 -- matches that of the next non-blank line in the source, then True is
285 -- returned, otherwise False.
287 --------------------
288 -- Is_Box_Comment --
289 --------------------
291 function Is_Box_Comment return Boolean is
292 S : Source_Ptr;
294 begin
295 -- Do we need to worry about UTF_32 line terminators here ???
297 S := Scan_Ptr + 3;
298 while Source (S) not in Line_Terminator loop
299 S := S + 1;
300 end loop;
302 return Source (S - 1) = '-' and then Source (S - 2) = '-';
303 end Is_Box_Comment;
305 --------------------------
306 -- Is_Special_Character --
307 --------------------------
309 function Is_Special_Character (C : Character) return Boolean is
310 begin
311 if GNAT_Mode then
312 return C = '!';
313 else
314 return
315 Character'Pos (C) in 16#21# .. 16#2F#
316 or else
317 Character'Pos (C) in 16#3A# .. 16#3F#;
318 end if;
319 end Is_Special_Character;
321 ----------------------------------------
322 -- Same_Column_As_Next_Non_Blank_Line --
323 ----------------------------------------
325 function Same_Column_As_Next_Non_Blank_Line return Boolean is
326 P : Source_Ptr;
328 begin
329 -- Step to end of line
331 P := Scan_Ptr + 2;
332 while Source (P) not in Line_Terminator loop
333 P := P + 1;
334 end loop;
336 -- Step past blanks, and line terminators (UTF_32 case???)
338 while Source (P) <= ' ' and then Source (P) /= EOF loop
339 P := P + 1;
340 end loop;
342 -- Compare columns
344 return Get_Column_Number (Scan_Ptr) = Get_Column_Number (P);
345 end Same_Column_As_Next_Non_Blank_Line;
347 -- Start of processing for Check_Comment
349 begin
350 -- Can never have a non-blank character preceding the first minus
352 if Style_Check_Comments then
353 if Scan_Ptr > Source_First (Current_Source_File)
354 and then Source (Scan_Ptr - 1) > ' '
355 then
356 Error_Msg_S ("(style) space required");
357 end if;
358 end if;
360 -- For a comment that is not at the start of the line, the only
361 -- requirement is that we cannot have a non-blank character after
362 -- the second minus sign or a special character.
364 if Scan_Ptr /= First_Non_Blank_Location then
365 if Style_Check_Comments then
366 if Source (Scan_Ptr + 2) > ' '
367 and then not Is_Special_Character (Source (Scan_Ptr + 2))
368 then
369 Error_Msg ("(style) space required", Scan_Ptr + 2);
370 end if;
371 end if;
373 return;
375 -- Case of a comment that is at the start of a line
377 else
378 -- First check, must be in appropriately indented column
380 if Style_Check_Indentation /= 0 then
381 if Start_Column rem Style_Check_Indentation /= 0 then
382 if not Same_Column_As_Next_Non_Blank_Line then
383 Error_Msg_S -- CODEFIX
384 ("(style) bad column");
385 end if;
387 return;
388 end if;
389 end if;
391 -- If we are not checking comments, nothing more to do
393 if not Style_Check_Comments then
394 return;
395 end if;
397 -- Case of not followed by a blank. Usually wrong, but there are
398 -- some exceptions that we permit.
400 if Source (Scan_Ptr + 2) /= ' ' then
401 C := Source (Scan_Ptr + 2);
403 -- Case of -- all on its own on a line is OK
405 if C < ' ' then
406 return;
407 end if;
409 -- Case of --x, x special character is OK (gnatprep/SPARK/etc.)
410 -- This is not permitted in internal GNAT implementation units
411 -- except for the case of --! as used by gnatprep output.
413 if Is_Special_Character (C) then
414 return;
415 end if;
417 -- The only other case in which we allow a character after
418 -- the -- other than a space is when we have a row of minus
419 -- signs (case of header lines for a box comment for example).
421 S := Scan_Ptr + 2;
422 while Source (S) >= ' ' loop
423 if Source (S) /= '-' then
424 if Is_Box_Comment then
425 Error_Space_Required (Scan_Ptr + 2);
426 else
427 Error_Msg ("(style) two spaces required", Scan_Ptr + 2);
428 end if;
430 return;
431 end if;
433 S := S + 1;
434 end loop;
436 -- If we are followed by a blank, then the comment is OK if the
437 -- character following this blank is another blank or a format
438 -- effector.
440 elsif Source (Scan_Ptr + 3) <= ' ' then
441 return;
443 -- Here is the case where we only have one blank after the two
444 -- minus signs, which is an error unless the line ends with two
445 -- minus signs, the case of a box comment.
447 elsif not Is_Box_Comment then
448 Error_Space_Required (Scan_Ptr + 3);
449 end if;
450 end if;
451 end Check_Comment;
453 -------------------
454 -- Check_Dot_Dot --
455 -------------------
457 -- In check token mode (-gnatyt), colon must be surrounded by spaces
459 procedure Check_Dot_Dot is
460 begin
461 if Style_Check_Tokens then
462 Require_Preceding_Space;
463 Require_Following_Space;
464 end if;
465 end Check_Dot_Dot;
467 ---------------
468 -- Check_EOF --
469 ---------------
471 -- In check blanks at end mode, check no blank lines precede the EOF
473 procedure Check_EOF is
474 begin
475 if Style_Check_Blank_Lines then
477 -- We expect one blank line, from the EOF, but no more than one
479 if Blank_Lines = 2 then
480 Error_Msg
481 ("(style) blank line not allowed at end of file",
482 Blank_Line_Location);
484 elsif Blank_Lines >= 3 then
485 Error_Msg
486 ("(style) blank lines not allowed at end of file",
487 Blank_Line_Location);
488 end if;
489 end if;
490 end Check_EOF;
492 -----------------------------------
493 -- Check_Exponentiation_Operator --
494 -----------------------------------
496 -- No spaces are required for the ** operator in GNAT style check mode
498 procedure Check_Exponentiation_Operator is
499 begin
500 null;
501 end Check_Exponentiation_Operator;
503 --------------
504 -- Check_HT --
505 --------------
507 -- In check horizontal tab mode (-gnatyh), tab characters are not allowed
509 procedure Check_HT is
510 begin
511 if Style_Check_Horizontal_Tabs then
512 Error_Msg_S ("(style) horizontal tab not allowed");
513 end if;
514 end Check_HT;
516 -----------------------
517 -- Check_Indentation --
518 -----------------------
520 -- In check indentation mode (-gnatyn for n a digit), a new statement or
521 -- declaration is required to start in a column that is a multiple of the
522 -- indentation amount.
524 procedure Check_Indentation is
525 begin
526 if Style_Check_Indentation /= 0 then
527 if Token_Ptr = First_Non_Blank_Location
528 and then Start_Column rem Style_Check_Indentation /= 0
529 then
530 Error_Msg_SC ("(style) bad indentation");
531 end if;
532 end if;
533 end Check_Indentation;
535 ----------------------
536 -- Check_Left_Paren --
537 ----------------------
539 -- In tone check mode (-gnatyt), left paren must not be preceded by an
540 -- identifier character or digit (a separating space is required) and
541 -- may never be followed by a space.
543 procedure Check_Left_Paren is
544 begin
545 if Style_Check_Tokens then
546 if Token_Ptr > Source_First (Current_Source_File)
547 and then Identifier_Char (Source (Token_Ptr - 1))
548 then
549 Error_Space_Required (Token_Ptr);
550 end if;
552 Check_No_Space_After;
553 end if;
554 end Check_Left_Paren;
556 ---------------------------
557 -- Check_Line_Max_Length --
558 ---------------------------
560 -- In check max line length mode (-gnatym), the line length must
561 -- not exceed the permitted maximum value.
563 procedure Check_Line_Max_Length (Len : Int) is
564 begin
565 if Style_Check_Max_Line_Length then
566 if Len > Style_Max_Line_Length then
567 Error_Msg
568 ("(style) this line is too long",
569 Current_Line_Start + Source_Ptr (Style_Max_Line_Length));
570 end if;
571 end if;
572 end Check_Line_Max_Length;
574 ---------------------------
575 -- Check_Line_Terminator --
576 ---------------------------
578 -- In check blanks at end mode (-gnatyb), lines may not end with a
579 -- trailing space.
581 -- In check form feeds mode (-gnatyf), the line terminator may not
582 -- be either of the characters FF or VT.
584 -- In check DOS line terminators node (-gnatyd), the line terminator
585 -- must be a single LF, without a following CR.
587 procedure Check_Line_Terminator (Len : Int) is
588 S : Source_Ptr;
590 L : Int := Len;
591 -- Length of line (adjusted down for blanks at end of line)
593 begin
594 -- Reset count of blank lines if first line
596 if Get_Logical_Line_Number (Scan_Ptr) = 1 then
597 Blank_Lines := 0;
598 end if;
600 -- Check FF/VT terminators
602 if Style_Check_Form_Feeds then
603 if Source (Scan_Ptr) = ASCII.FF then
604 Error_Msg_S ("(style) form feed not allowed");
605 elsif Source (Scan_Ptr) = ASCII.VT then
606 Error_Msg_S ("(style) vertical tab not allowed");
607 end if;
608 end if;
610 -- Check DOS line terminator
612 if Style_Check_DOS_Line_Terminator then
614 -- Ignore EOF, since we only get called with an EOF if it is the last
615 -- character in the buffer (and was therefore not in the source file),
616 -- since the terminating EOF is added to stop the scan.
618 if Source (Scan_Ptr) = EOF then
619 null;
621 -- Bad terminator if we don't have an LF
623 elsif Source (Scan_Ptr) /= LF then
624 Error_Msg_S ("(style) incorrect line terminator");
625 end if;
626 end if;
628 -- Remove trailing spaces
630 S := Scan_Ptr;
631 while L > 0 and then Is_White_Space (Source (S - 1)) loop
632 S := S - 1;
633 L := L - 1;
634 end loop;
636 -- Issue message for blanks at end of line if option enabled
638 if Style_Check_Blanks_At_End and then L < Len then
639 Error_Msg
640 ("(style) trailing spaces not permitted", S);
641 end if;
643 -- Deal with empty (blank) line
645 if L = 0 then
647 -- Increment blank line count
649 Blank_Lines := Blank_Lines + 1;
651 -- If first blank line, record location for later error message
653 if Blank_Lines = 1 then
654 Blank_Line_Location := Scan_Ptr;
655 end if;
657 -- Non-blank line, check for previous multiple blank lines
659 else
660 if Style_Check_Blank_Lines and then Blank_Lines > 1 then
661 Error_Msg -- CODEFIX
662 ("(style) multiple blank lines", Blank_Line_Location);
663 end if;
665 -- And reset blank line count
667 Blank_Lines := 0;
668 end if;
669 end Check_Line_Terminator;
671 --------------------------
672 -- Check_No_Space_After --
673 --------------------------
675 procedure Check_No_Space_After is
676 S : Source_Ptr;
678 begin
679 if Is_White_Space (Source (Scan_Ptr)) then
681 -- Allow one or more spaces if followed by comment
683 S := Scan_Ptr + 1;
684 loop
685 if Source (S) = '-' and then Source (S + 1) = '-' then
686 return;
688 elsif Is_White_Space (Source (S)) then
689 S := S + 1;
691 else
692 exit;
693 end if;
694 end loop;
696 Error_Space_Not_Allowed (Scan_Ptr);
697 end if;
698 end Check_No_Space_After;
700 ---------------------------
701 -- Check_No_Space_Before --
702 ---------------------------
704 procedure Check_No_Space_Before is
705 begin
706 if Token_Ptr > First_Non_Blank_Location
707 and then Source (Token_Ptr - 1) <= ' '
708 then
709 Error_Space_Not_Allowed (Token_Ptr - 1);
710 end if;
711 end Check_No_Space_Before;
713 -----------------------
714 -- Check_Pragma_Name --
715 -----------------------
717 -- In check pragma casing mode (-gnatyp), pragma names must be mixed
718 -- case, i.e. start with an upper case letter, and otherwise lower case,
719 -- except after an underline character.
721 procedure Check_Pragma_Name is
722 begin
723 if Style_Check_Pragma_Casing then
724 if Determine_Token_Casing /= Mixed_Case then
725 Error_Msg_SC -- CODEFIX
726 ("(style) bad capitalization, mixed case required");
727 end if;
728 end if;
729 end Check_Pragma_Name;
731 -----------------------
732 -- Check_Right_Paren --
733 -----------------------
735 -- In check tokens mode (-gnatyt), right paren must never be preceded by
736 -- a space unless it is the initial non-blank character on the line.
738 procedure Check_Right_Paren is
739 begin
740 if Style_Check_Tokens then
741 Check_No_Space_Before;
742 end if;
743 end Check_Right_Paren;
745 ---------------------
746 -- Check_Semicolon --
747 ---------------------
749 -- In check tokens mode (-gnatyt), semicolon does not permit a preceding
750 -- space and a following space is required.
752 procedure Check_Semicolon is
753 begin
754 if Style_Check_Tokens then
755 Check_No_Space_Before;
757 if Source (Scan_Ptr) > ' ' then
758 Error_Space_Required (Scan_Ptr);
759 end if;
760 end if;
761 end Check_Semicolon;
763 -------------------------------
764 -- Check_Separate_Stmt_Lines --
765 -------------------------------
767 procedure Check_Separate_Stmt_Lines is
768 begin
769 if Style_Check_Separate_Stmt_Lines then
770 Check_Separate_Stmt_Lines_Cont;
771 end if;
772 end Check_Separate_Stmt_Lines;
774 ------------------------------------
775 -- Check_Separate_Stmt_Lines_Cont --
776 ------------------------------------
778 procedure Check_Separate_Stmt_Lines_Cont is
779 S : Source_Ptr;
781 begin
782 -- Skip past white space
784 S := Scan_Ptr;
785 while Is_White_Space (Source (S)) loop
786 S := S + 1;
787 end loop;
789 -- Line terminator is OK
791 if Source (S) in Line_Terminator then
792 return;
794 -- Comment is OK
796 elsif Source (S) = '-' and then Source (S + 1) = '-' then
797 return;
799 -- ABORT keyword is OK after THEN (THEN ABORT case)
801 elsif Token = Tok_Then
802 and then (Source (S + 0) = 'a' or else Source (S + 0) = 'A')
803 and then (Source (S + 1) = 'b' or else Source (S + 1) = 'B')
804 and then (Source (S + 2) = 'o' or else Source (S + 2) = 'O')
805 and then (Source (S + 3) = 'r' or else Source (S + 3) = 'R')
806 and then (Source (S + 4) = 't' or else Source (S + 4) = 'T')
807 and then (Source (S + 5) in Line_Terminator
808 or else Is_White_Space (Source (S + 5)))
809 then
810 return;
812 -- PRAGMA keyword is OK after ELSE
814 elsif Token = Tok_Else
815 and then (Source (S + 0) = 'p' or else Source (S + 0) = 'P')
816 and then (Source (S + 1) = 'r' or else Source (S + 1) = 'R')
817 and then (Source (S + 2) = 'a' or else Source (S + 2) = 'A')
818 and then (Source (S + 3) = 'g' or else Source (S + 3) = 'G')
819 and then (Source (S + 4) = 'm' or else Source (S + 4) = 'M')
820 and then (Source (S + 5) = 'a' or else Source (S + 5) = 'A')
821 and then (Source (S + 6) in Line_Terminator
822 or else Is_White_Space (Source (S + 6)))
823 then
824 return;
826 -- Otherwise we have the style violation we are looking for
828 else
829 if Token = Tok_Then then
830 Error_Msg
831 ("(style) no statements may follow THEN on same line", S);
832 else
833 Error_Msg
834 ("(style) no statements may follow ELSE on same line", S);
835 end if;
836 end if;
837 end Check_Separate_Stmt_Lines_Cont;
839 ----------------
840 -- Check_Then --
841 ----------------
843 -- In check if then layout mode (-gnatyi), we expect a THEN keyword
844 -- to appear either on the same line as the IF, or on a separate line
845 -- after multiple conditions. In any case, it may not appear on the
846 -- line immediately following the line with the IF.
848 procedure Check_Then (If_Loc : Source_Ptr) is
849 begin
850 if Style_Check_If_Then_Layout then
851 if Get_Physical_Line_Number (Token_Ptr) =
852 Get_Physical_Line_Number (If_Loc) + 1
853 then
854 Error_Msg_SC ("(style) misplaced THEN");
855 end if;
856 end if;
857 end Check_Then;
859 -------------------------------
860 -- Check_Unary_Plus_Or_Minus --
861 -------------------------------
863 -- In check token mode (-gnatyt), unary plus or minus must not be
864 -- followed by a space.
866 procedure Check_Unary_Plus_Or_Minus is
867 begin
868 if Style_Check_Tokens then
869 Check_No_Space_After;
870 end if;
871 end Check_Unary_Plus_Or_Minus;
873 ------------------------
874 -- Check_Vertical_Bar --
875 ------------------------
877 -- In check token mode (-gnatyt), vertical bar must be surrounded by spaces
879 procedure Check_Vertical_Bar is
880 begin
881 if Style_Check_Tokens then
882 Require_Preceding_Space;
883 Require_Following_Space;
884 end if;
885 end Check_Vertical_Bar;
887 -----------------------
888 -- Check_Xtra_Parens --
889 -----------------------
891 procedure Check_Xtra_Parens (Loc : Source_Ptr) is
892 begin
893 if Style_Check_Xtra_Parens then
894 Error_Msg ("redundant parentheses?", Loc);
895 end if;
896 end Check_Xtra_Parens;
898 ----------------------------
899 -- Determine_Token_Casing --
900 ----------------------------
902 function Determine_Token_Casing return Casing_Type is
903 begin
904 return Determine_Casing (Source (Token_Ptr .. Scan_Ptr - 1));
905 end Determine_Token_Casing;
907 -----------------------------
908 -- Error_Space_Not_Allowed --
909 -----------------------------
911 procedure Error_Space_Not_Allowed (S : Source_Ptr) is
912 begin
913 Error_Msg ("(style) space not allowed", S);
914 end Error_Space_Not_Allowed;
916 --------------------------
917 -- Error_Space_Required --
918 --------------------------
920 procedure Error_Space_Required (S : Source_Ptr) is
921 begin
922 Error_Msg ("(style) space required", S);
923 end Error_Space_Required;
925 --------------------
926 -- Is_White_Space --
927 --------------------
929 function Is_White_Space (C : Character) return Boolean is
930 begin
931 return C = ' ' or else C = HT;
932 end Is_White_Space;
934 -------------------
935 -- Mode_In_Check --
936 -------------------
938 function Mode_In_Check return Boolean is
939 begin
940 return Style_Check and Style_Check_Mode_In;
941 end Mode_In_Check;
943 -----------------
944 -- No_End_Name --
945 -----------------
947 -- In check end/exit labels mode (-gnatye), always require the name of
948 -- a subprogram or package to be present on the END, so this is an error.
950 procedure No_End_Name (Name : Node_Id) is
951 begin
952 if Style_Check_End_Labels then
953 Error_Msg_Node_1 := Name;
954 Error_Msg_SP ("(style) `END &` required");
955 end if;
956 end No_End_Name;
958 ------------------
959 -- No_Exit_Name --
960 ------------------
962 -- In check end/exit labels mode (-gnatye), always require the name of
963 -- the loop to be present on the EXIT when exiting a named loop.
965 procedure No_Exit_Name (Name : Node_Id) is
966 begin
967 if Style_Check_End_Labels then
968 Error_Msg_Node_1 := Name;
969 Error_Msg_SP ("(style) `EXIT &` required");
970 end if;
971 end No_Exit_Name;
973 ----------------------------
974 -- Non_Lower_Case_Keyword --
975 ----------------------------
977 -- In check casing mode (-gnatyk), reserved keywords must be spelled
978 -- in all lower case (excluding keywords range, access, delta and digits
979 -- used as attribute designators).
981 procedure Non_Lower_Case_Keyword is
982 begin
983 if Style_Check_Keyword_Casing then
984 Error_Msg_SC -- CODEIX
985 ("(style) reserved words must be all lower case");
986 end if;
987 end Non_Lower_Case_Keyword;
989 -----------------------------
990 -- Require_Following_Space --
991 -----------------------------
993 procedure Require_Following_Space is
994 begin
995 if Source (Scan_Ptr) > ' ' then
996 Error_Space_Required (Scan_Ptr);
997 end if;
998 end Require_Following_Space;
1000 -----------------------------
1001 -- Require_Preceding_Space --
1002 -----------------------------
1004 procedure Require_Preceding_Space is
1005 begin
1006 if Token_Ptr > Source_First (Current_Source_File)
1007 and then Source (Token_Ptr - 1) > ' '
1008 then
1009 Error_Space_Required (Token_Ptr);
1010 end if;
1011 end Require_Preceding_Space;
1013 end Styleg;