Daily bump.
[official-gcc.git] / gcc / ada / scng.adb
blob30da224d90540e02f255b4a481e2d6dc31783bf3
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S C N 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 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 Scan_Ptr := Scan_Ptr + 1;
354 Error_Msg ("illegal wide character", Wptr);
355 end Error_Illegal_Wide_Character;
357 ---------------------
358 -- Error_Long_Line --
359 ---------------------
361 procedure Error_Long_Line is
362 begin
363 Error_Msg
364 ("this line is too long",
365 Current_Line_Start + Source_Ptr (Max_Line_Length));
366 end Error_Long_Line;
368 -------------------------------
369 -- Error_No_Double_Underline --
370 -------------------------------
372 procedure Error_No_Double_Underline is
373 begin
374 Underline_Found := False;
376 -- There are four cases, and we special case the messages
378 if Source (Scan_Ptr) = '_' then
379 if Source (Scan_Ptr - 1) = '_' then
380 Error_Msg_S -- CODEFIX
381 ("two consecutive underlines not permitted");
382 else
383 Error_Msg_S -- CODEFIX???
384 ("underline cannot follow punctuation character");
385 end if;
387 else
388 if Source (Scan_Ptr - 1) = '_' then
389 Error_Msg_S -- CODEFIX???
390 ("punctuation character cannot follow underline");
391 else
392 Error_Msg_S -- CODEFIX???
393 ("two consecutive punctuation characters not permitted");
394 end if;
395 end if;
396 end Error_No_Double_Underline;
398 ----------
399 -- Nlit --
400 ----------
402 procedure Nlit is
404 C : Character;
405 -- Current source program character
407 Base_Char : Character;
408 -- Either # or : (character at start of based number)
410 Base : Int;
411 -- Value of base
413 UI_Base : Uint;
414 -- Value of base in Uint format
416 UI_Int_Value : Uint;
417 -- Value of integer scanned by Scan_Integer in Uint format
419 UI_Num_Value : Uint;
420 -- Value of integer in numeric value being scanned
422 Scale : Int;
423 -- Scale value for real literal
425 UI_Scale : Uint;
426 -- Scale in Uint format
428 Exponent_Is_Negative : Boolean;
429 -- Set true for negative exponent
431 Extended_Digit_Value : Int;
432 -- Extended digit value
434 Point_Scanned : Boolean;
435 -- Flag for decimal point scanned in numeric literal
437 -----------------------
438 -- Local Subprograms --
439 -----------------------
441 procedure Error_Digit_Expected;
442 -- Signal error of bad digit, Scan_Ptr points to the location at
443 -- which the digit was expected on input, and is unchanged on return.
445 procedure Scan_Integer;
446 -- Procedure to scan integer literal. On entry, Scan_Ptr points to a
447 -- digit, on exit Scan_Ptr points past the last character of the
448 -- integer.
450 -- For each digit encountered, UI_Int_Value is multiplied by 10, and
451 -- the value of the digit added to the result. In addition, the
452 -- value in Scale is decremented by one for each actual digit
453 -- scanned.
455 --------------------------
456 -- Error_Digit_Expected --
457 --------------------------
459 procedure Error_Digit_Expected is
460 begin
461 Error_Msg_S ("digit expected");
462 end Error_Digit_Expected;
464 ------------------
465 -- Scan_Integer --
466 ------------------
468 procedure Scan_Integer is
469 C : Character;
470 -- Next character scanned
472 begin
473 C := Source (Scan_Ptr);
475 -- Loop through digits (allowing underlines)
477 loop
478 Accumulate_Checksum (C);
479 UI_Int_Value :=
480 UI_Int_Value * 10 + (Character'Pos (C) - Character'Pos ('0'));
481 Scan_Ptr := Scan_Ptr + 1;
482 Scale := Scale - 1;
483 C := Source (Scan_Ptr);
485 -- Case of underline encountered
487 if C = '_' then
489 -- We do not accumulate the '_' in the checksum, so that
490 -- 1_234 is equivalent to 1234, and does not trigger
491 -- compilation for "minimal recompilation" (gnatmake -m).
493 loop
494 Scan_Ptr := Scan_Ptr + 1;
495 C := Source (Scan_Ptr);
496 exit when C /= '_';
497 Error_No_Double_Underline;
498 end loop;
500 if C not in '0' .. '9' then
501 Error_Digit_Expected;
502 exit;
503 end if;
505 else
506 exit when C not in '0' .. '9';
507 end if;
508 end loop;
509 end Scan_Integer;
511 -- Start of Processing for Nlit
513 begin
514 Base := 10;
515 UI_Base := Uint_10;
516 UI_Int_Value := Uint_0;
517 Scale := 0;
518 Scan_Integer;
519 Point_Scanned := False;
520 UI_Num_Value := UI_Int_Value;
522 -- Various possibilities now for continuing the literal are period,
523 -- E/e (for exponent), or :/# (for based literal).
525 Scale := 0;
526 C := Source (Scan_Ptr);
528 if C = '.' then
530 -- Scan out point, but do not scan past .. which is a range
531 -- sequence, and must not be eaten up scanning a numeric literal.
533 while C = '.' and then Source (Scan_Ptr + 1) /= '.' loop
534 Accumulate_Checksum ('.');
536 if Point_Scanned then
537 Error_Msg_S ("duplicate point ignored");
538 end if;
540 Point_Scanned := True;
541 Scan_Ptr := Scan_Ptr + 1;
542 C := Source (Scan_Ptr);
544 if C not in '0' .. '9' then
545 Error_Msg
546 ("real literal cannot end with point", Scan_Ptr - 1);
547 else
548 Scan_Integer;
549 UI_Num_Value := UI_Int_Value;
550 end if;
551 end loop;
553 -- Based literal case. The base is the value we already scanned.
554 -- In the case of colon, we insist that the following character
555 -- is indeed an extended digit or a period. This catches a number
556 -- of common errors, as well as catching the well known tricky
557 -- bug otherwise arising from "x : integer range 1 .. 10:= 6;"
559 elsif C = '#'
560 or else (C = ':' and then
561 (Source (Scan_Ptr + 1) = '.'
562 or else
563 Source (Scan_Ptr + 1) in '0' .. '9'
564 or else
565 Source (Scan_Ptr + 1) in 'A' .. 'Z'
566 or else
567 Source (Scan_Ptr + 1) in 'a' .. 'z'))
568 then
569 if C = ':' then
570 Obsolescent_Check (Scan_Ptr);
572 if Warn_On_Obsolescent_Feature then
573 Error_Msg_S
574 ("use of "":"" is an obsolescent feature (RM J.2(3))?");
575 Error_Msg_S
576 ("\use ""'#"" instead?");
577 end if;
578 end if;
580 Accumulate_Checksum (C);
581 Base_Char := C;
582 UI_Base := UI_Int_Value;
584 if UI_Base < 2 or else UI_Base > 16 then
585 Error_Msg_SC ("base not 2-16");
586 UI_Base := Uint_16;
587 end if;
589 Base := UI_To_Int (UI_Base);
590 Scan_Ptr := Scan_Ptr + 1;
592 -- Scan out extended integer [. integer]
594 C := Source (Scan_Ptr);
595 UI_Int_Value := Uint_0;
596 Scale := 0;
598 loop
599 if C in '0' .. '9' then
600 Accumulate_Checksum (C);
601 Extended_Digit_Value :=
602 Int'(Character'Pos (C)) - Int'(Character'Pos ('0'));
604 elsif C in 'A' .. 'F' then
605 Accumulate_Checksum (Character'Val (Character'Pos (C) + 32));
606 Extended_Digit_Value :=
607 Int'(Character'Pos (C)) - Int'(Character'Pos ('A')) + 10;
609 elsif C in 'a' .. 'f' then
610 Accumulate_Checksum (C);
611 Extended_Digit_Value :=
612 Int'(Character'Pos (C)) - Int'(Character'Pos ('a')) + 10;
614 else
615 Error_Msg_S ("extended digit expected");
616 exit;
617 end if;
619 if Extended_Digit_Value >= Base then
620 Error_Msg_S ("digit '>= base");
621 end if;
623 UI_Int_Value := UI_Int_Value * UI_Base + Extended_Digit_Value;
624 Scale := Scale - 1;
625 Scan_Ptr := Scan_Ptr + 1;
626 C := Source (Scan_Ptr);
628 if C = '_' then
629 loop
630 Accumulate_Checksum ('_');
631 Scan_Ptr := Scan_Ptr + 1;
632 C := Source (Scan_Ptr);
633 exit when C /= '_';
634 Error_No_Double_Underline;
635 end loop;
637 elsif C = '.' then
638 Accumulate_Checksum ('.');
640 if Point_Scanned then
641 Error_Msg_S ("duplicate point ignored");
642 end if;
644 Scan_Ptr := Scan_Ptr + 1;
645 C := Source (Scan_Ptr);
646 Point_Scanned := True;
647 Scale := 0;
649 elsif C = Base_Char then
650 Accumulate_Checksum (C);
651 Scan_Ptr := Scan_Ptr + 1;
652 exit;
654 elsif C = '#' or else C = ':' then
655 Error_Msg_S ("based number delimiters must match");
656 Scan_Ptr := Scan_Ptr + 1;
657 exit;
659 elsif not Identifier_Char (C) then
660 if Base_Char = '#' then
661 Error_Msg_S ("missing '#");
662 else
663 Error_Msg_S ("missing ':");
664 end if;
666 exit;
667 end if;
669 end loop;
671 UI_Num_Value := UI_Int_Value;
672 end if;
674 -- Scan out exponent
676 if not Point_Scanned then
677 Scale := 0;
678 UI_Scale := Uint_0;
679 else
680 UI_Scale := UI_From_Int (Scale);
681 end if;
683 if Source (Scan_Ptr) = 'e' or else Source (Scan_Ptr) = 'E' then
684 Accumulate_Checksum ('e');
685 Scan_Ptr := Scan_Ptr + 1;
686 Exponent_Is_Negative := False;
688 if Source (Scan_Ptr) = '+' then
689 Accumulate_Checksum ('+');
690 Scan_Ptr := Scan_Ptr + 1;
692 elsif Source (Scan_Ptr) = '-' then
693 Accumulate_Checksum ('-');
695 if not Point_Scanned then
696 Error_Msg_S
697 ("negative exponent not allowed for integer literal");
698 else
699 Exponent_Is_Negative := True;
700 end if;
702 Scan_Ptr := Scan_Ptr + 1;
703 end if;
705 UI_Int_Value := Uint_0;
707 if Source (Scan_Ptr) in '0' .. '9' then
708 Scan_Integer;
709 else
710 Error_Digit_Expected;
711 end if;
713 if Exponent_Is_Negative then
714 UI_Scale := UI_Scale - UI_Int_Value;
715 else
716 UI_Scale := UI_Scale + UI_Int_Value;
717 end if;
718 end if;
720 -- Case of real literal to be returned
722 if Point_Scanned then
723 Token := Tok_Real_Literal;
724 Real_Literal_Value :=
725 UR_From_Components (
726 Num => UI_Num_Value,
727 Den => -UI_Scale,
728 Rbase => Base);
730 -- Case of integer literal to be returned
732 else
733 Token := Tok_Integer_Literal;
735 if UI_Scale = 0 then
736 Int_Literal_Value := UI_Num_Value;
738 -- Avoid doing possibly expensive calculations in cases like
739 -- parsing 163E800_000# when semantics will not be done anyway.
740 -- This is especially useful when parsing garbled input.
742 elsif Operating_Mode /= Check_Syntax
743 and then (Serious_Errors_Detected = 0 or else Try_Semantics)
744 then
745 Int_Literal_Value := UI_Num_Value * UI_Base ** UI_Scale;
747 else
748 Int_Literal_Value := No_Uint;
749 end if;
750 end if;
752 Accumulate_Token_Checksum;
754 return;
755 end Nlit;
757 ----------
758 -- Slit --
759 ----------
761 procedure Slit is
763 Delimiter : Character;
764 -- Delimiter (first character of string)
766 C : Character;
767 -- Current source program character
769 Code : Char_Code;
770 -- Current character code value
772 Err : Boolean;
773 -- Error flag for Scan_Wide call
775 procedure Error_Bad_String_Char;
776 -- Signal bad character in string/character literal. On entry
777 -- Scan_Ptr points to the improper character encountered during the
778 -- scan. Scan_Ptr is not modified, so it still points to the bad
779 -- character on return.
781 procedure Error_Unterminated_String;
782 -- Procedure called if a line terminator character is encountered
783 -- during scanning a string, meaning that the string is not properly
784 -- terminated.
786 procedure Set_String;
787 -- Procedure used to distinguish between string and operator symbol.
788 -- On entry the string has been scanned out, and its characters
789 -- start at Token_Ptr and end one character before Scan_Ptr. On exit
790 -- Token is set to Tok_String_Literal or Tok_Operator_Symbol as
791 -- appropriate, and Token_Node is appropriately initialized. In
792 -- addition, in the operator symbol case, Token_Name is
793 -- appropriately set.
795 ---------------------------
796 -- Error_Bad_String_Char --
797 ---------------------------
799 procedure Error_Bad_String_Char is
800 C : constant Character := Source (Scan_Ptr);
802 begin
803 if C = HT then
804 Error_Msg_S ("horizontal tab not allowed in string");
806 elsif C = VT or else C = FF then
807 Error_Msg_S ("format effector not allowed in string");
809 elsif C in Upper_Half_Character then
810 Error_Msg_S ("(Ada 83) upper half character not allowed");
812 else
813 Error_Msg_S ("control character not allowed in string");
814 end if;
815 end Error_Bad_String_Char;
817 -------------------------------
818 -- Error_Unterminated_String --
819 -------------------------------
821 procedure Error_Unterminated_String is
822 begin
823 -- An interesting little refinement. Consider the following
824 -- examples:
826 -- A := "this is an unterminated string;
827 -- A := "this is an unterminated string &
828 -- P(A, "this is a parameter that didn't get terminated);
830 -- We fiddle a little to do slightly better placement in these
831 -- cases also if there is white space at the end of the line we
832 -- place the flag at the start of this white space, not at the
833 -- end. Note that we only have to test for blanks, since tabs
834 -- aren't allowed in strings in the first place and would have
835 -- caused an error message.
837 -- Two more cases that we treat specially are:
839 -- A := "this string uses the wrong terminator'
840 -- A := "this string uses the wrong terminator' &
842 -- In these cases we give a different error message as well
844 -- We actually reposition the scan pointer to the point where we
845 -- place the flag in these cases, since it seems a better bet on
846 -- the original intention.
848 while Source (Scan_Ptr - 1) = ' '
849 or else Source (Scan_Ptr - 1) = '&'
850 loop
851 Scan_Ptr := Scan_Ptr - 1;
852 Unstore_String_Char;
853 end loop;
855 -- Check for case of incorrect string terminator, but single quote
856 -- is not considered incorrect if the opening terminator misused
857 -- a single quote (error message already given).
859 if Delimiter /= '''
860 and then Source (Scan_Ptr - 1) = '''
861 then
862 Unstore_String_Char;
863 Error_Msg
864 ("incorrect string terminator character", Scan_Ptr - 1);
865 return;
866 end if;
868 if Source (Scan_Ptr - 1) = ';' then
869 Scan_Ptr := Scan_Ptr - 1;
870 Unstore_String_Char;
872 if Source (Scan_Ptr - 1) = ')' then
873 Scan_Ptr := Scan_Ptr - 1;
874 Unstore_String_Char;
875 end if;
876 end if;
878 Error_Msg_S -- CODEFIX
879 ("missing string quote");
880 end Error_Unterminated_String;
882 ----------------
883 -- Set_String --
884 ----------------
886 procedure Set_String is
887 Slen : constant Int := Int (Scan_Ptr - Token_Ptr - 2);
888 C1 : Character;
889 C2 : Character;
890 C3 : Character;
892 begin
893 -- Token_Name is currently set to Error_Name. The following
894 -- section of code resets Token_Name to the proper Name_Op_xx
895 -- value if the string is a valid operator symbol, otherwise it is
896 -- left set to Error_Name.
898 if Slen = 1 then
899 C1 := Source (Token_Ptr + 1);
901 case C1 is
902 when '=' =>
903 Token_Name := Name_Op_Eq;
905 when '>' =>
906 Token_Name := Name_Op_Gt;
908 when '<' =>
909 Token_Name := Name_Op_Lt;
911 when '+' =>
912 Token_Name := Name_Op_Add;
914 when '-' =>
915 Token_Name := Name_Op_Subtract;
917 when '&' =>
918 Token_Name := Name_Op_Concat;
920 when '*' =>
921 Token_Name := Name_Op_Multiply;
923 when '/' =>
924 Token_Name := Name_Op_Divide;
926 when others =>
927 null;
928 end case;
930 elsif Slen = 2 then
931 C1 := Source (Token_Ptr + 1);
932 C2 := Source (Token_Ptr + 2);
934 if C1 = '*' and then C2 = '*' then
935 Token_Name := Name_Op_Expon;
937 elsif C2 = '=' then
939 if C1 = '/' then
940 Token_Name := Name_Op_Ne;
941 elsif C1 = '<' then
942 Token_Name := Name_Op_Le;
943 elsif C1 = '>' then
944 Token_Name := Name_Op_Ge;
945 end if;
947 elsif (C1 = 'O' or else C1 = 'o') and then -- OR
948 (C2 = 'R' or else C2 = 'r')
949 then
950 Token_Name := Name_Op_Or;
951 end if;
953 elsif Slen = 3 then
954 C1 := Source (Token_Ptr + 1);
955 C2 := Source (Token_Ptr + 2);
956 C3 := Source (Token_Ptr + 3);
958 if (C1 = 'A' or else C1 = 'a') and then -- AND
959 (C2 = 'N' or else C2 = 'n') and then
960 (C3 = 'D' or else C3 = 'd')
961 then
962 Token_Name := Name_Op_And;
964 elsif (C1 = 'A' or else C1 = 'a') and then -- ABS
965 (C2 = 'B' or else C2 = 'b') and then
966 (C3 = 'S' or else C3 = 's')
967 then
968 Token_Name := Name_Op_Abs;
970 elsif (C1 = 'M' or else C1 = 'm') and then -- MOD
971 (C2 = 'O' or else C2 = 'o') and then
972 (C3 = 'D' or else C3 = 'd')
973 then
974 Token_Name := Name_Op_Mod;
976 elsif (C1 = 'N' or else C1 = 'n') and then -- NOT
977 (C2 = 'O' or else C2 = 'o') and then
978 (C3 = 'T' or else C3 = 't')
979 then
980 Token_Name := Name_Op_Not;
982 elsif (C1 = 'R' or else C1 = 'r') and then -- REM
983 (C2 = 'E' or else C2 = 'e') and then
984 (C3 = 'M' or else C3 = 'm')
985 then
986 Token_Name := Name_Op_Rem;
988 elsif (C1 = 'X' or else C1 = 'x') and then -- XOR
989 (C2 = 'O' or else C2 = 'o') and then
990 (C3 = 'R' or else C3 = 'r')
991 then
992 Token_Name := Name_Op_Xor;
993 end if;
995 end if;
997 -- If it is an operator symbol, then Token_Name is set. If it is
998 -- some other string value, then Token_Name still contains
999 -- Error_Name.
1001 if Token_Name = Error_Name then
1002 Token := Tok_String_Literal;
1004 else
1005 Token := Tok_Operator_Symbol;
1006 end if;
1007 end Set_String;
1009 -- Start of processing for Slit
1011 begin
1012 -- On entry, Scan_Ptr points to the opening character of the string
1013 -- which is either a percent, double quote, or apostrophe (single
1014 -- quote). The latter case is an error detected by the character
1015 -- literal circuit.
1017 Delimiter := Source (Scan_Ptr);
1018 Accumulate_Checksum (Delimiter);
1019 Start_String;
1020 Scan_Ptr := Scan_Ptr + 1;
1022 -- Loop to scan out characters of string literal
1024 loop
1025 C := Source (Scan_Ptr);
1027 if C = Delimiter then
1028 Accumulate_Checksum (C);
1029 Scan_Ptr := Scan_Ptr + 1;
1030 exit when Source (Scan_Ptr) /= Delimiter;
1031 Code := Get_Char_Code (C);
1032 Accumulate_Checksum (C);
1033 Scan_Ptr := Scan_Ptr + 1;
1035 else
1036 if C = '"' and then Delimiter = '%' then
1037 Error_Msg_S
1038 ("quote not allowed in percent delimited string");
1039 Code := Get_Char_Code (C);
1040 Scan_Ptr := Scan_Ptr + 1;
1042 elsif (C = ESC
1043 and then Wide_Character_Encoding_Method
1044 in WC_ESC_Encoding_Method)
1045 or else (C in Upper_Half_Character
1046 and then Upper_Half_Encoding)
1047 or else (C = '['
1048 and then Source (Scan_Ptr + 1) = '"'
1049 and then Identifier_Char (Source (Scan_Ptr + 2)))
1050 then
1051 Wptr := Scan_Ptr;
1052 Scan_Wide (Source, Scan_Ptr, Code, Err);
1054 if Err then
1055 Error_Illegal_Wide_Character;
1056 Code := Get_Char_Code (' ');
1057 end if;
1059 Accumulate_Checksum (Code);
1061 -- In Ada 95 mode we allow any wide characters in a string
1062 -- but in Ada 2005, the set of characters allowed has been
1063 -- restricted to graphic characters.
1065 if Ada_Version >= Ada_05
1066 and then Is_UTF_32_Non_Graphic (UTF_32 (Code))
1067 then
1068 Error_Msg
1069 ("(Ada 2005) non-graphic character not permitted " &
1070 "in string literal", Wptr);
1071 end if;
1073 else
1074 Accumulate_Checksum (C);
1076 if C not in Graphic_Character then
1077 if C in Line_Terminator then
1078 Error_Unterminated_String;
1079 exit;
1081 elsif C in Upper_Half_Character then
1082 if Ada_Version = Ada_83 then
1083 Error_Bad_String_Char;
1084 end if;
1086 else
1087 Error_Bad_String_Char;
1088 end if;
1089 end if;
1091 Code := Get_Char_Code (C);
1092 Scan_Ptr := Scan_Ptr + 1;
1093 end if;
1094 end if;
1096 Store_String_Char (Code);
1098 if not In_Character_Range (Code) then
1099 Wide_Character_Found := True;
1100 end if;
1101 end loop;
1103 String_Literal_Id := End_String;
1104 Set_String;
1105 return;
1106 end Slit;
1108 -- Start of processing for Scan
1110 begin
1111 Prev_Token := Token;
1112 Prev_Token_Ptr := Token_Ptr;
1113 Token_Name := Error_Name;
1115 -- The following loop runs more than once only if a format effector
1116 -- (tab, vertical tab, form feed, line feed, carriage return) is
1117 -- encountered and skipped, or some error situation, such as an
1118 -- illegal character, is encountered.
1120 <<Scan_Next_Character>>
1122 loop
1123 -- Skip past blanks, loop is opened up for speed
1125 while Source (Scan_Ptr) = ' ' loop
1126 if Source (Scan_Ptr + 1) /= ' ' then
1127 Scan_Ptr := Scan_Ptr + 1;
1128 exit;
1129 end if;
1131 if Source (Scan_Ptr + 2) /= ' ' then
1132 Scan_Ptr := Scan_Ptr + 2;
1133 exit;
1134 end if;
1136 if Source (Scan_Ptr + 3) /= ' ' then
1137 Scan_Ptr := Scan_Ptr + 3;
1138 exit;
1139 end if;
1141 if Source (Scan_Ptr + 4) /= ' ' then
1142 Scan_Ptr := Scan_Ptr + 4;
1143 exit;
1144 end if;
1146 if Source (Scan_Ptr + 5) /= ' ' then
1147 Scan_Ptr := Scan_Ptr + 5;
1148 exit;
1149 end if;
1151 if Source (Scan_Ptr + 6) /= ' ' then
1152 Scan_Ptr := Scan_Ptr + 6;
1153 exit;
1154 end if;
1156 if Source (Scan_Ptr + 7) /= ' ' then
1157 Scan_Ptr := Scan_Ptr + 7;
1158 exit;
1159 end if;
1161 Scan_Ptr := Scan_Ptr + 8;
1162 end loop;
1164 -- We are now at a non-blank character, which is the first character
1165 -- of the token we will scan, and hence the value of Token_Ptr.
1167 Token_Ptr := Scan_Ptr;
1169 -- Here begins the main case statement which transfers control on the
1170 -- basis of the non-blank character we have encountered.
1172 case Source (Scan_Ptr) is
1174 -- Line terminator characters
1176 when CR | LF | FF | VT =>
1177 goto Scan_Line_Terminator;
1179 -- Horizontal tab, just skip past it
1181 when HT =>
1182 if Style_Check then
1183 Style.Check_HT;
1184 end if;
1186 Scan_Ptr := Scan_Ptr + 1;
1188 -- End of file character, treated as an end of file only if it is
1189 -- the last character in the buffer, otherwise it is ignored.
1191 when EOF =>
1192 if Scan_Ptr = Source_Last (Current_Source_File) then
1193 Check_End_Of_Line;
1195 if Style_Check then
1196 Style.Check_EOF;
1197 end if;
1199 Token := Tok_EOF;
1200 return;
1201 else
1202 Scan_Ptr := Scan_Ptr + 1;
1203 end if;
1205 -- Ampersand
1207 when '&' =>
1208 Accumulate_Checksum ('&');
1210 if Source (Scan_Ptr + 1) = '&' then
1211 Error_Msg_S ("'&'& should be `AND THEN`");
1212 Scan_Ptr := Scan_Ptr + 2;
1213 Token := Tok_And;
1214 return;
1216 else
1217 Scan_Ptr := Scan_Ptr + 1;
1218 Token := Tok_Ampersand;
1219 return;
1220 end if;
1222 -- Asterisk (can be multiplication operator or double asterisk which
1223 -- is the exponentiation compound delimiter).
1225 when '*' =>
1226 Accumulate_Checksum ('*');
1228 if Source (Scan_Ptr + 1) = '*' then
1229 Accumulate_Checksum ('*');
1230 Scan_Ptr := Scan_Ptr + 2;
1231 Token := Tok_Double_Asterisk;
1232 return;
1234 else
1235 Scan_Ptr := Scan_Ptr + 1;
1236 Token := Tok_Asterisk;
1237 return;
1238 end if;
1240 -- Colon, which can either be an isolated colon, or part of an
1241 -- assignment compound delimiter.
1243 when ':' =>
1244 Accumulate_Checksum (':');
1246 if Double_Char_Token ('=') then
1247 Token := Tok_Colon_Equal;
1249 if Style_Check then
1250 Style.Check_Colon_Equal;
1251 end if;
1253 return;
1255 elsif Source (Scan_Ptr + 1) = '-'
1256 and then Source (Scan_Ptr + 2) /= '-'
1257 then
1258 Token := Tok_Colon_Equal;
1259 Error_Msg (":- should be :=", Scan_Ptr);
1260 Scan_Ptr := Scan_Ptr + 2;
1261 return;
1263 else
1264 Scan_Ptr := Scan_Ptr + 1;
1265 Token := Tok_Colon;
1267 if Style_Check then
1268 Style.Check_Colon;
1269 end if;
1271 return;
1272 end if;
1274 -- Left parenthesis
1276 when '(' =>
1277 Accumulate_Checksum ('(');
1278 Scan_Ptr := Scan_Ptr + 1;
1279 Token := Tok_Left_Paren;
1281 if Style_Check then
1282 Style.Check_Left_Paren;
1283 end if;
1285 return;
1287 -- Left bracket
1289 when '[' =>
1290 if Source (Scan_Ptr + 1) = '"' then
1291 goto Scan_Wide_Character;
1293 else
1294 Error_Msg_S ("illegal character, replaced by ""(""");
1295 Scan_Ptr := Scan_Ptr + 1;
1296 Token := Tok_Left_Paren;
1297 return;
1298 end if;
1300 -- Left brace
1302 when '{' =>
1303 Error_Msg_S ("illegal character, replaced by ""(""");
1304 Scan_Ptr := Scan_Ptr + 1;
1305 Token := Tok_Left_Paren;
1306 return;
1308 -- Comma
1310 when ',' =>
1311 Accumulate_Checksum (',');
1312 Scan_Ptr := Scan_Ptr + 1;
1313 Token := Tok_Comma;
1315 if Style_Check then
1316 Style.Check_Comma;
1317 end if;
1319 return;
1321 -- Dot, which is either an isolated period, or part of a double dot
1322 -- compound delimiter sequence. We also check for the case of a
1323 -- digit following the period, to give a better error message.
1325 when '.' =>
1326 Accumulate_Checksum ('.');
1328 if Double_Char_Token ('.') then
1329 Token := Tok_Dot_Dot;
1331 if Style_Check then
1332 Style.Check_Dot_Dot;
1333 end if;
1335 return;
1337 elsif Source (Scan_Ptr + 1) in '0' .. '9' then
1338 Error_Msg_S ("numeric literal cannot start with point");
1339 Scan_Ptr := Scan_Ptr + 1;
1341 else
1342 Scan_Ptr := Scan_Ptr + 1;
1343 Token := Tok_Dot;
1344 return;
1345 end if;
1347 -- Equal, which can either be an equality operator, or part of the
1348 -- arrow (=>) compound delimiter.
1350 when '=' =>
1351 Accumulate_Checksum ('=');
1353 if Double_Char_Token ('>') then
1354 Token := Tok_Arrow;
1356 if Style_Check then
1357 Style.Check_Arrow;
1358 end if;
1360 return;
1362 elsif Source (Scan_Ptr + 1) = '=' then
1363 Error_Msg_S ("== should be =");
1364 Scan_Ptr := Scan_Ptr + 1;
1365 end if;
1367 Scan_Ptr := Scan_Ptr + 1;
1368 Token := Tok_Equal;
1369 return;
1371 -- Greater than, which can be a greater than operator, greater than
1372 -- or equal operator, or first character of a right label bracket.
1374 when '>' =>
1375 Accumulate_Checksum ('>');
1377 if Double_Char_Token ('=') then
1378 Token := Tok_Greater_Equal;
1379 return;
1381 elsif Double_Char_Token ('>') then
1382 Token := Tok_Greater_Greater;
1383 return;
1385 else
1386 Scan_Ptr := Scan_Ptr + 1;
1387 Token := Tok_Greater;
1388 return;
1389 end if;
1391 -- Less than, which can be a less than operator, less than or equal
1392 -- operator, or the first character of a left label bracket, or the
1393 -- first character of a box (<>) compound delimiter.
1395 when '<' =>
1396 Accumulate_Checksum ('<');
1398 if Double_Char_Token ('=') then
1399 Token := Tok_Less_Equal;
1400 return;
1402 elsif Double_Char_Token ('>') then
1403 Token := Tok_Box;
1405 if Style_Check then
1406 Style.Check_Box;
1407 end if;
1409 return;
1411 elsif Double_Char_Token ('<') then
1412 Token := Tok_Less_Less;
1413 return;
1415 else
1416 Scan_Ptr := Scan_Ptr + 1;
1417 Token := Tok_Less;
1418 return;
1419 end if;
1421 -- Minus, which is either a subtraction operator, or the first
1422 -- character of double minus starting a comment
1424 when '-' => Minus_Case : begin
1425 if Source (Scan_Ptr + 1) = '>' then
1426 Error_Msg_S ("invalid token");
1427 Scan_Ptr := Scan_Ptr + 2;
1428 Token := Tok_Arrow;
1429 return;
1431 elsif Source (Scan_Ptr + 1) /= '-' then
1432 Accumulate_Checksum ('-');
1433 Scan_Ptr := Scan_Ptr + 1;
1434 Token := Tok_Minus;
1435 return;
1437 -- Comment
1439 else -- Source (Scan_Ptr + 1) = '-' then
1440 if Style_Check then
1441 Style.Check_Comment;
1442 end if;
1444 Scan_Ptr := Scan_Ptr + 2;
1446 -- If we are in preprocessor mode with Replace_In_Comments set,
1447 -- then we return the "--" as a token on its own.
1449 if Replace_In_Comments then
1450 Token := Tok_Comment;
1451 return;
1452 end if;
1454 -- Otherwise scan out the comment
1456 Start_Of_Comment := Scan_Ptr;
1458 -- Loop to scan comment (this loop runs more than once only if
1459 -- a horizontal tab or other non-graphic character is scanned)
1461 loop
1462 -- Scan to non graphic character (opened up for speed)
1464 -- Note that we just eat left brackets, which means that
1465 -- bracket notation cannot be used for end of line
1466 -- characters in comments. This seems a reasonable choice,
1467 -- since no one would ever use brackets notation in a real
1468 -- program in this situation, and if we allow brackets
1469 -- notation, we forbid some valid comments which contain a
1470 -- brackets sequence that happens to match an end of line
1471 -- character.
1473 loop
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 exit when Source (Scan_Ptr) not in Graphic_Character;
1483 Scan_Ptr := Scan_Ptr + 1;
1484 end loop;
1486 -- Keep going if horizontal tab
1488 if Source (Scan_Ptr) = HT then
1489 if Style_Check then
1490 Style.Check_HT;
1491 end if;
1493 Scan_Ptr := Scan_Ptr + 1;
1495 -- Terminate scan of comment if line terminator
1497 elsif Source (Scan_Ptr) in Line_Terminator then
1498 exit;
1500 -- Terminate scan of comment if end of file encountered
1501 -- (embedded EOF character or real last character in file)
1503 elsif Source (Scan_Ptr) = EOF then
1504 exit;
1506 -- If we have a wide character, we have to scan it out,
1507 -- because it might be a legitimate line terminator
1509 elsif (Source (Scan_Ptr) = ESC
1510 and then Identifier_Char (ESC))
1511 or else
1512 (Source (Scan_Ptr) in Upper_Half_Character
1513 and then Upper_Half_Encoding)
1514 then
1515 declare
1516 Wptr : constant Source_Ptr := Scan_Ptr;
1517 Code : Char_Code;
1518 Err : Boolean;
1520 begin
1521 Scan_Wide (Source, Scan_Ptr, Code, Err);
1523 -- If not well formed wide character, then just skip
1524 -- past it and ignore it.
1526 if Err then
1527 Scan_Ptr := Wptr + 1;
1529 -- If UTF_32 terminator, terminate comment scan
1531 elsif Is_UTF_32_Line_Terminator (UTF_32 (Code)) then
1532 Scan_Ptr := Wptr;
1533 exit;
1534 end if;
1535 end;
1537 -- Keep going if character in 80-FF range, or is ESC. These
1538 -- characters are allowed in comments by RM-2.1(1), 2.7(2).
1539 -- They are allowed even in Ada 83 mode according to the
1540 -- approved AI. ESC was added to the AI in June 93.
1542 elsif Source (Scan_Ptr) in Upper_Half_Character
1543 or else Source (Scan_Ptr) = ESC
1544 then
1545 Scan_Ptr := Scan_Ptr + 1;
1547 -- Otherwise we have an illegal comment character
1549 else
1550 Error_Illegal_Character;
1551 end if;
1552 end loop;
1554 -- Note that, except when comments are tokens, we do NOT
1555 -- execute a return here, instead we fall through to reexecute
1556 -- the scan loop to look for a token.
1558 if Comment_Is_Token then
1559 Name_Len := Integer (Scan_Ptr - Start_Of_Comment);
1560 Name_Buffer (1 .. Name_Len) :=
1561 String (Source (Start_Of_Comment .. Scan_Ptr - 1));
1562 Comment_Id := Name_Find;
1563 Token := Tok_Comment;
1564 return;
1565 end if;
1566 end if;
1567 end Minus_Case;
1569 -- Double quote starting a string literal
1571 when '"' =>
1572 Slit;
1573 Post_Scan;
1574 return;
1576 -- Percent starting a string literal
1578 when '%' =>
1579 Obsolescent_Check (Token_Ptr);
1581 if Warn_On_Obsolescent_Feature then
1582 Error_Msg_S
1583 ("use of ""'%"" is an obsolescent feature (RM J.2(4))?");
1584 Error_Msg_S
1585 ("\use """""" instead?");
1586 end if;
1588 Slit;
1589 Post_Scan;
1590 return;
1592 -- Apostrophe. This can either be the start of a character literal,
1593 -- or an isolated apostrophe used in a qualified expression or an
1594 -- attribute. We treat it as a character literal if it does not
1595 -- follow a right parenthesis, identifier, the keyword ALL or
1596 -- a literal. This means that we correctly treat constructs like:
1598 -- A := CHARACTER'('A');
1600 -- Note that RM-2.2(7) does not require a separator between
1601 -- "CHARACTER" and "'" in the above.
1603 when ''' => Char_Literal_Case : declare
1604 Code : Char_Code;
1605 Err : Boolean;
1607 begin
1608 Accumulate_Checksum (''');
1609 Scan_Ptr := Scan_Ptr + 1;
1611 -- Here is where we make the test to distinguish the cases. Treat
1612 -- as apostrophe if previous token is an identifier, right paren
1613 -- or the reserved word "all" (latter case as in A.all'Address)
1614 -- (or the reserved word "project" in project files). Also treat
1615 -- it as apostrophe after a literal (this catches some legitimate
1616 -- cases, like A."abs"'Address, and also gives better error
1617 -- behavior for impossible cases like 123'xxx).
1619 if Prev_Token = Tok_Identifier
1620 or else Prev_Token = Tok_Right_Paren
1621 or else Prev_Token = Tok_All
1622 or else Prev_Token = Tok_Project
1623 or else Prev_Token in Token_Class_Literal
1624 then
1625 Token := Tok_Apostrophe;
1627 if Style_Check then
1628 Style.Check_Apostrophe;
1629 end if;
1631 return;
1633 -- Otherwise the apostrophe starts a character literal
1635 else
1636 -- Case of wide character literal
1638 if (Source (Scan_Ptr) = ESC
1639 and then
1640 Wide_Character_Encoding_Method in WC_ESC_Encoding_Method)
1641 or else
1642 (Source (Scan_Ptr) in Upper_Half_Character
1643 and then
1644 Upper_Half_Encoding)
1645 or else
1646 (Source (Scan_Ptr) = '['
1647 and then
1648 Source (Scan_Ptr + 1) = '"')
1649 then
1650 Wptr := Scan_Ptr;
1651 Scan_Wide (Source, Scan_Ptr, Code, Err);
1652 Accumulate_Checksum (Code);
1654 if Err then
1655 Error_Illegal_Wide_Character;
1656 Code := Character'Pos (' ');
1658 -- In Ada 95 mode we allow any wide character in a character
1659 -- literal, but in Ada 2005, the set of characters allowed
1660 -- is restricted to graphic characters.
1662 elsif Ada_Version >= Ada_05
1663 and then Is_UTF_32_Non_Graphic (UTF_32 (Code))
1664 then
1665 Error_Msg
1666 ("(Ada 2005) non-graphic character not permitted " &
1667 "in character literal", Wptr);
1668 end if;
1670 if Source (Scan_Ptr) /= ''' then
1671 Error_Msg_S ("missing apostrophe");
1672 else
1673 Scan_Ptr := Scan_Ptr + 1;
1674 end if;
1676 -- If we do not find a closing quote in the expected place then
1677 -- assume that we have a misguided attempt at a string literal.
1679 -- However, if previous token is RANGE, then we return an
1680 -- apostrophe instead since this gives better error recovery
1682 elsif Source (Scan_Ptr + 1) /= ''' then
1683 if Prev_Token = Tok_Range then
1684 Token := Tok_Apostrophe;
1685 return;
1687 else
1688 Scan_Ptr := Scan_Ptr - 1;
1689 Error_Msg_S
1690 ("strings are delimited by double quote character");
1691 Slit;
1692 Post_Scan;
1693 return;
1694 end if;
1696 -- Otherwise we have a (non-wide) character literal
1698 else
1699 Accumulate_Checksum (Source (Scan_Ptr));
1701 if Source (Scan_Ptr) not in Graphic_Character then
1702 if Source (Scan_Ptr) in Upper_Half_Character then
1703 if Ada_Version = Ada_83 then
1704 Error_Illegal_Character;
1705 end if;
1707 else
1708 Error_Illegal_Character;
1709 end if;
1710 end if;
1712 Code := Get_Char_Code (Source (Scan_Ptr));
1713 Scan_Ptr := Scan_Ptr + 2;
1714 end if;
1716 -- Fall through here with Scan_Ptr updated past the closing
1717 -- quote, and Code set to the Char_Code value for the literal
1719 Accumulate_Checksum (''');
1720 Token := Tok_Char_Literal;
1721 Set_Character_Literal_Name (Code);
1722 Token_Name := Name_Find;
1723 Character_Code := Code;
1724 Post_Scan;
1725 return;
1726 end if;
1727 end Char_Literal_Case;
1729 -- Right parenthesis
1731 when ')' =>
1732 Accumulate_Checksum (')');
1733 Scan_Ptr := Scan_Ptr + 1;
1734 Token := Tok_Right_Paren;
1736 if Style_Check then
1737 Style.Check_Right_Paren;
1738 end if;
1740 return;
1742 -- Right bracket or right brace, treated as right paren
1744 when ']' | '}' =>
1745 Error_Msg_S ("illegal character, replaced by "")""");
1746 Scan_Ptr := Scan_Ptr + 1;
1747 Token := Tok_Right_Paren;
1748 return;
1750 -- Slash (can be division operator or first character of not equal)
1752 when '/' =>
1753 Accumulate_Checksum ('/');
1755 if Double_Char_Token ('=') then
1756 Token := Tok_Not_Equal;
1757 return;
1758 else
1759 Scan_Ptr := Scan_Ptr + 1;
1760 Token := Tok_Slash;
1761 return;
1762 end if;
1764 -- Semicolon
1766 when ';' =>
1767 Accumulate_Checksum (';');
1768 Scan_Ptr := Scan_Ptr + 1;
1769 Token := Tok_Semicolon;
1771 if Style_Check then
1772 Style.Check_Semicolon;
1773 end if;
1775 return;
1777 -- Vertical bar
1779 when '|' => Vertical_Bar_Case : begin
1780 Accumulate_Checksum ('|');
1782 -- Special check for || to give nice message
1784 if Source (Scan_Ptr + 1) = '|' then
1785 Error_Msg_S ("""'|'|"" should be `OR ELSE`");
1786 Scan_Ptr := Scan_Ptr + 2;
1787 Token := Tok_Or;
1788 return;
1790 else
1791 Scan_Ptr := Scan_Ptr + 1;
1792 Token := Tok_Vertical_Bar;
1794 if Style_Check then
1795 Style.Check_Vertical_Bar;
1796 end if;
1798 return;
1799 end if;
1800 end Vertical_Bar_Case;
1802 -- Exclamation, replacement character for vertical bar
1804 when '!' => Exclamation_Case : begin
1805 Accumulate_Checksum ('!');
1806 Obsolescent_Check (Token_Ptr);
1808 if Warn_On_Obsolescent_Feature then
1809 Error_Msg_S
1810 ("use of ""'!"" is an obsolescent feature (RM J.2(2))?");
1811 Error_Msg_S
1812 ("\use ""'|"" instead?");
1813 end if;
1815 if Source (Scan_Ptr + 1) = '=' then
1816 Error_Msg_S ("'!= should be /=");
1817 Scan_Ptr := Scan_Ptr + 2;
1818 Token := Tok_Not_Equal;
1819 return;
1821 else
1822 Scan_Ptr := Scan_Ptr + 1;
1823 Token := Tok_Vertical_Bar;
1824 return;
1825 end if;
1826 end Exclamation_Case;
1828 -- Plus
1830 when '+' => Plus_Case : begin
1831 Accumulate_Checksum ('+');
1832 Scan_Ptr := Scan_Ptr + 1;
1833 Token := Tok_Plus;
1834 return;
1835 end Plus_Case;
1837 -- Digits starting a numeric literal
1839 when '0' .. '9' =>
1841 -- First a bit of a scan ahead to see if we have a case of an
1842 -- identifier starting with a digit (remembering exponent case).
1844 declare
1845 C : constant Character := Source (Scan_Ptr + 1);
1847 begin
1848 -- OK literal if digit followed by digit or underscore
1850 if C in '0' .. '9' or else C = '_' then
1851 null;
1853 -- OK literal if digit not followed by identifier char
1855 elsif not Identifier_Char (C) then
1856 null;
1858 -- OK literal if digit followed by e/E followed by digit/sign.
1859 -- We also allow underscore after the E, which is an error, but
1860 -- better handled by Nlit than deciding this is an identifier.
1862 elsif (C = 'e' or else C = 'E')
1863 and then (Source (Scan_Ptr + 2) in '0' .. '9'
1864 or else Source (Scan_Ptr + 2) = '+'
1865 or else Source (Scan_Ptr + 2) = '-'
1866 or else Source (Scan_Ptr + 2) = '_')
1867 then
1868 null;
1870 -- Here we have what really looks like an identifier that
1871 -- starts with a digit, so give error msg.
1873 else
1874 Error_Msg_S ("identifier may not start with digit");
1875 Name_Len := 1;
1876 Underline_Found := False;
1877 Name_Buffer (1) := Source (Scan_Ptr);
1878 Accumulate_Checksum (Name_Buffer (1));
1879 Scan_Ptr := Scan_Ptr + 1;
1880 goto Scan_Identifier;
1881 end if;
1882 end;
1884 -- Here we have an OK integer literal
1886 Nlit;
1888 if Identifier_Char (Source (Scan_Ptr)) then
1889 Error_Msg_S
1890 ("delimiter required between literal and identifier");
1891 end if;
1893 Post_Scan;
1894 return;
1896 -- Lower case letters
1898 when 'a' .. 'z' =>
1899 Name_Len := 1;
1900 Underline_Found := False;
1901 Name_Buffer (1) := Source (Scan_Ptr);
1902 Accumulate_Checksum (Name_Buffer (1));
1903 Scan_Ptr := Scan_Ptr + 1;
1904 goto Scan_Identifier;
1906 -- Upper case letters
1908 when 'A' .. 'Z' =>
1909 Name_Len := 1;
1910 Underline_Found := False;
1911 Name_Buffer (1) :=
1912 Character'Val (Character'Pos (Source (Scan_Ptr)) + 32);
1913 Accumulate_Checksum (Name_Buffer (1));
1914 Scan_Ptr := Scan_Ptr + 1;
1915 goto Scan_Identifier;
1917 -- Underline character
1919 when '_' =>
1920 if Special_Characters ('_') then
1921 Token_Ptr := Scan_Ptr;
1922 Scan_Ptr := Scan_Ptr + 1;
1923 Token := Tok_Special;
1924 Special_Character := '_';
1925 return;
1926 end if;
1928 Error_Msg_S ("identifier cannot start with underline");
1929 Name_Len := 1;
1930 Name_Buffer (1) := '_';
1931 Scan_Ptr := Scan_Ptr + 1;
1932 Underline_Found := False;
1933 goto Scan_Identifier;
1935 -- Space (not possible, because we scanned past blanks)
1937 when ' ' =>
1938 raise Program_Error;
1940 -- Characters in top half of ASCII 8-bit chart
1942 when Upper_Half_Character =>
1944 -- Wide character case
1946 if Upper_Half_Encoding then
1947 goto Scan_Wide_Character;
1949 -- Otherwise we have OK Latin-1 character
1951 else
1952 -- Upper half characters may possibly be identifier letters
1953 -- but can never be digits, so Identifier_Char can be used to
1954 -- test for a valid start of identifier character.
1956 if Identifier_Char (Source (Scan_Ptr)) then
1957 Name_Len := 0;
1958 Underline_Found := False;
1959 goto Scan_Identifier;
1960 else
1961 Error_Illegal_Character;
1962 end if;
1963 end if;
1965 when ESC =>
1967 -- ESC character, possible start of identifier if wide characters
1968 -- using ESC encoding are allowed in identifiers, which we can
1969 -- tell by looking at the Identifier_Char flag for ESC, which is
1970 -- only true if these conditions are met. In Ada 2005 mode, may
1971 -- also be valid UTF_32 space or line terminator character.
1973 if Identifier_Char (ESC) then
1974 Name_Len := 0;
1975 goto Scan_Wide_Character;
1976 else
1977 Error_Illegal_Character;
1978 end if;
1980 -- Invalid control characters
1982 when NUL | SOH | STX | ETX | EOT | ENQ | ACK | BEL | BS | ASCII.SO |
1983 SI | DLE | DC1 | DC2 | DC3 | DC4 | NAK | SYN | ETB | CAN |
1984 EM | FS | GS | RS | US | DEL
1986 Error_Illegal_Character;
1988 -- Invalid graphic characters
1990 when '#' | '$' | '?' | '@' | '`' | '\' | '^' | '~' =>
1992 -- If Set_Special_Character has been called for this character,
1993 -- set Scans.Special_Character and return a Special token.
1995 if Special_Characters (Source (Scan_Ptr)) then
1996 Token_Ptr := Scan_Ptr;
1997 Token := Tok_Special;
1998 Special_Character := Source (Scan_Ptr);
1999 Scan_Ptr := Scan_Ptr + 1;
2000 return;
2002 -- Otherwise, this is an illegal character
2004 else
2005 Error_Illegal_Character;
2006 end if;
2008 -- End switch on non-blank character
2010 end case;
2012 -- End loop past format effectors. The exit from this loop is by
2013 -- executing a return statement following completion of token scan
2014 -- (control never falls out of this loop to the code which follows)
2016 end loop;
2018 -- Wide_Character scanning routine. On entry we have encountered the
2019 -- initial character of a wide character sequence.
2021 <<Scan_Wide_Character>>
2023 declare
2024 Code : Char_Code;
2025 Cat : Category;
2026 Err : Boolean;
2028 begin
2029 Wptr := Scan_Ptr;
2030 Scan_Wide (Source, Scan_Ptr, Code, Err);
2032 -- If bad wide character, signal error and continue scan
2034 if Err then
2035 Error_Illegal_Wide_Character;
2036 goto Scan_Next_Character;
2037 end if;
2039 Cat := Get_Category (UTF_32 (Code));
2041 -- If OK letter, reset scan ptr and go scan identifier
2043 if Is_UTF_32_Letter (Cat) then
2044 Scan_Ptr := Wptr;
2045 Name_Len := 0;
2046 Underline_Found := False;
2047 goto Scan_Identifier;
2049 -- If OK wide space, ignore and keep scanning (we do not include
2050 -- any ignored spaces in checksum)
2052 elsif Is_UTF_32_Space (Cat) then
2053 goto Scan_Next_Character;
2055 -- If OK wide line terminator, terminate current line
2057 elsif Is_UTF_32_Line_Terminator (UTF_32 (Code)) then
2058 Scan_Ptr := Wptr;
2059 goto Scan_Line_Terminator;
2061 -- Punctuation is an error (at start of identifier)
2063 elsif Is_UTF_32_Punctuation (Cat) then
2064 Error_Msg
2065 ("identifier cannot start with punctuation", Wptr);
2066 Scan_Ptr := Wptr;
2067 Name_Len := 0;
2068 Underline_Found := False;
2069 goto Scan_Identifier;
2071 -- Mark character is an error (at start of identifier)
2073 elsif Is_UTF_32_Mark (Cat) then
2074 Error_Msg
2075 ("identifier cannot start with mark character", Wptr);
2076 Scan_Ptr := Wptr;
2077 Name_Len := 0;
2078 Underline_Found := False;
2079 goto Scan_Identifier;
2081 -- Other format character is an error (at start of identifier)
2083 elsif Is_UTF_32_Other (Cat) then
2084 Error_Msg
2085 ("identifier cannot start with other format character", Wptr);
2086 Scan_Ptr := Wptr;
2087 Name_Len := 0;
2088 Underline_Found := False;
2089 goto Scan_Identifier;
2091 -- Extended digit character is an error. Could be bad start of
2092 -- identifier or bad literal. Not worth doing too much to try to
2093 -- distinguish these cases, but we will do a little bit.
2095 elsif Is_UTF_32_Digit (Cat) then
2096 Error_Msg
2097 ("identifier cannot start with digit character", Wptr);
2098 Scan_Ptr := Wptr;
2099 Name_Len := 0;
2100 Underline_Found := False;
2101 goto Scan_Identifier;
2103 -- All other wide characters are illegal here
2105 else
2106 Error_Illegal_Wide_Character;
2107 goto Scan_Next_Character;
2108 end if;
2109 end;
2111 -- Routine to scan line terminator. On entry Scan_Ptr points to a
2112 -- character which is one of FF,LR,CR,VT, or one of the wide characters
2113 -- that is treated as a line terminator.
2115 <<Scan_Line_Terminator>>
2117 -- Check line too long
2119 Check_End_Of_Line;
2121 -- Set Token_Ptr, if End_Of_Line is a token, for the case when it is
2122 -- a physical line.
2124 if End_Of_Line_Is_Token then
2125 Token_Ptr := Scan_Ptr;
2126 end if;
2128 declare
2129 Physical : Boolean;
2131 begin
2132 Skip_Line_Terminators (Scan_Ptr, Physical);
2134 -- If we are at start of physical line, update scan pointers to
2135 -- reflect the start of the new line.
2137 if Physical then
2138 Current_Line_Start := Scan_Ptr;
2139 Start_Column := Set_Start_Column;
2140 First_Non_Blank_Location := Scan_Ptr;
2142 -- If End_Of_Line is a token, we return it as it is a
2143 -- physical line.
2145 if End_Of_Line_Is_Token then
2146 Token := Tok_End_Of_Line;
2147 return;
2148 end if;
2149 end if;
2150 end;
2152 goto Scan_Next_Character;
2154 -- Identifier scanning routine. On entry, some initial characters of
2155 -- the identifier may have already been stored in Name_Buffer. If so,
2156 -- Name_Len has the number of characters stored, otherwise Name_Len is
2157 -- set to zero on entry. Underline_Found is also set False on entry.
2159 <<Scan_Identifier>>
2161 -- This loop scans as fast as possible past lower half letters and
2162 -- digits, which we expect to be the most common characters.
2164 loop
2165 if Source (Scan_Ptr) in 'a' .. 'z'
2166 or else Source (Scan_Ptr) in '0' .. '9'
2167 then
2168 Name_Buffer (Name_Len + 1) := Source (Scan_Ptr);
2169 Accumulate_Checksum (Source (Scan_Ptr));
2171 elsif Source (Scan_Ptr) in 'A' .. 'Z' then
2172 Name_Buffer (Name_Len + 1) :=
2173 Character'Val (Character'Pos (Source (Scan_Ptr)) + 32);
2174 Accumulate_Checksum (Name_Buffer (Name_Len + 1));
2176 else
2177 exit;
2178 end if;
2180 Underline_Found := False;
2181 Scan_Ptr := Scan_Ptr + 1;
2182 Name_Len := Name_Len + 1;
2183 end loop;
2185 -- If we fall through, then we have encountered either an underline
2186 -- character, or an extended identifier character (i.e. one from the
2187 -- upper half), or a wide character, or an identifier terminator. The
2188 -- initial test speeds us up in the most common case where we have
2189 -- an identifier terminator. Note that ESC is an identifier character
2190 -- only if a wide character encoding method that uses ESC encoding
2191 -- is active, so if we find an ESC character we know that we have a
2192 -- wide character.
2194 if Identifier_Char (Source (Scan_Ptr))
2195 or else (Source (Scan_Ptr) in Upper_Half_Character
2196 and then Upper_Half_Encoding)
2197 then
2198 -- Case of underline
2200 if Source (Scan_Ptr) = '_' then
2201 Accumulate_Checksum ('_');
2203 if Underline_Found then
2204 Error_No_Double_Underline;
2205 else
2206 Underline_Found := True;
2207 Name_Len := Name_Len + 1;
2208 Name_Buffer (Name_Len) := '_';
2209 end if;
2211 Scan_Ptr := Scan_Ptr + 1;
2212 goto Scan_Identifier;
2214 -- Upper half character
2216 elsif Source (Scan_Ptr) in Upper_Half_Character
2217 and then not Upper_Half_Encoding
2218 then
2219 Accumulate_Checksum (Source (Scan_Ptr));
2220 Store_Encoded_Character
2221 (Get_Char_Code (Fold_Lower (Source (Scan_Ptr))));
2222 Scan_Ptr := Scan_Ptr + 1;
2223 Underline_Found := False;
2224 goto Scan_Identifier;
2226 -- Left bracket not followed by a quote terminates an identifier.
2227 -- This is an error, but we don't want to give a junk error msg
2228 -- about wide characters in this case!
2230 elsif Source (Scan_Ptr) = '['
2231 and then Source (Scan_Ptr + 1) /= '"'
2232 then
2233 null;
2235 -- We know we have a wide character encoding here (the current
2236 -- character is either ESC, left bracket, or an upper half
2237 -- character depending on the encoding method).
2239 else
2240 -- Scan out the wide character and insert the appropriate
2241 -- encoding into the name table entry for the identifier.
2243 declare
2244 Code : Char_Code;
2245 Err : Boolean;
2246 Chr : Character;
2247 Cat : Category;
2249 begin
2250 Wptr := Scan_Ptr;
2251 Scan_Wide (Source, Scan_Ptr, Code, Err);
2253 -- If error, signal error
2255 if Err then
2256 Error_Illegal_Wide_Character;
2258 -- If the character scanned is a normal identifier
2259 -- character, then we treat it that way.
2261 elsif In_Character_Range (Code)
2262 and then Identifier_Char (Get_Character (Code))
2263 then
2264 Chr := Get_Character (Code);
2265 Accumulate_Checksum (Chr);
2266 Store_Encoded_Character
2267 (Get_Char_Code (Fold_Lower (Chr)));
2268 Underline_Found := False;
2270 -- Here if not a normal identifier character
2272 else
2273 -- Make sure we are allowing wide characters in
2274 -- identifiers. Note that we allow wide character
2275 -- notation for an OK identifier character. This in
2276 -- particular allows bracket or other notation to be
2277 -- used for upper half letters.
2279 -- Wide characters are always allowed in Ada 2005
2281 if Identifier_Character_Set /= 'w'
2282 and then Ada_Version < Ada_05
2283 then
2284 Error_Msg
2285 ("wide character not allowed in identifier", Wptr);
2286 end if;
2288 Cat := Get_Category (UTF_32 (Code));
2290 -- If OK letter, store it folding to upper case. Note
2291 -- that we include the folded letter in the checksum.
2293 if Is_UTF_32_Letter (Cat) then
2294 Code :=
2295 Char_Code (UTF_32_To_Upper_Case (UTF_32 (Code)));
2296 Accumulate_Checksum (Code);
2297 Store_Encoded_Character (Code);
2298 Underline_Found := False;
2300 -- If OK extended digit or mark, then store it
2302 elsif Is_UTF_32_Digit (Cat)
2303 or else Is_UTF_32_Mark (Cat)
2304 then
2305 Accumulate_Checksum (Code);
2306 Store_Encoded_Character (Code);
2307 Underline_Found := False;
2309 -- Wide punctuation is also stored, but counts as an
2310 -- underline character for error checking purposes.
2312 elsif Is_UTF_32_Punctuation (Cat) then
2313 Accumulate_Checksum (Code);
2315 if Underline_Found then
2316 declare
2317 Cend : constant Source_Ptr := Scan_Ptr;
2318 begin
2319 Scan_Ptr := Wptr;
2320 Error_No_Double_Underline;
2321 Scan_Ptr := Cend;
2322 end;
2324 else
2325 Store_Encoded_Character (Code);
2326 Underline_Found := True;
2327 end if;
2329 -- Wide character in Unicode category "Other, Format"
2330 -- is accepted in an identifier, but is ignored and not
2331 -- stored. It seems reasonable to exclude it from the
2332 -- checksum.
2334 -- Note that it is correct (see AI-395) to simply strip
2335 -- other format characters, before testing for double
2336 -- underlines, or for reserved words).
2338 elsif Is_UTF_32_Other (Cat) then
2339 null;
2341 -- Wide character in category Separator,Space terminates
2343 elsif Is_UTF_32_Space (Cat) then
2344 goto Scan_Identifier_Complete;
2346 -- Any other wide character is not acceptable
2348 else
2349 Error_Msg
2350 ("invalid wide character in identifier", Wptr);
2351 end if;
2352 end if;
2354 goto Scan_Identifier;
2355 end;
2356 end if;
2357 end if;
2359 -- Scan of identifier is complete. The identifier is stored in
2360 -- Name_Buffer, and Scan_Ptr points past the last character.
2362 <<Scan_Identifier_Complete>>
2363 Token_Name := Name_Find;
2365 -- Check for identifier ending with underline or punctuation char
2367 if Underline_Found then
2368 Underline_Found := False;
2370 if Source (Scan_Ptr - 1) = '_' then
2371 Error_Msg
2372 ("identifier cannot end with underline", Scan_Ptr - 1);
2373 else
2374 Error_Msg
2375 ("identifier cannot end with punctuation character", Wptr);
2376 end if;
2377 end if;
2379 -- Here is where we check if it was a keyword
2381 if Is_Keyword_Name (Token_Name) then
2382 Token := Token_Type'Val (Get_Name_Table_Byte (Token_Name));
2384 -- Keyword style checks
2386 if Style_Check then
2388 -- Deal with possible style check for non-lower case keyword,
2389 -- but we don't treat ACCESS, DELTA, DIGITS, RANGE as keywords
2390 -- for this purpose if they appear as attribute designators.
2391 -- Actually we only check the first character for speed.
2393 -- Ada 2005 (AI-284): Do not apply the style check in case of
2394 -- "pragma Interface"
2396 -- Ada 2005 (AI-340): Do not apply the style check in case of
2397 -- MOD attribute.
2399 if Source (Token_Ptr) <= 'Z'
2400 and then (Prev_Token /= Tok_Apostrophe
2401 or else
2402 (Token /= Tok_Access and then
2403 Token /= Tok_Delta and then
2404 Token /= Tok_Digits and then
2405 Token /= Tok_Mod and then
2406 Token /= Tok_Range))
2407 and then (Token /= Tok_Interface
2408 or else
2409 (Token = Tok_Interface
2410 and then Prev_Token /= Tok_Pragma))
2411 then
2412 Style.Non_Lower_Case_Keyword;
2413 end if;
2415 -- Check THEN/ELSE style rules. These do not apply to AND THEN
2416 -- or OR ELSE, and do not apply in conditional expressions.
2418 if (Token = Tok_Then and then Prev_Token /= Tok_And)
2419 or else
2420 (Token = Tok_Else and then Prev_Token /= Tok_Or)
2421 then
2422 if Inside_Conditional_Expression = 0 then
2423 Style.Check_Separate_Stmt_Lines;
2424 end if;
2425 end if;
2426 end if;
2428 -- We must reset Token_Name since this is not an identifier and
2429 -- if we leave Token_Name set, the parser gets confused because
2430 -- it thinks it is dealing with an identifier instead of the
2431 -- corresponding keyword.
2433 Token_Name := No_Name;
2434 Accumulate_Token_Checksum;
2435 return;
2437 -- It is an identifier after all
2439 else
2440 Token := Tok_Identifier;
2441 Accumulate_Token_Checksum;
2442 Post_Scan;
2443 return;
2444 end if;
2445 end Scan;
2447 --------------------------
2448 -- Set_Comment_As_Token --
2449 --------------------------
2451 procedure Set_Comment_As_Token (Value : Boolean) is
2452 begin
2453 Comment_Is_Token := Value;
2454 end Set_Comment_As_Token;
2456 ------------------------------
2457 -- Set_End_Of_Line_As_Token --
2458 ------------------------------
2460 procedure Set_End_Of_Line_As_Token (Value : Boolean) is
2461 begin
2462 End_Of_Line_Is_Token := Value;
2463 end Set_End_Of_Line_As_Token;
2465 ---------------------------
2466 -- Set_Special_Character --
2467 ---------------------------
2469 procedure Set_Special_Character (C : Character) is
2470 begin
2471 case C is
2472 when '#' | '$' | '_' | '?' | '@' | '`' | '\' | '^' | '~' =>
2473 Special_Characters (C) := True;
2475 when others =>
2476 null;
2477 end case;
2478 end Set_Special_Character;
2480 ----------------------
2481 -- Set_Start_Column --
2482 ----------------------
2484 -- Note: it seems at first glance a little expensive to compute this value
2485 -- for every source line (since it is certainly not used for all source
2486 -- lines). On the other hand, it doesn't take much more work to skip past
2487 -- the initial white space on the line counting the columns than it would
2488 -- to scan past the white space using the standard scanning circuits.
2490 function Set_Start_Column return Column_Number is
2491 Start_Column : Column_Number := 0;
2493 begin
2494 -- Outer loop scans past horizontal tab characters
2496 Tabs_Loop : loop
2498 -- Inner loop scans past blanks as fast as possible, bumping Scan_Ptr
2499 -- past the blanks and adjusting Start_Column to account for them.
2501 Blanks_Loop : loop
2502 if Source (Scan_Ptr) = ' ' then
2503 if Source (Scan_Ptr + 1) = ' ' then
2504 if Source (Scan_Ptr + 2) = ' ' then
2505 if Source (Scan_Ptr + 3) = ' ' then
2506 if Source (Scan_Ptr + 4) = ' ' then
2507 if Source (Scan_Ptr + 5) = ' ' then
2508 if Source (Scan_Ptr + 6) = ' ' then
2509 Scan_Ptr := Scan_Ptr + 7;
2510 Start_Column := Start_Column + 7;
2511 else
2512 Scan_Ptr := Scan_Ptr + 6;
2513 Start_Column := Start_Column + 6;
2514 exit Blanks_Loop;
2515 end if;
2516 else
2517 Scan_Ptr := Scan_Ptr + 5;
2518 Start_Column := Start_Column + 5;
2519 exit Blanks_Loop;
2520 end if;
2521 else
2522 Scan_Ptr := Scan_Ptr + 4;
2523 Start_Column := Start_Column + 4;
2524 exit Blanks_Loop;
2525 end if;
2526 else
2527 Scan_Ptr := Scan_Ptr + 3;
2528 Start_Column := Start_Column + 3;
2529 exit Blanks_Loop;
2530 end if;
2531 else
2532 Scan_Ptr := Scan_Ptr + 2;
2533 Start_Column := Start_Column + 2;
2534 exit Blanks_Loop;
2535 end if;
2536 else
2537 Scan_Ptr := Scan_Ptr + 1;
2538 Start_Column := Start_Column + 1;
2539 exit Blanks_Loop;
2540 end if;
2541 else
2542 exit Blanks_Loop;
2543 end if;
2544 end loop Blanks_Loop;
2546 -- Outer loop keeps going only if a horizontal tab follows
2548 if Source (Scan_Ptr) = HT then
2549 if Style_Check then
2550 Style.Check_HT;
2551 end if;
2553 Scan_Ptr := Scan_Ptr + 1;
2554 Start_Column := (Start_Column / 8) * 8 + 8;
2555 else
2556 exit Tabs_Loop;
2557 end if;
2558 end loop Tabs_Loop;
2560 return Start_Column;
2562 -- A constraint error can happen only if we have a compiler with checks on
2563 -- and a line with a ludicrous number of tabs or spaces at the start. In
2564 -- such a case, we really don't care if Start_Column is right or not.
2566 exception
2567 when Constraint_Error =>
2568 return Start_Column;
2569 end Set_Start_Column;
2571 end Scng;