1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Csets
; use Csets
;
28 with Errout
; use Errout
;
29 with Hostparm
; use Hostparm
;
31 with Namet
; use Namet
;
33 with Sinput
; use Sinput
;
34 with Snames
; use Snames
;
35 with Stringt
; use Stringt
;
36 with Stylesw
; use Stylesw
;
37 with Uintp
; use Uintp
;
38 with Urealp
; use Urealp
;
39 with Widechar
; use Widechar
;
41 pragma Warnings
(Off
);
42 -- This package is used also by gnatcoll
44 with System
.UTF_32
; use System
.UTF_32
;
45 with System
.WCh_Con
; use System
.WCh_Con
;
51 -- Make control characters visible
53 Special_Characters
: array (Character) of Boolean := (others => False);
54 -- For characters that are Special token, the value is True
56 End_Of_Line_Is_Token
: Boolean := False;
57 -- True if End_Of_Line is a token
59 -----------------------
60 -- Local Subprograms --
61 -----------------------
63 procedure Accumulate_Token_Checksum
;
64 pragma Inline
(Accumulate_Token_Checksum
);
65 -- Called after each numeric literal and identifier/keyword. For keywords,
66 -- the token used is Tok_Identifier. This allows detection of additional
67 -- spaces added in sources when using the builder switch -m.
69 procedure Accumulate_Checksum
(C
: Character);
70 pragma Inline
(Accumulate_Checksum
);
71 -- This routine accumulates the checksum given character C. During the
72 -- scanning of a source file, this routine is called with every character
73 -- in the source, excluding blanks, and all control characters (except
74 -- that ESC is included in the checksum). Upper case letters not in string
75 -- literals are folded by the caller. See Sinput spec for the documentation
76 -- of the checksum algorithm. Note: checksum values are only used if we
77 -- generate code, so it is not necessary to worry about making the right
78 -- sequence of calls in any error situation.
80 procedure Accumulate_Checksum
(C
: Char_Code
);
81 pragma Inline
(Accumulate_Checksum
);
82 -- This version is identical, except that the argument, C, is a character
83 -- code value instead of a character. This is used when wide characters
84 -- are scanned. We use the character code rather than the ASCII characters
85 -- so that the checksum is independent of wide character encoding method.
87 procedure Initialize_Checksum
;
88 pragma Inline
(Initialize_Checksum
);
89 -- Initialize checksum value
91 -------------------------
92 -- Accumulate_Checksum --
93 -------------------------
95 procedure Accumulate_Checksum
(C
: Character) is
97 System
.CRC32
.Update
(System
.CRC32
.CRC32
(Checksum
), C
);
98 end Accumulate_Checksum
;
100 procedure Accumulate_Checksum
(C
: Char_Code
) is
103 Accumulate_Checksum
(Character'Val (C
/ 2 ** 24));
104 Accumulate_Checksum
(Character'Val ((C
/ 2 ** 16) mod 256));
105 Accumulate_Checksum
(Character'Val ((C
/ 256) mod 256));
107 Accumulate_Checksum
(Character'Val (C
/ 256));
110 Accumulate_Checksum
(Character'Val (C
mod 256));
111 end Accumulate_Checksum
;
113 -------------------------------
114 -- Accumulate_Token_Checksum --
115 -------------------------------
117 procedure Accumulate_Token_Checksum
is
120 (System
.CRC32
.CRC32
(Checksum
),
121 Character'Val (Token_Type
'Pos (Token
)));
122 end Accumulate_Token_Checksum
;
124 -----------------------
125 -- Check_End_Of_Line --
126 -----------------------
128 procedure Check_End_Of_Line
is
129 Len
: constant Int
:=
130 Int
(Scan_Ptr
- Current_Line_Start
) - Wide_Char_Byte_Count
;
134 Style
.Check_Line_Terminator
(Len
);
137 -- Deal with checking maximum line length
139 if Style_Check
and Style_Check_Max_Line_Length
then
140 Style
.Check_Line_Max_Length
(Len
);
142 -- If style checking is inactive, check maximum line length against
145 elsif Len
> Max_Line_Length
then
147 ("this line is too long",
148 Current_Line_Start
+ Source_Ptr
(Max_Line_Length
));
151 -- Now one more checking circuit. Normally we are only enforcing a limit
152 -- of physical characters, with tabs counting as one character. But if
153 -- after tab expansion we would have a total line length that exceeded
154 -- 32766, that would really cause trouble, because column positions
155 -- would exceed the maximum we allow for a column count. Note: the limit
156 -- is 32766 rather than 32767, since we use a value of 32767 for special
157 -- purposes (see Sinput). Now we really do not want to go messing with
158 -- tabs in the normal case, so what we do is to check for a line that
159 -- has more than 4096 physical characters. Any shorter line could not
160 -- be a problem, even if it was all tabs.
169 Ptr
:= Current_Line_Start
;
171 exit when Ptr
= Scan_Ptr
;
173 if Source
(Ptr
) = ASCII
.HT
then
174 Col
:= (Col
- 1 + 8) / 8 * 8 + 1;
181 ("this line is longer than 32766 characters",
183 raise Unrecoverable_Error
;
191 -- Reset wide character byte count for next line
193 Wide_Char_Byte_Count
:= 0;
194 end Check_End_Of_Line
;
196 ----------------------------
197 -- Determine_Token_Casing --
198 ----------------------------
200 function Determine_Token_Casing
return Casing_Type
is
202 return Determine_Casing
(Source
(Token_Ptr
.. Scan_Ptr
- 1));
203 end Determine_Token_Casing
;
205 -------------------------
206 -- Initialize_Checksum --
207 -------------------------
209 procedure Initialize_Checksum
is
211 System
.CRC32
.Initialize
(System
.CRC32
.CRC32
(Checksum
));
212 end Initialize_Checksum
;
214 ------------------------
215 -- Initialize_Scanner --
216 ------------------------
218 procedure Initialize_Scanner
(Index
: Source_File_Index
) is
220 -- Establish reserved words
222 Scans
.Initialize_Ada_Keywords
;
224 -- Initialize scan control variables
226 Current_Source_File
:= Index
;
227 Source
:= Source_Text
(Current_Source_File
);
228 Scan_Ptr
:= Source_First
(Current_Source_File
);
230 Token_Ptr
:= Scan_Ptr
;
231 Current_Line_Start
:= Scan_Ptr
;
233 Token_Name
:= No_Name
;
234 Start_Column
:= Set_Start_Column
;
235 First_Non_Blank_Location
:= Scan_Ptr
;
238 Wide_Char_Byte_Count
:= 0;
240 -- Do not call Scan, otherwise the License stuff does not work in Scn
242 end Initialize_Scanner
;
244 ------------------------------
245 -- Reset_Special_Characters --
246 ------------------------------
248 procedure Reset_Special_Characters
is
250 Special_Characters
:= (others => False);
251 end Reset_Special_Characters
;
259 Underline_Found
: Boolean;
260 -- During scanning of an identifier, set to True if last character
261 -- scanned was an underline or other punctuation character. This
262 -- is used to flag the error of two underlines/punctuations in a
263 -- row or ending an identifier with a underline/punctuation. Here
264 -- punctuation means any UTF_32 character in the Unicode category
265 -- Punctuation,Connector.
268 -- Used to remember start of last wide character scanned
270 function Double_Char_Token
(C
: Character) return Boolean;
271 -- This function is used for double character tokens like := or <>. It
272 -- checks if the character following Source (Scan_Ptr) is C, and if so
273 -- bumps Scan_Ptr past the pair of characters and returns True. A space
274 -- between the two characters is also recognized with an appropriate
275 -- error message being issued. If C is not present, False is returned.
276 -- Note that Double_Char_Token can only be used for tokens defined in
277 -- the Ada syntax (it's use for error cases like && is not appropriate
278 -- since we do not want a junk message for a case like &-space-&).
280 procedure Error_Illegal_Character
;
281 -- Give illegal character error, Scan_Ptr points to character. On
282 -- return, Scan_Ptr is bumped past the illegal character.
284 procedure Error_Illegal_Wide_Character
;
285 -- Give illegal wide character message. On return, Scan_Ptr is bumped
286 -- past the illegal character, which may still leave us pointing to
287 -- junk, not much we can do if the escape sequence is messed up.
289 procedure Error_No_Double_Underline
;
290 -- Signal error of two underline or punctuation characters in a row.
291 -- Called with Scan_Ptr pointing to second underline/punctuation char.
294 -- This is the procedure for scanning out numeric literals. On entry,
295 -- Scan_Ptr points to the digit that starts the numeric literal (the
296 -- checksum for this character has not been accumulated yet). On return
297 -- Scan_Ptr points past the last character of the numeric literal, Token
298 -- and Token_Node are set appropriately, and the checksum is updated.
301 -- This is the procedure for scanning out string literals. On entry,
302 -- Scan_Ptr points to the opening string quote (the checksum for this
303 -- character has not been accumulated yet). On return Scan_Ptr points
304 -- past the closing quote of the string literal, Token and Token_Node
305 -- are set appropriately, and the checksum is updated.
307 procedure Skip_Other_Format_Characters
;
308 -- Skips past any "other format" category characters at the current
309 -- cursor location (does not skip past spaces or any other characters).
311 function Start_Of_Wide_Character
return Boolean;
312 -- Returns True if the scan pointer is pointing to the start of a wide
313 -- character sequence, does not modify the scan pointer in any case.
315 procedure Check_Bidi
(Code
: Char_Code
);
316 -- Give a warning if Code is a bidirectional character, which can cause
317 -- security vulnerabilities. See the following article:
319 -- @article{boucher_trojansource_2021,
320 -- title = {Trojan {Source}: {Invisible} {Vulnerabilities}},
321 -- author = {Nicholas Boucher and Ross Anderson},
323 -- journal = {Preprint},
324 -- eprint = {2111.00169},
325 -- archivePrefix = {arXiv},
326 -- primaryClass = {cs.CR},
327 -- url = {https://arxiv.org/abs/2111.00169}
334 type Bidi_Characters
is
335 (LRE
, RLE
, LRO
, RLO
, LRI
, RLI
, FSI
, PDF
, PDI
);
336 Bidi_Character_Codes
: constant array (Bidi_Characters
) of Char_Code
:=
346 -- Above are the bidirectional characters, along with their Unicode code
349 procedure Check_Bidi
(Code
: Char_Code
) is
351 for Bidi_Code
of Bidi_Character_Codes
loop
352 if Code
= Bidi_Code
then
353 Error_Msg
("??bidirectional wide character", Wptr
);
358 -----------------------
359 -- Double_Char_Token --
360 -----------------------
362 function Double_Char_Token
(C
: Character) return Boolean is
364 if Source
(Scan_Ptr
+ 1) = C
then
365 Accumulate_Checksum
(C
);
366 Scan_Ptr
:= Scan_Ptr
+ 2;
369 elsif Source
(Scan_Ptr
+ 1) = ' '
370 and then Source
(Scan_Ptr
+ 2) = C
372 Scan_Ptr
:= Scan_Ptr
+ 1;
373 Error_Msg_S
-- CODEFIX
374 ("no space allowed here");
375 Scan_Ptr
:= Scan_Ptr
+ 2;
381 end Double_Char_Token
;
383 -----------------------------
384 -- Error_Illegal_Character --
385 -----------------------------
387 procedure Error_Illegal_Character
is
389 Error_Msg_S
("illegal character");
390 Scan_Ptr
:= Scan_Ptr
+ 1;
391 end Error_Illegal_Character
;
393 ----------------------------------
394 -- Error_Illegal_Wide_Character --
395 ----------------------------------
397 procedure Error_Illegal_Wide_Character
is
399 Scan_Ptr
:= Scan_Ptr
+ 1;
400 Error_Msg
("illegal wide character", Wptr
);
401 end Error_Illegal_Wide_Character
;
403 -------------------------------
404 -- Error_No_Double_Underline --
405 -------------------------------
407 procedure Error_No_Double_Underline
is
409 Underline_Found
:= False;
411 -- There are four cases, and we special case the messages
413 if Source
(Scan_Ptr
) = '_' then
414 if Source
(Scan_Ptr
- 1) = '_' then
415 Error_Msg_S
-- CODEFIX
416 ("two consecutive underlines not permitted");
418 Error_Msg_S
("underline cannot follow punctuation character");
422 if Source
(Scan_Ptr
- 1) = '_' then
423 Error_Msg_S
("punctuation character cannot follow underline");
426 ("two consecutive punctuation characters not permitted");
429 end Error_No_Double_Underline
;
438 -- Current source program character
440 Base_Char
: Character;
441 -- Either # or : (character at start of based number)
447 -- Value of base in Uint format
450 -- Value of integer scanned by Scan_Integer in Uint format
453 -- Value of integer in numeric value being scanned
456 -- Scale value for real literal
459 -- Scale in Uint format
461 Exponent_Is_Negative
: Boolean;
462 -- Set true for negative exponent
464 Extended_Digit_Value
: Int
;
465 -- Extended digit value
467 Point_Scanned
: Boolean;
468 -- Flag for decimal point scanned in numeric literal
470 -----------------------
471 -- Local Subprograms --
472 -----------------------
474 procedure Error_Digit_Expected
;
475 -- Signal error of bad digit, Scan_Ptr points to the location at
476 -- which the digit was expected on input, and is unchanged on return.
478 procedure Scan_Integer
;
479 -- Scan integer literal. On entry, Scan_Ptr points to a digit, on
480 -- exit Scan_Ptr points past the last character of the integer.
482 -- For each digit encountered, UI_Int_Value is multiplied by 10, and
483 -- the value of the digit added to the result. In addition, the value
484 -- in Scale is decremented by one for each actual digit scanned.
486 --------------------------
487 -- Error_Digit_Expected --
488 --------------------------
490 procedure Error_Digit_Expected
is
492 Error_Msg_S
("digit expected");
493 end Error_Digit_Expected
;
499 procedure Scan_Integer
is
501 -- Next character scanned
504 C
:= Source
(Scan_Ptr
);
506 -- Loop through digits (allowing underlines)
509 Accumulate_Checksum
(C
);
511 UI_Int_Value
* 10 + (Character'Pos (C
) - Character'Pos ('0'));
512 Scan_Ptr
:= Scan_Ptr
+ 1;
514 C
:= Source
(Scan_Ptr
);
516 -- Case of underline encountered
520 -- We do not accumulate the '_' in the checksum, so that
521 -- 1_234 is equivalent to 1234, and does not trigger
522 -- compilation for "minimal recompilation" (gnatmake -m).
525 Scan_Ptr
:= Scan_Ptr
+ 1;
526 C
:= Source
(Scan_Ptr
);
528 Error_No_Double_Underline
;
531 if C
not in '0' .. '9' then
532 Error_Digit_Expected
;
537 exit when C
not in '0' .. '9';
542 -- Start of processing for Nlit
547 UI_Int_Value
:= Uint_0
;
548 Based_Literal_Uses_Colon
:= False;
551 Point_Scanned
:= False;
552 UI_Num_Value
:= UI_Int_Value
;
554 -- Various possibilities now for continuing the literal are period,
555 -- E/e (for exponent), or :/# (for based literal).
558 C
:= Source
(Scan_Ptr
);
562 -- Scan out point, but do not scan past .. which is a range
563 -- sequence, and must not be eaten up scanning a numeric literal.
565 while C
= '.' and then Source
(Scan_Ptr
+ 1) /= '.' loop
566 Accumulate_Checksum
('.');
568 if Point_Scanned
then
569 Error_Msg_S
("duplicate point ignored");
572 Point_Scanned
:= True;
573 Scan_Ptr
:= Scan_Ptr
+ 1;
574 C
:= Source
(Scan_Ptr
);
576 if C
not in '0' .. '9' then
578 ("real literal cannot end with point", Scan_Ptr
- 1);
581 UI_Num_Value
:= UI_Int_Value
;
585 -- Based literal case. The base is the value we already scanned.
586 -- In the case of colon, we insist that the following character
587 -- is indeed an extended digit or a period. This catches a number
588 -- of common errors, as well as catching the well known tricky
589 -- bug otherwise arising from "x : integer range 1 .. 10:= 6;"
592 or else (C
= ':' and then
593 (Source
(Scan_Ptr
+ 1) = '.'
595 Source
(Scan_Ptr
+ 1) in '0' .. '9'
597 Source
(Scan_Ptr
+ 1) in 'A' .. 'Z'
599 Source
(Scan_Ptr
+ 1) in 'a' .. 'z'))
601 Accumulate_Checksum
(C
);
603 UI_Base
:= UI_Int_Value
;
605 if Base_Char
= ':' then
606 Based_Literal_Uses_Colon
:= True;
609 if UI_Base
< 2 or else UI_Base
> 16 then
610 Error_Msg_SC
("base not 2-16");
614 Base
:= UI_To_Int
(UI_Base
);
615 Scan_Ptr
:= Scan_Ptr
+ 1;
617 -- Scan out extended integer [. integer]
619 C
:= Source
(Scan_Ptr
);
620 UI_Int_Value
:= Uint_0
;
624 if C
in '0' .. '9' then
625 Accumulate_Checksum
(C
);
626 Extended_Digit_Value
:=
627 Int
'(Character'Pos (C)) - Int'(Character'Pos ('0'));
629 elsif C
in 'A' .. 'F' then
630 Accumulate_Checksum
(Character'Val (Character'Pos (C
) + 32));
631 Extended_Digit_Value
:=
632 Int
'(Character'Pos (C)) - Int'(Character'Pos ('A')) + 10;
634 elsif C
in 'a' .. 'f' then
635 Accumulate_Checksum
(C
);
636 Extended_Digit_Value
:=
637 Int
'(Character'Pos (C)) - Int'(Character'Pos ('a')) + 10;
640 Error_Msg_S
("extended digit expected");
644 if Extended_Digit_Value
>= Base
then
645 Error_Msg_S
("digit '>= base");
648 UI_Int_Value
:= UI_Int_Value
* UI_Base
+ Extended_Digit_Value
;
650 Scan_Ptr
:= Scan_Ptr
+ 1;
651 C
:= Source
(Scan_Ptr
);
655 Accumulate_Checksum
('_');
656 Scan_Ptr
:= Scan_Ptr
+ 1;
657 C
:= Source
(Scan_Ptr
);
659 Error_No_Double_Underline
;
663 Accumulate_Checksum
('.');
665 if Point_Scanned
then
666 Error_Msg_S
("duplicate point ignored");
669 Scan_Ptr
:= Scan_Ptr
+ 1;
670 C
:= Source
(Scan_Ptr
);
671 Point_Scanned
:= True;
674 elsif C
= Base_Char
then
675 Accumulate_Checksum
(C
);
676 Scan_Ptr
:= Scan_Ptr
+ 1;
679 elsif C
= '#' or else C
= ':' then
680 Error_Msg_S
("based number delimiters must match");
681 Scan_Ptr
:= Scan_Ptr
+ 1;
684 elsif not Identifier_Char
(C
) then
685 if Base_Char
= '#' then
686 Error_Msg_S
-- CODEFIX
689 Error_Msg_S
-- CODEFIX
698 UI_Num_Value
:= UI_Int_Value
;
703 if not Point_Scanned
then
707 UI_Scale
:= UI_From_Int
(Scale
);
710 if Source
(Scan_Ptr
) = 'e' or else Source
(Scan_Ptr
) = 'E' then
711 Accumulate_Checksum
('e');
712 Scan_Ptr
:= Scan_Ptr
+ 1;
713 Exponent_Is_Negative
:= False;
715 if Source
(Scan_Ptr
) = '+' then
716 Accumulate_Checksum
('+');
717 Scan_Ptr
:= Scan_Ptr
+ 1;
719 elsif Source
(Scan_Ptr
) = '-' then
720 Accumulate_Checksum
('-');
722 if not Point_Scanned
then
724 ("negative exponent not allowed for integer literal");
726 Exponent_Is_Negative
:= True;
729 Scan_Ptr
:= Scan_Ptr
+ 1;
732 UI_Int_Value
:= Uint_0
;
734 if Source
(Scan_Ptr
) in '0' .. '9' then
737 Error_Digit_Expected
;
740 if Exponent_Is_Negative
then
741 UI_Scale
:= UI_Scale
- UI_Int_Value
;
743 UI_Scale
:= UI_Scale
+ UI_Int_Value
;
747 -- Case of real literal to be returned
749 if Point_Scanned
then
750 Token
:= Tok_Real_Literal
;
751 Real_Literal_Value
:=
757 -- Case of integer literal to be returned
760 Token
:= Tok_Integer_Literal
;
763 Int_Literal_Value
:= UI_Num_Value
;
765 -- When the exponent is large, computing is expected to take a
766 -- rather unreasonable time. We generate an error so that it
767 -- does not appear that the compiler has gotten stuck. Such a
768 -- large exponent is most likely a typo anyway.
770 elsif UI_Scale
>= 800_000
then
771 Error_Msg_SC
("exponent too large");
772 Int_Literal_Value
:= No_Uint
;
774 -- Avoid doing possibly expensive calculations in cases like
775 -- parsing 163E800_000# when semantics will not be done anyway.
776 -- This is especially useful when parsing garbled input.
778 elsif Operating_Mode
/= Check_Syntax
779 and then (Serious_Errors_Detected
= 0 or else Try_Semantics
)
781 Int_Literal_Value
:= UI_Num_Value
* UI_Base
** UI_Scale
;
784 Int_Literal_Value
:= No_Uint
;
788 Accumulate_Token_Checksum
;
797 Delimiter
: Character;
798 -- Delimiter (first character of string)
801 -- Current source program character
804 -- Current character code value
807 -- Error flag for Scan_Wide call
809 String_Start
: Source_Ptr
;
810 -- Point to first character of string
812 procedure Error_Bad_String_Char
;
813 -- Signal bad character in string/character literal. On entry
814 -- Scan_Ptr points to the improper character encountered during the
815 -- scan. Scan_Ptr is not modified, so it still points to the bad
816 -- character on return.
818 procedure Error_Unterminated_String
;
819 -- Procedure called if a line terminator character is encountered
820 -- during scanning a string, meaning that the string is not properly
823 procedure Set_String
;
824 -- Procedure used to distinguish between string and operator symbol.
825 -- On entry the string has been scanned out, and its characters start
826 -- at Token_Ptr and end one character before Scan_Ptr. On exit Token
827 -- is set to Tok_String_Literal/Tok_Operator_Symbol as appropriate,
828 -- and Token_Node is appropriately initialized. In addition, in the
829 -- operator symbol case, Token_Name is appropriately set, and the
830 -- flags [Wide_]Wide_Character_Found are set appropriately.
832 ---------------------------
833 -- Error_Bad_String_Char --
834 ---------------------------
836 procedure Error_Bad_String_Char
is
837 C
: constant Character := Source
(Scan_Ptr
);
841 Error_Msg_S
("horizontal tab not allowed in string");
843 elsif C
= VT
or else C
= FF
then
844 Error_Msg_S
("format effector not allowed in string");
846 elsif C
in Upper_Half_Character
then
847 Error_Msg_S
("(Ada 83) upper half character not allowed");
850 Error_Msg_S
("control character not allowed in string");
852 end Error_Bad_String_Char
;
854 -------------------------------
855 -- Error_Unterminated_String --
856 -------------------------------
858 procedure Error_Unterminated_String
is
862 -- An interesting little refinement. Consider the following
865 -- A := "this is an unterminated string;
866 -- A := "this is an unterminated string &
867 -- P(A, "this is a parameter that didn't get terminated);
868 -- P("this is a parameter that didn't get terminated, A);
870 -- We fiddle a little to do slightly better placement in these
871 -- cases also if there is white space at the end of the line we
872 -- place the flag at the start of this white space, not at the
873 -- end. Note that we only have to test for blanks, since tabs
874 -- aren't allowed in strings in the first place and would have
875 -- caused an error message.
877 -- Two more cases that we treat specially are:
879 -- A := "this string uses the wrong terminator'
880 -- A := "this string uses the wrong terminator' &
882 -- In these cases we give a different error message as well
884 -- We actually reposition the scan pointer to the point where we
885 -- place the flag in these cases, since it seems a better bet on
886 -- the original intention.
888 while Source
(Scan_Ptr
- 1) = ' '
889 or else Source
(Scan_Ptr
- 1) = '&'
891 Scan_Ptr
:= Scan_Ptr
- 1;
895 -- Check for case of incorrect string terminator, but single quote
896 -- is not considered incorrect if the opening terminator misused
897 -- a single quote (error message already given).
900 and then Source
(Scan_Ptr
- 1) = '''
904 ("incorrect string terminator character", Scan_Ptr
- 1);
908 -- Backup over semicolon or right-paren/semicolon sequence
910 if Source
(Scan_Ptr
- 1) = ';' then
911 Scan_Ptr
:= Scan_Ptr
- 1;
914 if Source
(Scan_Ptr
- 1) = ')' then
915 Scan_Ptr
:= Scan_Ptr
- 1;
920 -- See if there is a comma in the string, if so, guess that
921 -- the first comma terminates the string.
924 while S
< Scan_Ptr
loop
925 if Source
(S
) = ',' then
926 while Scan_Ptr
> S
loop
927 Scan_Ptr
:= Scan_Ptr
- 1;
937 -- Now we have adjusted the scan pointer, give message
939 Error_Msg_S
-- CODEFIX
940 ("missing string quote");
941 end Error_Unterminated_String
;
947 procedure Set_String
is
948 Slen
: constant Int
:= Int
(Scan_Ptr
- Token_Ptr
- 2);
954 -- Skip processing operator symbols if we are scanning an
955 -- interpolated string literal.
957 if Inside_Interpolated_String_Literal
958 and then not Inside_Interpolated_String_Expression
962 -- Token_Name is currently set to Error_Name. The following
963 -- section of code resets Token_Name to the proper Name_Op_xx
964 -- value if the string is a valid operator symbol, otherwise it is
965 -- left set to Error_Name.
968 C1
:= Source
(Token_Ptr
+ 1);
972 Token_Name
:= Name_Op_Eq
;
975 Token_Name
:= Name_Op_Gt
;
978 Token_Name
:= Name_Op_Lt
;
981 Token_Name
:= Name_Op_Add
;
984 Token_Name
:= Name_Op_Subtract
;
987 Token_Name
:= Name_Op_Concat
;
990 Token_Name
:= Name_Op_Multiply
;
993 Token_Name
:= Name_Op_Divide
;
1000 C1
:= Source
(Token_Ptr
+ 1);
1001 C2
:= Source
(Token_Ptr
+ 2);
1003 if C1
= '*' and then C2
= '*' then
1004 Token_Name
:= Name_Op_Expon
;
1009 Token_Name
:= Name_Op_Ne
;
1011 Token_Name
:= Name_Op_Le
;
1013 Token_Name
:= Name_Op_Ge
;
1016 elsif (C1
= 'O' or else C1
= 'o') and then -- OR
1017 (C2
= 'R' or else C2
= 'r')
1019 Token_Name
:= Name_Op_Or
;
1023 C1
:= Source
(Token_Ptr
+ 1);
1024 C2
:= Source
(Token_Ptr
+ 2);
1025 C3
:= Source
(Token_Ptr
+ 3);
1027 if (C1
= 'A' or else C1
= 'a') and then -- AND
1028 (C2
= 'N' or else C2
= 'n') and then
1029 (C3
= 'D' or else C3
= 'd')
1031 Token_Name
:= Name_Op_And
;
1033 elsif (C1
= 'A' or else C1
= 'a') and then -- ABS
1034 (C2
= 'B' or else C2
= 'b') and then
1035 (C3
= 'S' or else C3
= 's')
1037 Token_Name
:= Name_Op_Abs
;
1039 elsif (C1
= 'M' or else C1
= 'm') and then -- MOD
1040 (C2
= 'O' or else C2
= 'o') and then
1041 (C3
= 'D' or else C3
= 'd')
1043 Token_Name
:= Name_Op_Mod
;
1045 elsif (C1
= 'N' or else C1
= 'n') and then -- NOT
1046 (C2
= 'O' or else C2
= 'o') and then
1047 (C3
= 'T' or else C3
= 't')
1049 Token_Name
:= Name_Op_Not
;
1051 elsif (C1
= 'R' or else C1
= 'r') and then -- REM
1052 (C2
= 'E' or else C2
= 'e') and then
1053 (C3
= 'M' or else C3
= 'm')
1055 Token_Name
:= Name_Op_Rem
;
1057 elsif (C1
= 'X' or else C1
= 'x') and then -- XOR
1058 (C2
= 'O' or else C2
= 'o') and then
1059 (C3
= 'R' or else C3
= 'r')
1061 Token_Name
:= Name_Op_Xor
;
1066 -- If it is an operator symbol, then Token_Name is set. If it is
1067 -- some other string value, then Token_Name still contains
1070 if Token_Name
= Error_Name
then
1071 Token
:= Tok_String_Literal
;
1074 Token
:= Tok_Operator_Symbol
;
1078 -- Start of processing for Slit
1081 -- On entry, Scan_Ptr points to the opening character of the string
1082 -- which is either a percent, double quote, or apostrophe (single
1083 -- quote). The latter case is an error detected by the character
1086 String_Start
:= Scan_Ptr
;
1088 -- Continuation of interpolated string literal
1090 if Inside_Interpolated_String_Literal
1091 and then Prev_Token
= Tok_Right_Curly_Bracket
1093 Scan_Ptr
:= Scan_Ptr
- 1;
1099 Delimiter
:= Source
(Scan_Ptr
);
1100 Accumulate_Checksum
(Delimiter
);
1104 Wide_Character_Found
:= False;
1105 Wide_Wide_Character_Found
:= False;
1106 Scan_Ptr
:= Scan_Ptr
+ 1;
1108 -- Loop to scan out characters of string literal
1111 C
:= Source
(Scan_Ptr
);
1113 if C
= Delimiter
then
1114 Accumulate_Checksum
(C
);
1115 Scan_Ptr
:= Scan_Ptr
+ 1;
1116 exit when Source
(Scan_Ptr
) /= Delimiter
;
1118 -- Unlike normal string literals, doubled delimiter has no
1119 -- special significance in interpolated string literals.
1121 if Inside_Interpolated_String_Literal
then
1123 ("double quotations not allowed in interpolated string");
1126 Code
:= Get_Char_Code
(C
);
1127 Accumulate_Checksum
(C
);
1128 Scan_Ptr
:= Scan_Ptr
+ 1;
1131 if C
= '"' and then Delimiter
= '%' then
1133 ("quote not allowed in percent delimited string");
1134 Code
:= Get_Char_Code
(C
);
1135 Scan_Ptr
:= Scan_Ptr
+ 1;
1137 -- Found interpolated expression
1139 elsif Inside_Interpolated_String_Literal
1142 Accumulate_Checksum
(C
);
1145 -- Escaped character in interpolated string literal
1147 elsif Inside_Interpolated_String_Literal
1150 Accumulate_Checksum
(C
);
1151 Scan_Ptr
:= Scan_Ptr
+ 1;
1152 C
:= Source
(Scan_Ptr
);
1153 Accumulate_Checksum
(C
);
1154 Scan_Ptr
:= Scan_Ptr
+ 1;
1157 when 'a' => Code
:= Get_Char_Code
(ASCII
.BEL
);
1158 when 'b' => Code
:= Get_Char_Code
(ASCII
.BS
);
1159 when 'f' => Code
:= Get_Char_Code
(ASCII
.FF
);
1160 when 'n' => Code
:= Get_Char_Code
(ASCII
.LF
);
1161 when 'r' => Code
:= Get_Char_Code
(ASCII
.CR
);
1162 when 't' => Code
:= Get_Char_Code
(ASCII
.HT
);
1163 when 'v' => Code
:= Get_Char_Code
(ASCII
.VT
);
1164 when '0' => Code
:= Get_Char_Code
(ASCII
.NUL
);
1165 when '\' |
'"' |
'{' |
'}'
1166 => Code
:= Get_Char_Code
(C
);
1168 Error_Msg_S
("illegal escaped character");
1171 elsif Start_Of_Wide_Character
then
1173 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1176 Error_Illegal_Wide_Character
;
1177 Code
:= Get_Char_Code
(' ');
1182 Accumulate_Checksum
(Code
);
1184 -- In Ada 95 mode we allow any wide characters in a string
1185 -- but in Ada 2005, the set of characters allowed has been
1186 -- restricted to graphic characters.
1188 if Ada_Version
>= Ada_2005
1189 and then Is_UTF_32_Non_Graphic
(UTF_32
(Code
))
1192 ("(Ada 2005) non-graphic character not permitted " &
1193 "in string literal", Wptr
);
1197 Accumulate_Checksum
(C
);
1199 if C
not in Graphic_Character
then
1200 if C
in Line_Terminator
then
1201 Error_Unterminated_String
;
1204 elsif C
in Upper_Half_Character
then
1205 if Ada_Version
= Ada_83
then
1206 Error_Bad_String_Char
;
1210 Error_Bad_String_Char
;
1214 Code
:= Get_Char_Code
(C
);
1215 Scan_Ptr
:= Scan_Ptr
+ 1;
1219 Store_String_Char
(Code
);
1221 if not In_Character_Range
(Code
) then
1222 if In_Wide_Character_Range
(Code
) then
1223 Wide_Character_Found
:= True;
1225 Wide_Wide_Character_Found
:= True;
1230 String_Literal_Id
:= End_String
;
1235 ----------------------------------
1236 -- Skip_Other_Format_Characters --
1237 ----------------------------------
1239 procedure Skip_Other_Format_Characters
is
1245 while Start_Of_Wide_Character
loop
1247 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1249 if not Is_UTF_32_Other
(UTF_32
(Code
)) then
1254 end Skip_Other_Format_Characters
;
1256 -----------------------------
1257 -- Start_Of_Wide_Character --
1258 -----------------------------
1260 function Start_Of_Wide_Character
return Boolean is
1261 C
: constant Character := Source
(Scan_Ptr
);
1264 -- ESC encoding method with ESC present
1267 and then Wide_Character_Encoding_Method
in WC_ESC_Encoding_Method
1271 -- Upper half character with upper half encoding
1273 elsif C
in Upper_Half_Character
and then Upper_Half_Encoding
then
1276 -- Brackets encoding
1279 and then Source
(Scan_Ptr
+ 1) = '"'
1280 and then Identifier_Char
(Source
(Scan_Ptr
+ 2))
1284 -- Not the start of a wide character
1289 end Start_Of_Wide_Character
;
1291 Token_Contains_Uppercase
: Boolean;
1293 -- Start of processing for Scan
1296 Prev_Token
:= Token
;
1297 Prev_Token_Ptr
:= Token_Ptr
;
1298 Token_Name
:= Error_Name
;
1300 if Inside_Interpolated_String_Literal
1301 and then Prev_Token
= Tok_Right_Curly_Bracket
1303 -- Consecutive interpolated expressions
1305 if Source
(Scan_Ptr
) = '{' then
1308 -- Ending delimiter placed immediately after interpolated expression
1310 elsif Source
(Scan_Ptr
) = '"' then
1311 Scan_Ptr
:= Scan_Ptr
+ 1;
1312 Prev_Token
:= Tok_String_Literal
;
1314 -- String literal placed after interpolated expression
1323 -- The following loop runs more than once only if a format effector
1324 -- (tab, vertical tab, form feed, line feed, carriage return) is
1325 -- encountered and skipped, or some error situation, such as an
1326 -- illegal character, is encountered.
1328 <<Scan_Next_Character
>>
1331 -- Skip past blanks, loop is opened up for speed
1333 while Source
(Scan_Ptr
) = ' ' loop
1334 if Source
(Scan_Ptr
+ 1) /= ' ' then
1335 Scan_Ptr
:= Scan_Ptr
+ 1;
1339 if Source
(Scan_Ptr
+ 2) /= ' ' then
1340 Scan_Ptr
:= Scan_Ptr
+ 2;
1344 if Source
(Scan_Ptr
+ 3) /= ' ' then
1345 Scan_Ptr
:= Scan_Ptr
+ 3;
1349 if Source
(Scan_Ptr
+ 4) /= ' ' then
1350 Scan_Ptr
:= Scan_Ptr
+ 4;
1354 if Source
(Scan_Ptr
+ 5) /= ' ' then
1355 Scan_Ptr
:= Scan_Ptr
+ 5;
1359 if Source
(Scan_Ptr
+ 6) /= ' ' then
1360 Scan_Ptr
:= Scan_Ptr
+ 6;
1364 if Source
(Scan_Ptr
+ 7) /= ' ' then
1365 Scan_Ptr
:= Scan_Ptr
+ 7;
1369 Scan_Ptr
:= Scan_Ptr
+ 8;
1372 -- We are now at a non-blank character, which is the first character
1373 -- of the token we will scan, and hence the value of Token_Ptr.
1375 Token_Ptr
:= Scan_Ptr
;
1377 Token_Contains_Uppercase
:= False;
1379 -- Here begins the main case statement which transfers control on the
1380 -- basis of the non-blank character we have encountered.
1382 case Source
(Scan_Ptr
) is
1384 -- Line terminator characters
1386 when CR | LF | FF | VT
=>
1387 goto Scan_Line_Terminator
;
1389 -- Horizontal tab, just skip past it
1396 Scan_Ptr
:= Scan_Ptr
+ 1;
1398 -- End of file character, treated as an end of file only if it is
1399 -- the last character in the buffer, otherwise it is ignored.
1402 if Scan_Ptr
= Source_Last
(Current_Source_File
) then
1412 Scan_Ptr
:= Scan_Ptr
+ 1;
1418 Accumulate_Checksum
('&');
1420 if Source
(Scan_Ptr
+ 1) = '&' then
1421 Error_Msg_S
-- CODEFIX
1422 ("'&'& should be `AND THEN`");
1423 Scan_Ptr
:= Scan_Ptr
+ 2;
1428 Scan_Ptr
:= Scan_Ptr
+ 1;
1429 Token
:= Tok_Ampersand
;
1433 -- AI12-0125-03 : @ is target_name
1436 Error_Msg_Ada_2022_Feature
("target name", Token_Ptr
);
1438 Accumulate_Checksum
('@');
1439 Scan_Ptr
:= Scan_Ptr
+ 1;
1440 Token
:= Tok_At_Sign
;
1443 -- Asterisk (can be multiplication operator or double asterisk which
1444 -- is the exponentiation compound delimiter).
1447 Accumulate_Checksum
('*');
1449 if Source
(Scan_Ptr
+ 1) = '*' then
1450 Accumulate_Checksum
('*');
1451 Scan_Ptr
:= Scan_Ptr
+ 2;
1452 Token
:= Tok_Double_Asterisk
;
1456 Scan_Ptr
:= Scan_Ptr
+ 1;
1457 Token
:= Tok_Asterisk
;
1461 -- Colon, which can either be an isolated colon, or part of an
1462 -- assignment compound delimiter.
1465 Accumulate_Checksum
(':');
1467 if Double_Char_Token
('=') then
1468 Token
:= Tok_Colon_Equal
;
1471 Style
.Check_Colon_Equal
;
1476 elsif Source
(Scan_Ptr
+ 1) = '-'
1477 and then Source
(Scan_Ptr
+ 2) /= '-'
1479 Token
:= Tok_Colon_Equal
;
1480 Error_Msg
-- CODEFIX
1481 (":- should be :=", Scan_Ptr
);
1482 Scan_Ptr
:= Scan_Ptr
+ 2;
1486 Scan_Ptr
:= Scan_Ptr
+ 1;
1499 Accumulate_Checksum
('(');
1500 Scan_Ptr
:= Scan_Ptr
+ 1;
1501 Token
:= Tok_Left_Paren
;
1504 Style
.Check_Left_Paren_Square_Bracket
;
1513 -- [] under -gnat2022 is an aggregate notation and the special
1514 -- wide character notation becomes unsupported since the two
1517 if Ada_Version
>= Ada_2022
then
1518 Scan_Ptr
:= Scan_Ptr
+ 1;
1519 Token
:= Tok_Left_Bracket
;
1522 Style
.Check_Left_Paren_Square_Bracket
;
1527 elsif Source
(Scan_Ptr
+ 1) = '"' then
1528 goto Scan_Wide_Character
;
1531 Error_Msg_S
("illegal character, replaced by ""(""");
1532 Scan_Ptr
:= Scan_Ptr
+ 1;
1533 Token
:= Tok_Left_Paren
;
1537 -- Left curly bracket, treated as right paren but proper delimiter
1538 -- of interpolated string literals when core extensions are allowed.
1541 if Core_Extensions_Allowed
then
1542 Scan_Ptr
:= Scan_Ptr
+ 1;
1543 Token
:= Tok_Left_Curly_Bracket
;
1546 Error_Msg_S
("illegal character, replaced by ""(""");
1547 Scan_Ptr
:= Scan_Ptr
+ 1;
1548 Token
:= Tok_Left_Paren
;
1556 Accumulate_Checksum
(',');
1557 Scan_Ptr
:= Scan_Ptr
+ 1;
1566 -- Dot, which is either an isolated period, or part of a double dot
1567 -- compound delimiter sequence. We also check for the case of a
1568 -- digit following the period, to give a better error message.
1571 Accumulate_Checksum
('.');
1573 if Double_Char_Token
('.') then
1574 Token
:= Tok_Dot_Dot
;
1577 Style
.Check_Dot_Dot
;
1582 elsif Source
(Scan_Ptr
+ 1) in '0' .. '9' then
1583 Error_Msg_S
("numeric literal cannot start with point");
1584 Scan_Ptr
:= Scan_Ptr
+ 1;
1587 Scan_Ptr
:= Scan_Ptr
+ 1;
1592 -- Equal, which can either be an equality operator, or part of the
1593 -- arrow (=>) compound delimiter.
1596 Accumulate_Checksum
('=');
1598 if Double_Char_Token
('>') then
1602 Style
.Check_Arrow
(Inside_Depends
);
1607 elsif Source
(Scan_Ptr
+ 1) = '=' then
1608 Error_Msg_S
-- CODEFIX
1610 Scan_Ptr
:= Scan_Ptr
+ 1;
1613 Scan_Ptr
:= Scan_Ptr
+ 1;
1617 -- Greater than, which can be a greater than operator, greater than
1618 -- or equal operator, or first character of a right label bracket.
1621 Accumulate_Checksum
('>');
1623 if Double_Char_Token
('=') then
1624 Token
:= Tok_Greater_Equal
;
1627 elsif Double_Char_Token
('>') then
1628 Token
:= Tok_Greater_Greater
;
1632 Scan_Ptr
:= Scan_Ptr
+ 1;
1633 Token
:= Tok_Greater
;
1637 -- Less than, which can be a less than operator, less than or equal
1638 -- operator, or the first character of a left label bracket, or the
1639 -- first character of a box (<>) compound delimiter.
1642 Accumulate_Checksum
('<');
1644 if Double_Char_Token
('=') then
1645 Token
:= Tok_Less_Equal
;
1648 elsif Double_Char_Token
('>') then
1657 elsif Double_Char_Token
('<') then
1658 Token
:= Tok_Less_Less
;
1662 Scan_Ptr
:= Scan_Ptr
+ 1;
1667 -- Minus, which is either a subtraction operator, or the first
1668 -- character of double minus starting a comment
1670 when '-' => Minus_Case
: begin
1671 if Source
(Scan_Ptr
+ 1) = '>' then
1672 Error_Msg_S
("invalid token");
1673 Scan_Ptr
:= Scan_Ptr
+ 2;
1677 elsif Source
(Scan_Ptr
+ 1) /= '-' then
1678 Accumulate_Checksum
('-');
1679 Scan_Ptr
:= Scan_Ptr
+ 1;
1685 else -- Source (Scan_Ptr + 1) = '-' then
1687 Style
.Check_Comment
;
1690 Scan_Ptr
:= Scan_Ptr
+ 2;
1692 -- If we are in preprocessor mode with Replace_In_Comments set,
1693 -- then we return the "--" as a token on its own.
1695 if Replace_In_Comments
then
1696 Token
:= Tok_Comment
;
1700 -- Loop to scan comment (this loop runs more than once only if
1701 -- a horizontal tab or other non-graphic character is scanned)
1704 -- Scan to non graphic character (opened up for speed)
1706 -- Note that we just eat left brackets, which means that
1707 -- bracket notation cannot be used for end of line
1708 -- characters in comments. This seems a reasonable choice,
1709 -- since no one would ever use brackets notation in a real
1710 -- program in this situation, and if we allow brackets
1711 -- notation, we forbid some valid comments which contain a
1712 -- brackets sequence that happens to match an end of line
1716 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1717 Scan_Ptr
:= Scan_Ptr
+ 1;
1718 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1719 Scan_Ptr
:= Scan_Ptr
+ 1;
1720 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1721 Scan_Ptr
:= Scan_Ptr
+ 1;
1722 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1723 Scan_Ptr
:= Scan_Ptr
+ 1;
1724 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1725 Scan_Ptr
:= Scan_Ptr
+ 1;
1728 -- Keep going if horizontal tab
1730 if Source
(Scan_Ptr
) = HT
then
1735 Scan_Ptr
:= Scan_Ptr
+ 1;
1737 -- Terminate scan of comment if line terminator
1739 elsif Source
(Scan_Ptr
) in Line_Terminator
then
1742 -- Terminate scan of comment if end of file encountered
1743 -- (embedded EOF character or real last character in file)
1745 elsif Source
(Scan_Ptr
) = EOF
then
1748 -- If we have a wide character, we have to scan it out,
1749 -- because it might be a legitimate line terminator
1751 elsif Start_Of_Wide_Character
then
1758 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1760 -- If not well formed wide character, then just skip
1761 -- past it and ignore it.
1764 Scan_Ptr
:= Wptr
+ 1;
1766 -- If UTF_32 terminator, terminate comment scan
1768 elsif Is_UTF_32_Line_Terminator
(UTF_32
(Code
)) then
1776 -- Keep going if character in 80-FF range, or is ESC. These
1777 -- characters are allowed in comments by RM-2.1(1), 2.7(2).
1778 -- They are allowed even in Ada 83 mode according to the
1779 -- approved AI. ESC was added to the AI in June 93.
1781 elsif Source
(Scan_Ptr
) in Upper_Half_Character
1782 or else Source
(Scan_Ptr
) = ESC
1784 Scan_Ptr
:= Scan_Ptr
+ 1;
1786 -- Otherwise we have an illegal comment character, ignore
1787 -- this error in relaxed semantics mode.
1790 if Relaxed_RM_Semantics
then
1791 Scan_Ptr
:= Scan_Ptr
+ 1;
1793 Error_Illegal_Character
;
1798 -- Note that we do not return here; instead we fall through to
1799 -- reexecute the scan loop to look for a token.
1803 -- Double quote or percent starting a string literal
1810 -- Apostrophe. This can either be the start of a character literal,
1811 -- or an isolated apostrophe used in a qualified expression or an
1812 -- attribute. In the following:
1814 -- A := CHARACTER'('A');
1816 -- the first apostrophe is treated as an isolated apostrophe, and the
1817 -- second one is treated as the start of the character literal 'A'.
1818 -- Note that RM-2.2(7) does not require a separator between "'" and
1819 -- "(" in the above, so we cannot use lookahead to distinguish the
1820 -- cases; we use look-back instead. Analysis of the grammar shows
1821 -- that some tokens can be followed by an apostrophe, and some by a
1822 -- character literal, but none by both. Some cannot be followed by
1823 -- either, so it doesn't matter what we do in those cases, except to
1824 -- get good error behavior.
1826 when ''' => Char_Literal_Case
: declare
1831 Accumulate_Checksum
(''');
1832 Scan_Ptr
:= Scan_Ptr
+ 1;
1834 -- Distinguish between apostrophe and character literal. It's an
1835 -- apostrophe if the previous token is one of the following.
1836 -- Reserved words are included for things like A.all'Address and
1837 -- T'Digits'Img. Strings literals are included for things like
1838 -- "abs"'Address. Other literals are included to give better error
1839 -- behavior for illegal cases like 123'Img.
1841 -- In Ada 2022, a target name (i.e. @) is a valid prefix of an
1842 -- attribute, and functions like a name.
1844 if Prev_Token
in Tok_All | Tok_At_Sign | Tok_Delta | Tok_Digits |
1845 Tok_Identifier | Tok_Project | Tok_Right_Paren |
1846 Tok_Right_Bracket | Token_Class_Literal
1848 Token
:= Tok_Apostrophe
;
1851 Style
.Check_Apostrophe
;
1856 -- Otherwise the apostrophe starts a character literal
1859 -- Case of wide character literal
1861 if Start_Of_Wide_Character
then
1863 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1866 Error_Illegal_Wide_Character
;
1867 Code
:= Character'Pos (' ');
1869 -- In Ada 95 mode we allow any wide character in a character
1870 -- literal, but in later versions, the set of characters
1871 -- allowed is restricted to graphic characters.
1873 elsif Ada_Version
>= Ada_2005
1874 and then Is_UTF_32_Non_Graphic
(UTF_32
(Code
))
1876 Error_Msg
-- CODEFIX
1877 ("(Ada 2005) non-graphic character not permitted " &
1878 "in character literal", Wptr
);
1883 Accumulate_Checksum
(Code
);
1885 if Source
(Scan_Ptr
) /= ''' then
1886 Error_Msg_S
("missing apostrophe");
1888 Scan_Ptr
:= Scan_Ptr
+ 1;
1891 -- If we do not find a closing quote in the expected place then
1892 -- assume that we have a misguided attempt at a string literal.
1894 -- However, if previous token is RANGE, then we return an
1895 -- apostrophe instead since this gives better error recovery
1897 elsif Source
(Scan_Ptr
+ 1) /= ''' then
1898 if Prev_Token
= Tok_Range
then
1899 Token
:= Tok_Apostrophe
;
1903 Scan_Ptr
:= Scan_Ptr
- 1;
1905 ("strings are delimited by double quote character");
1911 -- Otherwise we have a (non-wide) character literal
1914 Accumulate_Checksum
(Source
(Scan_Ptr
));
1916 if Source
(Scan_Ptr
) not in Graphic_Character
then
1917 if Source
(Scan_Ptr
) in Upper_Half_Character
then
1918 if Ada_Version
= Ada_83
then
1919 Error_Illegal_Character
;
1923 Error_Illegal_Character
;
1927 Code
:= Get_Char_Code
(Source
(Scan_Ptr
));
1928 Scan_Ptr
:= Scan_Ptr
+ 2;
1931 -- Fall through here with Scan_Ptr updated past the closing
1932 -- quote, and Code set to the Char_Code value for the literal
1934 Accumulate_Checksum
(''');
1935 Token
:= Tok_Char_Literal
;
1936 Set_Character_Literal_Name
(Code
);
1937 Token_Name
:= Name_Find
;
1938 Character_Code
:= Code
;
1942 end Char_Literal_Case
;
1944 -- Right parenthesis
1947 Accumulate_Checksum
(')');
1948 Scan_Ptr
:= Scan_Ptr
+ 1;
1949 Token
:= Tok_Right_Paren
;
1952 Style
.Check_Right_Paren
;
1957 -- Right bracket or right brace, treated as right paren but proper
1958 -- aggregate delimiter in Ada 2022.
1961 if Ada_Version
>= Ada_2022
then
1962 Token
:= Tok_Right_Bracket
;
1965 Error_Msg_S
("illegal character, replaced by "")""");
1966 Token
:= Tok_Right_Paren
;
1969 Scan_Ptr
:= Scan_Ptr
+ 1;
1972 -- Right curly bracket, treated as right paren but proper delimiter
1973 -- of interpolated string literals when core extensions are allowed.
1976 if Core_Extensions_Allowed
then
1977 Token
:= Tok_Right_Curly_Bracket
;
1980 Error_Msg_S
("illegal character, replaced by "")""");
1981 Token
:= Tok_Right_Paren
;
1984 Scan_Ptr
:= Scan_Ptr
+ 1;
1987 -- Slash (can be division operator or first character of not equal)
1990 Accumulate_Checksum
('/');
1992 if Double_Char_Token
('=') then
1993 Token
:= Tok_Not_Equal
;
1996 Scan_Ptr
:= Scan_Ptr
+ 1;
2004 Accumulate_Checksum
(';');
2005 Scan_Ptr
:= Scan_Ptr
+ 1;
2006 Token
:= Tok_Semicolon
;
2009 Style
.Check_Semicolon
;
2016 when '|' => Vertical_Bar_Case
: begin
2017 Accumulate_Checksum
('|');
2019 -- Special check for || to give nice message
2021 if Source
(Scan_Ptr
+ 1) = '|' then
2022 Error_Msg_S
-- CODEFIX
2023 ("""'|'|"" should be `OR ELSE`");
2024 Scan_Ptr
:= Scan_Ptr
+ 2;
2029 Scan_Ptr
:= Scan_Ptr
+ 1;
2030 Token
:= Tok_Vertical_Bar
;
2033 Style
.Check_Vertical_Bar
;
2039 end Vertical_Bar_Case
;
2041 -- Exclamation, replacement character for vertical bar
2043 when '!' => Exclamation_Case
: begin
2044 Accumulate_Checksum
('!');
2046 if Source
(Scan_Ptr
+ 1) = '=' then
2047 Error_Msg_S
-- CODEFIX
2048 ("'!= should be /=");
2049 Scan_Ptr
:= Scan_Ptr
+ 2;
2050 Token
:= Tok_Not_Equal
;
2054 Scan_Ptr
:= Scan_Ptr
+ 1;
2055 Token
:= Tok_Vertical_Bar
;
2059 end Exclamation_Case
;
2063 when '+' => Plus_Case
: begin
2064 Accumulate_Checksum
('+');
2065 Scan_Ptr
:= Scan_Ptr
+ 1;
2070 -- Digits starting a numeric literal
2074 -- First a bit of a scan ahead to see if we have a case of an
2075 -- identifier starting with a digit (remembering exponent case).
2078 C
: constant Character := Source
(Scan_Ptr
+ 1);
2081 -- OK literal if digit followed by digit or underscore
2083 if C
in '0' .. '9' or else C
= '_' then
2086 -- OK literal if digit not followed by identifier char
2088 elsif not Identifier_Char
(C
) then
2091 -- OK literal if digit followed by e/E followed by digit/sign.
2092 -- We also allow underscore after the E, which is an error, but
2093 -- better handled by Nlit than deciding this is an identifier.
2095 elsif (C
= 'e' or else C
= 'E')
2096 and then (Source
(Scan_Ptr
+ 2) in '0' .. '9'
2097 or else Source
(Scan_Ptr
+ 2) = '+'
2098 or else Source
(Scan_Ptr
+ 2) = '-'
2099 or else Source
(Scan_Ptr
+ 2) = '_')
2103 -- Here we have what really looks like an identifier that
2104 -- starts with a digit, so give error msg.
2107 Error_Msg_S
("identifier may not start with digit");
2109 Underline_Found
:= False;
2110 Name_Buffer
(1) := Source
(Scan_Ptr
);
2111 Accumulate_Checksum
(Name_Buffer
(1));
2112 Scan_Ptr
:= Scan_Ptr
+ 1;
2113 goto Scan_Identifier
;
2117 -- Here we have an OK integer literal
2121 -- Check for proper delimiter, ignoring other format characters
2123 Skip_Other_Format_Characters
;
2125 if Identifier_Char
(Source
(Scan_Ptr
)) then
2127 ("delimiter required between literal and identifier");
2133 -- Lower case letters
2136 if Core_Extensions_Allowed
2137 and then Source
(Scan_Ptr
) = 'f'
2138 and then Source
(Scan_Ptr
+ 1) = '"'
2140 Scan_Ptr
:= Scan_Ptr
+ 1;
2141 Accumulate_Checksum
(Source
(Scan_Ptr
));
2142 Token
:= Tok_Left_Interpolated_String
;
2147 Underline_Found
:= False;
2148 Name_Buffer
(1) := Source
(Scan_Ptr
);
2149 Accumulate_Checksum
(Name_Buffer
(1));
2150 Scan_Ptr
:= Scan_Ptr
+ 1;
2151 goto Scan_Identifier
;
2153 -- Upper case letters
2156 if Core_Extensions_Allowed
2157 and then Source
(Scan_Ptr
) = 'F'
2158 and then Source
(Scan_Ptr
+ 1) = '"'
2161 ("delimiter of interpolated string must be in lowercase");
2162 Scan_Ptr
:= Scan_Ptr
+ 1;
2163 Token
:= Tok_Left_Interpolated_String
;
2167 Token_Contains_Uppercase
:= True;
2169 Underline_Found
:= False;
2171 Character'Val (Character'Pos (Source
(Scan_Ptr
)) + 32);
2172 Accumulate_Checksum
(Name_Buffer
(1));
2173 Scan_Ptr
:= Scan_Ptr
+ 1;
2174 goto Scan_Identifier
;
2176 -- Underline character
2179 -- Identifiers with leading underscores are not allowed in Ada.
2180 -- However, we allow them in the run-time library, so we can
2181 -- create names that are hidden from normal Ada code. For an
2182 -- example, search for "Name_uNext", which is "_Next".
2184 if not In_Internal_Unit
(Scan_Ptr
) then
2185 Error_Msg_S
("identifier cannot start with underline");
2189 Name_Buffer
(1) := '_';
2190 Scan_Ptr
:= Scan_Ptr
+ 1;
2191 Underline_Found
:= False;
2192 goto Scan_Identifier
;
2194 -- Space (not possible, because we scanned past blanks)
2197 raise Program_Error
;
2199 -- Characters in top half of ASCII 8-bit chart
2201 when Upper_Half_Character
=>
2203 -- Wide character case
2205 if Upper_Half_Encoding
then
2206 goto Scan_Wide_Character
;
2208 -- Otherwise we have OK Latin-1 character
2211 -- Upper half characters may possibly be identifier letters
2212 -- but can never be digits, so Identifier_Char can be used to
2213 -- test for a valid start of identifier character.
2215 if Identifier_Char
(Source
(Scan_Ptr
)) then
2217 Underline_Found
:= False;
2218 goto Scan_Identifier
;
2220 Error_Illegal_Character
;
2226 -- ESC character, possible start of identifier if wide characters
2227 -- using ESC encoding are allowed in identifiers, which we can
2228 -- tell by looking at the Identifier_Char flag for ESC, which is
2229 -- only true if these conditions are met. In Ada 2005 mode, may
2230 -- also be valid UTF_32 space or line terminator character.
2232 if Identifier_Char
(ESC
) then
2234 goto Scan_Wide_Character
;
2236 Error_Illegal_Character
;
2239 -- Illegal characters
2241 when ACK | ASCII
.SO | BEL | BS | CAN | DC1 | DC2 | DC3 | DC4 | DEL
2242 | DLE | EM | ENQ | EOT | ETB | ETX | FS | GS | NAK | NUL | RS | SI
2243 | SOH | STX | SYN | US
2244 |
'?' |
'`' |
'\' |
'^' |
'~'
2246 Error_Illegal_Character
;
2248 -- Special preprocessor characters. If Set_Special_Character has been
2249 -- called, return a Special token. Otherwise give an error.
2251 when Special_Preprocessor_Character
=>
2253 -- If Set_Special_Character has been called for this character,
2254 -- set Scans.Special_Character and return a Special token.
2256 if Special_Characters
(Source
(Scan_Ptr
)) then
2257 Token_Ptr
:= Scan_Ptr
;
2258 Token
:= Tok_Special
;
2259 Special_Character
:= Source
(Scan_Ptr
);
2260 Scan_Ptr
:= Scan_Ptr
+ 1;
2263 -- Check for something looking like a preprocessor directive
2265 elsif Source
(Scan_Ptr
) = '#'
2266 and then (Source
(Scan_Ptr
+ 1 .. Scan_Ptr
+ 2) = "if"
2268 Source
(Scan_Ptr
+ 1 .. Scan_Ptr
+ 5) = "elsif"
2270 Source
(Scan_Ptr
+ 1 .. Scan_Ptr
+ 4) = "else"
2272 Source
(Scan_Ptr
+ 1 .. Scan_Ptr
+ 3) = "end")
2275 ("preprocessor directive ignored, preprocessor not active");
2277 -- Skip to end of line
2280 if Source
(Scan_Ptr
) in Graphic_Character
2282 Source
(Scan_Ptr
) = HT
2284 Scan_Ptr
:= Scan_Ptr
+ 1;
2286 -- Done if line terminator or EOF
2288 elsif Source
(Scan_Ptr
) in Line_Terminator
2290 Source
(Scan_Ptr
) = EOF
2294 -- If we have a wide character, we have to scan it out,
2295 -- because it might be a legitimate line terminator
2297 elsif Start_Of_Wide_Character
then
2299 Wptr
: constant Source_Ptr
:= Scan_Ptr
;
2304 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2306 -- If not well formed wide character, then just skip
2307 -- past it and ignore it.
2310 Scan_Ptr
:= Wptr
+ 1;
2312 -- If UTF_32 terminator, terminate comment scan
2314 elsif Is_UTF_32_Line_Terminator
(UTF_32
(Code
)) then
2320 -- Else keep going (don't worry about bad comment chars
2321 -- in this context, we just want to find the end of line.
2324 Scan_Ptr
:= Scan_Ptr
+ 1;
2328 -- Otherwise, this is an illegal character
2331 Error_Illegal_Character
;
2334 -- End switch on non-blank character
2338 -- End loop past format effectors. The exit from this loop is by
2339 -- executing a return statement following completion of token scan
2340 -- (control never falls out of this loop to the code that follows).
2344 pragma Assert
(False);
2346 -- Wide_Character scanning routine. On entry we have encountered the
2347 -- initial character of a wide character sequence.
2349 <<Scan_Wide_Character
>>
2357 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2359 -- If bad wide character, signal error and continue scan
2362 Error_Illegal_Wide_Character
;
2363 goto Scan_Next_Character
;
2366 Cat
:= Get_Category
(UTF_32
(Code
));
2368 -- If OK letter, reset scan ptr and go scan identifier
2370 if Is_UTF_32_Letter
(Cat
) then
2373 Underline_Found
:= False;
2374 goto Scan_Identifier
;
2376 -- If OK wide space, ignore and keep scanning (we do not include
2377 -- any ignored spaces in checksum)
2379 elsif Is_UTF_32_Space
(Cat
) then
2380 goto Scan_Next_Character
;
2382 -- If other format character, ignore and keep scanning (again we
2383 -- do not include in the checksum) (this is for AI-0079).
2385 elsif Is_UTF_32_Other
(Cat
) then
2386 goto Scan_Next_Character
;
2388 -- If OK wide line terminator, terminate current line
2390 elsif Is_UTF_32_Line_Terminator
(UTF_32
(Code
)) then
2392 goto Scan_Line_Terminator
;
2394 -- Punctuation is an error (at start of identifier)
2396 elsif Is_UTF_32_Punctuation
(Cat
) then
2397 Error_Msg
("identifier cannot start with punctuation", Wptr
);
2400 Underline_Found
:= False;
2401 goto Scan_Identifier
;
2403 -- Mark character is an error (at start of identifier)
2405 elsif Is_UTF_32_Mark
(Cat
) then
2406 Error_Msg
("identifier cannot start with mark character", Wptr
);
2409 Underline_Found
:= False;
2410 goto Scan_Identifier
;
2412 -- Extended digit character is an error. Could be bad start of
2413 -- identifier or bad literal. Not worth doing too much to try to
2414 -- distinguish these cases, but we will do a little bit.
2416 elsif Is_UTF_32_Digit
(Cat
) then
2418 ("identifier cannot start with digit character", Wptr
);
2421 Underline_Found
:= False;
2422 goto Scan_Identifier
;
2424 -- All other wide characters are illegal here
2427 Error_Illegal_Wide_Character
;
2428 goto Scan_Next_Character
;
2432 -- Routine to scan line terminator. On entry Scan_Ptr points to a
2433 -- character which is one of FF,LR,CR,VT, or one of the wide characters
2434 -- that is treated as a line terminator.
2436 <<Scan_Line_Terminator
>>
2438 -- Check line too long
2442 -- Set Token_Ptr, if End_Of_Line is a token, for the case when it is
2445 if End_Of_Line_Is_Token
then
2446 Token_Ptr
:= Scan_Ptr
;
2453 Skip_Line_Terminators
(Scan_Ptr
, Physical
);
2455 -- If we are at start of physical line, update scan pointers to
2456 -- reflect the start of the new line.
2459 Current_Line_Start
:= Scan_Ptr
;
2460 Start_Column
:= Set_Start_Column
;
2461 First_Non_Blank_Location
:= Scan_Ptr
;
2463 -- If End_Of_Line is a token, we return it as it is a
2466 if End_Of_Line_Is_Token
then
2467 Token
:= Tok_End_Of_Line
;
2473 goto Scan_Next_Character
;
2475 -- Identifier scanning routine. On entry, some initial characters of
2476 -- the identifier may have already been stored in Name_Buffer. If so,
2477 -- Name_Len has the number of characters stored, otherwise Name_Len is
2478 -- set to zero on entry. Underline_Found is also set False on entry.
2482 -- This loop scans as fast as possible past lower half letters and
2483 -- digits, which we expect to be the most common characters.
2486 if Source
(Scan_Ptr
) in 'a' .. 'z'
2487 or else Source
(Scan_Ptr
) in '0' .. '9'
2489 Name_Buffer
(Name_Len
+ 1) := Source
(Scan_Ptr
);
2490 Accumulate_Checksum
(Source
(Scan_Ptr
));
2492 elsif Source
(Scan_Ptr
) in 'A' .. 'Z' then
2493 Token_Contains_Uppercase
:= True;
2495 Name_Buffer
(Name_Len
+ 1) :=
2496 Character'Val (Character'Pos (Source
(Scan_Ptr
)) + 32);
2497 Accumulate_Checksum
(Name_Buffer
(Name_Len
+ 1));
2503 Underline_Found
:= False;
2504 Scan_Ptr
:= Scan_Ptr
+ 1;
2505 Name_Len
:= Name_Len
+ 1;
2508 -- If we fall through, then we have encountered either an underline
2509 -- character, or an extended identifier character (i.e. one from the
2510 -- upper half), or a wide character, or an identifier terminator. The
2511 -- initial test speeds us up in the most common case where we have
2512 -- an identifier terminator. Note that ESC is an identifier character
2513 -- only if a wide character encoding method that uses ESC encoding
2514 -- is active, so if we find an ESC character we know that we have a
2517 if Identifier_Char
(Source
(Scan_Ptr
))
2518 or else (Source
(Scan_Ptr
) in Upper_Half_Character
2519 and then Upper_Half_Encoding
)
2521 -- Case of underline
2523 if Source
(Scan_Ptr
) = '_' then
2524 Accumulate_Checksum
('_');
2526 if Underline_Found
then
2527 Error_No_Double_Underline
;
2529 Underline_Found
:= True;
2530 Name_Len
:= Name_Len
+ 1;
2531 Name_Buffer
(Name_Len
) := '_';
2534 Scan_Ptr
:= Scan_Ptr
+ 1;
2535 goto Scan_Identifier
;
2537 -- Upper half character
2539 elsif Source
(Scan_Ptr
) in Upper_Half_Character
2540 and then not Upper_Half_Encoding
2542 Accumulate_Checksum
(Source
(Scan_Ptr
));
2543 Store_Encoded_Character
2544 (Get_Char_Code
(Fold_Lower
(Source
(Scan_Ptr
))));
2545 Scan_Ptr
:= Scan_Ptr
+ 1;
2546 Underline_Found
:= False;
2547 goto Scan_Identifier
;
2549 -- Left bracket not followed by a quote terminates an identifier.
2550 -- This is an error, but we don't want to give a junk error msg
2551 -- about wide characters in this case.
2553 elsif Source
(Scan_Ptr
) = '['
2554 and then Source
(Scan_Ptr
+ 1) /= '"'
2558 -- We know we have a wide character encoding here (the current
2559 -- character is either ESC, left bracket, or an upper half
2560 -- character depending on the encoding method).
2563 -- Scan out the wide character and insert the appropriate
2564 -- encoding into the name table entry for the identifier.
2574 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2576 -- If error, signal error
2579 Error_Illegal_Wide_Character
;
2581 -- If the character scanned is a normal identifier
2582 -- character, then we treat it that way.
2584 elsif In_Character_Range
(Code
)
2585 and then Identifier_Char
(Get_Character
(Code
))
2587 Chr
:= Get_Character
(Code
);
2588 Accumulate_Checksum
(Chr
);
2589 Store_Encoded_Character
2590 (Get_Char_Code
(Fold_Lower
(Chr
)));
2591 Underline_Found
:= False;
2593 -- Here if not a normal identifier character
2596 Cat
:= Get_Category
(UTF_32
(Code
));
2598 -- Wide character in Unicode category "Other, Format"
2599 -- is not accepted in an identifier. This is because it
2600 -- it is considered a security risk (AI-0091).
2602 -- However, it is OK for such a character to appear at
2603 -- the end of an identifier.
2605 if Is_UTF_32_Other
(Cat
) then
2606 if not Identifier_Char
(Source
(Scan_Ptr
)) then
2607 goto Scan_Identifier_Complete
;
2610 ("identifier cannot contain other_format "
2611 & "character", Wptr
);
2612 goto Scan_Identifier
;
2615 -- Wide character in category Separator,Space terminates
2617 elsif Is_UTF_32_Space
(Cat
) then
2618 goto Scan_Identifier_Complete
;
2621 -- Here if wide character is part of the identifier
2623 -- Make sure we are allowing wide characters in
2624 -- identifiers. Note that we allow wide character
2625 -- notation for an OK identifier character. This in
2626 -- particular allows bracket or other notation to be
2627 -- used for upper half letters.
2629 -- Wide characters are always allowed in Ada 2005
2631 if Identifier_Character_Set
/= 'w'
2632 and then Ada_Version
< Ada_2005
2635 ("wide character not allowed in identifier", Wptr
);
2638 -- AI12-0004: An identifier shall only contain characters
2639 -- that may be present in Normalization Form KC.
2641 if not Is_UTF_32_NFKC
(UTF_32
(Code
)) then
2643 ("invalid wide character in identifier", Wptr
);
2645 -- If OK letter, store it folding to upper case. Note
2646 -- that we include the folded letter in the checksum.
2648 elsif Is_UTF_32_Letter
(Cat
) then
2650 Char_Code
(UTF_32_To_Upper_Case
(UTF_32
(Code
)));
2651 Accumulate_Checksum
(Code
);
2652 Store_Encoded_Character
(Code
);
2653 Underline_Found
:= False;
2655 -- If OK extended digit or mark, then store it
2657 elsif Is_UTF_32_Digit
(Cat
)
2658 or else Is_UTF_32_Mark
(Cat
)
2660 Accumulate_Checksum
(Code
);
2661 Store_Encoded_Character
(Code
);
2662 Underline_Found
:= False;
2664 -- Wide punctuation is also stored, but counts as an
2665 -- underline character for error checking purposes.
2667 elsif Is_UTF_32_Punctuation
(Cat
) then
2668 Accumulate_Checksum
(Code
);
2670 if Underline_Found
then
2672 Cend
: constant Source_Ptr
:= Scan_Ptr
;
2675 Error_No_Double_Underline
;
2680 Store_Encoded_Character
(Code
);
2681 Underline_Found
:= True;
2684 -- Any other wide character is not acceptable
2688 ("invalid wide character in identifier", Wptr
);
2692 goto Scan_Identifier
;
2697 -- Scan of identifier is complete. The identifier is stored in
2698 -- Name_Buffer, and Scan_Ptr points past the last character.
2700 <<Scan_Identifier_Complete
>>
2701 Token_Name
:= Name_Find
;
2703 -- Check for identifier ending with underline or punctuation char
2705 if Underline_Found
then
2706 Underline_Found
:= False;
2708 if Source
(Scan_Ptr
- 1) = '_' then
2710 ("identifier cannot end with underline", Scan_Ptr
- 1);
2713 ("identifier cannot end with punctuation character", Wptr
);
2717 -- We will assume it is an identifier, not a keyword, so that the
2718 -- checksum is independent of the Ada version.
2720 Token
:= Tok_Identifier
;
2722 -- Check if it is a keyword
2724 if Is_Keyword_Name
(Token_Name
) then
2725 Accumulate_Token_Checksum
;
2726 Token
:= Token_Type
'Val (Get_Name_Table_Byte
(Token_Name
));
2728 -- See Exp_Put_Image for documentation of Tagged_Seen
2730 if Token
= Tok_Tagged
then
2731 Tagged_Seen
:= True;
2734 -- Keyword style checks
2738 -- Deal with possible style check for non-lower case keyword,
2739 -- but we don't treat ACCESS, DELTA, DIGITS, RANGE as keywords
2740 -- for this purpose if they appear as attribute designators.
2741 -- Actually we only check the first character for speed.
2743 -- Ada 2005 (AI-284): Do not apply the style check in case of
2744 -- "pragma Interface"
2746 -- Ada 2005 (AI-340): Do not apply the style check in case of
2749 if Token_Contains_Uppercase
2750 and then (Prev_Token
/= Tok_Apostrophe
2752 (Token
/= Tok_Access
and then
2753 Token
/= Tok_Delta
and then
2754 Token
/= Tok_Digits
and then
2755 Token
/= Tok_Mod
and then
2756 Token
/= Tok_Range
))
2757 and then (Token
/= Tok_Interface
2759 (Token
= Tok_Interface
2760 and then Prev_Token
/= Tok_Pragma
))
2762 Style
.Non_Lower_Case_Keyword
;
2765 -- Check THEN/ELSE style rules. These do not apply to AND THEN
2766 -- or OR ELSE, and do not apply in if expressions.
2768 if (Token
= Tok_Then
and then Prev_Token
/= Tok_And
)
2770 (Token
= Tok_Else
and then Prev_Token
/= Tok_Or
)
2772 if Inside_If_Expression
= 0 then
2773 Style
.Check_Separate_Stmt_Lines
;
2778 -- We must reset Token_Name since this is not an identifier and
2779 -- if we leave Token_Name set, the parser gets confused because
2780 -- it thinks it is dealing with an identifier instead of the
2781 -- corresponding keyword.
2783 Token_Name
:= No_Name
;
2786 -- It is an identifier after all
2789 Accumulate_Token_Checksum
;
2794 ------------------------------
2795 -- Set_End_Of_Line_As_Token --
2796 ------------------------------
2798 procedure Set_End_Of_Line_As_Token
(Value
: Boolean) is
2800 End_Of_Line_Is_Token
:= Value
;
2801 end Set_End_Of_Line_As_Token
;
2803 ---------------------------
2804 -- Set_Special_Character --
2805 ---------------------------
2807 procedure Set_Special_Character
(C
: Special_Preprocessor_Character
) is
2809 Special_Characters
(C
) := True;
2810 end Set_Special_Character
;
2812 ----------------------
2813 -- Set_Start_Column --
2814 ----------------------
2816 -- Note: it seems at first glance a little expensive to compute this value
2817 -- for every source line (since it is certainly not used for all source
2818 -- lines). On the other hand, it doesn't take much more work to skip past
2819 -- the initial white space on the line counting the columns than it would
2820 -- to scan past the white space using the standard scanning circuits.
2822 function Set_Start_Column
return Column_Number
is
2823 Start_Column
: Column_Number
:= 0;
2826 -- Outer loop scans past horizontal tab characters
2830 -- Inner loop scans past blanks, bumping Scan_Ptr past the blanks and
2831 -- adjusting Start_Column to account for them.
2834 while Source
(Scan_Ptr
) = ' ' loop
2835 Scan_Ptr
:= Scan_Ptr
+ 1;
2836 Start_Column
:= Start_Column
+ 1;
2837 end loop Blanks_Loop
;
2839 -- Outer loop keeps going only if a horizontal tab follows
2841 if Source
(Scan_Ptr
) = HT
then
2846 Scan_Ptr
:= Scan_Ptr
+ 1;
2847 Start_Column
:= (Start_Column
/ 8) * 8 + 8;
2853 return Start_Column
;
2855 -- A constraint error can happen only if we have a compiler with checks on
2856 -- and a line with a ludicrous number of tabs or spaces at the start. In
2857 -- such a case, we really don't care if Start_Column is right or not.
2860 when Constraint_Error
=>
2861 return Column_Number
'Last;
2862 end Set_Start_Column
;