1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, 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 Restrict
; use Restrict
;
32 with Rident
; use Rident
;
33 with Scans
; use Scans
;
34 with Sinput
; use Sinput
;
35 with Snames
; use Snames
;
36 with Stringt
; use Stringt
;
37 with Stylesw
; use Stylesw
;
38 with Uintp
; use Uintp
;
39 with Urealp
; use Urealp
;
40 with Widechar
; use Widechar
;
42 pragma Warnings
(Off
);
43 -- This package is used also by gnatcoll
45 with System
.UTF_32
; use System
.UTF_32
;
46 with System
.WCh_Con
; use System
.WCh_Con
;
52 -- Make control characters visible
54 Special_Characters
: array (Character) of Boolean := (others => False);
55 -- For characters that are Special token, the value is True
57 Comment_Is_Token
: Boolean := False;
58 -- True if comments are tokens
60 End_Of_Line_Is_Token
: Boolean := False;
61 -- True if End_Of_Line is a token
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 procedure Accumulate_Token_Checksum
;
68 pragma Inline
(Accumulate_Token_Checksum
);
69 -- Called after each numeric literal and identifier/keyword. For keywords,
70 -- the token used is Tok_Identifier. This allows to detect additional
71 -- spaces added in sources when using the builder switch -m.
73 procedure Accumulate_Token_Checksum_GNAT_6_3
;
74 -- Used in place of Accumulate_Token_Checksum for GNAT versions 5.04 to
75 -- 6.3, when Tok_Some was not included in Token_Type and the actual
76 -- Token_Type was used for keywords. This procedure is never used in the
77 -- compiler or gnatmake, only in gprbuild.
79 procedure Accumulate_Token_Checksum_GNAT_5_03
;
80 -- Used in place of Accumulate_Token_Checksum for GNAT version 5.03, when
81 -- Tok_Interface, Tok_Some, Tok_Synchronized and Tok_Overriding were not
82 -- included in Token_Type and the actual Token_Type was used for keywords.
83 -- This procedure is never used in the compiler or gnatmake, only in
86 procedure Accumulate_Checksum
(C
: Character);
87 pragma Inline
(Accumulate_Checksum
);
88 -- This routine accumulates the checksum given character C. During the
89 -- scanning of a source file, this routine is called with every character
90 -- in the source, excluding blanks, and all control characters (except
91 -- that ESC is included in the checksum). Upper case letters not in string
92 -- literals are folded by the caller. See Sinput spec for the documentation
93 -- of the checksum algorithm. Note: checksum values are only used if we
94 -- generate code, so it is not necessary to worry about making the right
95 -- sequence of calls in any error situation.
97 procedure Accumulate_Checksum
(C
: Char_Code
);
98 pragma Inline
(Accumulate_Checksum
);
99 -- This version is identical, except that the argument, C, is a character
100 -- code value instead of a character. This is used when wide characters
101 -- are scanned. We use the character code rather than the ASCII characters
102 -- so that the checksum is independent of wide character encoding method.
104 procedure Initialize_Checksum
;
105 pragma Inline
(Initialize_Checksum
);
106 -- Initialize checksum value
108 -------------------------
109 -- Accumulate_Checksum --
110 -------------------------
112 procedure Accumulate_Checksum
(C
: Character) is
114 System
.CRC32
.Update
(System
.CRC32
.CRC32
(Checksum
), C
);
115 end Accumulate_Checksum
;
117 procedure Accumulate_Checksum
(C
: Char_Code
) is
120 Accumulate_Checksum
(Character'Val (C
/ 2 ** 24));
121 Accumulate_Checksum
(Character'Val ((C
/ 2 ** 16) mod 256));
122 Accumulate_Checksum
(Character'Val ((C
/ 256) mod 256));
124 Accumulate_Checksum
(Character'Val (C
/ 256));
127 Accumulate_Checksum
(Character'Val (C
mod 256));
128 end Accumulate_Checksum
;
130 -------------------------------
131 -- Accumulate_Token_Checksum --
132 -------------------------------
134 procedure Accumulate_Token_Checksum
is
137 (System
.CRC32
.CRC32
(Checksum
),
138 Character'Val (Token_Type
'Pos (Token
)));
139 end Accumulate_Token_Checksum
;
141 ----------------------------------------
142 -- Accumulate_Token_Checksum_GNAT_6_3 --
143 ----------------------------------------
145 procedure Accumulate_Token_Checksum_GNAT_6_3
is
147 -- Individual values of Token_Type are used, instead of subranges, so
148 -- that additions or suppressions of enumerated values in type
149 -- Token_Type are detected by the compiler.
152 when Tok_Integer_Literal | Tok_Real_Literal | Tok_String_Literal |
153 Tok_Char_Literal | Tok_Operator_Symbol | Tok_Identifier |
154 Tok_Double_Asterisk | Tok_Ampersand | Tok_Minus | Tok_Plus |
155 Tok_Asterisk | Tok_Mod | Tok_Rem | Tok_Slash | Tok_New |
156 Tok_Abs | Tok_Others | Tok_Null | Tok_Dot | Tok_Apostrophe |
157 Tok_Left_Paren | Tok_Delta | Tok_Digits | Tok_Range |
158 Tok_Right_Paren | Tok_Comma | Tok_And | Tok_Or | Tok_Xor |
159 Tok_Less | Tok_Equal | Tok_Greater | Tok_Not_Equal |
160 Tok_Greater_Equal | Tok_Less_Equal | Tok_In | Tok_Not |
161 Tok_Box | Tok_Colon_Equal | Tok_Colon | Tok_Greater_Greater |
162 Tok_Abstract | Tok_Access | Tok_Aliased | Tok_All | Tok_Array |
163 Tok_At | Tok_Body | Tok_Constant | Tok_Do | Tok_Is |
164 Tok_Interface | Tok_Limited | Tok_Of | Tok_Out | Tok_Record |
165 Tok_Renames | Tok_Reverse
=>
168 (System
.CRC32
.CRC32
(Checksum
),
169 Character'Val (Token_Type
'Pos (Token
)));
174 (System
.CRC32
.CRC32
(Checksum
),
175 Character'Val (Token_Type
'Pos (Tok_Identifier
)));
177 when Tok_Tagged | Tok_Then | Tok_Less_Less | Tok_Abort | Tok_Accept |
178 Tok_Case | Tok_Delay | Tok_Else | Tok_Elsif | Tok_End |
179 Tok_Exception | Tok_Exit | Tok_Goto | Tok_If | Tok_Pragma |
180 Tok_Raise | Tok_Requeue | Tok_Return | Tok_Select |
181 Tok_Terminate | Tok_Until | Tok_When | Tok_Begin | Tok_Declare |
182 Tok_For | Tok_Loop | Tok_While | Tok_Entry | Tok_Protected |
183 Tok_Task | Tok_Type | Tok_Subtype | Tok_Overriding |
184 Tok_Synchronized | Tok_Use | Tok_Function | Tok_Generic |
185 Tok_Package | Tok_Procedure | Tok_Private | Tok_With |
186 Tok_Separate | Tok_EOF | Tok_Semicolon | Tok_Arrow |
187 Tok_Vertical_Bar | Tok_Dot_Dot | Tok_Project | Tok_Extends |
188 Tok_External | Tok_External_As_List | Tok_Comment |
189 Tok_End_Of_Line | Tok_Special | Tok_SPARK_Hide | No_Token
=>
192 (System
.CRC32
.CRC32
(Checksum
),
193 Character'Val (Token_Type
'Pos (Token_Type
'Pred (Token
))));
195 end Accumulate_Token_Checksum_GNAT_6_3
;
197 -----------------------------------------
198 -- Accumulate_Token_Checksum_GNAT_5_03 --
199 -----------------------------------------
201 procedure Accumulate_Token_Checksum_GNAT_5_03
is
203 -- Individual values of Token_Type are used, instead of subranges, so
204 -- that additions or suppressions of enumerated values in type
205 -- Token_Type are detected by the compiler.
208 when Tok_Integer_Literal | Tok_Real_Literal | Tok_String_Literal |
209 Tok_Char_Literal | Tok_Operator_Symbol | Tok_Identifier |
210 Tok_Double_Asterisk | Tok_Ampersand | Tok_Minus | Tok_Plus |
211 Tok_Asterisk | Tok_Mod | Tok_Rem | Tok_Slash | Tok_New |
212 Tok_Abs | Tok_Others | Tok_Null | Tok_Dot | Tok_Apostrophe |
213 Tok_Left_Paren | Tok_Delta | Tok_Digits | Tok_Range |
214 Tok_Right_Paren | Tok_Comma | Tok_And | Tok_Or | Tok_Xor |
215 Tok_Less | Tok_Equal | Tok_Greater | Tok_Not_Equal |
216 Tok_Greater_Equal | Tok_Less_Equal | Tok_In | Tok_Not |
217 Tok_Box | Tok_Colon_Equal | Tok_Colon | Tok_Greater_Greater |
218 Tok_Abstract | Tok_Access | Tok_Aliased | Tok_All | Tok_Array |
219 Tok_At | Tok_Body | Tok_Constant | Tok_Do | Tok_Is
=>
222 (System
.CRC32
.CRC32
(Checksum
),
223 Character'Val (Token_Type
'Pos (Token
)));
225 when Tok_Interface | Tok_Some | Tok_Overriding | Tok_Synchronized
=>
227 (System
.CRC32
.CRC32
(Checksum
),
228 Character'Val (Token_Type
'Pos (Tok_Identifier
)));
230 when Tok_Limited | Tok_Of | Tok_Out | Tok_Record |
231 Tok_Renames | Tok_Reverse
=>
234 (System
.CRC32
.CRC32
(Checksum
),
235 Character'Val (Token_Type
'Pos (Token
) - 1));
237 when Tok_Tagged | Tok_Then | Tok_Less_Less | Tok_Abort | Tok_Accept |
238 Tok_Case | Tok_Delay | Tok_Else | Tok_Elsif | Tok_End |
239 Tok_Exception | Tok_Exit | Tok_Goto | Tok_If | Tok_Pragma |
240 Tok_Raise | Tok_Requeue | Tok_Return | Tok_Select |
241 Tok_Terminate | Tok_Until | Tok_When | Tok_Begin | Tok_Declare |
242 Tok_For | Tok_Loop | Tok_While | Tok_Entry | Tok_Protected |
243 Tok_Task | Tok_Type | Tok_Subtype
=>
246 (System
.CRC32
.CRC32
(Checksum
),
247 Character'Val (Token_Type
'Pos (Token
) - 2));
249 when Tok_Use | Tok_Function | Tok_Generic |
250 Tok_Package | Tok_Procedure | Tok_Private | Tok_With |
251 Tok_Separate | Tok_EOF | Tok_Semicolon | Tok_Arrow |
252 Tok_Vertical_Bar | Tok_Dot_Dot | Tok_Project | Tok_Extends |
253 Tok_External | Tok_External_As_List | Tok_Comment |
254 Tok_End_Of_Line | Tok_Special | Tok_SPARK_Hide | No_Token
=>
257 (System
.CRC32
.CRC32
(Checksum
),
258 Character'Val (Token_Type
'Pos (Token
) - 4));
260 end Accumulate_Token_Checksum_GNAT_5_03
;
262 ----------------------------
263 -- Determine_Token_Casing --
264 ----------------------------
266 function Determine_Token_Casing
return Casing_Type
is
268 return Determine_Casing
(Source
(Token_Ptr
.. Scan_Ptr
- 1));
269 end Determine_Token_Casing
;
271 -------------------------
272 -- Initialize_Checksum --
273 -------------------------
275 procedure Initialize_Checksum
is
277 System
.CRC32
.Initialize
(System
.CRC32
.CRC32
(Checksum
));
278 end Initialize_Checksum
;
280 ------------------------
281 -- Initialize_Scanner --
282 ------------------------
284 procedure Initialize_Scanner
(Index
: Source_File_Index
) is
286 -- Establish reserved words
288 Scans
.Initialize_Ada_Keywords
;
290 -- Initialize scan control variables
292 Current_Source_File
:= Index
;
293 Source
:= Source_Text
(Current_Source_File
);
294 Scan_Ptr
:= Source_First
(Current_Source_File
);
296 Token_Ptr
:= Scan_Ptr
;
297 Current_Line_Start
:= Scan_Ptr
;
299 Token_Name
:= No_Name
;
300 Start_Column
:= Set_Start_Column
;
301 First_Non_Blank_Location
:= Scan_Ptr
;
304 Wide_Char_Byte_Count
:= 0;
306 -- Do not call Scan, otherwise the License stuff does not work in Scn
308 end Initialize_Scanner
;
310 ------------------------------
311 -- Reset_Special_Characters --
312 ------------------------------
314 procedure Reset_Special_Characters
is
316 Special_Characters
:= (others => False);
317 end Reset_Special_Characters
;
325 Start_Of_Comment
: Source_Ptr
;
326 -- Record start of comment position
328 Underline_Found
: Boolean;
329 -- During scanning of an identifier, set to True if last character
330 -- scanned was an underline or other punctuation character. This
331 -- is used to flag the error of two underlines/punctuations in a
332 -- row or ending an identifier with a underline/punctuation. Here
333 -- punctuation means any UTF_32 character in the Unicode category
334 -- Punctuation,Connector.
337 -- Used to remember start of last wide character scanned
339 procedure Check_End_Of_Line
;
340 -- Called when end of line encountered. Checks that line is not too
341 -- long, and that other style checks for the end of line are met.
343 function Double_Char_Token
(C
: Character) return Boolean;
344 -- This function is used for double character tokens like := or <>. It
345 -- checks if the character following Source (Scan_Ptr) is C, and if so
346 -- bumps Scan_Ptr past the pair of characters and returns True. A space
347 -- between the two characters is also recognized with an appropriate
348 -- error message being issued. If C is not present, False is returned.
349 -- Note that Double_Char_Token can only be used for tokens defined in
350 -- the Ada syntax (it's use for error cases like && is not appropriate
351 -- since we do not want a junk message for a case like &-space-&).
353 procedure Error_Illegal_Character
;
354 -- Give illegal character error, Scan_Ptr points to character. On
355 -- return, Scan_Ptr is bumped past the illegal character.
357 procedure Error_Illegal_Wide_Character
;
358 -- Give illegal wide character message. On return, Scan_Ptr is bumped
359 -- past the illegal character, which may still leave us pointing to
360 -- junk, not much we can do if the escape sequence is messed up!
362 procedure Error_Long_Line
;
363 -- Signal error of excessively long line
365 procedure Error_No_Double_Underline
;
366 -- Signal error of two underline or punctuation characters in a row.
367 -- Called with Scan_Ptr pointing to second underline/punctuation char.
370 -- This is the procedure for scanning out numeric literals. On entry,
371 -- Scan_Ptr points to the digit that starts the numeric literal (the
372 -- checksum for this character has not been accumulated yet). On return
373 -- Scan_Ptr points past the last character of the numeric literal, Token
374 -- and Token_Node are set appropriately, and the checksum is updated.
377 -- This is the procedure for scanning out string literals. On entry,
378 -- Scan_Ptr points to the opening string quote (the checksum for this
379 -- character has not been accumulated yet). On return Scan_Ptr points
380 -- past the closing quote of the string literal, Token and Token_Node
381 -- are set appropriately, and the checksum is updated.
383 procedure Skip_Other_Format_Characters
;
384 -- Skips past any "other format" category characters at the current
385 -- cursor location (does not skip past spaces or any other characters).
387 function Start_Of_Wide_Character
return Boolean;
388 -- Returns True if the scan pointer is pointing to the start of a wide
389 -- character sequence, does not modify the scan pointer in any case.
391 -----------------------
392 -- Check_End_Of_Line --
393 -----------------------
395 procedure Check_End_Of_Line
is
396 Len
: constant Int
:=
398 Int
(Current_Line_Start
) -
399 Wide_Char_Byte_Count
;
403 Style
.Check_Line_Terminator
(Len
);
406 -- Deal with checking maximum line length
408 if Style_Check
and Style_Check_Max_Line_Length
then
409 Style
.Check_Line_Max_Length
(Len
);
411 -- If style checking is inactive, check maximum line length against
414 elsif Len
> Max_Line_Length
then
418 -- Now one more checking circuit. Normally we are only enforcing a
419 -- limit of physical characters, with tabs counting as one character.
420 -- But if after tab expansion we would have a total line length that
421 -- exceeded 32766, that would really cause trouble, because column
422 -- positions would exceed the maximum we allow for a column count.
423 -- Note: the limit is 32766 rather than 32767, since we use a value
424 -- of 32767 for special purposes (see Sinput). Now we really do not
425 -- want to go messing with tabs in the normal case, so what we do is
426 -- to check for a line that has more than 4096 physical characters.
427 -- Any shorter line could not be a problem, even if it was all tabs.
436 Ptr
:= Current_Line_Start
;
438 exit when Ptr
= Scan_Ptr
;
440 if Source
(Ptr
) = ASCII
.HT
then
441 Col
:= (Col
- 1 + 8) / 8 * 8 + 1;
448 ("this line is longer than 32766 characters",
450 raise Unrecoverable_Error
;
458 -- Reset wide character byte count for next line
460 Wide_Char_Byte_Count
:= 0;
461 end Check_End_Of_Line
;
463 -----------------------
464 -- Double_Char_Token --
465 -----------------------
467 function Double_Char_Token
(C
: Character) return Boolean is
469 if Source
(Scan_Ptr
+ 1) = C
then
470 Accumulate_Checksum
(C
);
471 Scan_Ptr
:= Scan_Ptr
+ 2;
474 elsif Source
(Scan_Ptr
+ 1) = ' '
475 and then Source
(Scan_Ptr
+ 2) = C
477 Scan_Ptr
:= Scan_Ptr
+ 1;
478 Error_Msg_S
-- CODEFIX
479 ("no space allowed here");
480 Scan_Ptr
:= Scan_Ptr
+ 2;
486 end Double_Char_Token
;
488 -----------------------------
489 -- Error_Illegal_Character --
490 -----------------------------
492 procedure Error_Illegal_Character
is
494 Error_Msg_S
("illegal character");
495 Scan_Ptr
:= Scan_Ptr
+ 1;
496 end Error_Illegal_Character
;
498 ----------------------------------
499 -- Error_Illegal_Wide_Character --
500 ----------------------------------
502 procedure Error_Illegal_Wide_Character
is
504 Scan_Ptr
:= Scan_Ptr
+ 1;
505 Error_Msg
("illegal wide character", Wptr
);
506 end Error_Illegal_Wide_Character
;
508 ---------------------
509 -- Error_Long_Line --
510 ---------------------
512 procedure Error_Long_Line
is
515 ("this line is too long",
516 Current_Line_Start
+ Source_Ptr
(Max_Line_Length
));
519 -------------------------------
520 -- Error_No_Double_Underline --
521 -------------------------------
523 procedure Error_No_Double_Underline
is
525 Underline_Found
:= False;
527 -- There are four cases, and we special case the messages
529 if Source
(Scan_Ptr
) = '_' then
530 if Source
(Scan_Ptr
- 1) = '_' then
531 Error_Msg_S
-- CODEFIX
532 ("two consecutive underlines not permitted");
534 Error_Msg_S
("underline cannot follow punctuation character");
538 if Source
(Scan_Ptr
- 1) = '_' then
539 Error_Msg_S
("punctuation character cannot follow underline");
542 ("two consecutive punctuation characters not permitted");
545 end Error_No_Double_Underline
;
554 -- Current source program character
556 Base_Char
: Character;
557 -- Either # or : (character at start of based number)
563 -- Value of base in Uint format
566 -- Value of integer scanned by Scan_Integer in Uint format
569 -- Value of integer in numeric value being scanned
572 -- Scale value for real literal
575 -- Scale in Uint format
577 Exponent_Is_Negative
: Boolean;
578 -- Set true for negative exponent
580 Extended_Digit_Value
: Int
;
581 -- Extended digit value
583 Point_Scanned
: Boolean;
584 -- Flag for decimal point scanned in numeric literal
586 -----------------------
587 -- Local Subprograms --
588 -----------------------
590 procedure Error_Digit_Expected
;
591 -- Signal error of bad digit, Scan_Ptr points to the location at
592 -- which the digit was expected on input, and is unchanged on return.
594 procedure Scan_Integer
;
595 -- Procedure to scan integer literal. On entry, Scan_Ptr points to a
596 -- digit, on exit Scan_Ptr points past the last character of the
599 -- For each digit encountered, UI_Int_Value is multiplied by 10, and
600 -- the value of the digit added to the result. In addition, the
601 -- value in Scale is decremented by one for each actual digit
604 --------------------------
605 -- Error_Digit_Expected --
606 --------------------------
608 procedure Error_Digit_Expected
is
610 Error_Msg_S
("digit expected");
611 end Error_Digit_Expected
;
617 procedure Scan_Integer
is
619 -- Next character scanned
622 C
:= Source
(Scan_Ptr
);
624 -- Loop through digits (allowing underlines)
627 Accumulate_Checksum
(C
);
629 UI_Int_Value
* 10 + (Character'Pos (C
) - Character'Pos ('0'));
630 Scan_Ptr
:= Scan_Ptr
+ 1;
632 C
:= Source
(Scan_Ptr
);
634 -- Case of underline encountered
638 -- We do not accumulate the '_' in the checksum, so that
639 -- 1_234 is equivalent to 1234, and does not trigger
640 -- compilation for "minimal recompilation" (gnatmake -m).
643 Scan_Ptr
:= Scan_Ptr
+ 1;
644 C
:= Source
(Scan_Ptr
);
646 Error_No_Double_Underline
;
649 if C
not in '0' .. '9' then
650 Error_Digit_Expected
;
655 exit when C
not in '0' .. '9';
660 -- Start of Processing for Nlit
665 UI_Int_Value
:= Uint_0
;
666 Based_Literal_Uses_Colon
:= False;
669 Point_Scanned
:= False;
670 UI_Num_Value
:= UI_Int_Value
;
672 -- Various possibilities now for continuing the literal are period,
673 -- E/e (for exponent), or :/# (for based literal).
676 C
:= Source
(Scan_Ptr
);
680 -- Scan out point, but do not scan past .. which is a range
681 -- sequence, and must not be eaten up scanning a numeric literal.
683 while C
= '.' and then Source
(Scan_Ptr
+ 1) /= '.' loop
684 Accumulate_Checksum
('.');
686 if Point_Scanned
then
687 Error_Msg_S
("duplicate point ignored");
690 Point_Scanned
:= True;
691 Scan_Ptr
:= Scan_Ptr
+ 1;
692 C
:= Source
(Scan_Ptr
);
694 if C
not in '0' .. '9' then
696 ("real literal cannot end with point", Scan_Ptr
- 1);
699 UI_Num_Value
:= UI_Int_Value
;
703 -- Based literal case. The base is the value we already scanned.
704 -- In the case of colon, we insist that the following character
705 -- is indeed an extended digit or a period. This catches a number
706 -- of common errors, as well as catching the well known tricky
707 -- bug otherwise arising from "x : integer range 1 .. 10:= 6;"
710 or else (C
= ':' and then
711 (Source
(Scan_Ptr
+ 1) = '.'
713 Source
(Scan_Ptr
+ 1) in '0' .. '9'
715 Source
(Scan_Ptr
+ 1) in 'A' .. 'Z'
717 Source
(Scan_Ptr
+ 1) in 'a' .. 'z'))
719 Accumulate_Checksum
(C
);
721 UI_Base
:= UI_Int_Value
;
723 if Base_Char
= ':' then
724 Based_Literal_Uses_Colon
:= True;
727 if UI_Base
< 2 or else UI_Base
> 16 then
728 Error_Msg_SC
("base not 2-16");
732 Base
:= UI_To_Int
(UI_Base
);
733 Scan_Ptr
:= Scan_Ptr
+ 1;
735 -- Scan out extended integer [. integer]
737 C
:= Source
(Scan_Ptr
);
738 UI_Int_Value
:= Uint_0
;
742 if C
in '0' .. '9' then
743 Accumulate_Checksum
(C
);
744 Extended_Digit_Value
:=
745 Int
'(Character'Pos (C)) - Int'(Character'Pos ('0'));
747 elsif C
in 'A' .. 'F' then
748 Accumulate_Checksum
(Character'Val (Character'Pos (C
) + 32));
749 Extended_Digit_Value
:=
750 Int
'(Character'Pos (C)) - Int'(Character'Pos ('A')) + 10;
752 elsif C
in 'a' .. 'f' then
753 Accumulate_Checksum
(C
);
754 Extended_Digit_Value
:=
755 Int
'(Character'Pos (C)) - Int'(Character'Pos ('a')) + 10;
758 Error_Msg_S
("extended digit expected");
762 if Extended_Digit_Value
>= Base
then
763 Error_Msg_S
("digit '>= base");
766 UI_Int_Value
:= UI_Int_Value
* UI_Base
+ Extended_Digit_Value
;
768 Scan_Ptr
:= Scan_Ptr
+ 1;
769 C
:= Source
(Scan_Ptr
);
773 Accumulate_Checksum
('_');
774 Scan_Ptr
:= Scan_Ptr
+ 1;
775 C
:= Source
(Scan_Ptr
);
777 Error_No_Double_Underline
;
781 Accumulate_Checksum
('.');
783 if Point_Scanned
then
784 Error_Msg_S
("duplicate point ignored");
787 Scan_Ptr
:= Scan_Ptr
+ 1;
788 C
:= Source
(Scan_Ptr
);
789 Point_Scanned
:= True;
792 elsif C
= Base_Char
then
793 Accumulate_Checksum
(C
);
794 Scan_Ptr
:= Scan_Ptr
+ 1;
797 elsif C
= '#' or else C
= ':' then
798 Error_Msg_S
("based number delimiters must match");
799 Scan_Ptr
:= Scan_Ptr
+ 1;
802 elsif not Identifier_Char
(C
) then
803 if Base_Char
= '#' then
804 Error_Msg_S
-- CODEFIX
807 Error_Msg_S
-- CODEFIX
816 UI_Num_Value
:= UI_Int_Value
;
821 if not Point_Scanned
then
825 UI_Scale
:= UI_From_Int
(Scale
);
828 if Source
(Scan_Ptr
) = 'e' or else Source
(Scan_Ptr
) = 'E' then
829 Accumulate_Checksum
('e');
830 Scan_Ptr
:= Scan_Ptr
+ 1;
831 Exponent_Is_Negative
:= False;
833 if Source
(Scan_Ptr
) = '+' then
834 Accumulate_Checksum
('+');
835 Scan_Ptr
:= Scan_Ptr
+ 1;
837 elsif Source
(Scan_Ptr
) = '-' then
838 Accumulate_Checksum
('-');
840 if not Point_Scanned
then
842 ("negative exponent not allowed for integer literal");
844 Exponent_Is_Negative
:= True;
847 Scan_Ptr
:= Scan_Ptr
+ 1;
850 UI_Int_Value
:= Uint_0
;
852 if Source
(Scan_Ptr
) in '0' .. '9' then
855 Error_Digit_Expected
;
858 if Exponent_Is_Negative
then
859 UI_Scale
:= UI_Scale
- UI_Int_Value
;
861 UI_Scale
:= UI_Scale
+ UI_Int_Value
;
865 -- Case of real literal to be returned
867 if Point_Scanned
then
868 Token
:= Tok_Real_Literal
;
869 Real_Literal_Value
:=
875 -- Case of integer literal to be returned
878 Token
:= Tok_Integer_Literal
;
881 Int_Literal_Value
:= UI_Num_Value
;
883 -- Avoid doing possibly expensive calculations in cases like
884 -- parsing 163E800_000# when semantics will not be done anyway.
885 -- This is especially useful when parsing garbled input.
887 elsif Operating_Mode
/= Check_Syntax
888 and then (Serious_Errors_Detected
= 0 or else Try_Semantics
)
890 Int_Literal_Value
:= UI_Num_Value
* UI_Base
** UI_Scale
;
893 Int_Literal_Value
:= No_Uint
;
897 if Checksum_Accumulate_Token_Checksum
then
898 Accumulate_Token_Checksum
;
910 Delimiter
: Character;
911 -- Delimiter (first character of string)
914 -- Current source program character
917 -- Current character code value
920 -- Error flag for Scan_Wide call
922 String_Start
: Source_Ptr
;
923 -- Point to first character of string
925 procedure Error_Bad_String_Char
;
926 -- Signal bad character in string/character literal. On entry
927 -- Scan_Ptr points to the improper character encountered during the
928 -- scan. Scan_Ptr is not modified, so it still points to the bad
929 -- character on return.
931 procedure Error_Unterminated_String
;
932 -- Procedure called if a line terminator character is encountered
933 -- during scanning a string, meaning that the string is not properly
936 procedure Set_String
;
937 -- Procedure used to distinguish between string and operator symbol.
938 -- On entry the string has been scanned out, and its characters start
939 -- at Token_Ptr and end one character before Scan_Ptr. On exit Token
940 -- is set to Tok_String_Literal/Tok_Operator_Symbol as appropriate,
941 -- and Token_Node is appropriately initialized. In addition, in the
942 -- operator symbol case, Token_Name is appropriately set, and the
943 -- flags [Wide_]Wide_Character_Found are set appropriately.
945 ---------------------------
946 -- Error_Bad_String_Char --
947 ---------------------------
949 procedure Error_Bad_String_Char
is
950 C
: constant Character := Source
(Scan_Ptr
);
954 Error_Msg_S
("horizontal tab not allowed in string");
956 elsif C
= VT
or else C
= FF
then
957 Error_Msg_S
("format effector not allowed in string");
959 elsif C
in Upper_Half_Character
then
960 Error_Msg_S
("(Ada 83) upper half character not allowed");
963 Error_Msg_S
("control character not allowed in string");
965 end Error_Bad_String_Char
;
967 -------------------------------
968 -- Error_Unterminated_String --
969 -------------------------------
971 procedure Error_Unterminated_String
is
975 -- An interesting little refinement. Consider the following
978 -- A := "this is an unterminated string;
979 -- A := "this is an unterminated string &
980 -- P(A, "this is a parameter that didn't get terminated);
981 -- P("this is a parameter that didn't get terminated, A);
983 -- We fiddle a little to do slightly better placement in these
984 -- cases also if there is white space at the end of the line we
985 -- place the flag at the start of this white space, not at the
986 -- end. Note that we only have to test for blanks, since tabs
987 -- aren't allowed in strings in the first place and would have
988 -- caused an error message.
990 -- Two more cases that we treat specially are:
992 -- A := "this string uses the wrong terminator'
993 -- A := "this string uses the wrong terminator' &
995 -- In these cases we give a different error message as well
997 -- We actually reposition the scan pointer to the point where we
998 -- place the flag in these cases, since it seems a better bet on
999 -- the original intention.
1001 while Source
(Scan_Ptr
- 1) = ' '
1002 or else Source
(Scan_Ptr
- 1) = '&'
1004 Scan_Ptr
:= Scan_Ptr
- 1;
1005 Unstore_String_Char
;
1008 -- Check for case of incorrect string terminator, but single quote
1009 -- is not considered incorrect if the opening terminator misused
1010 -- a single quote (error message already given).
1013 and then Source
(Scan_Ptr
- 1) = '''
1015 Unstore_String_Char
;
1017 ("incorrect string terminator character", Scan_Ptr
- 1);
1021 -- Backup over semicolon or right-paren/semicolon sequence
1023 if Source
(Scan_Ptr
- 1) = ';' then
1024 Scan_Ptr
:= Scan_Ptr
- 1;
1025 Unstore_String_Char
;
1027 if Source
(Scan_Ptr
- 1) = ')' then
1028 Scan_Ptr
:= Scan_Ptr
- 1;
1029 Unstore_String_Char
;
1033 -- See if there is a comma in the string, if so, guess that
1034 -- the first comma terminates the string.
1037 while S
< Scan_Ptr
loop
1038 if Source
(S
) = ',' then
1039 while Scan_Ptr
> S
loop
1040 Scan_Ptr
:= Scan_Ptr
- 1;
1041 Unstore_String_Char
;
1050 -- Now we have adjusted the scan pointer, give message
1052 Error_Msg_S
-- CODEFIX
1053 ("missing string quote");
1054 end Error_Unterminated_String
;
1060 procedure Set_String
is
1061 Slen
: constant Int
:= Int
(Scan_Ptr
- Token_Ptr
- 2);
1067 -- Token_Name is currently set to Error_Name. The following
1068 -- section of code resets Token_Name to the proper Name_Op_xx
1069 -- value if the string is a valid operator symbol, otherwise it is
1070 -- left set to Error_Name.
1073 C1
:= Source
(Token_Ptr
+ 1);
1077 Token_Name
:= Name_Op_Eq
;
1080 Token_Name
:= Name_Op_Gt
;
1083 Token_Name
:= Name_Op_Lt
;
1086 Token_Name
:= Name_Op_Add
;
1089 Token_Name
:= Name_Op_Subtract
;
1092 Token_Name
:= Name_Op_Concat
;
1095 Token_Name
:= Name_Op_Multiply
;
1098 Token_Name
:= Name_Op_Divide
;
1105 C1
:= Source
(Token_Ptr
+ 1);
1106 C2
:= Source
(Token_Ptr
+ 2);
1108 if C1
= '*' and then C2
= '*' then
1109 Token_Name
:= Name_Op_Expon
;
1114 Token_Name
:= Name_Op_Ne
;
1116 Token_Name
:= Name_Op_Le
;
1118 Token_Name
:= Name_Op_Ge
;
1121 elsif (C1
= 'O' or else C1
= 'o') and then -- OR
1122 (C2
= 'R' or else C2
= 'r')
1124 Token_Name
:= Name_Op_Or
;
1128 C1
:= Source
(Token_Ptr
+ 1);
1129 C2
:= Source
(Token_Ptr
+ 2);
1130 C3
:= Source
(Token_Ptr
+ 3);
1132 if (C1
= 'A' or else C1
= 'a') and then -- AND
1133 (C2
= 'N' or else C2
= 'n') and then
1134 (C3
= 'D' or else C3
= 'd')
1136 Token_Name
:= Name_Op_And
;
1138 elsif (C1
= 'A' or else C1
= 'a') and then -- ABS
1139 (C2
= 'B' or else C2
= 'b') and then
1140 (C3
= 'S' or else C3
= 's')
1142 Token_Name
:= Name_Op_Abs
;
1144 elsif (C1
= 'M' or else C1
= 'm') and then -- MOD
1145 (C2
= 'O' or else C2
= 'o') and then
1146 (C3
= 'D' or else C3
= 'd')
1148 Token_Name
:= Name_Op_Mod
;
1150 elsif (C1
= 'N' or else C1
= 'n') and then -- NOT
1151 (C2
= 'O' or else C2
= 'o') and then
1152 (C3
= 'T' or else C3
= 't')
1154 Token_Name
:= Name_Op_Not
;
1156 elsif (C1
= 'R' or else C1
= 'r') and then -- REM
1157 (C2
= 'E' or else C2
= 'e') and then
1158 (C3
= 'M' or else C3
= 'm')
1160 Token_Name
:= Name_Op_Rem
;
1162 elsif (C1
= 'X' or else C1
= 'x') and then -- XOR
1163 (C2
= 'O' or else C2
= 'o') and then
1164 (C3
= 'R' or else C3
= 'r')
1166 Token_Name
:= Name_Op_Xor
;
1171 -- If it is an operator symbol, then Token_Name is set. If it is
1172 -- some other string value, then Token_Name still contains
1175 if Token_Name
= Error_Name
then
1176 Token
:= Tok_String_Literal
;
1179 Token
:= Tok_Operator_Symbol
;
1183 -- Start of processing for Slit
1186 -- On entry, Scan_Ptr points to the opening character of the string
1187 -- which is either a percent, double quote, or apostrophe (single
1188 -- quote). The latter case is an error detected by the character
1191 String_Start
:= Scan_Ptr
;
1193 Delimiter
:= Source
(Scan_Ptr
);
1194 Accumulate_Checksum
(Delimiter
);
1197 Wide_Character_Found
:= False;
1198 Wide_Wide_Character_Found
:= False;
1199 Scan_Ptr
:= Scan_Ptr
+ 1;
1201 -- Loop to scan out characters of string literal
1204 C
:= Source
(Scan_Ptr
);
1206 if C
= Delimiter
then
1207 Accumulate_Checksum
(C
);
1208 Scan_Ptr
:= Scan_Ptr
+ 1;
1209 exit when Source
(Scan_Ptr
) /= Delimiter
;
1210 Code
:= Get_Char_Code
(C
);
1211 Accumulate_Checksum
(C
);
1212 Scan_Ptr
:= Scan_Ptr
+ 1;
1215 if C
= '"' and then Delimiter
= '%' then
1217 ("quote not allowed in percent delimited string");
1218 Code
:= Get_Char_Code
(C
);
1219 Scan_Ptr
:= Scan_Ptr
+ 1;
1221 elsif Start_Of_Wide_Character
then
1223 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1226 Error_Illegal_Wide_Character
;
1227 Code
:= Get_Char_Code
(' ');
1230 Accumulate_Checksum
(Code
);
1232 -- In Ada 95 mode we allow any wide characters in a string
1233 -- but in Ada 2005, the set of characters allowed has been
1234 -- restricted to graphic characters.
1236 if Ada_Version
>= Ada_2005
1237 and then Is_UTF_32_Non_Graphic
(UTF_32
(Code
))
1240 ("(Ada 2005) non-graphic character not permitted " &
1241 "in string literal", Wptr
);
1245 Accumulate_Checksum
(C
);
1247 if C
not in Graphic_Character
then
1248 if C
in Line_Terminator
then
1249 Error_Unterminated_String
;
1252 elsif C
in Upper_Half_Character
then
1253 if Ada_Version
= Ada_83
then
1254 Error_Bad_String_Char
;
1258 Error_Bad_String_Char
;
1262 Code
:= Get_Char_Code
(C
);
1263 Scan_Ptr
:= Scan_Ptr
+ 1;
1267 Store_String_Char
(Code
);
1269 if not In_Character_Range
(Code
) then
1270 if In_Wide_Character_Range
(Code
) then
1271 Wide_Character_Found
:= True;
1273 Wide_Wide_Character_Found
:= True;
1278 String_Literal_Id
:= End_String
;
1283 ----------------------------------
1284 -- Skip_Other_Format_Characters --
1285 ----------------------------------
1287 procedure Skip_Other_Format_Characters
is
1293 while Start_Of_Wide_Character
loop
1295 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1297 if not Is_UTF_32_Other
(UTF_32
(Code
)) then
1302 end Skip_Other_Format_Characters
;
1304 -----------------------------
1305 -- Start_Of_Wide_Character --
1306 -----------------------------
1308 function Start_Of_Wide_Character
return Boolean is
1309 C
: constant Character := Source
(Scan_Ptr
);
1312 -- ESC encoding method with ESC present
1315 and then Wide_Character_Encoding_Method
in WC_ESC_Encoding_Method
1319 -- Upper half character with upper half encoding
1321 elsif C
in Upper_Half_Character
and then Upper_Half_Encoding
then
1324 -- Brackets encoding
1327 and then Source
(Scan_Ptr
+ 1) = '"'
1328 and then Identifier_Char
(Source
(Scan_Ptr
+ 2))
1332 -- Not the start of a wide character
1337 end Start_Of_Wide_Character
;
1339 -- Start of processing for Scan
1342 Prev_Token
:= Token
;
1343 Prev_Token_Ptr
:= Token_Ptr
;
1344 Token_Name
:= Error_Name
;
1346 -- The following loop runs more than once only if a format effector
1347 -- (tab, vertical tab, form feed, line feed, carriage return) is
1348 -- encountered and skipped, or some error situation, such as an
1349 -- illegal character, is encountered.
1351 <<Scan_Next_Character
>>
1354 -- Skip past blanks, loop is opened up for speed
1356 while Source
(Scan_Ptr
) = ' ' loop
1357 if Source
(Scan_Ptr
+ 1) /= ' ' then
1358 Scan_Ptr
:= Scan_Ptr
+ 1;
1362 if Source
(Scan_Ptr
+ 2) /= ' ' then
1363 Scan_Ptr
:= Scan_Ptr
+ 2;
1367 if Source
(Scan_Ptr
+ 3) /= ' ' then
1368 Scan_Ptr
:= Scan_Ptr
+ 3;
1372 if Source
(Scan_Ptr
+ 4) /= ' ' then
1373 Scan_Ptr
:= Scan_Ptr
+ 4;
1377 if Source
(Scan_Ptr
+ 5) /= ' ' then
1378 Scan_Ptr
:= Scan_Ptr
+ 5;
1382 if Source
(Scan_Ptr
+ 6) /= ' ' then
1383 Scan_Ptr
:= Scan_Ptr
+ 6;
1387 if Source
(Scan_Ptr
+ 7) /= ' ' then
1388 Scan_Ptr
:= Scan_Ptr
+ 7;
1392 Scan_Ptr
:= Scan_Ptr
+ 8;
1395 -- We are now at a non-blank character, which is the first character
1396 -- of the token we will scan, and hence the value of Token_Ptr.
1398 Token_Ptr
:= Scan_Ptr
;
1400 -- Here begins the main case statement which transfers control on the
1401 -- basis of the non-blank character we have encountered.
1403 case Source
(Scan_Ptr
) is
1405 -- Line terminator characters
1407 when CR | LF | FF | VT
=>
1408 goto Scan_Line_Terminator
;
1410 -- Horizontal tab, just skip past it
1417 Scan_Ptr
:= Scan_Ptr
+ 1;
1419 -- End of file character, treated as an end of file only if it is
1420 -- the last character in the buffer, otherwise it is ignored.
1423 if Scan_Ptr
= Source_Last
(Current_Source_File
) then
1433 Scan_Ptr
:= Scan_Ptr
+ 1;
1439 Accumulate_Checksum
('&');
1441 if Source
(Scan_Ptr
+ 1) = '&' then
1442 Error_Msg_S
-- CODEFIX
1443 ("'&'& should be `AND THEN`");
1444 Scan_Ptr
:= Scan_Ptr
+ 2;
1449 Scan_Ptr
:= Scan_Ptr
+ 1;
1450 Token
:= Tok_Ampersand
;
1454 -- Asterisk (can be multiplication operator or double asterisk which
1455 -- is the exponentiation compound delimiter).
1458 Accumulate_Checksum
('*');
1460 if Source
(Scan_Ptr
+ 1) = '*' then
1461 Accumulate_Checksum
('*');
1462 Scan_Ptr
:= Scan_Ptr
+ 2;
1463 Token
:= Tok_Double_Asterisk
;
1467 Scan_Ptr
:= Scan_Ptr
+ 1;
1468 Token
:= Tok_Asterisk
;
1472 -- Colon, which can either be an isolated colon, or part of an
1473 -- assignment compound delimiter.
1476 Accumulate_Checksum
(':');
1478 if Double_Char_Token
('=') then
1479 Token
:= Tok_Colon_Equal
;
1482 Style
.Check_Colon_Equal
;
1487 elsif Source
(Scan_Ptr
+ 1) = '-'
1488 and then Source
(Scan_Ptr
+ 2) /= '-'
1490 Token
:= Tok_Colon_Equal
;
1491 Error_Msg
-- CODEFIX
1492 (":- should be :=", Scan_Ptr
);
1493 Scan_Ptr
:= Scan_Ptr
+ 2;
1497 Scan_Ptr
:= Scan_Ptr
+ 1;
1510 Accumulate_Checksum
('(');
1511 Scan_Ptr
:= Scan_Ptr
+ 1;
1512 Token
:= Tok_Left_Paren
;
1515 Style
.Check_Left_Paren
;
1523 if Source
(Scan_Ptr
+ 1) = '"' then
1524 goto Scan_Wide_Character
;
1527 Error_Msg_S
("illegal character, replaced by ""(""");
1528 Scan_Ptr
:= Scan_Ptr
+ 1;
1529 Token
:= Tok_Left_Paren
;
1536 Error_Msg_S
("illegal character, replaced by ""(""");
1537 Scan_Ptr
:= Scan_Ptr
+ 1;
1538 Token
:= Tok_Left_Paren
;
1544 Accumulate_Checksum
(',');
1545 Scan_Ptr
:= Scan_Ptr
+ 1;
1554 -- Dot, which is either an isolated period, or part of a double dot
1555 -- compound delimiter sequence. We also check for the case of a
1556 -- digit following the period, to give a better error message.
1559 Accumulate_Checksum
('.');
1561 if Double_Char_Token
('.') then
1562 Token
:= Tok_Dot_Dot
;
1565 Style
.Check_Dot_Dot
;
1570 elsif Source
(Scan_Ptr
+ 1) in '0' .. '9' then
1571 Error_Msg_S
("numeric literal cannot start with point");
1572 Scan_Ptr
:= Scan_Ptr
+ 1;
1575 Scan_Ptr
:= Scan_Ptr
+ 1;
1580 -- Equal, which can either be an equality operator, or part of the
1581 -- arrow (=>) compound delimiter.
1584 Accumulate_Checksum
('=');
1586 if Double_Char_Token
('>') then
1595 elsif Source
(Scan_Ptr
+ 1) = '=' then
1596 Error_Msg_S
-- CODEFIX
1598 Scan_Ptr
:= Scan_Ptr
+ 1;
1601 Scan_Ptr
:= Scan_Ptr
+ 1;
1605 -- Greater than, which can be a greater than operator, greater than
1606 -- or equal operator, or first character of a right label bracket.
1609 Accumulate_Checksum
('>');
1611 if Double_Char_Token
('=') then
1612 Token
:= Tok_Greater_Equal
;
1615 elsif Double_Char_Token
('>') then
1616 Token
:= Tok_Greater_Greater
;
1620 Scan_Ptr
:= Scan_Ptr
+ 1;
1621 Token
:= Tok_Greater
;
1625 -- Less than, which can be a less than operator, less than or equal
1626 -- operator, or the first character of a left label bracket, or the
1627 -- first character of a box (<>) compound delimiter.
1630 Accumulate_Checksum
('<');
1632 if Double_Char_Token
('=') then
1633 Token
:= Tok_Less_Equal
;
1636 elsif Double_Char_Token
('>') then
1645 elsif Double_Char_Token
('<') then
1646 Token
:= Tok_Less_Less
;
1650 Scan_Ptr
:= Scan_Ptr
+ 1;
1655 -- Minus, which is either a subtraction operator, or the first
1656 -- character of double minus starting a comment
1658 when '-' => Minus_Case
: begin
1659 if Source
(Scan_Ptr
+ 1) = '>' then
1660 Error_Msg_S
("invalid token");
1661 Scan_Ptr
:= Scan_Ptr
+ 2;
1665 elsif Source
(Scan_Ptr
+ 1) /= '-' then
1666 Accumulate_Checksum
('-');
1667 Scan_Ptr
:= Scan_Ptr
+ 1;
1673 else -- Source (Scan_Ptr + 1) = '-' then
1675 Style
.Check_Comment
;
1678 Scan_Ptr
:= Scan_Ptr
+ 2;
1680 -- If we are in preprocessor mode with Replace_In_Comments set,
1681 -- then we return the "--" as a token on its own.
1683 if Replace_In_Comments
then
1684 Token
:= Tok_Comment
;
1688 -- Otherwise scan out the comment
1690 Start_Of_Comment
:= Scan_Ptr
;
1692 -- Loop to scan comment (this loop runs more than once only if
1693 -- a horizontal tab or other non-graphic character is scanned)
1696 -- Scan to non graphic character (opened up for speed)
1698 -- Note that we just eat left brackets, which means that
1699 -- bracket notation cannot be used for end of line
1700 -- characters in comments. This seems a reasonable choice,
1701 -- since no one would ever use brackets notation in a real
1702 -- program in this situation, and if we allow brackets
1703 -- notation, we forbid some valid comments which contain a
1704 -- brackets sequence that happens to match an end of line
1708 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1709 Scan_Ptr
:= Scan_Ptr
+ 1;
1710 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1711 Scan_Ptr
:= Scan_Ptr
+ 1;
1712 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1713 Scan_Ptr
:= Scan_Ptr
+ 1;
1714 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1715 Scan_Ptr
:= Scan_Ptr
+ 1;
1716 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1717 Scan_Ptr
:= Scan_Ptr
+ 1;
1720 -- Keep going if horizontal tab
1722 if Source
(Scan_Ptr
) = HT
then
1727 Scan_Ptr
:= Scan_Ptr
+ 1;
1729 -- Terminate scan of comment if line terminator
1731 elsif Source
(Scan_Ptr
) in Line_Terminator
then
1734 -- Terminate scan of comment if end of file encountered
1735 -- (embedded EOF character or real last character in file)
1737 elsif Source
(Scan_Ptr
) = EOF
then
1740 -- If we have a wide character, we have to scan it out,
1741 -- because it might be a legitimate line terminator
1743 elsif Start_Of_Wide_Character
then
1745 Wptr
: constant Source_Ptr
:= Scan_Ptr
;
1750 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1752 -- If not well formed wide character, then just skip
1753 -- past it and ignore it.
1756 Scan_Ptr
:= Wptr
+ 1;
1758 -- If UTF_32 terminator, terminate comment scan
1760 elsif Is_UTF_32_Line_Terminator
(UTF_32
(Code
)) then
1766 -- Keep going if character in 80-FF range, or is ESC. These
1767 -- characters are allowed in comments by RM-2.1(1), 2.7(2).
1768 -- They are allowed even in Ada 83 mode according to the
1769 -- approved AI. ESC was added to the AI in June 93.
1771 elsif Source
(Scan_Ptr
) in Upper_Half_Character
1772 or else Source
(Scan_Ptr
) = ESC
1774 Scan_Ptr
:= Scan_Ptr
+ 1;
1776 -- Otherwise we have an illegal comment character
1779 Error_Illegal_Character
;
1783 -- Note that, except when comments are tokens, we do NOT
1784 -- execute a return here, instead we fall through to reexecute
1785 -- the scan loop to look for a token.
1787 if Comment_Is_Token
then
1788 Name_Len
:= Integer (Scan_Ptr
- Start_Of_Comment
);
1789 Name_Buffer
(1 .. Name_Len
) :=
1790 String (Source
(Start_Of_Comment
.. Scan_Ptr
- 1));
1791 Comment_Id
:= Name_Find
;
1792 Token
:= Tok_Comment
;
1796 -- If the SPARK restriction is set for this unit, then generate
1797 -- a token Tok_SPARK_Hide for a SPARK HIDE directive.
1799 if Restriction_Check_Required
(SPARK
)
1800 and then Source
(Start_Of_Comment
) = '#'
1803 Scan_SPARK_Ptr
: Source_Ptr
;
1806 Scan_SPARK_Ptr
:= Start_Of_Comment
+ 1;
1810 while Source
(Scan_SPARK_Ptr
) = ' '
1811 or else Source
(Scan_SPARK_Ptr
) = HT
1813 Scan_SPARK_Ptr
:= Scan_SPARK_Ptr
+ 1;
1816 -- Recognize HIDE directive. SPARK input cannot be
1817 -- encoded as wide characters, so only deal with
1818 -- lower/upper case.
1820 if (Source
(Scan_SPARK_Ptr
) = 'h'
1821 or else Source
(Scan_SPARK_Ptr
) = 'H')
1822 and then (Source
(Scan_SPARK_Ptr
+ 1) = 'i'
1823 or else Source
(Scan_SPARK_Ptr
+ 1) = 'I')
1824 and then (Source
(Scan_SPARK_Ptr
+ 2) = 'd'
1825 or else Source
(Scan_SPARK_Ptr
+ 2) = 'D')
1826 and then (Source
(Scan_SPARK_Ptr
+ 3) = 'e'
1827 or else Source
(Scan_SPARK_Ptr
+ 3) = 'E')
1828 and then (Source
(Scan_SPARK_Ptr
+ 4) = ' '
1829 or else Source
(Scan_SPARK_Ptr
+ 4) = HT
)
1831 Token
:= Tok_SPARK_Hide
;
1839 -- Double quote or percent starting a string literal
1846 -- Apostrophe. This can either be the start of a character literal,
1847 -- or an isolated apostrophe used in a qualified expression or an
1848 -- attribute. We treat it as a character literal if it does not
1849 -- follow a right parenthesis, identifier, the keyword ALL or
1850 -- a literal. This means that we correctly treat constructs like:
1852 -- A := CHARACTER'('A');
1854 -- Note that RM-2.2(7) does not require a separator between
1855 -- "CHARACTER" and "'" in the above.
1857 when ''' => Char_Literal_Case
: declare
1862 Accumulate_Checksum
(''');
1863 Scan_Ptr
:= Scan_Ptr
+ 1;
1865 -- Here is where we make the test to distinguish the cases. Treat
1866 -- as apostrophe if previous token is an identifier, right paren
1867 -- or the reserved word "all" (latter case as in A.all'Address)
1868 -- (or the reserved word "project" in project files). Also treat
1869 -- it as apostrophe after a literal (this catches some legitimate
1870 -- cases, like A."abs"'Address, and also gives better error
1871 -- behavior for impossible cases like 123'xxx).
1873 if Prev_Token
= Tok_Identifier
1874 or else Prev_Token
= Tok_Right_Paren
1875 or else Prev_Token
= Tok_All
1876 or else Prev_Token
= Tok_Project
1877 or else Prev_Token
in Token_Class_Literal
1879 Token
:= Tok_Apostrophe
;
1882 Style
.Check_Apostrophe
;
1887 -- Otherwise the apostrophe starts a character literal
1890 -- Case of wide character literal
1892 if Start_Of_Wide_Character
then
1894 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1895 Accumulate_Checksum
(Code
);
1898 Error_Illegal_Wide_Character
;
1899 Code
:= Character'Pos (' ');
1901 -- In Ada 95 mode we allow any wide character in a character
1902 -- literal, but in Ada 2005, the set of characters allowed
1903 -- is restricted to graphic characters.
1905 elsif Ada_Version
>= Ada_2005
1906 and then Is_UTF_32_Non_Graphic
(UTF_32
(Code
))
1908 Error_Msg
-- CODEFIX????
1909 ("(Ada 2005) non-graphic character not permitted " &
1910 "in character literal", Wptr
);
1913 if Source
(Scan_Ptr
) /= ''' then
1914 Error_Msg_S
("missing apostrophe");
1916 Scan_Ptr
:= Scan_Ptr
+ 1;
1919 -- If we do not find a closing quote in the expected place then
1920 -- assume that we have a misguided attempt at a string literal.
1922 -- However, if previous token is RANGE, then we return an
1923 -- apostrophe instead since this gives better error recovery
1925 elsif Source
(Scan_Ptr
+ 1) /= ''' then
1926 if Prev_Token
= Tok_Range
then
1927 Token
:= Tok_Apostrophe
;
1931 Scan_Ptr
:= Scan_Ptr
- 1;
1933 ("strings are delimited by double quote character");
1939 -- Otherwise we have a (non-wide) character literal
1942 Accumulate_Checksum
(Source
(Scan_Ptr
));
1944 if Source
(Scan_Ptr
) not in Graphic_Character
then
1945 if Source
(Scan_Ptr
) in Upper_Half_Character
then
1946 if Ada_Version
= Ada_83
then
1947 Error_Illegal_Character
;
1951 Error_Illegal_Character
;
1955 Code
:= Get_Char_Code
(Source
(Scan_Ptr
));
1956 Scan_Ptr
:= Scan_Ptr
+ 2;
1959 -- Fall through here with Scan_Ptr updated past the closing
1960 -- quote, and Code set to the Char_Code value for the literal
1962 Accumulate_Checksum
(''');
1963 Token
:= Tok_Char_Literal
;
1964 Set_Character_Literal_Name
(Code
);
1965 Token_Name
:= Name_Find
;
1966 Character_Code
:= Code
;
1970 end Char_Literal_Case
;
1972 -- Right parenthesis
1975 Accumulate_Checksum
(')');
1976 Scan_Ptr
:= Scan_Ptr
+ 1;
1977 Token
:= Tok_Right_Paren
;
1980 Style
.Check_Right_Paren
;
1985 -- Right bracket or right brace, treated as right paren
1988 Error_Msg_S
("illegal character, replaced by "")""");
1989 Scan_Ptr
:= Scan_Ptr
+ 1;
1990 Token
:= Tok_Right_Paren
;
1993 -- Slash (can be division operator or first character of not equal)
1996 Accumulate_Checksum
('/');
1998 if Double_Char_Token
('=') then
1999 Token
:= Tok_Not_Equal
;
2002 Scan_Ptr
:= Scan_Ptr
+ 1;
2010 Accumulate_Checksum
(';');
2011 Scan_Ptr
:= Scan_Ptr
+ 1;
2012 Token
:= Tok_Semicolon
;
2015 Style
.Check_Semicolon
;
2022 when '|' => Vertical_Bar_Case
: begin
2023 Accumulate_Checksum
('|');
2025 -- Special check for || to give nice message
2027 if Source
(Scan_Ptr
+ 1) = '|' then
2028 Error_Msg_S
-- CODEFIX
2029 ("""'|'|"" should be `OR ELSE`");
2030 Scan_Ptr
:= Scan_Ptr
+ 2;
2035 Scan_Ptr
:= Scan_Ptr
+ 1;
2036 Token
:= Tok_Vertical_Bar
;
2039 Style
.Check_Vertical_Bar
;
2045 end Vertical_Bar_Case
;
2047 -- Exclamation, replacement character for vertical bar
2049 when '!' => Exclamation_Case
: begin
2050 Accumulate_Checksum
('!');
2052 if Source
(Scan_Ptr
+ 1) = '=' then
2053 Error_Msg_S
-- CODEFIX
2054 ("'!= should be /=");
2055 Scan_Ptr
:= Scan_Ptr
+ 2;
2056 Token
:= Tok_Not_Equal
;
2060 Scan_Ptr
:= Scan_Ptr
+ 1;
2061 Token
:= Tok_Vertical_Bar
;
2065 end Exclamation_Case
;
2069 when '+' => Plus_Case
: begin
2070 Accumulate_Checksum
('+');
2071 Scan_Ptr
:= Scan_Ptr
+ 1;
2076 -- Digits starting a numeric literal
2080 -- First a bit of a scan ahead to see if we have a case of an
2081 -- identifier starting with a digit (remembering exponent case).
2084 C
: constant Character := Source
(Scan_Ptr
+ 1);
2087 -- OK literal if digit followed by digit or underscore
2089 if C
in '0' .. '9' or else C
= '_' then
2092 -- OK literal if digit not followed by identifier char
2094 elsif not Identifier_Char
(C
) then
2097 -- OK literal if digit followed by e/E followed by digit/sign.
2098 -- We also allow underscore after the E, which is an error, but
2099 -- better handled by Nlit than deciding this is an identifier.
2101 elsif (C
= 'e' or else C
= 'E')
2102 and then (Source
(Scan_Ptr
+ 2) in '0' .. '9'
2103 or else Source
(Scan_Ptr
+ 2) = '+'
2104 or else Source
(Scan_Ptr
+ 2) = '-'
2105 or else Source
(Scan_Ptr
+ 2) = '_')
2109 -- Here we have what really looks like an identifier that
2110 -- starts with a digit, so give error msg.
2113 Error_Msg_S
("identifier may not start with digit");
2115 Underline_Found
:= False;
2116 Name_Buffer
(1) := Source
(Scan_Ptr
);
2117 Accumulate_Checksum
(Name_Buffer
(1));
2118 Scan_Ptr
:= Scan_Ptr
+ 1;
2119 goto Scan_Identifier
;
2123 -- Here we have an OK integer literal
2127 -- Check for proper delimiter, ignoring other format characters
2129 Skip_Other_Format_Characters
;
2131 if Identifier_Char
(Source
(Scan_Ptr
)) then
2133 ("delimiter required between literal and identifier");
2139 -- Lower case letters
2143 Underline_Found
:= False;
2144 Name_Buffer
(1) := Source
(Scan_Ptr
);
2145 Accumulate_Checksum
(Name_Buffer
(1));
2146 Scan_Ptr
:= Scan_Ptr
+ 1;
2147 goto Scan_Identifier
;
2149 -- Upper case letters
2153 Underline_Found
:= False;
2155 Character'Val (Character'Pos (Source
(Scan_Ptr
)) + 32);
2156 Accumulate_Checksum
(Name_Buffer
(1));
2157 Scan_Ptr
:= Scan_Ptr
+ 1;
2158 goto Scan_Identifier
;
2160 -- Underline character
2163 if Special_Characters
('_') then
2164 Token_Ptr
:= Scan_Ptr
;
2165 Scan_Ptr
:= Scan_Ptr
+ 1;
2166 Token
:= Tok_Special
;
2167 Special_Character
:= '_';
2171 Error_Msg_S
("identifier cannot start with underline");
2173 Name_Buffer
(1) := '_';
2174 Scan_Ptr
:= Scan_Ptr
+ 1;
2175 Underline_Found
:= False;
2176 goto Scan_Identifier
;
2178 -- Space (not possible, because we scanned past blanks)
2181 raise Program_Error
;
2183 -- Characters in top half of ASCII 8-bit chart
2185 when Upper_Half_Character
=>
2187 -- Wide character case
2189 if Upper_Half_Encoding
then
2190 goto Scan_Wide_Character
;
2192 -- Otherwise we have OK Latin-1 character
2195 -- Upper half characters may possibly be identifier letters
2196 -- but can never be digits, so Identifier_Char can be used to
2197 -- test for a valid start of identifier character.
2199 if Identifier_Char
(Source
(Scan_Ptr
)) then
2201 Underline_Found
:= False;
2202 goto Scan_Identifier
;
2204 Error_Illegal_Character
;
2210 -- ESC character, possible start of identifier if wide characters
2211 -- using ESC encoding are allowed in identifiers, which we can
2212 -- tell by looking at the Identifier_Char flag for ESC, which is
2213 -- only true if these conditions are met. In Ada 2005 mode, may
2214 -- also be valid UTF_32 space or line terminator character.
2216 if Identifier_Char
(ESC
) then
2218 goto Scan_Wide_Character
;
2220 Error_Illegal_Character
;
2223 -- Invalid control characters
2225 when NUL | SOH | STX | ETX | EOT | ENQ | ACK | BEL | BS | ASCII
.SO |
2226 SI | DLE | DC1 | DC2 | DC3 | DC4 | NAK | SYN | ETB | CAN |
2227 EM | FS | GS | RS | US | DEL
2229 Error_Illegal_Character
;
2231 -- Invalid graphic characters
2233 when '#' |
'$' |
'?' |
'@' |
'`' |
'\' |
'^' |
'~' =>
2235 -- If Set_Special_Character has been called for this character,
2236 -- set Scans.Special_Character and return a Special token.
2238 if Special_Characters
(Source
(Scan_Ptr
)) then
2239 Token_Ptr
:= Scan_Ptr
;
2240 Token
:= Tok_Special
;
2241 Special_Character
:= Source
(Scan_Ptr
);
2242 Scan_Ptr
:= Scan_Ptr
+ 1;
2245 -- Otherwise, this is an illegal character
2248 Error_Illegal_Character
;
2251 -- End switch on non-blank character
2255 -- End loop past format effectors. The exit from this loop is by
2256 -- executing a return statement following completion of token scan
2257 -- (control never falls out of this loop to the code which follows)
2261 -- Wide_Character scanning routine. On entry we have encountered the
2262 -- initial character of a wide character sequence.
2264 <<Scan_Wide_Character
>>
2273 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2275 -- If bad wide character, signal error and continue scan
2278 Error_Illegal_Wide_Character
;
2279 goto Scan_Next_Character
;
2282 Cat
:= Get_Category
(UTF_32
(Code
));
2284 -- If OK letter, reset scan ptr and go scan identifier
2286 if Is_UTF_32_Letter
(Cat
) then
2289 Underline_Found
:= False;
2290 goto Scan_Identifier
;
2292 -- If OK wide space, ignore and keep scanning (we do not include
2293 -- any ignored spaces in checksum)
2295 elsif Is_UTF_32_Space
(Cat
) then
2296 goto Scan_Next_Character
;
2298 -- If other format character, ignore and keep scanning (again we
2299 -- do not include in the checksum) (this is for AI-0079).
2301 elsif Is_UTF_32_Other
(Cat
) then
2302 goto Scan_Next_Character
;
2304 -- If OK wide line terminator, terminate current line
2306 elsif Is_UTF_32_Line_Terminator
(UTF_32
(Code
)) then
2308 goto Scan_Line_Terminator
;
2310 -- Punctuation is an error (at start of identifier)
2312 elsif Is_UTF_32_Punctuation
(Cat
) then
2313 Error_Msg
("identifier cannot start with punctuation", Wptr
);
2316 Underline_Found
:= False;
2317 goto Scan_Identifier
;
2319 -- Mark character is an error (at start of identifier)
2321 elsif Is_UTF_32_Mark
(Cat
) then
2322 Error_Msg
("identifier cannot start with mark character", Wptr
);
2325 Underline_Found
:= False;
2326 goto Scan_Identifier
;
2328 -- Extended digit character is an error. Could be bad start of
2329 -- identifier or bad literal. Not worth doing too much to try to
2330 -- distinguish these cases, but we will do a little bit.
2332 elsif Is_UTF_32_Digit
(Cat
) then
2334 ("identifier cannot start with digit character", Wptr
);
2337 Underline_Found
:= False;
2338 goto Scan_Identifier
;
2340 -- All other wide characters are illegal here
2343 Error_Illegal_Wide_Character
;
2344 goto Scan_Next_Character
;
2348 -- Routine to scan line terminator. On entry Scan_Ptr points to a
2349 -- character which is one of FF,LR,CR,VT, or one of the wide characters
2350 -- that is treated as a line terminator.
2352 <<Scan_Line_Terminator
>>
2354 -- Check line too long
2358 -- Set Token_Ptr, if End_Of_Line is a token, for the case when it is
2361 if End_Of_Line_Is_Token
then
2362 Token_Ptr
:= Scan_Ptr
;
2369 Skip_Line_Terminators
(Scan_Ptr
, Physical
);
2371 -- If we are at start of physical line, update scan pointers to
2372 -- reflect the start of the new line.
2375 Current_Line_Start
:= Scan_Ptr
;
2376 Start_Column
:= Set_Start_Column
;
2377 First_Non_Blank_Location
:= Scan_Ptr
;
2379 -- If End_Of_Line is a token, we return it as it is a
2382 if End_Of_Line_Is_Token
then
2383 Token
:= Tok_End_Of_Line
;
2389 goto Scan_Next_Character
;
2391 -- Identifier scanning routine. On entry, some initial characters of
2392 -- the identifier may have already been stored in Name_Buffer. If so,
2393 -- Name_Len has the number of characters stored, otherwise Name_Len is
2394 -- set to zero on entry. Underline_Found is also set False on entry.
2398 -- This loop scans as fast as possible past lower half letters and
2399 -- digits, which we expect to be the most common characters.
2402 if Source
(Scan_Ptr
) in 'a' .. 'z'
2403 or else Source
(Scan_Ptr
) in '0' .. '9'
2405 Name_Buffer
(Name_Len
+ 1) := Source
(Scan_Ptr
);
2406 Accumulate_Checksum
(Source
(Scan_Ptr
));
2408 elsif Source
(Scan_Ptr
) in 'A' .. 'Z' then
2409 Name_Buffer
(Name_Len
+ 1) :=
2410 Character'Val (Character'Pos (Source
(Scan_Ptr
)) + 32);
2411 Accumulate_Checksum
(Name_Buffer
(Name_Len
+ 1));
2417 Underline_Found
:= False;
2418 Scan_Ptr
:= Scan_Ptr
+ 1;
2419 Name_Len
:= Name_Len
+ 1;
2422 -- If we fall through, then we have encountered either an underline
2423 -- character, or an extended identifier character (i.e. one from the
2424 -- upper half), or a wide character, or an identifier terminator. The
2425 -- initial test speeds us up in the most common case where we have
2426 -- an identifier terminator. Note that ESC is an identifier character
2427 -- only if a wide character encoding method that uses ESC encoding
2428 -- is active, so if we find an ESC character we know that we have a
2431 if Identifier_Char
(Source
(Scan_Ptr
))
2432 or else (Source
(Scan_Ptr
) in Upper_Half_Character
2433 and then Upper_Half_Encoding
)
2435 -- Case of underline
2437 if Source
(Scan_Ptr
) = '_' then
2438 Accumulate_Checksum
('_');
2440 if Underline_Found
then
2441 Error_No_Double_Underline
;
2443 Underline_Found
:= True;
2444 Name_Len
:= Name_Len
+ 1;
2445 Name_Buffer
(Name_Len
) := '_';
2448 Scan_Ptr
:= Scan_Ptr
+ 1;
2449 goto Scan_Identifier
;
2451 -- Upper half character
2453 elsif Source
(Scan_Ptr
) in Upper_Half_Character
2454 and then not Upper_Half_Encoding
2456 Accumulate_Checksum
(Source
(Scan_Ptr
));
2457 Store_Encoded_Character
2458 (Get_Char_Code
(Fold_Lower
(Source
(Scan_Ptr
))));
2459 Scan_Ptr
:= Scan_Ptr
+ 1;
2460 Underline_Found
:= False;
2461 goto Scan_Identifier
;
2463 -- Left bracket not followed by a quote terminates an identifier.
2464 -- This is an error, but we don't want to give a junk error msg
2465 -- about wide characters in this case!
2467 elsif Source
(Scan_Ptr
) = '['
2468 and then Source
(Scan_Ptr
+ 1) /= '"'
2472 -- We know we have a wide character encoding here (the current
2473 -- character is either ESC, left bracket, or an upper half
2474 -- character depending on the encoding method).
2477 -- Scan out the wide character and insert the appropriate
2478 -- encoding into the name table entry for the identifier.
2488 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2490 -- If error, signal error
2493 Error_Illegal_Wide_Character
;
2495 -- If the character scanned is a normal identifier
2496 -- character, then we treat it that way.
2498 elsif In_Character_Range
(Code
)
2499 and then Identifier_Char
(Get_Character
(Code
))
2501 Chr
:= Get_Character
(Code
);
2502 Accumulate_Checksum
(Chr
);
2503 Store_Encoded_Character
2504 (Get_Char_Code
(Fold_Lower
(Chr
)));
2505 Underline_Found
:= False;
2507 -- Here if not a normal identifier character
2510 Cat
:= Get_Category
(UTF_32
(Code
));
2512 -- Wide character in Unicode category "Other, Format"
2513 -- is not accepted in an identifier. This is because it
2514 -- it is considered a security risk (AI-0091).
2516 -- However, it is OK for such a character to appear at
2517 -- the end of an identifier.
2519 if Is_UTF_32_Other
(Cat
) then
2520 if not Identifier_Char
(Source
(Scan_Ptr
)) then
2521 goto Scan_Identifier_Complete
;
2524 ("identifier cannot contain other_format "
2525 & "character", Wptr
);
2526 goto Scan_Identifier
;
2529 -- Wide character in category Separator,Space terminates
2531 elsif Is_UTF_32_Space
(Cat
) then
2532 goto Scan_Identifier_Complete
;
2535 -- Here if wide character is part of the identifier
2537 -- Make sure we are allowing wide characters in
2538 -- identifiers. Note that we allow wide character
2539 -- notation for an OK identifier character. This in
2540 -- particular allows bracket or other notation to be
2541 -- used for upper half letters.
2543 -- Wide characters are always allowed in Ada 2005
2545 if Identifier_Character_Set
/= 'w'
2546 and then Ada_Version
< Ada_2005
2549 ("wide character not allowed in identifier", Wptr
);
2552 -- If OK letter, store it folding to upper case. Note
2553 -- that we include the folded letter in the checksum.
2555 if Is_UTF_32_Letter
(Cat
) then
2557 Char_Code
(UTF_32_To_Upper_Case
(UTF_32
(Code
)));
2558 Accumulate_Checksum
(Code
);
2559 Store_Encoded_Character
(Code
);
2560 Underline_Found
:= False;
2562 -- If OK extended digit or mark, then store it
2564 elsif Is_UTF_32_Digit
(Cat
)
2565 or else Is_UTF_32_Mark
(Cat
)
2567 Accumulate_Checksum
(Code
);
2568 Store_Encoded_Character
(Code
);
2569 Underline_Found
:= False;
2571 -- Wide punctuation is also stored, but counts as an
2572 -- underline character for error checking purposes.
2574 elsif Is_UTF_32_Punctuation
(Cat
) then
2575 Accumulate_Checksum
(Code
);
2577 if Underline_Found
then
2579 Cend
: constant Source_Ptr
:= Scan_Ptr
;
2582 Error_No_Double_Underline
;
2587 Store_Encoded_Character
(Code
);
2588 Underline_Found
:= True;
2591 -- Any other wide character is not acceptable
2595 ("invalid wide character in identifier", Wptr
);
2599 goto Scan_Identifier
;
2604 -- Scan of identifier is complete. The identifier is stored in
2605 -- Name_Buffer, and Scan_Ptr points past the last character.
2607 <<Scan_Identifier_Complete
>>
2608 Token_Name
:= Name_Find
;
2610 -- Check for identifier ending with underline or punctuation char
2612 if Underline_Found
then
2613 Underline_Found
:= False;
2615 if Source
(Scan_Ptr
- 1) = '_' then
2617 ("identifier cannot end with underline", Scan_Ptr
- 1);
2620 ("identifier cannot end with punctuation character", Wptr
);
2624 -- We will assume it is an identifier, not a keyword, so that the
2625 -- checksum is independent of the Ada version.
2627 Token
:= Tok_Identifier
;
2629 -- Here is where we check if it was a keyword
2631 if Is_Keyword_Name
(Token_Name
) then
2632 if Opt
.Checksum_GNAT_6_3
then
2633 Token
:= Token_Type
'Val (Get_Name_Table_Byte
(Token_Name
));
2635 if Checksum_Accumulate_Token_Checksum
then
2636 if Checksum_GNAT_5_03
then
2637 Accumulate_Token_Checksum_GNAT_5_03
;
2639 Accumulate_Token_Checksum_GNAT_6_3
;
2644 Accumulate_Token_Checksum
;
2645 Token
:= Token_Type
'Val (Get_Name_Table_Byte
(Token_Name
));
2648 -- Keyword style checks
2652 -- Deal with possible style check for non-lower case keyword,
2653 -- but we don't treat ACCESS, DELTA, DIGITS, RANGE as keywords
2654 -- for this purpose if they appear as attribute designators.
2655 -- Actually we only check the first character for speed.
2657 -- Ada 2005 (AI-284): Do not apply the style check in case of
2658 -- "pragma Interface"
2660 -- Ada 2005 (AI-340): Do not apply the style check in case of
2663 if Source
(Token_Ptr
) <= 'Z'
2664 and then (Prev_Token
/= Tok_Apostrophe
2666 (Token
/= Tok_Access
and then
2667 Token
/= Tok_Delta
and then
2668 Token
/= Tok_Digits
and then
2669 Token
/= Tok_Mod
and then
2670 Token
/= Tok_Range
))
2671 and then (Token
/= Tok_Interface
2673 (Token
= Tok_Interface
2674 and then Prev_Token
/= Tok_Pragma
))
2676 Style
.Non_Lower_Case_Keyword
;
2679 -- Check THEN/ELSE style rules. These do not apply to AND THEN
2680 -- or OR ELSE, and do not apply in conditional expressions.
2682 if (Token
= Tok_Then
and then Prev_Token
/= Tok_And
)
2684 (Token
= Tok_Else
and then Prev_Token
/= Tok_Or
)
2686 if Inside_Conditional_Expression
= 0 then
2687 Style
.Check_Separate_Stmt_Lines
;
2692 -- We must reset Token_Name since this is not an identifier and
2693 -- if we leave Token_Name set, the parser gets confused because
2694 -- it thinks it is dealing with an identifier instead of the
2695 -- corresponding keyword.
2697 Token_Name
:= No_Name
;
2700 -- It is an identifier after all
2703 if Checksum_Accumulate_Token_Checksum
then
2704 Accumulate_Token_Checksum
;
2712 --------------------------
2713 -- Set_Comment_As_Token --
2714 --------------------------
2716 procedure Set_Comment_As_Token
(Value
: Boolean) is
2718 Comment_Is_Token
:= Value
;
2719 end Set_Comment_As_Token
;
2721 ------------------------------
2722 -- Set_End_Of_Line_As_Token --
2723 ------------------------------
2725 procedure Set_End_Of_Line_As_Token
(Value
: Boolean) is
2727 End_Of_Line_Is_Token
:= Value
;
2728 end Set_End_Of_Line_As_Token
;
2730 ---------------------------
2731 -- Set_Special_Character --
2732 ---------------------------
2734 procedure Set_Special_Character
(C
: Character) is
2737 when '#' |
'$' |
'_' |
'?' |
'@' |
'`' |
'\' |
'^' |
'~' =>
2738 Special_Characters
(C
) := True;
2743 end Set_Special_Character
;
2745 ----------------------
2746 -- Set_Start_Column --
2747 ----------------------
2749 -- Note: it seems at first glance a little expensive to compute this value
2750 -- for every source line (since it is certainly not used for all source
2751 -- lines). On the other hand, it doesn't take much more work to skip past
2752 -- the initial white space on the line counting the columns than it would
2753 -- to scan past the white space using the standard scanning circuits.
2755 function Set_Start_Column
return Column_Number
is
2756 Start_Column
: Column_Number
:= 0;
2759 -- Outer loop scans past horizontal tab characters
2763 -- Inner loop scans past blanks as fast as possible, bumping Scan_Ptr
2764 -- past the blanks and adjusting Start_Column to account for them.
2767 if Source
(Scan_Ptr
) = ' ' then
2768 if Source
(Scan_Ptr
+ 1) = ' ' then
2769 if Source
(Scan_Ptr
+ 2) = ' ' then
2770 if Source
(Scan_Ptr
+ 3) = ' ' then
2771 if Source
(Scan_Ptr
+ 4) = ' ' then
2772 if Source
(Scan_Ptr
+ 5) = ' ' then
2773 if Source
(Scan_Ptr
+ 6) = ' ' then
2774 Scan_Ptr
:= Scan_Ptr
+ 7;
2775 Start_Column
:= Start_Column
+ 7;
2777 Scan_Ptr
:= Scan_Ptr
+ 6;
2778 Start_Column
:= Start_Column
+ 6;
2782 Scan_Ptr
:= Scan_Ptr
+ 5;
2783 Start_Column
:= Start_Column
+ 5;
2787 Scan_Ptr
:= Scan_Ptr
+ 4;
2788 Start_Column
:= Start_Column
+ 4;
2792 Scan_Ptr
:= Scan_Ptr
+ 3;
2793 Start_Column
:= Start_Column
+ 3;
2797 Scan_Ptr
:= Scan_Ptr
+ 2;
2798 Start_Column
:= Start_Column
+ 2;
2802 Scan_Ptr
:= Scan_Ptr
+ 1;
2803 Start_Column
:= Start_Column
+ 1;
2809 end loop Blanks_Loop
;
2811 -- Outer loop keeps going only if a horizontal tab follows
2813 if Source
(Scan_Ptr
) = HT
then
2818 Scan_Ptr
:= Scan_Ptr
+ 1;
2819 Start_Column
:= (Start_Column
/ 8) * 8 + 8;
2825 return Start_Column
;
2827 -- A constraint error can happen only if we have a compiler with checks on
2828 -- and a line with a ludicrous number of tabs or spaces at the start. In
2829 -- such a case, we really don't care if Start_Column is right or not.
2832 when Constraint_Error
=>
2833 return Start_Column
;
2834 end Set_Start_Column
;