1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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 Csets
; use Csets
;
27 with Err_Vars
; use Err_Vars
;
28 with Hostparm
; use Hostparm
;
29 with Namet
; use Namet
;
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
;
41 with System
.UTF_32
; use System
.UTF_32
;
42 with System
.WCh_Con
; use System
.WCh_Con
;
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
93 System
.CRC32
.Update
(System
.CRC32
.CRC32
(Checksum
), C
);
94 end Accumulate_Checksum
;
96 procedure Accumulate_Checksum
(C
: Char_Code
) is
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));
103 Accumulate_Checksum
(Character'Val (C
/ 256));
106 Accumulate_Checksum
(Character'Val (C
mod 256));
107 end Accumulate_Checksum
;
109 -------------------------------
110 -- Accumulate_Token_Checksum --
111 -------------------------------
113 procedure Accumulate_Token_Checksum
is
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
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
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
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
);
154 Token_Ptr
:= Scan_Ptr
;
155 Current_Line_Start
:= Scan_Ptr
;
157 Token_Name
:= No_Name
;
158 Start_Column
:= Set_Start_Column
;
159 First_Non_Blank_Location
:= Scan_Ptr
;
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
174 Special_Characters
:= (others => False);
175 end Reset_Special_Characters
;
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.
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.
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.
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
:=
248 Int
(Current_Line_Start
) -
249 Wide_Char_Byte_Count
;
253 Style
.Check_Line_Terminator
(Len
);
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
264 elsif Len
> Max_Line_Length
then
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.
286 Ptr
:= Current_Line_Start
;
288 exit when Ptr
= Scan_Ptr
;
290 if Source
(Ptr
) = ASCII
.HT
then
291 Col
:= (Col
- 1 + 8) / 8 * 8 + 1;
298 ("this line is longer than 32766 characters",
300 raise Unrecoverable_Error
;
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
319 if Source
(Scan_Ptr
+ 1) = C
then
320 Accumulate_Checksum
(C
);
321 Scan_Ptr
:= Scan_Ptr
+ 2;
324 elsif Source
(Scan_Ptr
+ 1) = ' '
325 and then Source
(Scan_Ptr
+ 2) = C
327 Scan_Ptr
:= Scan_Ptr
+ 1;
328 Error_Msg_S
("no space allowed here");
329 Scan_Ptr
:= Scan_Ptr
+ 2;
335 end Double_Char_Token
;
337 -----------------------------
338 -- Error_Illegal_Character --
339 -----------------------------
341 procedure Error_Illegal_Character
is
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
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
364 ("this line is too long",
365 Current_Line_Start
+ Source_Ptr
(Max_Line_Length
));
368 -------------------------------
369 -- Error_No_Double_Underline --
370 -------------------------------
372 procedure Error_No_Double_Underline
is
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");
383 Error_Msg_S
-- CODEFIX???
384 ("underline cannot follow punctuation character");
388 if Source
(Scan_Ptr
- 1) = '_' then
389 Error_Msg_S
-- CODEFIX???
390 ("punctuation character cannot follow underline");
392 Error_Msg_S
-- CODEFIX???
393 ("two consecutive punctuation characters not permitted");
396 end Error_No_Double_Underline
;
405 -- Current source program character
407 Base_Char
: Character;
408 -- Either # or : (character at start of based number)
414 -- Value of base in Uint format
417 -- Value of integer scanned by Scan_Integer in Uint format
420 -- Value of integer in numeric value being scanned
423 -- Scale value for real literal
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
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
455 --------------------------
456 -- Error_Digit_Expected --
457 --------------------------
459 procedure Error_Digit_Expected
is
461 Error_Msg_S
("digit expected");
462 end Error_Digit_Expected
;
468 procedure Scan_Integer
is
470 -- Next character scanned
473 C
:= Source
(Scan_Ptr
);
475 -- Loop through digits (allowing underlines)
478 Accumulate_Checksum
(C
);
480 UI_Int_Value
* 10 + (Character'Pos (C
) - Character'Pos ('0'));
481 Scan_Ptr
:= Scan_Ptr
+ 1;
483 C
:= Source
(Scan_Ptr
);
485 -- Case of underline encountered
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).
494 Scan_Ptr
:= Scan_Ptr
+ 1;
495 C
:= Source
(Scan_Ptr
);
497 Error_No_Double_Underline
;
500 if C
not in '0' .. '9' then
501 Error_Digit_Expected
;
506 exit when C
not in '0' .. '9';
511 -- Start of Processing for Nlit
516 UI_Int_Value
:= Uint_0
;
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).
526 C
:= Source
(Scan_Ptr
);
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");
540 Point_Scanned
:= True;
541 Scan_Ptr
:= Scan_Ptr
+ 1;
542 C
:= Source
(Scan_Ptr
);
544 if C
not in '0' .. '9' then
546 ("real literal cannot end with point", Scan_Ptr
- 1);
549 UI_Num_Value
:= UI_Int_Value
;
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;"
560 or else (C
= ':' and then
561 (Source
(Scan_Ptr
+ 1) = '.'
563 Source
(Scan_Ptr
+ 1) in '0' .. '9'
565 Source
(Scan_Ptr
+ 1) in 'A' .. 'Z'
567 Source
(Scan_Ptr
+ 1) in 'a' .. 'z'))
570 Obsolescent_Check
(Scan_Ptr
);
572 if Warn_On_Obsolescent_Feature
then
574 ("use of "":"" is an obsolescent feature (RM J.2(3))?");
576 ("\use ""'#"" instead?");
580 Accumulate_Checksum
(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");
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
;
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;
615 Error_Msg_S
("extended digit expected");
619 if Extended_Digit_Value
>= Base
then
620 Error_Msg_S
("digit '>= base");
623 UI_Int_Value
:= UI_Int_Value
* UI_Base
+ Extended_Digit_Value
;
625 Scan_Ptr
:= Scan_Ptr
+ 1;
626 C
:= Source
(Scan_Ptr
);
630 Accumulate_Checksum
('_');
631 Scan_Ptr
:= Scan_Ptr
+ 1;
632 C
:= Source
(Scan_Ptr
);
634 Error_No_Double_Underline
;
638 Accumulate_Checksum
('.');
640 if Point_Scanned
then
641 Error_Msg_S
("duplicate point ignored");
644 Scan_Ptr
:= Scan_Ptr
+ 1;
645 C
:= Source
(Scan_Ptr
);
646 Point_Scanned
:= True;
649 elsif C
= Base_Char
then
650 Accumulate_Checksum
(C
);
651 Scan_Ptr
:= Scan_Ptr
+ 1;
654 elsif C
= '#' or else C
= ':' then
655 Error_Msg_S
("based number delimiters must match");
656 Scan_Ptr
:= Scan_Ptr
+ 1;
659 elsif not Identifier_Char
(C
) then
660 if Base_Char
= '#' then
661 Error_Msg_S
("missing '#");
663 Error_Msg_S
("missing ':");
671 UI_Num_Value
:= UI_Int_Value
;
676 if not Point_Scanned
then
680 UI_Scale
:= UI_From_Int
(Scale
);
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
697 ("negative exponent not allowed for integer literal");
699 Exponent_Is_Negative
:= True;
702 Scan_Ptr
:= Scan_Ptr
+ 1;
705 UI_Int_Value
:= Uint_0
;
707 if Source
(Scan_Ptr
) in '0' .. '9' then
710 Error_Digit_Expected
;
713 if Exponent_Is_Negative
then
714 UI_Scale
:= UI_Scale
- UI_Int_Value
;
716 UI_Scale
:= UI_Scale
+ UI_Int_Value
;
720 -- Case of real literal to be returned
722 if Point_Scanned
then
723 Token
:= Tok_Real_Literal
;
724 Real_Literal_Value
:=
730 -- Case of integer literal to be returned
733 Token
:= Tok_Integer_Literal
;
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
)
745 Int_Literal_Value
:= UI_Num_Value
* UI_Base
** UI_Scale
;
748 Int_Literal_Value
:= No_Uint
;
752 Accumulate_Token_Checksum
;
763 Delimiter
: Character;
764 -- Delimiter (first character of string)
767 -- Current source program character
770 -- Current character code value
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
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 start
789 -- at Token_Ptr and end one character before Scan_Ptr. On exit Token
790 -- is set to Tok_String_Literal/Tok_Operator_Symbol as appropriate,
791 -- and Token_Node is appropriately initialized. In addition, in the
792 -- operator symbol case, Token_Name is appropriately set, and the
793 -- flags [Wide_]Wide_Character_Found are set appropriately.
795 ---------------------------
796 -- Error_Bad_String_Char --
797 ---------------------------
799 procedure Error_Bad_String_Char
is
800 C
: constant Character := Source
(Scan_Ptr
);
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");
813 Error_Msg_S
("control character not allowed in string");
815 end Error_Bad_String_Char
;
817 -------------------------------
818 -- Error_Unterminated_String --
819 -------------------------------
821 procedure Error_Unterminated_String
is
823 -- An interesting little refinement. Consider the following
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) = '&'
851 Scan_Ptr
:= Scan_Ptr
- 1;
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).
860 and then Source
(Scan_Ptr
- 1) = '''
864 ("incorrect string terminator character", Scan_Ptr
- 1);
868 if Source
(Scan_Ptr
- 1) = ';' then
869 Scan_Ptr
:= Scan_Ptr
- 1;
872 if Source
(Scan_Ptr
- 1) = ')' then
873 Scan_Ptr
:= Scan_Ptr
- 1;
878 Error_Msg_S
-- CODEFIX
879 ("missing string quote");
880 end Error_Unterminated_String
;
886 procedure Set_String
is
887 Slen
: constant Int
:= Int
(Scan_Ptr
- Token_Ptr
- 2);
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.
899 C1
:= Source
(Token_Ptr
+ 1);
903 Token_Name
:= Name_Op_Eq
;
906 Token_Name
:= Name_Op_Gt
;
909 Token_Name
:= Name_Op_Lt
;
912 Token_Name
:= Name_Op_Add
;
915 Token_Name
:= Name_Op_Subtract
;
918 Token_Name
:= Name_Op_Concat
;
921 Token_Name
:= Name_Op_Multiply
;
924 Token_Name
:= Name_Op_Divide
;
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
;
940 Token_Name
:= Name_Op_Ne
;
942 Token_Name
:= Name_Op_Le
;
944 Token_Name
:= Name_Op_Ge
;
947 elsif (C1
= 'O' or else C1
= 'o') and then -- OR
948 (C2
= 'R' or else C2
= 'r')
950 Token_Name
:= Name_Op_Or
;
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')
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')
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')
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')
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')
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')
992 Token_Name
:= Name_Op_Xor
;
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
1001 if Token_Name
= Error_Name
then
1002 Token
:= Tok_String_Literal
;
1005 Token
:= Tok_Operator_Symbol
;
1009 -- Start of processing for Slit
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
1017 Delimiter
:= Source
(Scan_Ptr
);
1018 Accumulate_Checksum
(Delimiter
);
1021 Wide_Character_Found
:= False;
1022 Wide_Wide_Character_Found
:= False;
1023 Scan_Ptr
:= Scan_Ptr
+ 1;
1025 -- Loop to scan out characters of string literal
1028 C
:= Source
(Scan_Ptr
);
1030 if C
= Delimiter
then
1031 Accumulate_Checksum
(C
);
1032 Scan_Ptr
:= Scan_Ptr
+ 1;
1033 exit when Source
(Scan_Ptr
) /= Delimiter
;
1034 Code
:= Get_Char_Code
(C
);
1035 Accumulate_Checksum
(C
);
1036 Scan_Ptr
:= Scan_Ptr
+ 1;
1039 if C
= '"' and then Delimiter
= '%' then
1041 ("quote not allowed in percent delimited string");
1042 Code
:= Get_Char_Code
(C
);
1043 Scan_Ptr
:= Scan_Ptr
+ 1;
1046 and then Wide_Character_Encoding_Method
1047 in WC_ESC_Encoding_Method
)
1048 or else (C
in Upper_Half_Character
1049 and then Upper_Half_Encoding
)
1051 and then Source
(Scan_Ptr
+ 1) = '"'
1052 and then Identifier_Char
(Source
(Scan_Ptr
+ 2)))
1055 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1058 Error_Illegal_Wide_Character
;
1059 Code
:= Get_Char_Code
(' ');
1062 Accumulate_Checksum
(Code
);
1064 -- In Ada 95 mode we allow any wide characters in a string
1065 -- but in Ada 2005, the set of characters allowed has been
1066 -- restricted to graphic characters.
1068 if Ada_Version
>= Ada_05
1069 and then Is_UTF_32_Non_Graphic
(UTF_32
(Code
))
1072 ("(Ada 2005) non-graphic character not permitted " &
1073 "in string literal", Wptr
);
1077 Accumulate_Checksum
(C
);
1079 if C
not in Graphic_Character
then
1080 if C
in Line_Terminator
then
1081 Error_Unterminated_String
;
1084 elsif C
in Upper_Half_Character
then
1085 if Ada_Version
= Ada_83
then
1086 Error_Bad_String_Char
;
1090 Error_Bad_String_Char
;
1094 Code
:= Get_Char_Code
(C
);
1095 Scan_Ptr
:= Scan_Ptr
+ 1;
1099 Store_String_Char
(Code
);
1101 if not In_Character_Range
(Code
) then
1102 if In_Wide_Character_Range
(Code
) then
1103 Wide_Character_Found
:= True;
1105 Wide_Wide_Character_Found
:= True;
1110 String_Literal_Id
:= End_String
;
1115 -- Start of processing for Scan
1118 Prev_Token
:= Token
;
1119 Prev_Token_Ptr
:= Token_Ptr
;
1120 Token_Name
:= Error_Name
;
1122 -- The following loop runs more than once only if a format effector
1123 -- (tab, vertical tab, form feed, line feed, carriage return) is
1124 -- encountered and skipped, or some error situation, such as an
1125 -- illegal character, is encountered.
1127 <<Scan_Next_Character
>>
1130 -- Skip past blanks, loop is opened up for speed
1132 while Source
(Scan_Ptr
) = ' ' loop
1133 if Source
(Scan_Ptr
+ 1) /= ' ' then
1134 Scan_Ptr
:= Scan_Ptr
+ 1;
1138 if Source
(Scan_Ptr
+ 2) /= ' ' then
1139 Scan_Ptr
:= Scan_Ptr
+ 2;
1143 if Source
(Scan_Ptr
+ 3) /= ' ' then
1144 Scan_Ptr
:= Scan_Ptr
+ 3;
1148 if Source
(Scan_Ptr
+ 4) /= ' ' then
1149 Scan_Ptr
:= Scan_Ptr
+ 4;
1153 if Source
(Scan_Ptr
+ 5) /= ' ' then
1154 Scan_Ptr
:= Scan_Ptr
+ 5;
1158 if Source
(Scan_Ptr
+ 6) /= ' ' then
1159 Scan_Ptr
:= Scan_Ptr
+ 6;
1163 if Source
(Scan_Ptr
+ 7) /= ' ' then
1164 Scan_Ptr
:= Scan_Ptr
+ 7;
1168 Scan_Ptr
:= Scan_Ptr
+ 8;
1171 -- We are now at a non-blank character, which is the first character
1172 -- of the token we will scan, and hence the value of Token_Ptr.
1174 Token_Ptr
:= Scan_Ptr
;
1176 -- Here begins the main case statement which transfers control on the
1177 -- basis of the non-blank character we have encountered.
1179 case Source
(Scan_Ptr
) is
1181 -- Line terminator characters
1183 when CR | LF | FF | VT
=>
1184 goto Scan_Line_Terminator
;
1186 -- Horizontal tab, just skip past it
1193 Scan_Ptr
:= Scan_Ptr
+ 1;
1195 -- End of file character, treated as an end of file only if it is
1196 -- the last character in the buffer, otherwise it is ignored.
1199 if Scan_Ptr
= Source_Last
(Current_Source_File
) then
1209 Scan_Ptr
:= Scan_Ptr
+ 1;
1215 Accumulate_Checksum
('&');
1217 if Source
(Scan_Ptr
+ 1) = '&' then
1218 Error_Msg_S
("'&'& should be `AND THEN`");
1219 Scan_Ptr
:= Scan_Ptr
+ 2;
1224 Scan_Ptr
:= Scan_Ptr
+ 1;
1225 Token
:= Tok_Ampersand
;
1229 -- Asterisk (can be multiplication operator or double asterisk which
1230 -- is the exponentiation compound delimiter).
1233 Accumulate_Checksum
('*');
1235 if Source
(Scan_Ptr
+ 1) = '*' then
1236 Accumulate_Checksum
('*');
1237 Scan_Ptr
:= Scan_Ptr
+ 2;
1238 Token
:= Tok_Double_Asterisk
;
1242 Scan_Ptr
:= Scan_Ptr
+ 1;
1243 Token
:= Tok_Asterisk
;
1247 -- Colon, which can either be an isolated colon, or part of an
1248 -- assignment compound delimiter.
1251 Accumulate_Checksum
(':');
1253 if Double_Char_Token
('=') then
1254 Token
:= Tok_Colon_Equal
;
1257 Style
.Check_Colon_Equal
;
1262 elsif Source
(Scan_Ptr
+ 1) = '-'
1263 and then Source
(Scan_Ptr
+ 2) /= '-'
1265 Token
:= Tok_Colon_Equal
;
1266 Error_Msg
(":- should be :=", Scan_Ptr
);
1267 Scan_Ptr
:= Scan_Ptr
+ 2;
1271 Scan_Ptr
:= Scan_Ptr
+ 1;
1284 Accumulate_Checksum
('(');
1285 Scan_Ptr
:= Scan_Ptr
+ 1;
1286 Token
:= Tok_Left_Paren
;
1289 Style
.Check_Left_Paren
;
1297 if Source
(Scan_Ptr
+ 1) = '"' then
1298 goto Scan_Wide_Character
;
1301 Error_Msg_S
("illegal character, replaced by ""(""");
1302 Scan_Ptr
:= Scan_Ptr
+ 1;
1303 Token
:= Tok_Left_Paren
;
1310 Error_Msg_S
("illegal character, replaced by ""(""");
1311 Scan_Ptr
:= Scan_Ptr
+ 1;
1312 Token
:= Tok_Left_Paren
;
1318 Accumulate_Checksum
(',');
1319 Scan_Ptr
:= Scan_Ptr
+ 1;
1328 -- Dot, which is either an isolated period, or part of a double dot
1329 -- compound delimiter sequence. We also check for the case of a
1330 -- digit following the period, to give a better error message.
1333 Accumulate_Checksum
('.');
1335 if Double_Char_Token
('.') then
1336 Token
:= Tok_Dot_Dot
;
1339 Style
.Check_Dot_Dot
;
1344 elsif Source
(Scan_Ptr
+ 1) in '0' .. '9' then
1345 Error_Msg_S
("numeric literal cannot start with point");
1346 Scan_Ptr
:= Scan_Ptr
+ 1;
1349 Scan_Ptr
:= Scan_Ptr
+ 1;
1354 -- Equal, which can either be an equality operator, or part of the
1355 -- arrow (=>) compound delimiter.
1358 Accumulate_Checksum
('=');
1360 if Double_Char_Token
('>') then
1369 elsif Source
(Scan_Ptr
+ 1) = '=' then
1370 Error_Msg_S
("== should be =");
1371 Scan_Ptr
:= Scan_Ptr
+ 1;
1374 Scan_Ptr
:= Scan_Ptr
+ 1;
1378 -- Greater than, which can be a greater than operator, greater than
1379 -- or equal operator, or first character of a right label bracket.
1382 Accumulate_Checksum
('>');
1384 if Double_Char_Token
('=') then
1385 Token
:= Tok_Greater_Equal
;
1388 elsif Double_Char_Token
('>') then
1389 Token
:= Tok_Greater_Greater
;
1393 Scan_Ptr
:= Scan_Ptr
+ 1;
1394 Token
:= Tok_Greater
;
1398 -- Less than, which can be a less than operator, less than or equal
1399 -- operator, or the first character of a left label bracket, or the
1400 -- first character of a box (<>) compound delimiter.
1403 Accumulate_Checksum
('<');
1405 if Double_Char_Token
('=') then
1406 Token
:= Tok_Less_Equal
;
1409 elsif Double_Char_Token
('>') then
1418 elsif Double_Char_Token
('<') then
1419 Token
:= Tok_Less_Less
;
1423 Scan_Ptr
:= Scan_Ptr
+ 1;
1428 -- Minus, which is either a subtraction operator, or the first
1429 -- character of double minus starting a comment
1431 when '-' => Minus_Case
: begin
1432 if Source
(Scan_Ptr
+ 1) = '>' then
1433 Error_Msg_S
("invalid token");
1434 Scan_Ptr
:= Scan_Ptr
+ 2;
1438 elsif Source
(Scan_Ptr
+ 1) /= '-' then
1439 Accumulate_Checksum
('-');
1440 Scan_Ptr
:= Scan_Ptr
+ 1;
1446 else -- Source (Scan_Ptr + 1) = '-' then
1448 Style
.Check_Comment
;
1451 Scan_Ptr
:= Scan_Ptr
+ 2;
1453 -- If we are in preprocessor mode with Replace_In_Comments set,
1454 -- then we return the "--" as a token on its own.
1456 if Replace_In_Comments
then
1457 Token
:= Tok_Comment
;
1461 -- Otherwise scan out the comment
1463 Start_Of_Comment
:= Scan_Ptr
;
1465 -- Loop to scan comment (this loop runs more than once only if
1466 -- a horizontal tab or other non-graphic character is scanned)
1469 -- Scan to non graphic character (opened up for speed)
1471 -- Note that we just eat left brackets, which means that
1472 -- bracket notation cannot be used for end of line
1473 -- characters in comments. This seems a reasonable choice,
1474 -- since no one would ever use brackets notation in a real
1475 -- program in this situation, and if we allow brackets
1476 -- notation, we forbid some valid comments which contain a
1477 -- brackets sequence that happens to match an end of line
1481 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1482 Scan_Ptr
:= Scan_Ptr
+ 1;
1483 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1484 Scan_Ptr
:= Scan_Ptr
+ 1;
1485 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1486 Scan_Ptr
:= Scan_Ptr
+ 1;
1487 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1488 Scan_Ptr
:= Scan_Ptr
+ 1;
1489 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1490 Scan_Ptr
:= Scan_Ptr
+ 1;
1493 -- Keep going if horizontal tab
1495 if Source
(Scan_Ptr
) = HT
then
1500 Scan_Ptr
:= Scan_Ptr
+ 1;
1502 -- Terminate scan of comment if line terminator
1504 elsif Source
(Scan_Ptr
) in Line_Terminator
then
1507 -- Terminate scan of comment if end of file encountered
1508 -- (embedded EOF character or real last character in file)
1510 elsif Source
(Scan_Ptr
) = EOF
then
1513 -- If we have a wide character, we have to scan it out,
1514 -- because it might be a legitimate line terminator
1516 elsif (Source
(Scan_Ptr
) = ESC
1517 and then Identifier_Char
(ESC
))
1519 (Source
(Scan_Ptr
) in Upper_Half_Character
1520 and then Upper_Half_Encoding
)
1523 Wptr
: constant Source_Ptr
:= Scan_Ptr
;
1528 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1530 -- If not well formed wide character, then just skip
1531 -- past it and ignore it.
1534 Scan_Ptr
:= Wptr
+ 1;
1536 -- If UTF_32 terminator, terminate comment scan
1538 elsif Is_UTF_32_Line_Terminator
(UTF_32
(Code
)) then
1544 -- Keep going if character in 80-FF range, or is ESC. These
1545 -- characters are allowed in comments by RM-2.1(1), 2.7(2).
1546 -- They are allowed even in Ada 83 mode according to the
1547 -- approved AI. ESC was added to the AI in June 93.
1549 elsif Source
(Scan_Ptr
) in Upper_Half_Character
1550 or else Source
(Scan_Ptr
) = ESC
1552 Scan_Ptr
:= Scan_Ptr
+ 1;
1554 -- Otherwise we have an illegal comment character
1557 Error_Illegal_Character
;
1561 -- Note that, except when comments are tokens, we do NOT
1562 -- execute a return here, instead we fall through to reexecute
1563 -- the scan loop to look for a token.
1565 if Comment_Is_Token
then
1566 Name_Len
:= Integer (Scan_Ptr
- Start_Of_Comment
);
1567 Name_Buffer
(1 .. Name_Len
) :=
1568 String (Source
(Start_Of_Comment
.. Scan_Ptr
- 1));
1569 Comment_Id
:= Name_Find
;
1570 Token
:= Tok_Comment
;
1576 -- Double quote starting a string literal
1583 -- Percent starting a string literal
1586 Obsolescent_Check
(Token_Ptr
);
1588 if Warn_On_Obsolescent_Feature
then
1590 ("use of ""'%"" is an obsolescent feature (RM J.2(4))?");
1592 ("\use """""" instead?");
1599 -- Apostrophe. This can either be the start of a character literal,
1600 -- or an isolated apostrophe used in a qualified expression or an
1601 -- attribute. We treat it as a character literal if it does not
1602 -- follow a right parenthesis, identifier, the keyword ALL or
1603 -- a literal. This means that we correctly treat constructs like:
1605 -- A := CHARACTER'('A');
1607 -- Note that RM-2.2(7) does not require a separator between
1608 -- "CHARACTER" and "'" in the above.
1610 when ''' => Char_Literal_Case
: declare
1615 Accumulate_Checksum
(''');
1616 Scan_Ptr
:= Scan_Ptr
+ 1;
1618 -- Here is where we make the test to distinguish the cases. Treat
1619 -- as apostrophe if previous token is an identifier, right paren
1620 -- or the reserved word "all" (latter case as in A.all'Address)
1621 -- (or the reserved word "project" in project files). Also treat
1622 -- it as apostrophe after a literal (this catches some legitimate
1623 -- cases, like A."abs"'Address, and also gives better error
1624 -- behavior for impossible cases like 123'xxx).
1626 if Prev_Token
= Tok_Identifier
1627 or else Prev_Token
= Tok_Right_Paren
1628 or else Prev_Token
= Tok_All
1629 or else Prev_Token
= Tok_Project
1630 or else Prev_Token
in Token_Class_Literal
1632 Token
:= Tok_Apostrophe
;
1635 Style
.Check_Apostrophe
;
1640 -- Otherwise the apostrophe starts a character literal
1643 -- Case of wide character literal
1645 if (Source
(Scan_Ptr
) = ESC
1647 Wide_Character_Encoding_Method
in WC_ESC_Encoding_Method
)
1649 (Source
(Scan_Ptr
) in Upper_Half_Character
1651 Upper_Half_Encoding
)
1653 (Source
(Scan_Ptr
) = '['
1655 Source
(Scan_Ptr
+ 1) = '"')
1658 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1659 Accumulate_Checksum
(Code
);
1662 Error_Illegal_Wide_Character
;
1663 Code
:= Character'Pos (' ');
1665 -- In Ada 95 mode we allow any wide character in a character
1666 -- literal, but in Ada 2005, the set of characters allowed
1667 -- is restricted to graphic characters.
1669 elsif Ada_Version
>= Ada_05
1670 and then Is_UTF_32_Non_Graphic
(UTF_32
(Code
))
1673 ("(Ada 2005) non-graphic character not permitted " &
1674 "in character literal", Wptr
);
1677 if Source
(Scan_Ptr
) /= ''' then
1678 Error_Msg_S
("missing apostrophe");
1680 Scan_Ptr
:= Scan_Ptr
+ 1;
1683 -- If we do not find a closing quote in the expected place then
1684 -- assume that we have a misguided attempt at a string literal.
1686 -- However, if previous token is RANGE, then we return an
1687 -- apostrophe instead since this gives better error recovery
1689 elsif Source
(Scan_Ptr
+ 1) /= ''' then
1690 if Prev_Token
= Tok_Range
then
1691 Token
:= Tok_Apostrophe
;
1695 Scan_Ptr
:= Scan_Ptr
- 1;
1697 ("strings are delimited by double quote character");
1703 -- Otherwise we have a (non-wide) character literal
1706 Accumulate_Checksum
(Source
(Scan_Ptr
));
1708 if Source
(Scan_Ptr
) not in Graphic_Character
then
1709 if Source
(Scan_Ptr
) in Upper_Half_Character
then
1710 if Ada_Version
= Ada_83
then
1711 Error_Illegal_Character
;
1715 Error_Illegal_Character
;
1719 Code
:= Get_Char_Code
(Source
(Scan_Ptr
));
1720 Scan_Ptr
:= Scan_Ptr
+ 2;
1723 -- Fall through here with Scan_Ptr updated past the closing
1724 -- quote, and Code set to the Char_Code value for the literal
1726 Accumulate_Checksum
(''');
1727 Token
:= Tok_Char_Literal
;
1728 Set_Character_Literal_Name
(Code
);
1729 Token_Name
:= Name_Find
;
1730 Character_Code
:= Code
;
1734 end Char_Literal_Case
;
1736 -- Right parenthesis
1739 Accumulate_Checksum
(')');
1740 Scan_Ptr
:= Scan_Ptr
+ 1;
1741 Token
:= Tok_Right_Paren
;
1744 Style
.Check_Right_Paren
;
1749 -- Right bracket or right brace, treated as right paren
1752 Error_Msg_S
("illegal character, replaced by "")""");
1753 Scan_Ptr
:= Scan_Ptr
+ 1;
1754 Token
:= Tok_Right_Paren
;
1757 -- Slash (can be division operator or first character of not equal)
1760 Accumulate_Checksum
('/');
1762 if Double_Char_Token
('=') then
1763 Token
:= Tok_Not_Equal
;
1766 Scan_Ptr
:= Scan_Ptr
+ 1;
1774 Accumulate_Checksum
(';');
1775 Scan_Ptr
:= Scan_Ptr
+ 1;
1776 Token
:= Tok_Semicolon
;
1779 Style
.Check_Semicolon
;
1786 when '|' => Vertical_Bar_Case
: begin
1787 Accumulate_Checksum
('|');
1789 -- Special check for || to give nice message
1791 if Source
(Scan_Ptr
+ 1) = '|' then
1792 Error_Msg_S
("""'|'|"" should be `OR ELSE`");
1793 Scan_Ptr
:= Scan_Ptr
+ 2;
1798 Scan_Ptr
:= Scan_Ptr
+ 1;
1799 Token
:= Tok_Vertical_Bar
;
1802 Style
.Check_Vertical_Bar
;
1807 end Vertical_Bar_Case
;
1809 -- Exclamation, replacement character for vertical bar
1811 when '!' => Exclamation_Case
: begin
1812 Accumulate_Checksum
('!');
1813 Obsolescent_Check
(Token_Ptr
);
1815 if Warn_On_Obsolescent_Feature
then
1817 ("use of ""'!"" is an obsolescent feature (RM J.2(2))?");
1819 ("\use ""'|"" instead?");
1822 if Source
(Scan_Ptr
+ 1) = '=' then
1823 Error_Msg_S
("'!= should be /=");
1824 Scan_Ptr
:= Scan_Ptr
+ 2;
1825 Token
:= Tok_Not_Equal
;
1829 Scan_Ptr
:= Scan_Ptr
+ 1;
1830 Token
:= Tok_Vertical_Bar
;
1833 end Exclamation_Case
;
1837 when '+' => Plus_Case
: begin
1838 Accumulate_Checksum
('+');
1839 Scan_Ptr
:= Scan_Ptr
+ 1;
1844 -- Digits starting a numeric literal
1848 -- First a bit of a scan ahead to see if we have a case of an
1849 -- identifier starting with a digit (remembering exponent case).
1852 C
: constant Character := Source
(Scan_Ptr
+ 1);
1855 -- OK literal if digit followed by digit or underscore
1857 if C
in '0' .. '9' or else C
= '_' then
1860 -- OK literal if digit not followed by identifier char
1862 elsif not Identifier_Char
(C
) then
1865 -- OK literal if digit followed by e/E followed by digit/sign.
1866 -- We also allow underscore after the E, which is an error, but
1867 -- better handled by Nlit than deciding this is an identifier.
1869 elsif (C
= 'e' or else C
= 'E')
1870 and then (Source
(Scan_Ptr
+ 2) in '0' .. '9'
1871 or else Source
(Scan_Ptr
+ 2) = '+'
1872 or else Source
(Scan_Ptr
+ 2) = '-'
1873 or else Source
(Scan_Ptr
+ 2) = '_')
1877 -- Here we have what really looks like an identifier that
1878 -- starts with a digit, so give error msg.
1881 Error_Msg_S
("identifier may not start with digit");
1883 Underline_Found
:= False;
1884 Name_Buffer
(1) := Source
(Scan_Ptr
);
1885 Accumulate_Checksum
(Name_Buffer
(1));
1886 Scan_Ptr
:= Scan_Ptr
+ 1;
1887 goto Scan_Identifier
;
1891 -- Here we have an OK integer literal
1895 if Identifier_Char
(Source
(Scan_Ptr
)) then
1897 ("delimiter required between literal and identifier");
1903 -- Lower case letters
1907 Underline_Found
:= False;
1908 Name_Buffer
(1) := Source
(Scan_Ptr
);
1909 Accumulate_Checksum
(Name_Buffer
(1));
1910 Scan_Ptr
:= Scan_Ptr
+ 1;
1911 goto Scan_Identifier
;
1913 -- Upper case letters
1917 Underline_Found
:= False;
1919 Character'Val (Character'Pos (Source
(Scan_Ptr
)) + 32);
1920 Accumulate_Checksum
(Name_Buffer
(1));
1921 Scan_Ptr
:= Scan_Ptr
+ 1;
1922 goto Scan_Identifier
;
1924 -- Underline character
1927 if Special_Characters
('_') then
1928 Token_Ptr
:= Scan_Ptr
;
1929 Scan_Ptr
:= Scan_Ptr
+ 1;
1930 Token
:= Tok_Special
;
1931 Special_Character
:= '_';
1935 Error_Msg_S
("identifier cannot start with underline");
1937 Name_Buffer
(1) := '_';
1938 Scan_Ptr
:= Scan_Ptr
+ 1;
1939 Underline_Found
:= False;
1940 goto Scan_Identifier
;
1942 -- Space (not possible, because we scanned past blanks)
1945 raise Program_Error
;
1947 -- Characters in top half of ASCII 8-bit chart
1949 when Upper_Half_Character
=>
1951 -- Wide character case
1953 if Upper_Half_Encoding
then
1954 goto Scan_Wide_Character
;
1956 -- Otherwise we have OK Latin-1 character
1959 -- Upper half characters may possibly be identifier letters
1960 -- but can never be digits, so Identifier_Char can be used to
1961 -- test for a valid start of identifier character.
1963 if Identifier_Char
(Source
(Scan_Ptr
)) then
1965 Underline_Found
:= False;
1966 goto Scan_Identifier
;
1968 Error_Illegal_Character
;
1974 -- ESC character, possible start of identifier if wide characters
1975 -- using ESC encoding are allowed in identifiers, which we can
1976 -- tell by looking at the Identifier_Char flag for ESC, which is
1977 -- only true if these conditions are met. In Ada 2005 mode, may
1978 -- also be valid UTF_32 space or line terminator character.
1980 if Identifier_Char
(ESC
) then
1982 goto Scan_Wide_Character
;
1984 Error_Illegal_Character
;
1987 -- Invalid control characters
1989 when NUL | SOH | STX | ETX | EOT | ENQ | ACK | BEL | BS | ASCII
.SO |
1990 SI | DLE | DC1 | DC2 | DC3 | DC4 | NAK | SYN | ETB | CAN |
1991 EM | FS | GS | RS | US | DEL
1993 Error_Illegal_Character
;
1995 -- Invalid graphic characters
1997 when '#' |
'$' |
'?' |
'@' |
'`' |
'\' |
'^' |
'~' =>
1999 -- If Set_Special_Character has been called for this character,
2000 -- set Scans.Special_Character and return a Special token.
2002 if Special_Characters
(Source
(Scan_Ptr
)) then
2003 Token_Ptr
:= Scan_Ptr
;
2004 Token
:= Tok_Special
;
2005 Special_Character
:= Source
(Scan_Ptr
);
2006 Scan_Ptr
:= Scan_Ptr
+ 1;
2009 -- Otherwise, this is an illegal character
2012 Error_Illegal_Character
;
2015 -- End switch on non-blank character
2019 -- End loop past format effectors. The exit from this loop is by
2020 -- executing a return statement following completion of token scan
2021 -- (control never falls out of this loop to the code which follows)
2025 -- Wide_Character scanning routine. On entry we have encountered the
2026 -- initial character of a wide character sequence.
2028 <<Scan_Wide_Character
>>
2037 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2039 -- If bad wide character, signal error and continue scan
2042 Error_Illegal_Wide_Character
;
2043 goto Scan_Next_Character
;
2046 Cat
:= Get_Category
(UTF_32
(Code
));
2048 -- If OK letter, reset scan ptr and go scan identifier
2050 if Is_UTF_32_Letter
(Cat
) then
2053 Underline_Found
:= False;
2054 goto Scan_Identifier
;
2056 -- If OK wide space, ignore and keep scanning (we do not include
2057 -- any ignored spaces in checksum)
2059 elsif Is_UTF_32_Space
(Cat
) then
2060 goto Scan_Next_Character
;
2062 -- If OK wide line terminator, terminate current line
2064 elsif Is_UTF_32_Line_Terminator
(UTF_32
(Code
)) then
2066 goto Scan_Line_Terminator
;
2068 -- Punctuation is an error (at start of identifier)
2070 elsif Is_UTF_32_Punctuation
(Cat
) then
2072 ("identifier cannot start with punctuation", Wptr
);
2075 Underline_Found
:= False;
2076 goto Scan_Identifier
;
2078 -- Mark character is an error (at start of identifier)
2080 elsif Is_UTF_32_Mark
(Cat
) then
2082 ("identifier cannot start with mark character", Wptr
);
2085 Underline_Found
:= False;
2086 goto Scan_Identifier
;
2088 -- Other format character is an error (at start of identifier)
2090 elsif Is_UTF_32_Other
(Cat
) then
2092 ("identifier cannot start with other format character", Wptr
);
2095 Underline_Found
:= False;
2096 goto Scan_Identifier
;
2098 -- Extended digit character is an error. Could be bad start of
2099 -- identifier or bad literal. Not worth doing too much to try to
2100 -- distinguish these cases, but we will do a little bit.
2102 elsif Is_UTF_32_Digit
(Cat
) then
2104 ("identifier cannot start with digit character", Wptr
);
2107 Underline_Found
:= False;
2108 goto Scan_Identifier
;
2110 -- All other wide characters are illegal here
2113 Error_Illegal_Wide_Character
;
2114 goto Scan_Next_Character
;
2118 -- Routine to scan line terminator. On entry Scan_Ptr points to a
2119 -- character which is one of FF,LR,CR,VT, or one of the wide characters
2120 -- that is treated as a line terminator.
2122 <<Scan_Line_Terminator
>>
2124 -- Check line too long
2128 -- Set Token_Ptr, if End_Of_Line is a token, for the case when it is
2131 if End_Of_Line_Is_Token
then
2132 Token_Ptr
:= Scan_Ptr
;
2139 Skip_Line_Terminators
(Scan_Ptr
, Physical
);
2141 -- If we are at start of physical line, update scan pointers to
2142 -- reflect the start of the new line.
2145 Current_Line_Start
:= Scan_Ptr
;
2146 Start_Column
:= Set_Start_Column
;
2147 First_Non_Blank_Location
:= Scan_Ptr
;
2149 -- If End_Of_Line is a token, we return it as it is a
2152 if End_Of_Line_Is_Token
then
2153 Token
:= Tok_End_Of_Line
;
2159 goto Scan_Next_Character
;
2161 -- Identifier scanning routine. On entry, some initial characters of
2162 -- the identifier may have already been stored in Name_Buffer. If so,
2163 -- Name_Len has the number of characters stored, otherwise Name_Len is
2164 -- set to zero on entry. Underline_Found is also set False on entry.
2168 -- This loop scans as fast as possible past lower half letters and
2169 -- digits, which we expect to be the most common characters.
2172 if Source
(Scan_Ptr
) in 'a' .. 'z'
2173 or else Source
(Scan_Ptr
) in '0' .. '9'
2175 Name_Buffer
(Name_Len
+ 1) := Source
(Scan_Ptr
);
2176 Accumulate_Checksum
(Source
(Scan_Ptr
));
2178 elsif Source
(Scan_Ptr
) in 'A' .. 'Z' then
2179 Name_Buffer
(Name_Len
+ 1) :=
2180 Character'Val (Character'Pos (Source
(Scan_Ptr
)) + 32);
2181 Accumulate_Checksum
(Name_Buffer
(Name_Len
+ 1));
2187 Underline_Found
:= False;
2188 Scan_Ptr
:= Scan_Ptr
+ 1;
2189 Name_Len
:= Name_Len
+ 1;
2192 -- If we fall through, then we have encountered either an underline
2193 -- character, or an extended identifier character (i.e. one from the
2194 -- upper half), or a wide character, or an identifier terminator. The
2195 -- initial test speeds us up in the most common case where we have
2196 -- an identifier terminator. Note that ESC is an identifier character
2197 -- only if a wide character encoding method that uses ESC encoding
2198 -- is active, so if we find an ESC character we know that we have a
2201 if Identifier_Char
(Source
(Scan_Ptr
))
2202 or else (Source
(Scan_Ptr
) in Upper_Half_Character
2203 and then Upper_Half_Encoding
)
2205 -- Case of underline
2207 if Source
(Scan_Ptr
) = '_' then
2208 Accumulate_Checksum
('_');
2210 if Underline_Found
then
2211 Error_No_Double_Underline
;
2213 Underline_Found
:= True;
2214 Name_Len
:= Name_Len
+ 1;
2215 Name_Buffer
(Name_Len
) := '_';
2218 Scan_Ptr
:= Scan_Ptr
+ 1;
2219 goto Scan_Identifier
;
2221 -- Upper half character
2223 elsif Source
(Scan_Ptr
) in Upper_Half_Character
2224 and then not Upper_Half_Encoding
2226 Accumulate_Checksum
(Source
(Scan_Ptr
));
2227 Store_Encoded_Character
2228 (Get_Char_Code
(Fold_Lower
(Source
(Scan_Ptr
))));
2229 Scan_Ptr
:= Scan_Ptr
+ 1;
2230 Underline_Found
:= False;
2231 goto Scan_Identifier
;
2233 -- Left bracket not followed by a quote terminates an identifier.
2234 -- This is an error, but we don't want to give a junk error msg
2235 -- about wide characters in this case!
2237 elsif Source
(Scan_Ptr
) = '['
2238 and then Source
(Scan_Ptr
+ 1) /= '"'
2242 -- We know we have a wide character encoding here (the current
2243 -- character is either ESC, left bracket, or an upper half
2244 -- character depending on the encoding method).
2247 -- Scan out the wide character and insert the appropriate
2248 -- encoding into the name table entry for the identifier.
2258 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2260 -- If error, signal error
2263 Error_Illegal_Wide_Character
;
2265 -- If the character scanned is a normal identifier
2266 -- character, then we treat it that way.
2268 elsif In_Character_Range
(Code
)
2269 and then Identifier_Char
(Get_Character
(Code
))
2271 Chr
:= Get_Character
(Code
);
2272 Accumulate_Checksum
(Chr
);
2273 Store_Encoded_Character
2274 (Get_Char_Code
(Fold_Lower
(Chr
)));
2275 Underline_Found
:= False;
2277 -- Here if not a normal identifier character
2280 -- Make sure we are allowing wide characters in
2281 -- identifiers. Note that we allow wide character
2282 -- notation for an OK identifier character. This in
2283 -- particular allows bracket or other notation to be
2284 -- used for upper half letters.
2286 -- Wide characters are always allowed in Ada 2005
2288 if Identifier_Character_Set
/= 'w'
2289 and then Ada_Version
< Ada_05
2292 ("wide character not allowed in identifier", Wptr
);
2295 Cat
:= Get_Category
(UTF_32
(Code
));
2297 -- If OK letter, store it folding to upper case. Note
2298 -- that we include the folded letter in the checksum.
2300 if Is_UTF_32_Letter
(Cat
) then
2302 Char_Code
(UTF_32_To_Upper_Case
(UTF_32
(Code
)));
2303 Accumulate_Checksum
(Code
);
2304 Store_Encoded_Character
(Code
);
2305 Underline_Found
:= False;
2307 -- If OK extended digit or mark, then store it
2309 elsif Is_UTF_32_Digit
(Cat
)
2310 or else Is_UTF_32_Mark
(Cat
)
2312 Accumulate_Checksum
(Code
);
2313 Store_Encoded_Character
(Code
);
2314 Underline_Found
:= False;
2316 -- Wide punctuation is also stored, but counts as an
2317 -- underline character for error checking purposes.
2319 elsif Is_UTF_32_Punctuation
(Cat
) then
2320 Accumulate_Checksum
(Code
);
2322 if Underline_Found
then
2324 Cend
: constant Source_Ptr
:= Scan_Ptr
;
2327 Error_No_Double_Underline
;
2332 Store_Encoded_Character
(Code
);
2333 Underline_Found
:= True;
2336 -- Wide character in Unicode category "Other, Format"
2337 -- is accepted in an identifier, but is ignored and not
2338 -- stored. It seems reasonable to exclude it from the
2341 -- Note that it is correct (see AI-395) to simply strip
2342 -- other format characters, before testing for double
2343 -- underlines, or for reserved words).
2345 elsif Is_UTF_32_Other
(Cat
) then
2348 -- Wide character in category Separator,Space terminates
2350 elsif Is_UTF_32_Space
(Cat
) then
2351 goto Scan_Identifier_Complete
;
2353 -- Any other wide character is not acceptable
2357 ("invalid wide character in identifier", Wptr
);
2361 goto Scan_Identifier
;
2366 -- Scan of identifier is complete. The identifier is stored in
2367 -- Name_Buffer, and Scan_Ptr points past the last character.
2369 <<Scan_Identifier_Complete
>>
2370 Token_Name
:= Name_Find
;
2372 -- Check for identifier ending with underline or punctuation char
2374 if Underline_Found
then
2375 Underline_Found
:= False;
2377 if Source
(Scan_Ptr
- 1) = '_' then
2379 ("identifier cannot end with underline", Scan_Ptr
- 1);
2382 ("identifier cannot end with punctuation character", Wptr
);
2386 -- Here is where we check if it was a keyword
2388 if Is_Keyword_Name
(Token_Name
) then
2389 Token
:= Token_Type
'Val (Get_Name_Table_Byte
(Token_Name
));
2391 -- Keyword style checks
2395 -- Deal with possible style check for non-lower case keyword,
2396 -- but we don't treat ACCESS, DELTA, DIGITS, RANGE as keywords
2397 -- for this purpose if they appear as attribute designators.
2398 -- Actually we only check the first character for speed.
2400 -- Ada 2005 (AI-284): Do not apply the style check in case of
2401 -- "pragma Interface"
2403 -- Ada 2005 (AI-340): Do not apply the style check in case of
2406 if Source
(Token_Ptr
) <= 'Z'
2407 and then (Prev_Token
/= Tok_Apostrophe
2409 (Token
/= Tok_Access
and then
2410 Token
/= Tok_Delta
and then
2411 Token
/= Tok_Digits
and then
2412 Token
/= Tok_Mod
and then
2413 Token
/= Tok_Range
))
2414 and then (Token
/= Tok_Interface
2416 (Token
= Tok_Interface
2417 and then Prev_Token
/= Tok_Pragma
))
2419 Style
.Non_Lower_Case_Keyword
;
2422 -- Check THEN/ELSE style rules. These do not apply to AND THEN
2423 -- or OR ELSE, and do not apply in conditional expressions.
2425 if (Token
= Tok_Then
and then Prev_Token
/= Tok_And
)
2427 (Token
= Tok_Else
and then Prev_Token
/= Tok_Or
)
2429 if Inside_Conditional_Expression
= 0 then
2430 Style
.Check_Separate_Stmt_Lines
;
2435 -- We must reset Token_Name since this is not an identifier and
2436 -- if we leave Token_Name set, the parser gets confused because
2437 -- it thinks it is dealing with an identifier instead of the
2438 -- corresponding keyword.
2440 Token_Name
:= No_Name
;
2441 Accumulate_Token_Checksum
;
2444 -- It is an identifier after all
2447 Token
:= Tok_Identifier
;
2448 Accumulate_Token_Checksum
;
2454 --------------------------
2455 -- Set_Comment_As_Token --
2456 --------------------------
2458 procedure Set_Comment_As_Token
(Value
: Boolean) is
2460 Comment_Is_Token
:= Value
;
2461 end Set_Comment_As_Token
;
2463 ------------------------------
2464 -- Set_End_Of_Line_As_Token --
2465 ------------------------------
2467 procedure Set_End_Of_Line_As_Token
(Value
: Boolean) is
2469 End_Of_Line_Is_Token
:= Value
;
2470 end Set_End_Of_Line_As_Token
;
2472 ---------------------------
2473 -- Set_Special_Character --
2474 ---------------------------
2476 procedure Set_Special_Character
(C
: Character) is
2479 when '#' |
'$' |
'_' |
'?' |
'@' |
'`' |
'\' |
'^' |
'~' =>
2480 Special_Characters
(C
) := True;
2485 end Set_Special_Character
;
2487 ----------------------
2488 -- Set_Start_Column --
2489 ----------------------
2491 -- Note: it seems at first glance a little expensive to compute this value
2492 -- for every source line (since it is certainly not used for all source
2493 -- lines). On the other hand, it doesn't take much more work to skip past
2494 -- the initial white space on the line counting the columns than it would
2495 -- to scan past the white space using the standard scanning circuits.
2497 function Set_Start_Column
return Column_Number
is
2498 Start_Column
: Column_Number
:= 0;
2501 -- Outer loop scans past horizontal tab characters
2505 -- Inner loop scans past blanks as fast as possible, bumping Scan_Ptr
2506 -- past the blanks and adjusting Start_Column to account for them.
2509 if Source
(Scan_Ptr
) = ' ' then
2510 if Source
(Scan_Ptr
+ 1) = ' ' then
2511 if Source
(Scan_Ptr
+ 2) = ' ' then
2512 if Source
(Scan_Ptr
+ 3) = ' ' then
2513 if Source
(Scan_Ptr
+ 4) = ' ' then
2514 if Source
(Scan_Ptr
+ 5) = ' ' then
2515 if Source
(Scan_Ptr
+ 6) = ' ' then
2516 Scan_Ptr
:= Scan_Ptr
+ 7;
2517 Start_Column
:= Start_Column
+ 7;
2519 Scan_Ptr
:= Scan_Ptr
+ 6;
2520 Start_Column
:= Start_Column
+ 6;
2524 Scan_Ptr
:= Scan_Ptr
+ 5;
2525 Start_Column
:= Start_Column
+ 5;
2529 Scan_Ptr
:= Scan_Ptr
+ 4;
2530 Start_Column
:= Start_Column
+ 4;
2534 Scan_Ptr
:= Scan_Ptr
+ 3;
2535 Start_Column
:= Start_Column
+ 3;
2539 Scan_Ptr
:= Scan_Ptr
+ 2;
2540 Start_Column
:= Start_Column
+ 2;
2544 Scan_Ptr
:= Scan_Ptr
+ 1;
2545 Start_Column
:= Start_Column
+ 1;
2551 end loop Blanks_Loop
;
2553 -- Outer loop keeps going only if a horizontal tab follows
2555 if Source
(Scan_Ptr
) = HT
then
2560 Scan_Ptr
:= Scan_Ptr
+ 1;
2561 Start_Column
:= (Start_Column
/ 8) * 8 + 8;
2567 return Start_Column
;
2569 -- A constraint error can happen only if we have a compiler with checks on
2570 -- and a line with a ludicrous number of tabs or spaces at the start. In
2571 -- such a case, we really don't care if Start_Column is right or not.
2574 when Constraint_Error
=>
2575 return Start_Column
;
2576 end Set_Start_Column
;