2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ada / scng.adb
blob76f63f9353b2f5caba00add94e8d6d45f39e4714
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S C N G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2008, 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 with Csets; use Csets;
27 with Err_Vars; use Err_Vars;
28 with Hostparm; use Hostparm;
29 with Namet; use Namet;
30 with Opt; use Opt;
31 with Scans; use Scans;
32 with Sinput; use Sinput;
33 with Snames; use Snames;
34 with Stringt; use Stringt;
35 with Stylesw; use Stylesw;
36 with Uintp; use Uintp;
37 with Urealp; use Urealp;
38 with Widechar; use Widechar;
40 with System.CRC32;
41 with System.UTF_32; use System.UTF_32;
42 with System.WCh_Con; use System.WCh_Con;
44 package body Scng is
46 use ASCII;
47 -- Make control characters visible
49 Special_Characters : array (Character) of Boolean := (others => False);
50 -- For characters that are Special token, the value is True
52 Comment_Is_Token : Boolean := False;
53 -- True if comments are tokens
55 End_Of_Line_Is_Token : Boolean := False;
56 -- True if End_Of_Line is a token
58 -----------------------
59 -- Local Subprograms --
60 -----------------------
62 procedure Accumulate_Token_Checksum;
63 pragma Inline (Accumulate_Token_Checksum);
65 procedure Accumulate_Checksum (C : Character);
66 pragma Inline (Accumulate_Checksum);
67 -- This routine accumulates the checksum given character C. During the
68 -- scanning of a source file, this routine is called with every character
69 -- in the source, excluding blanks, and all control characters (except
70 -- that ESC is included in the checksum). Upper case letters not in string
71 -- literals are folded by the caller. See Sinput spec for the documentation
72 -- of the checksum algorithm. Note: checksum values are only used if we
73 -- generate code, so it is not necessary to worry about making the right
74 -- sequence of calls in any error situation.
76 procedure Accumulate_Checksum (C : Char_Code);
77 pragma Inline (Accumulate_Checksum);
78 -- This version is identical, except that the argument, C, is a character
79 -- code value instead of a character. This is used when wide characters
80 -- are scanned. We use the character code rather than the ASCII characters
81 -- so that the checksum is independent of wide character encoding method.
83 procedure Initialize_Checksum;
84 pragma Inline (Initialize_Checksum);
85 -- Initialize checksum value
87 -------------------------
88 -- Accumulate_Checksum --
89 -------------------------
91 procedure Accumulate_Checksum (C : Character) is
92 begin
93 System.CRC32.Update (System.CRC32.CRC32 (Checksum), C);
94 end Accumulate_Checksum;
96 procedure Accumulate_Checksum (C : Char_Code) is
97 begin
98 if C > 16#FFFF# then
99 Accumulate_Checksum (Character'Val (C / 2 ** 24));
100 Accumulate_Checksum (Character'Val ((C / 2 ** 16) mod 256));
101 Accumulate_Checksum (Character'Val ((C / 256) mod 256));
102 else
103 Accumulate_Checksum (Character'Val (C / 256));
104 end if;
106 Accumulate_Checksum (Character'Val (C mod 256));
107 end Accumulate_Checksum;
109 -------------------------------
110 -- Accumulate_Token_Checksum --
111 -------------------------------
113 procedure Accumulate_Token_Checksum is
114 begin
115 System.CRC32.Update
116 (System.CRC32.CRC32 (Checksum),
117 Character'Val (Token_Type'Pos (Token)));
118 end Accumulate_Token_Checksum;
120 ----------------------------
121 -- Determine_Token_Casing --
122 ----------------------------
124 function Determine_Token_Casing return Casing_Type is
125 begin
126 return Determine_Casing (Source (Token_Ptr .. Scan_Ptr - 1));
127 end Determine_Token_Casing;
129 -------------------------
130 -- Initialize_Checksum --
131 -------------------------
133 procedure Initialize_Checksum is
134 begin
135 System.CRC32.Initialize (System.CRC32.CRC32 (Checksum));
136 end Initialize_Checksum;
138 ------------------------
139 -- Initialize_Scanner --
140 ------------------------
142 procedure Initialize_Scanner (Index : Source_File_Index) is
143 begin
144 -- Establish reserved words
146 Scans.Initialize_Ada_Keywords;
148 -- Initialize scan control variables
150 Current_Source_File := Index;
151 Source := Source_Text (Current_Source_File);
152 Scan_Ptr := Source_First (Current_Source_File);
153 Token := No_Token;
154 Token_Ptr := Scan_Ptr;
155 Current_Line_Start := Scan_Ptr;
156 Token_Node := Empty;
157 Token_Name := No_Name;
158 Start_Column := Set_Start_Column;
159 First_Non_Blank_Location := Scan_Ptr;
161 Initialize_Checksum;
162 Wide_Char_Byte_Count := 0;
164 -- Do not call Scan, otherwise the License stuff does not work in Scn
166 end Initialize_Scanner;
168 ------------------------------
169 -- Reset_Special_Characters --
170 ------------------------------
172 procedure Reset_Special_Characters is
173 begin
174 Special_Characters := (others => False);
175 end Reset_Special_Characters;
177 ----------
178 -- Scan --
179 ----------
181 procedure Scan is
183 Start_Of_Comment : Source_Ptr;
184 -- Record start of comment position
186 Underline_Found : Boolean;
187 -- During scanning of an identifier, set to True if last character
188 -- scanned was an underline or other punctuation character. This
189 -- is used to flag the error of two underlines/punctuations in a
190 -- row or ending an identifier with a underline/punctuation. Here
191 -- punctuation means any UTF_32 character in the Unicode category
192 -- Punctuation,Connector.
194 Wptr : Source_Ptr;
195 -- Used to remember start of last wide character scanned
197 procedure Check_End_Of_Line;
198 -- Called when end of line encountered. Checks that line is not too
199 -- long, and that other style checks for the end of line are met.
201 function Double_Char_Token (C : Character) return Boolean;
202 -- This function is used for double character tokens like := or <>. It
203 -- checks if the character following Source (Scan_Ptr) is C, and if so
204 -- bumps Scan_Ptr past the pair of characters and returns True. A space
205 -- between the two characters is also recognized with an appropriate
206 -- error message being issued. If C is not present, False is returned.
207 -- Note that Double_Char_Token can only be used for tokens defined in
208 -- the Ada syntax (it's use for error cases like && is not appropriate
209 -- since we do not want a junk message for a case like &-space-&).
211 procedure Error_Illegal_Character;
212 -- Give illegal character error, Scan_Ptr points to character. On
213 -- return, Scan_Ptr is bumped past the illegal character.
215 procedure Error_Illegal_Wide_Character;
216 -- Give illegal wide character message. On return, Scan_Ptr is bumped
217 -- past the illegal character, which may still leave us pointing to
218 -- junk, not much we can do if the escape sequence is messed up!
220 procedure Error_Long_Line;
221 -- Signal error of excessively long line
223 procedure Error_No_Double_Underline;
224 -- Signal error of two underline or punctuation characters in a row.
225 -- Called with Scan_Ptr pointing to second underline/punctuation char.
227 procedure Nlit;
228 -- This is the procedure for scanning out numeric literals. On entry,
229 -- Scan_Ptr points to the digit that starts the numeric literal (the
230 -- checksum for this character has not been accumulated yet). On return
231 -- Scan_Ptr points past the last character of the numeric literal, Token
232 -- and Token_Node are set appropriately, and the checksum is updated.
234 procedure Slit;
235 -- This is the procedure for scanning out string literals. On entry,
236 -- Scan_Ptr points to the opening string quote (the checksum for this
237 -- character has not been accumulated yet). On return Scan_Ptr points
238 -- past the closing quote of the string literal, Token and Token_Node
239 -- are set appropriately, and the checksum is updated.
241 -----------------------
242 -- Check_End_Of_Line --
243 -----------------------
245 procedure Check_End_Of_Line is
246 Len : constant Int :=
247 Int (Scan_Ptr) -
248 Int (Current_Line_Start) -
249 Wide_Char_Byte_Count;
251 begin
252 if Style_Check then
253 Style.Check_Line_Terminator (Len);
254 end if;
256 -- Deal with checking maximum line length
258 if Style_Check and Style_Check_Max_Line_Length then
259 Style.Check_Line_Max_Length (Len);
261 -- If style checking is inactive, check maximum line length against
262 -- standard value.
264 elsif Len > Max_Line_Length then
265 Error_Long_Line;
266 end if;
268 -- Now one more checking circuit. Normally we are only enforcing a
269 -- limit of physical characters, with tabs counting as one character.
270 -- But if after tab expansion we would have a total line length that
271 -- exceeded 32766, that would really cause trouble, because column
272 -- positions would exceed the maximum we allow for a column count.
273 -- Note: the limit is 32766 rather than 32767, since we use a value
274 -- of 32767 for special purposes (see Sinput). Now we really do not
275 -- want to go messing with tabs in the normal case, so what we do is
276 -- to check for a line that has more than 4096 physical characters.
277 -- Any shorter line could not be a problem, even if it was all tabs.
279 if Len >= 4096 then
280 declare
281 Col : Natural;
282 Ptr : Source_Ptr;
284 begin
285 Col := 1;
286 Ptr := Current_Line_Start;
287 loop
288 exit when Ptr = Scan_Ptr;
290 if Source (Ptr) = ASCII.HT then
291 Col := (Col - 1 + 8) / 8 * 8 + 1;
292 else
293 Col := Col + 1;
294 end if;
296 if Col > 32766 then
297 Error_Msg
298 ("this line is longer than 32766 characters",
299 Current_Line_Start);
300 raise Unrecoverable_Error;
301 end if;
303 Ptr := Ptr + 1;
304 end loop;
305 end;
306 end if;
308 -- Reset wide character byte count for next line
310 Wide_Char_Byte_Count := 0;
311 end Check_End_Of_Line;
313 -----------------------
314 -- Double_Char_Token --
315 -----------------------
317 function Double_Char_Token (C : Character) return Boolean is
318 begin
319 if Source (Scan_Ptr + 1) = C then
320 Accumulate_Checksum (C);
321 Scan_Ptr := Scan_Ptr + 2;
322 return True;
324 elsif Source (Scan_Ptr + 1) = ' '
325 and then Source (Scan_Ptr + 2) = C
326 then
327 Scan_Ptr := Scan_Ptr + 1;
328 Error_Msg_S ("no space allowed here");
329 Scan_Ptr := Scan_Ptr + 2;
330 return True;
332 else
333 return False;
334 end if;
335 end Double_Char_Token;
337 -----------------------------
338 -- Error_Illegal_Character --
339 -----------------------------
341 procedure Error_Illegal_Character is
342 begin
343 Error_Msg_S ("illegal character");
344 Scan_Ptr := Scan_Ptr + 1;
345 end Error_Illegal_Character;
347 ----------------------------------
348 -- Error_Illegal_Wide_Character --
349 ----------------------------------
351 procedure Error_Illegal_Wide_Character is
352 begin
353 Error_Msg ("illegal wide character", Wptr);
354 end Error_Illegal_Wide_Character;
356 ---------------------
357 -- Error_Long_Line --
358 ---------------------
360 procedure Error_Long_Line is
361 begin
362 Error_Msg
363 ("this line is too long",
364 Current_Line_Start + Source_Ptr (Max_Line_Length));
365 end Error_Long_Line;
367 -------------------------------
368 -- Error_No_Double_Underline --
369 -------------------------------
371 procedure Error_No_Double_Underline is
372 begin
373 Underline_Found := False;
375 -- There are four cases, and we special case the messages
377 if Source (Scan_Ptr) = '_' then
378 if Source (Scan_Ptr - 1) = '_' then
379 Error_Msg_S
380 ("two consecutive underlines not permitted");
381 else
382 Error_Msg_S
383 ("underline cannot follow punctuation character");
384 end if;
386 else
387 if Source (Scan_Ptr - 1) = '_' then
388 Error_Msg_S
389 ("punctuation character cannot follow underline");
390 else
391 Error_Msg_S
392 ("two consecutive punctuation characters not permitted");
393 end if;
394 end if;
395 end Error_No_Double_Underline;
397 ----------
398 -- Nlit --
399 ----------
401 procedure Nlit is
403 C : Character;
404 -- Current source program character
406 Base_Char : Character;
407 -- Either # or : (character at start of based number)
409 Base : Int;
410 -- Value of base
412 UI_Base : Uint;
413 -- Value of base in Uint format
415 UI_Int_Value : Uint;
416 -- Value of integer scanned by Scan_Integer in Uint format
418 UI_Num_Value : Uint;
419 -- Value of integer in numeric value being scanned
421 Scale : Int;
422 -- Scale value for real literal
424 UI_Scale : Uint;
425 -- Scale in Uint format
427 Exponent_Is_Negative : Boolean;
428 -- Set true for negative exponent
430 Extended_Digit_Value : Int;
431 -- Extended digit value
433 Point_Scanned : Boolean;
434 -- Flag for decimal point scanned in numeric literal
436 -----------------------
437 -- Local Subprograms --
438 -----------------------
440 procedure Error_Digit_Expected;
441 -- Signal error of bad digit, Scan_Ptr points to the location at
442 -- which the digit was expected on input, and is unchanged on return.
444 procedure Scan_Integer;
445 -- Procedure to scan integer literal. On entry, Scan_Ptr points to a
446 -- digit, on exit Scan_Ptr points past the last character of the
447 -- integer.
449 -- For each digit encountered, UI_Int_Value is multiplied by 10, and
450 -- the value of the digit added to the result. In addition, the
451 -- value in Scale is decremented by one for each actual digit
452 -- scanned.
454 --------------------------
455 -- Error_Digit_Expected --
456 --------------------------
458 procedure Error_Digit_Expected is
459 begin
460 Error_Msg_S ("digit expected");
461 end Error_Digit_Expected;
463 ------------------
464 -- Scan_Integer --
465 ------------------
467 procedure Scan_Integer is
468 C : Character;
469 -- Next character scanned
471 begin
472 C := Source (Scan_Ptr);
474 -- Loop through digits (allowing underlines)
476 loop
477 Accumulate_Checksum (C);
478 UI_Int_Value :=
479 UI_Int_Value * 10 + (Character'Pos (C) - Character'Pos ('0'));
480 Scan_Ptr := Scan_Ptr + 1;
481 Scale := Scale - 1;
482 C := Source (Scan_Ptr);
484 -- Case of underline encountered
486 if C = '_' then
488 -- We do not accumulate the '_' in the checksum, so that
489 -- 1_234 is equivalent to 1234, and does not trigger
490 -- compilation for "minimal recompilation" (gnatmake -m).
492 loop
493 Scan_Ptr := Scan_Ptr + 1;
494 C := Source (Scan_Ptr);
495 exit when C /= '_';
496 Error_No_Double_Underline;
497 end loop;
499 if C not in '0' .. '9' then
500 Error_Digit_Expected;
501 exit;
502 end if;
504 else
505 exit when C not in '0' .. '9';
506 end if;
507 end loop;
508 end Scan_Integer;
510 -- Start of Processing for Nlit
512 begin
513 Base := 10;
514 UI_Base := Uint_10;
515 UI_Int_Value := Uint_0;
516 Scale := 0;
517 Scan_Integer;
518 Point_Scanned := False;
519 UI_Num_Value := UI_Int_Value;
521 -- Various possibilities now for continuing the literal are period,
522 -- E/e (for exponent), or :/# (for based literal).
524 Scale := 0;
525 C := Source (Scan_Ptr);
527 if C = '.' then
529 -- Scan out point, but do not scan past .. which is a range
530 -- sequence, and must not be eaten up scanning a numeric literal.
532 while C = '.' and then Source (Scan_Ptr + 1) /= '.' loop
533 Accumulate_Checksum ('.');
535 if Point_Scanned then
536 Error_Msg_S ("duplicate point ignored");
537 end if;
539 Point_Scanned := True;
540 Scan_Ptr := Scan_Ptr + 1;
541 C := Source (Scan_Ptr);
543 if C not in '0' .. '9' then
544 Error_Msg
545 ("real literal cannot end with point", Scan_Ptr - 1);
546 else
547 Scan_Integer;
548 UI_Num_Value := UI_Int_Value;
549 end if;
550 end loop;
552 -- Based literal case. The base is the value we already scanned.
553 -- In the case of colon, we insist that the following character
554 -- is indeed an extended digit or a period. This catches a number
555 -- of common errors, as well as catching the well known tricky
556 -- bug otherwise arising from "x : integer range 1 .. 10:= 6;"
558 elsif C = '#'
559 or else (C = ':' and then
560 (Source (Scan_Ptr + 1) = '.'
561 or else
562 Source (Scan_Ptr + 1) in '0' .. '9'
563 or else
564 Source (Scan_Ptr + 1) in 'A' .. 'Z'
565 or else
566 Source (Scan_Ptr + 1) in 'a' .. 'z'))
567 then
568 if C = ':' then
569 Obsolescent_Check (Scan_Ptr);
571 if Warn_On_Obsolescent_Feature then
572 Error_Msg_S
573 ("use of "":"" is an obsolescent feature (RM J.2(3))?");
574 Error_Msg_S
575 ("\use ""'#"" instead?");
576 end if;
577 end if;
579 Accumulate_Checksum (C);
580 Base_Char := C;
581 UI_Base := UI_Int_Value;
583 if UI_Base < 2 or else UI_Base > 16 then
584 Error_Msg_SC ("base not 2-16");
585 UI_Base := Uint_16;
586 end if;
588 Base := UI_To_Int (UI_Base);
589 Scan_Ptr := Scan_Ptr + 1;
591 -- Scan out extended integer [. integer]
593 C := Source (Scan_Ptr);
594 UI_Int_Value := Uint_0;
595 Scale := 0;
597 loop
598 if C in '0' .. '9' then
599 Accumulate_Checksum (C);
600 Extended_Digit_Value :=
601 Int'(Character'Pos (C)) - Int'(Character'Pos ('0'));
603 elsif C in 'A' .. 'F' then
604 Accumulate_Checksum (Character'Val (Character'Pos (C) + 32));
605 Extended_Digit_Value :=
606 Int'(Character'Pos (C)) - Int'(Character'Pos ('A')) + 10;
608 elsif C in 'a' .. 'f' then
609 Accumulate_Checksum (C);
610 Extended_Digit_Value :=
611 Int'(Character'Pos (C)) - Int'(Character'Pos ('a')) + 10;
613 else
614 Error_Msg_S ("extended digit expected");
615 exit;
616 end if;
618 if Extended_Digit_Value >= Base then
619 Error_Msg_S ("digit '>= base");
620 end if;
622 UI_Int_Value := UI_Int_Value * UI_Base + Extended_Digit_Value;
623 Scale := Scale - 1;
624 Scan_Ptr := Scan_Ptr + 1;
625 C := Source (Scan_Ptr);
627 if C = '_' then
628 loop
629 Accumulate_Checksum ('_');
630 Scan_Ptr := Scan_Ptr + 1;
631 C := Source (Scan_Ptr);
632 exit when C /= '_';
633 Error_No_Double_Underline;
634 end loop;
636 elsif C = '.' then
637 Accumulate_Checksum ('.');
639 if Point_Scanned then
640 Error_Msg_S ("duplicate point ignored");
641 end if;
643 Scan_Ptr := Scan_Ptr + 1;
644 C := Source (Scan_Ptr);
645 Point_Scanned := True;
646 Scale := 0;
648 elsif C = Base_Char then
649 Accumulate_Checksum (C);
650 Scan_Ptr := Scan_Ptr + 1;
651 exit;
653 elsif C = '#' or else C = ':' then
654 Error_Msg_S ("based number delimiters must match");
655 Scan_Ptr := Scan_Ptr + 1;
656 exit;
658 elsif not Identifier_Char (C) then
659 if Base_Char = '#' then
660 Error_Msg_S ("missing '#");
661 else
662 Error_Msg_S ("missing ':");
663 end if;
665 exit;
666 end if;
668 end loop;
670 UI_Num_Value := UI_Int_Value;
671 end if;
673 -- Scan out exponent
675 if not Point_Scanned then
676 Scale := 0;
677 UI_Scale := Uint_0;
678 else
679 UI_Scale := UI_From_Int (Scale);
680 end if;
682 if Source (Scan_Ptr) = 'e' or else Source (Scan_Ptr) = 'E' then
683 Accumulate_Checksum ('e');
684 Scan_Ptr := Scan_Ptr + 1;
685 Exponent_Is_Negative := False;
687 if Source (Scan_Ptr) = '+' then
688 Accumulate_Checksum ('+');
689 Scan_Ptr := Scan_Ptr + 1;
691 elsif Source (Scan_Ptr) = '-' then
692 Accumulate_Checksum ('-');
694 if not Point_Scanned then
695 Error_Msg_S
696 ("negative exponent not allowed for integer literal");
697 else
698 Exponent_Is_Negative := True;
699 end if;
701 Scan_Ptr := Scan_Ptr + 1;
702 end if;
704 UI_Int_Value := Uint_0;
706 if Source (Scan_Ptr) in '0' .. '9' then
707 Scan_Integer;
708 else
709 Error_Digit_Expected;
710 end if;
712 if Exponent_Is_Negative then
713 UI_Scale := UI_Scale - UI_Int_Value;
714 else
715 UI_Scale := UI_Scale + UI_Int_Value;
716 end if;
717 end if;
719 -- Case of real literal to be returned
721 if Point_Scanned then
722 Token := Tok_Real_Literal;
723 Real_Literal_Value :=
724 UR_From_Components (
725 Num => UI_Num_Value,
726 Den => -UI_Scale,
727 Rbase => Base);
729 -- Case of integer literal to be returned
731 else
732 Token := Tok_Integer_Literal;
734 if UI_Scale = 0 then
735 Int_Literal_Value := UI_Num_Value;
737 -- Avoid doing possibly expensive calculations in cases like
738 -- parsing 163E800_000# when semantics will not be done anyway.
739 -- This is especially useful when parsing garbled input.
741 elsif Operating_Mode /= Check_Syntax
742 and then (Serious_Errors_Detected = 0 or else Try_Semantics)
743 then
744 Int_Literal_Value := UI_Num_Value * UI_Base ** UI_Scale;
746 else
747 Int_Literal_Value := No_Uint;
748 end if;
749 end if;
751 Accumulate_Token_Checksum;
753 return;
754 end Nlit;
756 ----------
757 -- Slit --
758 ----------
760 procedure Slit is
762 Delimiter : Character;
763 -- Delimiter (first character of string)
765 C : Character;
766 -- Current source program character
768 Code : Char_Code;
769 -- Current character code value
771 Err : Boolean;
772 -- Error flag for Scan_Wide call
774 procedure Error_Bad_String_Char;
775 -- Signal bad character in string/character literal. On entry
776 -- Scan_Ptr points to the improper character encountered during the
777 -- scan. Scan_Ptr is not modified, so it still points to the bad
778 -- character on return.
780 procedure Error_Unterminated_String;
781 -- Procedure called if a line terminator character is encountered
782 -- during scanning a string, meaning that the string is not properly
783 -- terminated.
785 procedure Set_String;
786 -- Procedure used to distinguish between string and operator symbol.
787 -- On entry the string has been scanned out, and its characters
788 -- start at Token_Ptr and end one character before Scan_Ptr. On exit
789 -- Token is set to Tok_String_Literal or Tok_Operator_Symbol as
790 -- appropriate, and Token_Node is appropriately initialized. In
791 -- addition, in the operator symbol case, Token_Name is
792 -- appropriately set.
794 ---------------------------
795 -- Error_Bad_String_Char --
796 ---------------------------
798 procedure Error_Bad_String_Char is
799 C : constant Character := Source (Scan_Ptr);
801 begin
802 if C = HT then
803 Error_Msg_S ("horizontal tab not allowed in string");
805 elsif C = VT or else C = FF then
806 Error_Msg_S ("format effector not allowed in string");
808 elsif C in Upper_Half_Character then
809 Error_Msg_S ("(Ada 83) upper half character not allowed");
811 else
812 Error_Msg_S ("control character not allowed in string");
813 end if;
814 end Error_Bad_String_Char;
816 -------------------------------
817 -- Error_Unterminated_String --
818 -------------------------------
820 procedure Error_Unterminated_String is
821 begin
822 -- An interesting little refinement. Consider the following
823 -- examples:
825 -- A := "this is an unterminated string;
826 -- A := "this is an unterminated string &
827 -- P(A, "this is a parameter that didn't get terminated);
829 -- We fiddle a little to do slightly better placement in these
830 -- cases also if there is white space at the end of the line we
831 -- place the flag at the start of this white space, not at the
832 -- end. Note that we only have to test for blanks, since tabs
833 -- aren't allowed in strings in the first place and would have
834 -- caused an error message.
836 -- Two more cases that we treat specially are:
838 -- A := "this string uses the wrong terminator'
839 -- A := "this string uses the wrong terminator' &
841 -- In these cases we give a different error message as well
843 -- We actually reposition the scan pointer to the point where we
844 -- place the flag in these cases, since it seems a better bet on
845 -- the original intention.
847 while Source (Scan_Ptr - 1) = ' '
848 or else Source (Scan_Ptr - 1) = '&'
849 loop
850 Scan_Ptr := Scan_Ptr - 1;
851 Unstore_String_Char;
852 end loop;
854 -- Check for case of incorrect string terminator, but single quote
855 -- is not considered incorrect if the opening terminator misused
856 -- a single quote (error message already given).
858 if Delimiter /= '''
859 and then Source (Scan_Ptr - 1) = '''
860 then
861 Unstore_String_Char;
862 Error_Msg
863 ("incorrect string terminator character", Scan_Ptr - 1);
864 return;
865 end if;
867 if Source (Scan_Ptr - 1) = ';' then
868 Scan_Ptr := Scan_Ptr - 1;
869 Unstore_String_Char;
871 if Source (Scan_Ptr - 1) = ')' then
872 Scan_Ptr := Scan_Ptr - 1;
873 Unstore_String_Char;
874 end if;
875 end if;
877 Error_Msg_S ("missing string quote");
878 end Error_Unterminated_String;
880 ----------------
881 -- Set_String --
882 ----------------
884 procedure Set_String is
885 Slen : constant Int := Int (Scan_Ptr - Token_Ptr - 2);
886 C1 : Character;
887 C2 : Character;
888 C3 : Character;
890 begin
891 -- Token_Name is currently set to Error_Name. The following
892 -- section of code resets Token_Name to the proper Name_Op_xx
893 -- value if the string is a valid operator symbol, otherwise it is
894 -- left set to Error_Name.
896 if Slen = 1 then
897 C1 := Source (Token_Ptr + 1);
899 case C1 is
900 when '=' =>
901 Token_Name := Name_Op_Eq;
903 when '>' =>
904 Token_Name := Name_Op_Gt;
906 when '<' =>
907 Token_Name := Name_Op_Lt;
909 when '+' =>
910 Token_Name := Name_Op_Add;
912 when '-' =>
913 Token_Name := Name_Op_Subtract;
915 when '&' =>
916 Token_Name := Name_Op_Concat;
918 when '*' =>
919 Token_Name := Name_Op_Multiply;
921 when '/' =>
922 Token_Name := Name_Op_Divide;
924 when others =>
925 null;
926 end case;
928 elsif Slen = 2 then
929 C1 := Source (Token_Ptr + 1);
930 C2 := Source (Token_Ptr + 2);
932 if C1 = '*' and then C2 = '*' then
933 Token_Name := Name_Op_Expon;
935 elsif C2 = '=' then
937 if C1 = '/' then
938 Token_Name := Name_Op_Ne;
939 elsif C1 = '<' then
940 Token_Name := Name_Op_Le;
941 elsif C1 = '>' then
942 Token_Name := Name_Op_Ge;
943 end if;
945 elsif (C1 = 'O' or else C1 = 'o') and then -- OR
946 (C2 = 'R' or else C2 = 'r')
947 then
948 Token_Name := Name_Op_Or;
949 end if;
951 elsif Slen = 3 then
952 C1 := Source (Token_Ptr + 1);
953 C2 := Source (Token_Ptr + 2);
954 C3 := Source (Token_Ptr + 3);
956 if (C1 = 'A' or else C1 = 'a') and then -- AND
957 (C2 = 'N' or else C2 = 'n') and then
958 (C3 = 'D' or else C3 = 'd')
959 then
960 Token_Name := Name_Op_And;
962 elsif (C1 = 'A' or else C1 = 'a') and then -- ABS
963 (C2 = 'B' or else C2 = 'b') and then
964 (C3 = 'S' or else C3 = 's')
965 then
966 Token_Name := Name_Op_Abs;
968 elsif (C1 = 'M' or else C1 = 'm') and then -- MOD
969 (C2 = 'O' or else C2 = 'o') and then
970 (C3 = 'D' or else C3 = 'd')
971 then
972 Token_Name := Name_Op_Mod;
974 elsif (C1 = 'N' or else C1 = 'n') and then -- NOT
975 (C2 = 'O' or else C2 = 'o') and then
976 (C3 = 'T' or else C3 = 't')
977 then
978 Token_Name := Name_Op_Not;
980 elsif (C1 = 'R' or else C1 = 'r') and then -- REM
981 (C2 = 'E' or else C2 = 'e') and then
982 (C3 = 'M' or else C3 = 'm')
983 then
984 Token_Name := Name_Op_Rem;
986 elsif (C1 = 'X' or else C1 = 'x') and then -- XOR
987 (C2 = 'O' or else C2 = 'o') and then
988 (C3 = 'R' or else C3 = 'r')
989 then
990 Token_Name := Name_Op_Xor;
991 end if;
993 end if;
995 -- If it is an operator symbol, then Token_Name is set. If it is
996 -- some other string value, then Token_Name still contains
997 -- Error_Name.
999 if Token_Name = Error_Name then
1000 Token := Tok_String_Literal;
1002 else
1003 Token := Tok_Operator_Symbol;
1004 end if;
1005 end Set_String;
1007 -- Start of processing for Slit
1009 begin
1010 -- On entry, Scan_Ptr points to the opening character of the string
1011 -- which is either a percent, double quote, or apostrophe (single
1012 -- quote). The latter case is an error detected by the character
1013 -- literal circuit.
1015 Delimiter := Source (Scan_Ptr);
1016 Accumulate_Checksum (Delimiter);
1017 Start_String;
1018 Scan_Ptr := Scan_Ptr + 1;
1020 -- Loop to scan out characters of string literal
1022 loop
1023 C := Source (Scan_Ptr);
1025 if C = Delimiter then
1026 Accumulate_Checksum (C);
1027 Scan_Ptr := Scan_Ptr + 1;
1028 exit when Source (Scan_Ptr) /= Delimiter;
1029 Code := Get_Char_Code (C);
1030 Accumulate_Checksum (C);
1031 Scan_Ptr := Scan_Ptr + 1;
1033 else
1034 if C = '"' and then Delimiter = '%' then
1035 Error_Msg_S
1036 ("quote not allowed in percent delimited string");
1037 Code := Get_Char_Code (C);
1038 Scan_Ptr := Scan_Ptr + 1;
1040 elsif (C = ESC
1041 and then Wide_Character_Encoding_Method
1042 in WC_ESC_Encoding_Method)
1043 or else (C in Upper_Half_Character
1044 and then Upper_Half_Encoding)
1045 or else (C = '['
1046 and then Source (Scan_Ptr + 1) = '"'
1047 and then Identifier_Char (Source (Scan_Ptr + 2)))
1048 then
1049 Wptr := Scan_Ptr;
1050 Scan_Wide (Source, Scan_Ptr, Code, Err);
1052 if Err then
1053 Error_Illegal_Wide_Character;
1054 Code := Get_Char_Code (' ');
1055 end if;
1057 Accumulate_Checksum (Code);
1059 -- In Ada 95 mode we allow any wide characters in a string
1060 -- but in Ada 2005, the set of characters allowed has been
1061 -- restricted to graphic characters.
1063 if Ada_Version >= Ada_05
1064 and then Is_UTF_32_Non_Graphic (UTF_32 (Code))
1065 then
1066 Error_Msg
1067 ("(Ada 2005) non-graphic character not permitted " &
1068 "in string literal", Wptr);
1069 end if;
1071 else
1072 Accumulate_Checksum (C);
1074 if C not in Graphic_Character then
1075 if C in Line_Terminator then
1076 Error_Unterminated_String;
1077 exit;
1079 elsif C in Upper_Half_Character then
1080 if Ada_Version = Ada_83 then
1081 Error_Bad_String_Char;
1082 end if;
1084 else
1085 Error_Bad_String_Char;
1086 end if;
1087 end if;
1089 Code := Get_Char_Code (C);
1090 Scan_Ptr := Scan_Ptr + 1;
1091 end if;
1092 end if;
1094 Store_String_Char (Code);
1096 if not In_Character_Range (Code) then
1097 Wide_Character_Found := True;
1098 end if;
1099 end loop;
1101 String_Literal_Id := End_String;
1102 Set_String;
1103 return;
1104 end Slit;
1106 -- Start of processing for Scan
1108 begin
1109 Prev_Token := Token;
1110 Prev_Token_Ptr := Token_Ptr;
1111 Token_Name := Error_Name;
1113 -- The following loop runs more than once only if a format effector
1114 -- (tab, vertical tab, form feed, line feed, carriage return) is
1115 -- encountered and skipped, or some error situation, such as an
1116 -- illegal character, is encountered.
1118 <<Scan_Next_Character>>
1120 loop
1121 -- Skip past blanks, loop is opened up for speed
1123 while Source (Scan_Ptr) = ' ' loop
1124 if Source (Scan_Ptr + 1) /= ' ' then
1125 Scan_Ptr := Scan_Ptr + 1;
1126 exit;
1127 end if;
1129 if Source (Scan_Ptr + 2) /= ' ' then
1130 Scan_Ptr := Scan_Ptr + 2;
1131 exit;
1132 end if;
1134 if Source (Scan_Ptr + 3) /= ' ' then
1135 Scan_Ptr := Scan_Ptr + 3;
1136 exit;
1137 end if;
1139 if Source (Scan_Ptr + 4) /= ' ' then
1140 Scan_Ptr := Scan_Ptr + 4;
1141 exit;
1142 end if;
1144 if Source (Scan_Ptr + 5) /= ' ' then
1145 Scan_Ptr := Scan_Ptr + 5;
1146 exit;
1147 end if;
1149 if Source (Scan_Ptr + 6) /= ' ' then
1150 Scan_Ptr := Scan_Ptr + 6;
1151 exit;
1152 end if;
1154 if Source (Scan_Ptr + 7) /= ' ' then
1155 Scan_Ptr := Scan_Ptr + 7;
1156 exit;
1157 end if;
1159 Scan_Ptr := Scan_Ptr + 8;
1160 end loop;
1162 -- We are now at a non-blank character, which is the first character
1163 -- of the token we will scan, and hence the value of Token_Ptr.
1165 Token_Ptr := Scan_Ptr;
1167 -- Here begins the main case statement which transfers control on the
1168 -- basis of the non-blank character we have encountered.
1170 case Source (Scan_Ptr) is
1172 -- Line terminator characters
1174 when CR | LF | FF | VT =>
1175 goto Scan_Line_Terminator;
1177 -- Horizontal tab, just skip past it
1179 when HT =>
1180 if Style_Check then
1181 Style.Check_HT;
1182 end if;
1184 Scan_Ptr := Scan_Ptr + 1;
1186 -- End of file character, treated as an end of file only if it is
1187 -- the last character in the buffer, otherwise it is ignored.
1189 when EOF =>
1190 if Scan_Ptr = Source_Last (Current_Source_File) then
1191 Check_End_Of_Line;
1193 if Style_Check then
1194 Style.Check_EOF;
1195 end if;
1197 Token := Tok_EOF;
1198 return;
1199 else
1200 Scan_Ptr := Scan_Ptr + 1;
1201 end if;
1203 -- Ampersand
1205 when '&' =>
1206 Accumulate_Checksum ('&');
1208 if Source (Scan_Ptr + 1) = '&' then
1209 Error_Msg_S ("'&'& should be `AND THEN`");
1210 Scan_Ptr := Scan_Ptr + 2;
1211 Token := Tok_And;
1212 return;
1214 else
1215 Scan_Ptr := Scan_Ptr + 1;
1216 Token := Tok_Ampersand;
1217 return;
1218 end if;
1220 -- Asterisk (can be multiplication operator or double asterisk which
1221 -- is the exponentiation compound delimiter).
1223 when '*' =>
1224 Accumulate_Checksum ('*');
1226 if Source (Scan_Ptr + 1) = '*' then
1227 Accumulate_Checksum ('*');
1228 Scan_Ptr := Scan_Ptr + 2;
1229 Token := Tok_Double_Asterisk;
1230 return;
1232 else
1233 Scan_Ptr := Scan_Ptr + 1;
1234 Token := Tok_Asterisk;
1235 return;
1236 end if;
1238 -- Colon, which can either be an isolated colon, or part of an
1239 -- assignment compound delimiter.
1241 when ':' =>
1242 Accumulate_Checksum (':');
1244 if Double_Char_Token ('=') then
1245 Token := Tok_Colon_Equal;
1247 if Style_Check then
1248 Style.Check_Colon_Equal;
1249 end if;
1251 return;
1253 elsif Source (Scan_Ptr + 1) = '-'
1254 and then Source (Scan_Ptr + 2) /= '-'
1255 then
1256 Token := Tok_Colon_Equal;
1257 Error_Msg (":- should be :=", Scan_Ptr);
1258 Scan_Ptr := Scan_Ptr + 2;
1259 return;
1261 else
1262 Scan_Ptr := Scan_Ptr + 1;
1263 Token := Tok_Colon;
1265 if Style_Check then
1266 Style.Check_Colon;
1267 end if;
1269 return;
1270 end if;
1272 -- Left parenthesis
1274 when '(' =>
1275 Accumulate_Checksum ('(');
1276 Scan_Ptr := Scan_Ptr + 1;
1277 Token := Tok_Left_Paren;
1279 if Style_Check then
1280 Style.Check_Left_Paren;
1281 end if;
1283 return;
1285 -- Left bracket
1287 when '[' =>
1288 if Source (Scan_Ptr + 1) = '"' then
1289 goto Scan_Wide_Character;
1291 else
1292 Error_Msg_S ("illegal character, replaced by ""(""");
1293 Scan_Ptr := Scan_Ptr + 1;
1294 Token := Tok_Left_Paren;
1295 return;
1296 end if;
1298 -- Left brace
1300 when '{' =>
1301 Error_Msg_S ("illegal character, replaced by ""(""");
1302 Scan_Ptr := Scan_Ptr + 1;
1303 Token := Tok_Left_Paren;
1304 return;
1306 -- Comma
1308 when ',' =>
1309 Accumulate_Checksum (',');
1310 Scan_Ptr := Scan_Ptr + 1;
1311 Token := Tok_Comma;
1313 if Style_Check then
1314 Style.Check_Comma;
1315 end if;
1317 return;
1319 -- Dot, which is either an isolated period, or part of a double dot
1320 -- compound delimiter sequence. We also check for the case of a
1321 -- digit following the period, to give a better error message.
1323 when '.' =>
1324 Accumulate_Checksum ('.');
1326 if Double_Char_Token ('.') then
1327 Token := Tok_Dot_Dot;
1329 if Style_Check then
1330 Style.Check_Dot_Dot;
1331 end if;
1333 return;
1335 elsif Source (Scan_Ptr + 1) in '0' .. '9' then
1336 Error_Msg_S ("numeric literal cannot start with point");
1337 Scan_Ptr := Scan_Ptr + 1;
1339 else
1340 Scan_Ptr := Scan_Ptr + 1;
1341 Token := Tok_Dot;
1342 return;
1343 end if;
1345 -- Equal, which can either be an equality operator, or part of the
1346 -- arrow (=>) compound delimiter.
1348 when '=' =>
1349 Accumulate_Checksum ('=');
1351 if Double_Char_Token ('>') then
1352 Token := Tok_Arrow;
1354 if Style_Check then
1355 Style.Check_Arrow;
1356 end if;
1358 return;
1360 elsif Source (Scan_Ptr + 1) = '=' then
1361 Error_Msg_S ("== should be =");
1362 Scan_Ptr := Scan_Ptr + 1;
1363 end if;
1365 Scan_Ptr := Scan_Ptr + 1;
1366 Token := Tok_Equal;
1367 return;
1369 -- Greater than, which can be a greater than operator, greater than
1370 -- or equal operator, or first character of a right label bracket.
1372 when '>' =>
1373 Accumulate_Checksum ('>');
1375 if Double_Char_Token ('=') then
1376 Token := Tok_Greater_Equal;
1377 return;
1379 elsif Double_Char_Token ('>') then
1380 Token := Tok_Greater_Greater;
1381 return;
1383 else
1384 Scan_Ptr := Scan_Ptr + 1;
1385 Token := Tok_Greater;
1386 return;
1387 end if;
1389 -- Less than, which can be a less than operator, less than or equal
1390 -- operator, or the first character of a left label bracket, or the
1391 -- first character of a box (<>) compound delimiter.
1393 when '<' =>
1394 Accumulate_Checksum ('<');
1396 if Double_Char_Token ('=') then
1397 Token := Tok_Less_Equal;
1398 return;
1400 elsif Double_Char_Token ('>') then
1401 Token := Tok_Box;
1403 if Style_Check then
1404 Style.Check_Box;
1405 end if;
1407 return;
1409 elsif Double_Char_Token ('<') then
1410 Token := Tok_Less_Less;
1411 return;
1413 else
1414 Scan_Ptr := Scan_Ptr + 1;
1415 Token := Tok_Less;
1416 return;
1417 end if;
1419 -- Minus, which is either a subtraction operator, or the first
1420 -- character of double minus starting a comment
1422 when '-' => Minus_Case : begin
1423 if Source (Scan_Ptr + 1) = '>' then
1424 Error_Msg_S ("invalid token");
1425 Scan_Ptr := Scan_Ptr + 2;
1426 Token := Tok_Arrow;
1427 return;
1429 elsif Source (Scan_Ptr + 1) /= '-' then
1430 Accumulate_Checksum ('-');
1431 Scan_Ptr := Scan_Ptr + 1;
1432 Token := Tok_Minus;
1433 return;
1435 -- Comment
1437 else -- Source (Scan_Ptr + 1) = '-' then
1438 if Style_Check then
1439 Style.Check_Comment;
1440 end if;
1442 Scan_Ptr := Scan_Ptr + 2;
1444 -- If we are in preprocessor mode with Replace_In_Comments set,
1445 -- then we return the "--" as a token on its own.
1447 if Replace_In_Comments then
1448 Token := Tok_Comment;
1449 return;
1450 end if;
1452 -- Otherwise scan out the comment
1454 Start_Of_Comment := Scan_Ptr;
1456 -- Loop to scan comment (this loop runs more than once only if
1457 -- a horizontal tab or other non-graphic character is scanned)
1459 loop
1460 -- Scan to non graphic character (opened up for speed)
1462 -- Note that we just eat left brackets, which means that
1463 -- bracket notation cannot be used for end of line
1464 -- characters in comments. This seems a reasonable choice,
1465 -- since no one would ever use brackets notation in a real
1466 -- program in this situation, and if we allow brackets
1467 -- notation, we forbid some valid comments which contain a
1468 -- brackets sequence that happens to match an end of line
1469 -- character.
1471 loop
1472 exit when Source (Scan_Ptr) not in Graphic_Character;
1473 Scan_Ptr := Scan_Ptr + 1;
1474 exit when Source (Scan_Ptr) not in Graphic_Character;
1475 Scan_Ptr := Scan_Ptr + 1;
1476 exit when Source (Scan_Ptr) not in Graphic_Character;
1477 Scan_Ptr := Scan_Ptr + 1;
1478 exit when Source (Scan_Ptr) not in Graphic_Character;
1479 Scan_Ptr := Scan_Ptr + 1;
1480 exit when Source (Scan_Ptr) not in Graphic_Character;
1481 Scan_Ptr := Scan_Ptr + 1;
1482 end loop;
1484 -- Keep going if horizontal tab
1486 if Source (Scan_Ptr) = HT then
1487 if Style_Check then
1488 Style.Check_HT;
1489 end if;
1491 Scan_Ptr := Scan_Ptr + 1;
1493 -- Terminate scan of comment if line terminator
1495 elsif Source (Scan_Ptr) in Line_Terminator then
1496 exit;
1498 -- Terminate scan of comment if end of file encountered
1499 -- (embedded EOF character or real last character in file)
1501 elsif Source (Scan_Ptr) = EOF then
1502 exit;
1504 -- If we have a wide character, we have to scan it out,
1505 -- because it might be a legitimate line terminator
1507 elsif (Source (Scan_Ptr) = ESC
1508 and then Identifier_Char (ESC))
1509 or else
1510 (Source (Scan_Ptr) in Upper_Half_Character
1511 and then Upper_Half_Encoding)
1512 then
1513 declare
1514 Wptr : constant Source_Ptr := Scan_Ptr;
1515 Code : Char_Code;
1516 Err : Boolean;
1518 begin
1519 Scan_Wide (Source, Scan_Ptr, Code, Err);
1521 -- If not well formed wide character, then just skip
1522 -- past it and ignore it.
1524 if Err then
1525 Scan_Ptr := Wptr + 1;
1527 -- If UTF_32 terminator, terminate comment scan
1529 elsif Is_UTF_32_Line_Terminator (UTF_32 (Code)) then
1530 Scan_Ptr := Wptr;
1531 exit;
1532 end if;
1533 end;
1535 -- Keep going if character in 80-FF range, or is ESC. These
1536 -- characters are allowed in comments by RM-2.1(1), 2.7(2).
1537 -- They are allowed even in Ada 83 mode according to the
1538 -- approved AI. ESC was added to the AI in June 93.
1540 elsif Source (Scan_Ptr) in Upper_Half_Character
1541 or else Source (Scan_Ptr) = ESC
1542 then
1543 Scan_Ptr := Scan_Ptr + 1;
1545 -- Otherwise we have an illegal comment character
1547 else
1548 Error_Illegal_Character;
1549 end if;
1550 end loop;
1552 -- Note that, except when comments are tokens, we do NOT
1553 -- execute a return here, instead we fall through to reexecute
1554 -- the scan loop to look for a token.
1556 if Comment_Is_Token then
1557 Name_Len := Integer (Scan_Ptr - Start_Of_Comment);
1558 Name_Buffer (1 .. Name_Len) :=
1559 String (Source (Start_Of_Comment .. Scan_Ptr - 1));
1560 Comment_Id := Name_Find;
1561 Token := Tok_Comment;
1562 return;
1563 end if;
1564 end if;
1565 end Minus_Case;
1567 -- Double quote starting a string literal
1569 when '"' =>
1570 Slit;
1571 Post_Scan;
1572 return;
1574 -- Percent starting a string literal
1576 when '%' =>
1577 Obsolescent_Check (Token_Ptr);
1579 if Warn_On_Obsolescent_Feature then
1580 Error_Msg_S
1581 ("use of ""'%"" is an obsolescent feature (RM J.2(4))?");
1582 Error_Msg_S
1583 ("\use """""" instead?");
1584 end if;
1586 Slit;
1587 Post_Scan;
1588 return;
1590 -- Apostrophe. This can either be the start of a character literal,
1591 -- or an isolated apostrophe used in a qualified expression or an
1592 -- attribute. We treat it as a character literal if it does not
1593 -- follow a right parenthesis, identifier, the keyword ALL or
1594 -- a literal. This means that we correctly treat constructs like:
1596 -- A := CHARACTER'('A');
1598 -- Note that RM-2.2(7) does not require a separator between
1599 -- "CHARACTER" and "'" in the above.
1601 when ''' => Char_Literal_Case : declare
1602 Code : Char_Code;
1603 Err : Boolean;
1605 begin
1606 Accumulate_Checksum (''');
1607 Scan_Ptr := Scan_Ptr + 1;
1609 -- Here is where we make the test to distinguish the cases. Treat
1610 -- as apostrophe if previous token is an identifier, right paren
1611 -- or the reserved word "all" (latter case as in A.all'Address)
1612 -- (or the reserved word "project" in project files). Also treat
1613 -- it as apostrophe after a literal (this catches some legitimate
1614 -- cases, like A."abs"'Address, and also gives better error
1615 -- behavior for impossible cases like 123'xxx).
1617 if Prev_Token = Tok_Identifier
1618 or else Prev_Token = Tok_Right_Paren
1619 or else Prev_Token = Tok_All
1620 or else Prev_Token = Tok_Project
1621 or else Prev_Token in Token_Class_Literal
1622 then
1623 Token := Tok_Apostrophe;
1625 if Style_Check then
1626 Style.Check_Apostrophe;
1627 end if;
1629 return;
1631 -- Otherwise the apostrophe starts a character literal
1633 else
1634 -- Case of wide character literal
1636 if (Source (Scan_Ptr) = ESC
1637 and then
1638 Wide_Character_Encoding_Method in WC_ESC_Encoding_Method)
1639 or else
1640 (Source (Scan_Ptr) in Upper_Half_Character
1641 and then
1642 Upper_Half_Encoding)
1643 or else
1644 (Source (Scan_Ptr) = '['
1645 and then
1646 Source (Scan_Ptr + 1) = '"')
1647 then
1648 Wptr := Scan_Ptr;
1649 Scan_Wide (Source, Scan_Ptr, Code, Err);
1650 Accumulate_Checksum (Code);
1652 if Err then
1653 Error_Illegal_Wide_Character;
1654 Code := Character'Pos (' ');
1656 -- In Ada 95 mode we allow any wide character in a character
1657 -- literal, but in Ada 2005, the set of characters allowed
1658 -- is restricted to graphic characters.
1660 elsif Ada_Version >= Ada_05
1661 and then Is_UTF_32_Non_Graphic (UTF_32 (Code))
1662 then
1663 Error_Msg
1664 ("(Ada 2005) non-graphic character not permitted " &
1665 "in character literal", Wptr);
1666 end if;
1668 if Source (Scan_Ptr) /= ''' then
1669 Error_Msg_S ("missing apostrophe");
1670 else
1671 Scan_Ptr := Scan_Ptr + 1;
1672 end if;
1674 -- If we do not find a closing quote in the expected place then
1675 -- assume that we have a misguided attempt at a string literal.
1677 -- However, if previous token is RANGE, then we return an
1678 -- apostrophe instead since this gives better error recovery
1680 elsif Source (Scan_Ptr + 1) /= ''' then
1681 if Prev_Token = Tok_Range then
1682 Token := Tok_Apostrophe;
1683 return;
1685 else
1686 Scan_Ptr := Scan_Ptr - 1;
1687 Error_Msg_S
1688 ("strings are delimited by double quote character");
1689 Slit;
1690 Post_Scan;
1691 return;
1692 end if;
1694 -- Otherwise we have a (non-wide) character literal
1696 else
1697 Accumulate_Checksum (Source (Scan_Ptr));
1699 if Source (Scan_Ptr) not in Graphic_Character then
1700 if Source (Scan_Ptr) in Upper_Half_Character then
1701 if Ada_Version = Ada_83 then
1702 Error_Illegal_Character;
1703 end if;
1705 else
1706 Error_Illegal_Character;
1707 end if;
1708 end if;
1710 Code := Get_Char_Code (Source (Scan_Ptr));
1711 Scan_Ptr := Scan_Ptr + 2;
1712 end if;
1714 -- Fall through here with Scan_Ptr updated past the closing
1715 -- quote, and Code set to the Char_Code value for the literal
1717 Accumulate_Checksum (''');
1718 Token := Tok_Char_Literal;
1719 Set_Character_Literal_Name (Code);
1720 Token_Name := Name_Find;
1721 Character_Code := Code;
1722 Post_Scan;
1723 return;
1724 end if;
1725 end Char_Literal_Case;
1727 -- Right parenthesis
1729 when ')' =>
1730 Accumulate_Checksum (')');
1731 Scan_Ptr := Scan_Ptr + 1;
1732 Token := Tok_Right_Paren;
1734 if Style_Check then
1735 Style.Check_Right_Paren;
1736 end if;
1738 return;
1740 -- Right bracket or right brace, treated as right paren
1742 when ']' | '}' =>
1743 Error_Msg_S ("illegal character, replaced by "")""");
1744 Scan_Ptr := Scan_Ptr + 1;
1745 Token := Tok_Right_Paren;
1746 return;
1748 -- Slash (can be division operator or first character of not equal)
1750 when '/' =>
1751 Accumulate_Checksum ('/');
1753 if Double_Char_Token ('=') then
1754 Token := Tok_Not_Equal;
1755 return;
1756 else
1757 Scan_Ptr := Scan_Ptr + 1;
1758 Token := Tok_Slash;
1759 return;
1760 end if;
1762 -- Semicolon
1764 when ';' =>
1765 Accumulate_Checksum (';');
1766 Scan_Ptr := Scan_Ptr + 1;
1767 Token := Tok_Semicolon;
1769 if Style_Check then
1770 Style.Check_Semicolon;
1771 end if;
1773 return;
1775 -- Vertical bar
1777 when '|' => Vertical_Bar_Case : begin
1778 Accumulate_Checksum ('|');
1780 -- Special check for || to give nice message
1782 if Source (Scan_Ptr + 1) = '|' then
1783 Error_Msg_S ("""'|'|"" should be `OR ELSE`");
1784 Scan_Ptr := Scan_Ptr + 2;
1785 Token := Tok_Or;
1786 return;
1788 else
1789 Scan_Ptr := Scan_Ptr + 1;
1790 Token := Tok_Vertical_Bar;
1792 if Style_Check then
1793 Style.Check_Vertical_Bar;
1794 end if;
1796 return;
1797 end if;
1798 end Vertical_Bar_Case;
1800 -- Exclamation, replacement character for vertical bar
1802 when '!' => Exclamation_Case : begin
1803 Accumulate_Checksum ('!');
1804 Obsolescent_Check (Token_Ptr);
1806 if Warn_On_Obsolescent_Feature then
1807 Error_Msg_S
1808 ("use of ""'!"" is an obsolescent feature (RM J.2(2))?");
1809 Error_Msg_S
1810 ("\use ""'|"" instead?");
1811 end if;
1813 if Source (Scan_Ptr + 1) = '=' then
1814 Error_Msg_S ("'!= should be /=");
1815 Scan_Ptr := Scan_Ptr + 2;
1816 Token := Tok_Not_Equal;
1817 return;
1819 else
1820 Scan_Ptr := Scan_Ptr + 1;
1821 Token := Tok_Vertical_Bar;
1822 return;
1823 end if;
1824 end Exclamation_Case;
1826 -- Plus
1828 when '+' => Plus_Case : begin
1829 Accumulate_Checksum ('+');
1830 Scan_Ptr := Scan_Ptr + 1;
1831 Token := Tok_Plus;
1832 return;
1833 end Plus_Case;
1835 -- Digits starting a numeric literal
1837 when '0' .. '9' =>
1839 -- First a bit of a scan ahead to see if we have a case of an
1840 -- identifier starting with a digit (remembering exponent case).
1842 declare
1843 C : constant Character := Source (Scan_Ptr + 1);
1845 begin
1846 -- OK literal if digit followed by digit or underscore
1848 if C in '0' .. '9' or else C = '_' then
1849 null;
1851 -- OK literal if digit not followed by identifier char
1853 elsif not Identifier_Char (C) then
1854 null;
1856 -- OK literal if digit followed by e/E followed by digit/sign.
1857 -- We also allow underscore after the E, which is an error, but
1858 -- better handled by Nlit than deciding this is an identifier.
1860 elsif (C = 'e' or else C = 'E')
1861 and then (Source (Scan_Ptr + 2) in '0' .. '9'
1862 or else Source (Scan_Ptr + 2) = '+'
1863 or else Source (Scan_Ptr + 2) = '-'
1864 or else Source (Scan_Ptr + 2) = '_')
1865 then
1866 null;
1868 -- Here we have what really looks like an identifier that
1869 -- starts with a digit, so give error msg.
1871 else
1872 Error_Msg_S ("identifier may not start with digit");
1873 Name_Len := 1;
1874 Underline_Found := False;
1875 Name_Buffer (1) := Source (Scan_Ptr);
1876 Accumulate_Checksum (Name_Buffer (1));
1877 Scan_Ptr := Scan_Ptr + 1;
1878 goto Scan_Identifier;
1879 end if;
1880 end;
1882 -- Here we have an OK integer literal
1884 Nlit;
1886 if Identifier_Char (Source (Scan_Ptr)) then
1887 Error_Msg_S
1888 ("delimiter required between literal and identifier");
1889 end if;
1891 Post_Scan;
1892 return;
1894 -- Lower case letters
1896 when 'a' .. 'z' =>
1897 Name_Len := 1;
1898 Underline_Found := False;
1899 Name_Buffer (1) := Source (Scan_Ptr);
1900 Accumulate_Checksum (Name_Buffer (1));
1901 Scan_Ptr := Scan_Ptr + 1;
1902 goto Scan_Identifier;
1904 -- Upper case letters
1906 when 'A' .. 'Z' =>
1907 Name_Len := 1;
1908 Underline_Found := False;
1909 Name_Buffer (1) :=
1910 Character'Val (Character'Pos (Source (Scan_Ptr)) + 32);
1911 Accumulate_Checksum (Name_Buffer (1));
1912 Scan_Ptr := Scan_Ptr + 1;
1913 goto Scan_Identifier;
1915 -- Underline character
1917 when '_' =>
1918 if Special_Characters ('_') then
1919 Token_Ptr := Scan_Ptr;
1920 Scan_Ptr := Scan_Ptr + 1;
1921 Token := Tok_Special;
1922 Special_Character := '_';
1923 return;
1924 end if;
1926 Error_Msg_S ("identifier cannot start with underline");
1927 Name_Len := 1;
1928 Name_Buffer (1) := '_';
1929 Scan_Ptr := Scan_Ptr + 1;
1930 Underline_Found := False;
1931 goto Scan_Identifier;
1933 -- Space (not possible, because we scanned past blanks)
1935 when ' ' =>
1936 raise Program_Error;
1938 -- Characters in top half of ASCII 8-bit chart
1940 when Upper_Half_Character =>
1942 -- Wide character case
1944 if Upper_Half_Encoding then
1945 goto Scan_Wide_Character;
1947 -- Otherwise we have OK Latin-1 character
1949 else
1950 -- Upper half characters may possibly be identifier letters
1951 -- but can never be digits, so Identifier_Char can be used to
1952 -- test for a valid start of identifier character.
1954 if Identifier_Char (Source (Scan_Ptr)) then
1955 Name_Len := 0;
1956 Underline_Found := False;
1957 goto Scan_Identifier;
1958 else
1959 Error_Illegal_Character;
1960 end if;
1961 end if;
1963 when ESC =>
1965 -- ESC character, possible start of identifier if wide characters
1966 -- using ESC encoding are allowed in identifiers, which we can
1967 -- tell by looking at the Identifier_Char flag for ESC, which is
1968 -- only true if these conditions are met. In Ada 2005 mode, may
1969 -- also be valid UTF_32 space or line terminator character.
1971 if Identifier_Char (ESC) then
1972 Name_Len := 0;
1973 goto Scan_Wide_Character;
1974 else
1975 Error_Illegal_Character;
1976 end if;
1978 -- Invalid control characters
1980 when NUL | SOH | STX | ETX | EOT | ENQ | ACK | BEL | BS | ASCII.SO |
1981 SI | DLE | DC1 | DC2 | DC3 | DC4 | NAK | SYN | ETB | CAN |
1982 EM | FS | GS | RS | US | DEL
1984 Error_Illegal_Character;
1986 -- Invalid graphic characters
1988 when '#' | '$' | '?' | '@' | '`' | '\' | '^' | '~' =>
1990 -- If Set_Special_Character has been called for this character,
1991 -- set Scans.Special_Character and return a Special token.
1993 if Special_Characters (Source (Scan_Ptr)) then
1994 Token_Ptr := Scan_Ptr;
1995 Token := Tok_Special;
1996 Special_Character := Source (Scan_Ptr);
1997 Scan_Ptr := Scan_Ptr + 1;
1998 return;
2000 -- Otherwise, this is an illegal character
2002 else
2003 Error_Illegal_Character;
2004 end if;
2006 -- End switch on non-blank character
2008 end case;
2010 -- End loop past format effectors. The exit from this loop is by
2011 -- executing a return statement following completion of token scan
2012 -- (control never falls out of this loop to the code which follows)
2014 end loop;
2016 -- Wide_Character scanning routine. On entry we have encountered the
2017 -- initial character of a wide character sequence.
2019 <<Scan_Wide_Character>>
2021 declare
2022 Code : Char_Code;
2023 Cat : Category;
2024 Err : Boolean;
2026 begin
2027 Wptr := Scan_Ptr;
2028 Scan_Wide (Source, Scan_Ptr, Code, Err);
2030 -- If bad wide character, signal error and continue scan
2032 if Err then
2033 Error_Illegal_Wide_Character;
2034 goto Scan_Next_Character;
2035 end if;
2037 Cat := Get_Category (UTF_32 (Code));
2039 -- If OK letter, reset scan ptr and go scan identifier
2041 if Is_UTF_32_Letter (Cat) then
2042 Scan_Ptr := Wptr;
2043 Name_Len := 0;
2044 Underline_Found := False;
2045 goto Scan_Identifier;
2047 -- If OK wide space, ignore and keep scanning (we do not include
2048 -- any ignored spaces in checksum)
2050 elsif Is_UTF_32_Space (Cat) then
2051 goto Scan_Next_Character;
2053 -- If OK wide line terminator, terminate current line
2055 elsif Is_UTF_32_Line_Terminator (UTF_32 (Code)) then
2056 Scan_Ptr := Wptr;
2057 goto Scan_Line_Terminator;
2059 -- Punctuation is an error (at start of identifier)
2061 elsif Is_UTF_32_Punctuation (Cat) then
2062 Error_Msg
2063 ("identifier cannot start with punctuation", Wptr);
2064 Scan_Ptr := Wptr;
2065 Name_Len := 0;
2066 Underline_Found := False;
2067 goto Scan_Identifier;
2069 -- Mark character is an error (at start of identifier)
2071 elsif Is_UTF_32_Mark (Cat) then
2072 Error_Msg
2073 ("identifier cannot start with mark character", Wptr);
2074 Scan_Ptr := Wptr;
2075 Name_Len := 0;
2076 Underline_Found := False;
2077 goto Scan_Identifier;
2079 -- Other format character is an error (at start of identifier)
2081 elsif Is_UTF_32_Other (Cat) then
2082 Error_Msg
2083 ("identifier cannot start with other format character", Wptr);
2084 Scan_Ptr := Wptr;
2085 Name_Len := 0;
2086 Underline_Found := False;
2087 goto Scan_Identifier;
2089 -- Extended digit character is an error. Could be bad start of
2090 -- identifier or bad literal. Not worth doing too much to try to
2091 -- distinguish these cases, but we will do a little bit.
2093 elsif Is_UTF_32_Digit (Cat) then
2094 Error_Msg
2095 ("identifier cannot start with digit character", Wptr);
2096 Scan_Ptr := Wptr;
2097 Name_Len := 0;
2098 Underline_Found := False;
2099 goto Scan_Identifier;
2101 -- All other wide characters are illegal here
2103 else
2104 Error_Illegal_Wide_Character;
2105 goto Scan_Next_Character;
2106 end if;
2107 end;
2109 -- Routine to scan line terminator. On entry Scan_Ptr points to a
2110 -- character which is one of FF,LR,CR,VT, or one of the wide characters
2111 -- that is treated as a line terminator.
2113 <<Scan_Line_Terminator>>
2115 -- Check line too long
2117 Check_End_Of_Line;
2119 -- Set Token_Ptr, if End_Of_Line is a token, for the case when it is
2120 -- a physical line.
2122 if End_Of_Line_Is_Token then
2123 Token_Ptr := Scan_Ptr;
2124 end if;
2126 declare
2127 Physical : Boolean;
2129 begin
2130 Skip_Line_Terminators (Scan_Ptr, Physical);
2132 -- If we are at start of physical line, update scan pointers to
2133 -- reflect the start of the new line.
2135 if Physical then
2136 Current_Line_Start := Scan_Ptr;
2137 Start_Column := Set_Start_Column;
2138 First_Non_Blank_Location := Scan_Ptr;
2140 -- If End_Of_Line is a token, we return it as it is a
2141 -- physical line.
2143 if End_Of_Line_Is_Token then
2144 Token := Tok_End_Of_Line;
2145 return;
2146 end if;
2147 end if;
2148 end;
2150 goto Scan_Next_Character;
2152 -- Identifier scanning routine. On entry, some initial characters of
2153 -- the identifier may have already been stored in Name_Buffer. If so,
2154 -- Name_Len has the number of characters stored, otherwise Name_Len is
2155 -- set to zero on entry. Underline_Found is also set False on entry.
2157 <<Scan_Identifier>>
2159 -- This loop scans as fast as possible past lower half letters and
2160 -- digits, which we expect to be the most common characters.
2162 loop
2163 if Source (Scan_Ptr) in 'a' .. 'z'
2164 or else Source (Scan_Ptr) in '0' .. '9'
2165 then
2166 Name_Buffer (Name_Len + 1) := Source (Scan_Ptr);
2167 Accumulate_Checksum (Source (Scan_Ptr));
2169 elsif Source (Scan_Ptr) in 'A' .. 'Z' then
2170 Name_Buffer (Name_Len + 1) :=
2171 Character'Val (Character'Pos (Source (Scan_Ptr)) + 32);
2172 Accumulate_Checksum (Name_Buffer (Name_Len + 1));
2174 else
2175 exit;
2176 end if;
2178 Underline_Found := False;
2179 Scan_Ptr := Scan_Ptr + 1;
2180 Name_Len := Name_Len + 1;
2181 end loop;
2183 -- If we fall through, then we have encountered either an underline
2184 -- character, or an extended identifier character (i.e. one from the
2185 -- upper half), or a wide character, or an identifier terminator. The
2186 -- initial test speeds us up in the most common case where we have
2187 -- an identifier terminator. Note that ESC is an identifier character
2188 -- only if a wide character encoding method that uses ESC encoding
2189 -- is active, so if we find an ESC character we know that we have a
2190 -- wide character.
2192 if Identifier_Char (Source (Scan_Ptr))
2193 or else (Source (Scan_Ptr) in Upper_Half_Character
2194 and then Upper_Half_Encoding)
2195 then
2196 -- Case of underline
2198 if Source (Scan_Ptr) = '_' then
2199 Accumulate_Checksum ('_');
2201 if Underline_Found then
2202 Error_No_Double_Underline;
2203 else
2204 Underline_Found := True;
2205 Name_Len := Name_Len + 1;
2206 Name_Buffer (Name_Len) := '_';
2207 end if;
2209 Scan_Ptr := Scan_Ptr + 1;
2210 goto Scan_Identifier;
2212 -- Upper half character
2214 elsif Source (Scan_Ptr) in Upper_Half_Character
2215 and then not Upper_Half_Encoding
2216 then
2217 Accumulate_Checksum (Source (Scan_Ptr));
2218 Store_Encoded_Character
2219 (Get_Char_Code (Fold_Lower (Source (Scan_Ptr))));
2220 Scan_Ptr := Scan_Ptr + 1;
2221 Underline_Found := False;
2222 goto Scan_Identifier;
2224 -- Left bracket not followed by a quote terminates an identifier.
2225 -- This is an error, but we don't want to give a junk error msg
2226 -- about wide characters in this case!
2228 elsif Source (Scan_Ptr) = '['
2229 and then Source (Scan_Ptr + 1) /= '"'
2230 then
2231 null;
2233 -- We know we have a wide character encoding here (the current
2234 -- character is either ESC, left bracket, or an upper half
2235 -- character depending on the encoding method).
2237 else
2238 -- Scan out the wide character and insert the appropriate
2239 -- encoding into the name table entry for the identifier.
2241 declare
2242 Code : Char_Code;
2243 Err : Boolean;
2244 Chr : Character;
2245 Cat : Category;
2247 begin
2248 Wptr := Scan_Ptr;
2249 Scan_Wide (Source, Scan_Ptr, Code, Err);
2251 -- If error, signal error
2253 if Err then
2254 Error_Illegal_Wide_Character;
2256 -- If the character scanned is a normal identifier
2257 -- character, then we treat it that way.
2259 elsif In_Character_Range (Code)
2260 and then Identifier_Char (Get_Character (Code))
2261 then
2262 Chr := Get_Character (Code);
2263 Accumulate_Checksum (Chr);
2264 Store_Encoded_Character
2265 (Get_Char_Code (Fold_Lower (Chr)));
2266 Underline_Found := False;
2268 -- Here if not a normal identifier character
2270 else
2271 -- Make sure we are allowing wide characters in
2272 -- identifiers. Note that we allow wide character
2273 -- notation for an OK identifier character. This in
2274 -- particular allows bracket or other notation to be
2275 -- used for upper half letters.
2277 -- Wide characters are always allowed in Ada 2005
2279 if Identifier_Character_Set /= 'w'
2280 and then Ada_Version < Ada_05
2281 then
2282 Error_Msg
2283 ("wide character not allowed in identifier", Wptr);
2284 end if;
2286 Cat := Get_Category (UTF_32 (Code));
2288 -- If OK letter, store it folding to upper case. Note
2289 -- that we include the folded letter in the checksum.
2291 if Is_UTF_32_Letter (Cat) then
2292 Code :=
2293 Char_Code (UTF_32_To_Upper_Case (UTF_32 (Code)));
2294 Accumulate_Checksum (Code);
2295 Store_Encoded_Character (Code);
2296 Underline_Found := False;
2298 -- If OK extended digit or mark, then store it
2300 elsif Is_UTF_32_Digit (Cat)
2301 or else Is_UTF_32_Mark (Cat)
2302 then
2303 Accumulate_Checksum (Code);
2304 Store_Encoded_Character (Code);
2305 Underline_Found := False;
2307 -- Wide punctuation is also stored, but counts as an
2308 -- underline character for error checking purposes.
2310 elsif Is_UTF_32_Punctuation (Cat) then
2311 Accumulate_Checksum (Code);
2313 if Underline_Found then
2314 declare
2315 Cend : constant Source_Ptr := Scan_Ptr;
2316 begin
2317 Scan_Ptr := Wptr;
2318 Error_No_Double_Underline;
2319 Scan_Ptr := Cend;
2320 end;
2322 else
2323 Store_Encoded_Character (Code);
2324 Underline_Found := True;
2325 end if;
2327 -- Wide character in Unicode category "Other, Format"
2328 -- is accepted in an identifier, but is ignored and not
2329 -- stored. It seems reasonable to exclude it from the
2330 -- checksum.
2332 -- Note that it is correct (see AI-395) to simply strip
2333 -- other format characters, before testing for double
2334 -- underlines, or for reserved words).
2336 elsif Is_UTF_32_Other (Cat) then
2337 null;
2339 -- Wide character in category Separator,Space terminates
2341 elsif Is_UTF_32_Space (Cat) then
2342 goto Scan_Identifier_Complete;
2344 -- Any other wide character is not acceptable
2346 else
2347 Error_Msg
2348 ("invalid wide character in identifier", Wptr);
2349 end if;
2350 end if;
2352 goto Scan_Identifier;
2353 end;
2354 end if;
2355 end if;
2357 -- Scan of identifier is complete. The identifier is stored in
2358 -- Name_Buffer, and Scan_Ptr points past the last character.
2360 <<Scan_Identifier_Complete>>
2361 Token_Name := Name_Find;
2363 -- Check for identifier ending with underline or punctuation char
2365 if Underline_Found then
2366 Underline_Found := False;
2368 if Source (Scan_Ptr - 1) = '_' then
2369 Error_Msg
2370 ("identifier cannot end with underline", Scan_Ptr - 1);
2371 else
2372 Error_Msg
2373 ("identifier cannot end with punctuation character", Wptr);
2374 end if;
2375 end if;
2377 -- Here is where we check if it was a keyword
2379 if Is_Keyword_Name (Token_Name) then
2380 Token := Token_Type'Val (Get_Name_Table_Byte (Token_Name));
2382 -- Keyword style checks
2384 if Style_Check then
2386 -- Deal with possible style check for non-lower case keyword,
2387 -- but we don't treat ACCESS, DELTA, DIGITS, RANGE as keywords
2388 -- for this purpose if they appear as attribute designators.
2389 -- Actually we only check the first character for speed.
2391 -- Ada 2005 (AI-284): Do not apply the style check in case of
2392 -- "pragma Interface"
2394 -- Ada 2005 (AI-340): Do not apply the style check in case of
2395 -- MOD attribute.
2397 if Source (Token_Ptr) <= 'Z'
2398 and then (Prev_Token /= Tok_Apostrophe
2399 or else
2400 (Token /= Tok_Access and then
2401 Token /= Tok_Delta and then
2402 Token /= Tok_Digits and then
2403 Token /= Tok_Mod and then
2404 Token /= Tok_Range))
2405 and then (Token /= Tok_Interface
2406 or else
2407 (Token = Tok_Interface
2408 and then Prev_Token /= Tok_Pragma))
2409 then
2410 Style.Non_Lower_Case_Keyword;
2411 end if;
2413 if (Token = Tok_Then and then Prev_Token /= Tok_And)
2414 or else
2415 (Token = Tok_Else and then Prev_Token /= Tok_Or)
2416 then
2417 Style.Check_Separate_Stmt_Lines;
2418 end if;
2419 end if;
2421 -- We must reset Token_Name since this is not an identifier and
2422 -- if we leave Token_Name set, the parser gets confused because
2423 -- it thinks it is dealing with an identifier instead of the
2424 -- corresponding keyword.
2426 Token_Name := No_Name;
2427 Accumulate_Token_Checksum;
2428 return;
2430 -- It is an identifier after all
2432 else
2433 Token := Tok_Identifier;
2434 Accumulate_Token_Checksum;
2435 Post_Scan;
2436 return;
2437 end if;
2438 end Scan;
2440 --------------------------
2441 -- Set_Comment_As_Token --
2442 --------------------------
2444 procedure Set_Comment_As_Token (Value : Boolean) is
2445 begin
2446 Comment_Is_Token := Value;
2447 end Set_Comment_As_Token;
2449 ------------------------------
2450 -- Set_End_Of_Line_As_Token --
2451 ------------------------------
2453 procedure Set_End_Of_Line_As_Token (Value : Boolean) is
2454 begin
2455 End_Of_Line_Is_Token := Value;
2456 end Set_End_Of_Line_As_Token;
2458 ---------------------------
2459 -- Set_Special_Character --
2460 ---------------------------
2462 procedure Set_Special_Character (C : Character) is
2463 begin
2464 case C is
2465 when '#' | '$' | '_' | '?' | '@' | '`' | '\' | '^' | '~' =>
2466 Special_Characters (C) := True;
2468 when others =>
2469 null;
2470 end case;
2471 end Set_Special_Character;
2473 ----------------------
2474 -- Set_Start_Column --
2475 ----------------------
2477 -- Note: it seems at first glance a little expensive to compute this value
2478 -- for every source line (since it is certainly not used for all source
2479 -- lines). On the other hand, it doesn't take much more work to skip past
2480 -- the initial white space on the line counting the columns than it would
2481 -- to scan past the white space using the standard scanning circuits.
2483 function Set_Start_Column return Column_Number is
2484 Start_Column : Column_Number := 0;
2486 begin
2487 -- Outer loop scans past horizontal tab characters
2489 Tabs_Loop : loop
2491 -- Inner loop scans past blanks as fast as possible, bumping Scan_Ptr
2492 -- past the blanks and adjusting Start_Column to account for them.
2494 Blanks_Loop : loop
2495 if Source (Scan_Ptr) = ' ' then
2496 if Source (Scan_Ptr + 1) = ' ' then
2497 if Source (Scan_Ptr + 2) = ' ' then
2498 if Source (Scan_Ptr + 3) = ' ' then
2499 if Source (Scan_Ptr + 4) = ' ' then
2500 if Source (Scan_Ptr + 5) = ' ' then
2501 if Source (Scan_Ptr + 6) = ' ' then
2502 Scan_Ptr := Scan_Ptr + 7;
2503 Start_Column := Start_Column + 7;
2504 else
2505 Scan_Ptr := Scan_Ptr + 6;
2506 Start_Column := Start_Column + 6;
2507 exit Blanks_Loop;
2508 end if;
2509 else
2510 Scan_Ptr := Scan_Ptr + 5;
2511 Start_Column := Start_Column + 5;
2512 exit Blanks_Loop;
2513 end if;
2514 else
2515 Scan_Ptr := Scan_Ptr + 4;
2516 Start_Column := Start_Column + 4;
2517 exit Blanks_Loop;
2518 end if;
2519 else
2520 Scan_Ptr := Scan_Ptr + 3;
2521 Start_Column := Start_Column + 3;
2522 exit Blanks_Loop;
2523 end if;
2524 else
2525 Scan_Ptr := Scan_Ptr + 2;
2526 Start_Column := Start_Column + 2;
2527 exit Blanks_Loop;
2528 end if;
2529 else
2530 Scan_Ptr := Scan_Ptr + 1;
2531 Start_Column := Start_Column + 1;
2532 exit Blanks_Loop;
2533 end if;
2534 else
2535 exit Blanks_Loop;
2536 end if;
2537 end loop Blanks_Loop;
2539 -- Outer loop keeps going only if a horizontal tab follows
2541 if Source (Scan_Ptr) = HT then
2542 if Style_Check then
2543 Style.Check_HT;
2544 end if;
2546 Scan_Ptr := Scan_Ptr + 1;
2547 Start_Column := (Start_Column / 8) * 8 + 8;
2548 else
2549 exit Tabs_Loop;
2550 end if;
2552 end loop Tabs_Loop;
2554 return Start_Column;
2556 -- A constraint error can happen only if we have a compiler with checks on
2557 -- and a line with a ludicrous number of tabs or spaces at the start. In
2558 -- such a case, we really don't care if Start_Column is right or not.
2560 exception
2561 when Constraint_Error =>
2562 return Start_Column;
2563 end Set_Start_Column;
2565 end Scng;