1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Csets
; use Csets
;
28 with 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 detection of 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.
175 | Tok_Double_Asterisk
179 | Tok_Greater_Greater
182 | Tok_Integer_Literal
196 | Tok_Operator_Symbol
213 (System
.CRC32
.CRC32
(Checksum
),
214 Character'Val (Token_Type
'Pos (Token
)));
218 (System
.CRC32
.CRC32
(Checksum
),
219 Character'Val (Token_Type
'Pos (Tok_Identifier
)));
241 | Tok_External_As_List
279 (System
.CRC32
.CRC32
(Checksum
),
280 Character'Val (Token_Type
'Pos (Token_Type
'Pred (Token
))));
282 end Accumulate_Token_Checksum_GNAT_6_3
;
284 -----------------------------------------
285 -- Accumulate_Token_Checksum_GNAT_5_03 --
286 -----------------------------------------
288 procedure Accumulate_Token_Checksum_GNAT_5_03
is
290 -- Individual values of Token_Type are used, instead of subranges, so
291 -- that additions or suppressions of enumerated values in type
292 -- Token_Type are detected by the compiler.
318 | Tok_Double_Asterisk
322 | Tok_Greater_Greater
325 | Tok_Integer_Literal
336 | Tok_Operator_Symbol
349 (System
.CRC32
.CRC32
(Checksum
),
350 Character'Val (Token_Type
'Pos (Token
)));
358 (System
.CRC32
.CRC32
(Checksum
),
359 Character'Val (Token_Type
'Pos (Tok_Identifier
)));
369 (System
.CRC32
.CRC32
(Checksum
),
370 Character'Val (Token_Type
'Pos (Token
) - 1));
406 (System
.CRC32
.CRC32
(Checksum
),
407 Character'Val (Token_Type
'Pos (Token
) - 2));
417 | Tok_External_As_List
433 (System
.CRC32
.CRC32
(Checksum
),
434 Character'Val (Token_Type
'Pos (Token
) - 4));
436 end Accumulate_Token_Checksum_GNAT_5_03
;
438 -----------------------
439 -- Check_End_Of_Line --
440 -----------------------
442 procedure Check_End_Of_Line
is
443 Len
: constant Int
:=
445 Int
(Current_Line_Start
) -
446 Wide_Char_Byte_Count
;
448 -- Start of processing for Check_End_Of_Line
452 Style
.Check_Line_Terminator
(Len
);
455 -- Deal with checking maximum line length
457 if Style_Check
and Style_Check_Max_Line_Length
then
458 Style
.Check_Line_Max_Length
(Len
);
460 -- If style checking is inactive, check maximum line length against
463 elsif Len
> Max_Line_Length
then
465 ("this line is too long",
466 Current_Line_Start
+ Source_Ptr
(Max_Line_Length
));
469 -- Now one more checking circuit. Normally we are only enforcing a limit
470 -- of physical characters, with tabs counting as one character. But if
471 -- after tab expansion we would have a total line length that exceeded
472 -- 32766, that would really cause trouble, because column positions
473 -- would exceed the maximum we allow for a column count. Note: the limit
474 -- is 32766 rather than 32767, since we use a value of 32767 for special
475 -- purposes (see Sinput). Now we really do not want to go messing with
476 -- tabs in the normal case, so what we do is to check for a line that
477 -- has more than 4096 physical characters. Any shorter line could not
478 -- be a problem, even if it was all tabs.
487 Ptr
:= Current_Line_Start
;
489 exit when Ptr
= Scan_Ptr
;
491 if Source
(Ptr
) = ASCII
.HT
then
492 Col
:= (Col
- 1 + 8) / 8 * 8 + 1;
499 ("this line is longer than 32766 characters",
501 raise Unrecoverable_Error
;
509 -- Reset wide character byte count for next line
511 Wide_Char_Byte_Count
:= 0;
512 end Check_End_Of_Line
;
514 ----------------------------
515 -- Determine_Token_Casing --
516 ----------------------------
518 function Determine_Token_Casing
return Casing_Type
is
520 return Determine_Casing
(Source
(Token_Ptr
.. Scan_Ptr
- 1));
521 end Determine_Token_Casing
;
523 -------------------------
524 -- Initialize_Checksum --
525 -------------------------
527 procedure Initialize_Checksum
is
529 System
.CRC32
.Initialize
(System
.CRC32
.CRC32
(Checksum
));
530 end Initialize_Checksum
;
532 ------------------------
533 -- Initialize_Scanner --
534 ------------------------
536 procedure Initialize_Scanner
(Index
: Source_File_Index
) is
538 -- Establish reserved words
540 Scans
.Initialize_Ada_Keywords
;
542 -- Initialize scan control variables
544 Current_Source_File
:= Index
;
545 Source
:= Source_Text
(Current_Source_File
);
546 Scan_Ptr
:= Source_First
(Current_Source_File
);
548 Token_Ptr
:= Scan_Ptr
;
549 Current_Line_Start
:= Scan_Ptr
;
551 Token_Name
:= No_Name
;
552 Start_Column
:= Set_Start_Column
;
553 First_Non_Blank_Location
:= Scan_Ptr
;
556 Wide_Char_Byte_Count
:= 0;
558 -- Do not call Scan, otherwise the License stuff does not work in Scn
560 end Initialize_Scanner
;
562 ------------------------------
563 -- Reset_Special_Characters --
564 ------------------------------
566 procedure Reset_Special_Characters
is
568 Special_Characters
:= (others => False);
569 end Reset_Special_Characters
;
577 Start_Of_Comment
: Source_Ptr
;
578 -- Record start of comment position
580 Underline_Found
: Boolean;
581 -- During scanning of an identifier, set to True if last character
582 -- scanned was an underline or other punctuation character. This
583 -- is used to flag the error of two underlines/punctuations in a
584 -- row or ending an identifier with a underline/punctuation. Here
585 -- punctuation means any UTF_32 character in the Unicode category
586 -- Punctuation,Connector.
589 -- Used to remember start of last wide character scanned
591 function Double_Char_Token
(C
: Character) return Boolean;
592 -- This function is used for double character tokens like := or <>. It
593 -- checks if the character following Source (Scan_Ptr) is C, and if so
594 -- bumps Scan_Ptr past the pair of characters and returns True. A space
595 -- between the two characters is also recognized with an appropriate
596 -- error message being issued. If C is not present, False is returned.
597 -- Note that Double_Char_Token can only be used for tokens defined in
598 -- the Ada syntax (it's use for error cases like && is not appropriate
599 -- since we do not want a junk message for a case like &-space-&).
601 procedure Error_Illegal_Character
;
602 -- Give illegal character error, Scan_Ptr points to character. On
603 -- return, Scan_Ptr is bumped past the illegal character.
605 procedure Error_Illegal_Wide_Character
;
606 -- Give illegal wide character message. On return, Scan_Ptr is bumped
607 -- past the illegal character, which may still leave us pointing to
608 -- junk, not much we can do if the escape sequence is messed up.
610 procedure Error_No_Double_Underline
;
611 -- Signal error of two underline or punctuation characters in a row.
612 -- Called with Scan_Ptr pointing to second underline/punctuation char.
615 -- This is the procedure for scanning out numeric literals. On entry,
616 -- Scan_Ptr points to the digit that starts the numeric literal (the
617 -- checksum for this character has not been accumulated yet). On return
618 -- Scan_Ptr points past the last character of the numeric literal, Token
619 -- and Token_Node are set appropriately, and the checksum is updated.
622 -- This is the procedure for scanning out string literals. On entry,
623 -- Scan_Ptr points to the opening string quote (the checksum for this
624 -- character has not been accumulated yet). On return Scan_Ptr points
625 -- past the closing quote of the string literal, Token and Token_Node
626 -- are set appropriately, and the checksum is updated.
628 procedure Skip_Other_Format_Characters
;
629 -- Skips past any "other format" category characters at the current
630 -- cursor location (does not skip past spaces or any other characters).
632 function Start_Of_Wide_Character
return Boolean;
633 -- Returns True if the scan pointer is pointing to the start of a wide
634 -- character sequence, does not modify the scan pointer in any case.
636 -----------------------
637 -- Double_Char_Token --
638 -----------------------
640 function Double_Char_Token
(C
: Character) return Boolean is
642 if Source
(Scan_Ptr
+ 1) = C
then
643 Accumulate_Checksum
(C
);
644 Scan_Ptr
:= Scan_Ptr
+ 2;
647 elsif Source
(Scan_Ptr
+ 1) = ' '
648 and then Source
(Scan_Ptr
+ 2) = C
650 Scan_Ptr
:= Scan_Ptr
+ 1;
651 Error_Msg_S
-- CODEFIX
652 ("no space allowed here");
653 Scan_Ptr
:= Scan_Ptr
+ 2;
659 end Double_Char_Token
;
661 -----------------------------
662 -- Error_Illegal_Character --
663 -----------------------------
665 procedure Error_Illegal_Character
is
667 Error_Msg_S
("illegal character");
668 Scan_Ptr
:= Scan_Ptr
+ 1;
669 end Error_Illegal_Character
;
671 ----------------------------------
672 -- Error_Illegal_Wide_Character --
673 ----------------------------------
675 procedure Error_Illegal_Wide_Character
is
677 Scan_Ptr
:= Scan_Ptr
+ 1;
678 Error_Msg
("illegal wide character", Wptr
);
679 end Error_Illegal_Wide_Character
;
681 -------------------------------
682 -- Error_No_Double_Underline --
683 -------------------------------
685 procedure Error_No_Double_Underline
is
687 Underline_Found
:= False;
689 -- There are four cases, and we special case the messages
691 if Source
(Scan_Ptr
) = '_' then
692 if Source
(Scan_Ptr
- 1) = '_' then
693 Error_Msg_S
-- CODEFIX
694 ("two consecutive underlines not permitted");
696 Error_Msg_S
("underline cannot follow punctuation character");
700 if Source
(Scan_Ptr
- 1) = '_' then
701 Error_Msg_S
("punctuation character cannot follow underline");
704 ("two consecutive punctuation characters not permitted");
707 end Error_No_Double_Underline
;
716 -- Current source program character
718 Base_Char
: Character;
719 -- Either # or : (character at start of based number)
725 -- Value of base in Uint format
728 -- Value of integer scanned by Scan_Integer in Uint format
731 -- Value of integer in numeric value being scanned
734 -- Scale value for real literal
737 -- Scale in Uint format
739 Exponent_Is_Negative
: Boolean;
740 -- Set true for negative exponent
742 Extended_Digit_Value
: Int
;
743 -- Extended digit value
745 Point_Scanned
: Boolean;
746 -- Flag for decimal point scanned in numeric literal
748 -----------------------
749 -- Local Subprograms --
750 -----------------------
752 procedure Error_Digit_Expected
;
753 -- Signal error of bad digit, Scan_Ptr points to the location at
754 -- which the digit was expected on input, and is unchanged on return.
756 procedure Scan_Integer
;
757 -- Scan integer literal. On entry, Scan_Ptr points to a digit, on
758 -- exit Scan_Ptr points past the last character of the integer.
760 -- For each digit encountered, UI_Int_Value is multiplied by 10, and
761 -- the value of the digit added to the result. In addition, the value
762 -- in Scale is decremented by one for each actual digit scanned.
764 --------------------------
765 -- Error_Digit_Expected --
766 --------------------------
768 procedure Error_Digit_Expected
is
770 Error_Msg_S
("digit expected");
771 end Error_Digit_Expected
;
777 procedure Scan_Integer
is
779 -- Next character scanned
782 C
:= Source
(Scan_Ptr
);
784 -- Loop through digits (allowing underlines)
787 Accumulate_Checksum
(C
);
789 UI_Int_Value
* 10 + (Character'Pos (C
) - Character'Pos ('0'));
790 Scan_Ptr
:= Scan_Ptr
+ 1;
792 C
:= Source
(Scan_Ptr
);
794 -- Case of underline encountered
798 -- We do not accumulate the '_' in the checksum, so that
799 -- 1_234 is equivalent to 1234, and does not trigger
800 -- compilation for "minimal recompilation" (gnatmake -m).
803 Scan_Ptr
:= Scan_Ptr
+ 1;
804 C
:= Source
(Scan_Ptr
);
806 Error_No_Double_Underline
;
809 if C
not in '0' .. '9' then
810 Error_Digit_Expected
;
815 exit when C
not in '0' .. '9';
820 -- Start of processing for Nlit
825 UI_Int_Value
:= Uint_0
;
826 Based_Literal_Uses_Colon
:= False;
829 Point_Scanned
:= False;
830 UI_Num_Value
:= UI_Int_Value
;
832 -- Various possibilities now for continuing the literal are period,
833 -- E/e (for exponent), or :/# (for based literal).
836 C
:= Source
(Scan_Ptr
);
840 -- Scan out point, but do not scan past .. which is a range
841 -- sequence, and must not be eaten up scanning a numeric literal.
843 while C
= '.' and then Source
(Scan_Ptr
+ 1) /= '.' loop
844 Accumulate_Checksum
('.');
846 if Point_Scanned
then
847 Error_Msg_S
("duplicate point ignored");
850 Point_Scanned
:= True;
851 Scan_Ptr
:= Scan_Ptr
+ 1;
852 C
:= Source
(Scan_Ptr
);
854 if C
not in '0' .. '9' then
856 ("real literal cannot end with point", Scan_Ptr
- 1);
859 UI_Num_Value
:= UI_Int_Value
;
863 -- Based literal case. The base is the value we already scanned.
864 -- In the case of colon, we insist that the following character
865 -- is indeed an extended digit or a period. This catches a number
866 -- of common errors, as well as catching the well known tricky
867 -- bug otherwise arising from "x : integer range 1 .. 10:= 6;"
870 or else (C
= ':' and then
871 (Source
(Scan_Ptr
+ 1) = '.'
873 Source
(Scan_Ptr
+ 1) in '0' .. '9'
875 Source
(Scan_Ptr
+ 1) in 'A' .. 'Z'
877 Source
(Scan_Ptr
+ 1) in 'a' .. 'z'))
879 Accumulate_Checksum
(C
);
881 UI_Base
:= UI_Int_Value
;
883 if Base_Char
= ':' then
884 Based_Literal_Uses_Colon
:= True;
887 if UI_Base
< 2 or else UI_Base
> 16 then
888 Error_Msg_SC
("base not 2-16");
892 Base
:= UI_To_Int
(UI_Base
);
893 Scan_Ptr
:= Scan_Ptr
+ 1;
895 -- Scan out extended integer [. integer]
897 C
:= Source
(Scan_Ptr
);
898 UI_Int_Value
:= Uint_0
;
902 if C
in '0' .. '9' then
903 Accumulate_Checksum
(C
);
904 Extended_Digit_Value
:=
905 Int
'(Character'Pos (C)) - Int'(Character'Pos ('0'));
907 elsif C
in 'A' .. 'F' then
908 Accumulate_Checksum
(Character'Val (Character'Pos (C
) + 32));
909 Extended_Digit_Value
:=
910 Int
'(Character'Pos (C)) - Int'(Character'Pos ('A')) + 10;
912 elsif C
in 'a' .. 'f' then
913 Accumulate_Checksum
(C
);
914 Extended_Digit_Value
:=
915 Int
'(Character'Pos (C)) - Int'(Character'Pos ('a')) + 10;
918 Error_Msg_S
("extended digit expected");
922 if Extended_Digit_Value
>= Base
then
923 Error_Msg_S
("digit '>= base");
926 UI_Int_Value
:= UI_Int_Value
* UI_Base
+ Extended_Digit_Value
;
928 Scan_Ptr
:= Scan_Ptr
+ 1;
929 C
:= Source
(Scan_Ptr
);
933 Accumulate_Checksum
('_');
934 Scan_Ptr
:= Scan_Ptr
+ 1;
935 C
:= Source
(Scan_Ptr
);
937 Error_No_Double_Underline
;
941 Accumulate_Checksum
('.');
943 if Point_Scanned
then
944 Error_Msg_S
("duplicate point ignored");
947 Scan_Ptr
:= Scan_Ptr
+ 1;
948 C
:= Source
(Scan_Ptr
);
949 Point_Scanned
:= True;
952 elsif C
= Base_Char
then
953 Accumulate_Checksum
(C
);
954 Scan_Ptr
:= Scan_Ptr
+ 1;
957 elsif C
= '#' or else C
= ':' then
958 Error_Msg_S
("based number delimiters must match");
959 Scan_Ptr
:= Scan_Ptr
+ 1;
962 elsif not Identifier_Char
(C
) then
963 if Base_Char
= '#' then
964 Error_Msg_S
-- CODEFIX
967 Error_Msg_S
-- CODEFIX
976 UI_Num_Value
:= UI_Int_Value
;
981 if not Point_Scanned
then
985 UI_Scale
:= UI_From_Int
(Scale
);
988 if Source
(Scan_Ptr
) = 'e' or else Source
(Scan_Ptr
) = 'E' then
989 Accumulate_Checksum
('e');
990 Scan_Ptr
:= Scan_Ptr
+ 1;
991 Exponent_Is_Negative
:= False;
993 if Source
(Scan_Ptr
) = '+' then
994 Accumulate_Checksum
('+');
995 Scan_Ptr
:= Scan_Ptr
+ 1;
997 elsif Source
(Scan_Ptr
) = '-' then
998 Accumulate_Checksum
('-');
1000 if not Point_Scanned
then
1002 ("negative exponent not allowed for integer literal");
1004 Exponent_Is_Negative
:= True;
1007 Scan_Ptr
:= Scan_Ptr
+ 1;
1010 UI_Int_Value
:= Uint_0
;
1012 if Source
(Scan_Ptr
) in '0' .. '9' then
1015 Error_Digit_Expected
;
1018 if Exponent_Is_Negative
then
1019 UI_Scale
:= UI_Scale
- UI_Int_Value
;
1021 UI_Scale
:= UI_Scale
+ UI_Int_Value
;
1025 -- Case of real literal to be returned
1027 if Point_Scanned
then
1028 Token
:= Tok_Real_Literal
;
1029 Real_Literal_Value
:=
1030 UR_From_Components
(
1031 Num
=> UI_Num_Value
,
1035 -- Case of integer literal to be returned
1038 Token
:= Tok_Integer_Literal
;
1040 if UI_Scale
= 0 then
1041 Int_Literal_Value
:= UI_Num_Value
;
1043 -- Avoid doing possibly expensive calculations in cases like
1044 -- parsing 163E800_000# when semantics will not be done anyway.
1045 -- This is especially useful when parsing garbled input.
1047 elsif Operating_Mode
/= Check_Syntax
1048 and then (Serious_Errors_Detected
= 0 or else Try_Semantics
)
1050 Int_Literal_Value
:= UI_Num_Value
* UI_Base
** UI_Scale
;
1053 Int_Literal_Value
:= No_Uint
;
1057 if Checksum_Accumulate_Token_Checksum
then
1058 Accumulate_Token_Checksum
;
1070 Delimiter
: Character;
1071 -- Delimiter (first character of string)
1074 -- Current source program character
1077 -- Current character code value
1080 -- Error flag for Scan_Wide call
1082 String_Start
: Source_Ptr
;
1083 -- Point to first character of string
1085 procedure Error_Bad_String_Char
;
1086 -- Signal bad character in string/character literal. On entry
1087 -- Scan_Ptr points to the improper character encountered during the
1088 -- scan. Scan_Ptr is not modified, so it still points to the bad
1089 -- character on return.
1091 procedure Error_Unterminated_String
;
1092 -- Procedure called if a line terminator character is encountered
1093 -- during scanning a string, meaning that the string is not properly
1096 procedure Set_String
;
1097 -- Procedure used to distinguish between string and operator symbol.
1098 -- On entry the string has been scanned out, and its characters start
1099 -- at Token_Ptr and end one character before Scan_Ptr. On exit Token
1100 -- is set to Tok_String_Literal/Tok_Operator_Symbol as appropriate,
1101 -- and Token_Node is appropriately initialized. In addition, in the
1102 -- operator symbol case, Token_Name is appropriately set, and the
1103 -- flags [Wide_]Wide_Character_Found are set appropriately.
1105 ---------------------------
1106 -- Error_Bad_String_Char --
1107 ---------------------------
1109 procedure Error_Bad_String_Char
is
1110 C
: constant Character := Source
(Scan_Ptr
);
1114 Error_Msg_S
("horizontal tab not allowed in string");
1116 elsif C
= VT
or else C
= FF
then
1117 Error_Msg_S
("format effector not allowed in string");
1119 elsif C
in Upper_Half_Character
then
1120 Error_Msg_S
("(Ada 83) upper half character not allowed");
1123 Error_Msg_S
("control character not allowed in string");
1125 end Error_Bad_String_Char
;
1127 -------------------------------
1128 -- Error_Unterminated_String --
1129 -------------------------------
1131 procedure Error_Unterminated_String
is
1135 -- An interesting little refinement. Consider the following
1138 -- A := "this is an unterminated string;
1139 -- A := "this is an unterminated string &
1140 -- P(A, "this is a parameter that didn't get terminated);
1141 -- P("this is a parameter that didn't get terminated, A);
1143 -- We fiddle a little to do slightly better placement in these
1144 -- cases also if there is white space at the end of the line we
1145 -- place the flag at the start of this white space, not at the
1146 -- end. Note that we only have to test for blanks, since tabs
1147 -- aren't allowed in strings in the first place and would have
1148 -- caused an error message.
1150 -- Two more cases that we treat specially are:
1152 -- A := "this string uses the wrong terminator'
1153 -- A := "this string uses the wrong terminator' &
1155 -- In these cases we give a different error message as well
1157 -- We actually reposition the scan pointer to the point where we
1158 -- place the flag in these cases, since it seems a better bet on
1159 -- the original intention.
1161 while Source
(Scan_Ptr
- 1) = ' '
1162 or else Source
(Scan_Ptr
- 1) = '&'
1164 Scan_Ptr
:= Scan_Ptr
- 1;
1165 Unstore_String_Char
;
1168 -- Check for case of incorrect string terminator, but single quote
1169 -- is not considered incorrect if the opening terminator misused
1170 -- a single quote (error message already given).
1173 and then Source
(Scan_Ptr
- 1) = '''
1175 Unstore_String_Char
;
1177 ("incorrect string terminator character", Scan_Ptr
- 1);
1181 -- Backup over semicolon or right-paren/semicolon sequence
1183 if Source
(Scan_Ptr
- 1) = ';' then
1184 Scan_Ptr
:= Scan_Ptr
- 1;
1185 Unstore_String_Char
;
1187 if Source
(Scan_Ptr
- 1) = ')' then
1188 Scan_Ptr
:= Scan_Ptr
- 1;
1189 Unstore_String_Char
;
1193 -- See if there is a comma in the string, if so, guess that
1194 -- the first comma terminates the string.
1197 while S
< Scan_Ptr
loop
1198 if Source
(S
) = ',' then
1199 while Scan_Ptr
> S
loop
1200 Scan_Ptr
:= Scan_Ptr
- 1;
1201 Unstore_String_Char
;
1210 -- Now we have adjusted the scan pointer, give message
1212 Error_Msg_S
-- CODEFIX
1213 ("missing string quote");
1214 end Error_Unterminated_String
;
1220 procedure Set_String
is
1221 Slen
: constant Int
:= Int
(Scan_Ptr
- Token_Ptr
- 2);
1227 -- Token_Name is currently set to Error_Name. The following
1228 -- section of code resets Token_Name to the proper Name_Op_xx
1229 -- value if the string is a valid operator symbol, otherwise it is
1230 -- left set to Error_Name.
1233 C1
:= Source
(Token_Ptr
+ 1);
1237 Token_Name
:= Name_Op_Eq
;
1240 Token_Name
:= Name_Op_Gt
;
1243 Token_Name
:= Name_Op_Lt
;
1246 Token_Name
:= Name_Op_Add
;
1249 Token_Name
:= Name_Op_Subtract
;
1252 Token_Name
:= Name_Op_Concat
;
1255 Token_Name
:= Name_Op_Multiply
;
1258 Token_Name
:= Name_Op_Divide
;
1265 C1
:= Source
(Token_Ptr
+ 1);
1266 C2
:= Source
(Token_Ptr
+ 2);
1268 if C1
= '*' and then C2
= '*' then
1269 Token_Name
:= Name_Op_Expon
;
1274 Token_Name
:= Name_Op_Ne
;
1276 Token_Name
:= Name_Op_Le
;
1278 Token_Name
:= Name_Op_Ge
;
1281 elsif (C1
= 'O' or else C1
= 'o') and then -- OR
1282 (C2
= 'R' or else C2
= 'r')
1284 Token_Name
:= Name_Op_Or
;
1288 C1
:= Source
(Token_Ptr
+ 1);
1289 C2
:= Source
(Token_Ptr
+ 2);
1290 C3
:= Source
(Token_Ptr
+ 3);
1292 if (C1
= 'A' or else C1
= 'a') and then -- AND
1293 (C2
= 'N' or else C2
= 'n') and then
1294 (C3
= 'D' or else C3
= 'd')
1296 Token_Name
:= Name_Op_And
;
1298 elsif (C1
= 'A' or else C1
= 'a') and then -- ABS
1299 (C2
= 'B' or else C2
= 'b') and then
1300 (C3
= 'S' or else C3
= 's')
1302 Token_Name
:= Name_Op_Abs
;
1304 elsif (C1
= 'M' or else C1
= 'm') and then -- MOD
1305 (C2
= 'O' or else C2
= 'o') and then
1306 (C3
= 'D' or else C3
= 'd')
1308 Token_Name
:= Name_Op_Mod
;
1310 elsif (C1
= 'N' or else C1
= 'n') and then -- NOT
1311 (C2
= 'O' or else C2
= 'o') and then
1312 (C3
= 'T' or else C3
= 't')
1314 Token_Name
:= Name_Op_Not
;
1316 elsif (C1
= 'R' or else C1
= 'r') and then -- REM
1317 (C2
= 'E' or else C2
= 'e') and then
1318 (C3
= 'M' or else C3
= 'm')
1320 Token_Name
:= Name_Op_Rem
;
1322 elsif (C1
= 'X' or else C1
= 'x') and then -- XOR
1323 (C2
= 'O' or else C2
= 'o') and then
1324 (C3
= 'R' or else C3
= 'r')
1326 Token_Name
:= Name_Op_Xor
;
1331 -- If it is an operator symbol, then Token_Name is set. If it is
1332 -- some other string value, then Token_Name still contains
1335 if Token_Name
= Error_Name
then
1336 Token
:= Tok_String_Literal
;
1339 Token
:= Tok_Operator_Symbol
;
1343 -- Start of processing for Slit
1346 -- On entry, Scan_Ptr points to the opening character of the string
1347 -- which is either a percent, double quote, or apostrophe (single
1348 -- quote). The latter case is an error detected by the character
1351 String_Start
:= Scan_Ptr
;
1353 Delimiter
:= Source
(Scan_Ptr
);
1354 Accumulate_Checksum
(Delimiter
);
1357 Wide_Character_Found
:= False;
1358 Wide_Wide_Character_Found
:= False;
1359 Scan_Ptr
:= Scan_Ptr
+ 1;
1361 -- Loop to scan out characters of string literal
1364 C
:= Source
(Scan_Ptr
);
1366 if C
= Delimiter
then
1367 Accumulate_Checksum
(C
);
1368 Scan_Ptr
:= Scan_Ptr
+ 1;
1369 exit when Source
(Scan_Ptr
) /= Delimiter
;
1370 Code
:= Get_Char_Code
(C
);
1371 Accumulate_Checksum
(C
);
1372 Scan_Ptr
:= Scan_Ptr
+ 1;
1375 if C
= '"' and then Delimiter
= '%' then
1377 ("quote not allowed in percent delimited string");
1378 Code
:= Get_Char_Code
(C
);
1379 Scan_Ptr
:= Scan_Ptr
+ 1;
1381 elsif Start_Of_Wide_Character
then
1383 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1386 Error_Illegal_Wide_Character
;
1387 Code
:= Get_Char_Code
(' ');
1390 Accumulate_Checksum
(Code
);
1392 -- In Ada 95 mode we allow any wide characters in a string
1393 -- but in Ada 2005, the set of characters allowed has been
1394 -- restricted to graphic characters.
1396 if Ada_Version
>= Ada_2005
1397 and then Is_UTF_32_Non_Graphic
(UTF_32
(Code
))
1400 ("(Ada 2005) non-graphic character not permitted " &
1401 "in string literal", Wptr
);
1405 Accumulate_Checksum
(C
);
1407 if C
not in Graphic_Character
then
1408 if C
in Line_Terminator
then
1409 Error_Unterminated_String
;
1412 elsif C
in Upper_Half_Character
then
1413 if Ada_Version
= Ada_83
then
1414 Error_Bad_String_Char
;
1418 Error_Bad_String_Char
;
1422 Code
:= Get_Char_Code
(C
);
1423 Scan_Ptr
:= Scan_Ptr
+ 1;
1427 Store_String_Char
(Code
);
1429 if not In_Character_Range
(Code
) then
1430 if In_Wide_Character_Range
(Code
) then
1431 Wide_Character_Found
:= True;
1433 Wide_Wide_Character_Found
:= True;
1438 String_Literal_Id
:= End_String
;
1443 ----------------------------------
1444 -- Skip_Other_Format_Characters --
1445 ----------------------------------
1447 procedure Skip_Other_Format_Characters
is
1453 while Start_Of_Wide_Character
loop
1455 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1457 if not Is_UTF_32_Other
(UTF_32
(Code
)) then
1462 end Skip_Other_Format_Characters
;
1464 -----------------------------
1465 -- Start_Of_Wide_Character --
1466 -----------------------------
1468 function Start_Of_Wide_Character
return Boolean is
1469 C
: constant Character := Source
(Scan_Ptr
);
1472 -- ESC encoding method with ESC present
1475 and then Wide_Character_Encoding_Method
in WC_ESC_Encoding_Method
1479 -- Upper half character with upper half encoding
1481 elsif C
in Upper_Half_Character
and then Upper_Half_Encoding
then
1484 -- Brackets encoding
1487 and then Source
(Scan_Ptr
+ 1) = '"'
1488 and then Identifier_Char
(Source
(Scan_Ptr
+ 2))
1492 -- Not the start of a wide character
1497 end Start_Of_Wide_Character
;
1499 -- Start of processing for Scan
1502 Prev_Token
:= Token
;
1503 Prev_Token_Ptr
:= Token_Ptr
;
1504 Token_Name
:= Error_Name
;
1506 -- The following loop runs more than once only if a format effector
1507 -- (tab, vertical tab, form feed, line feed, carriage return) is
1508 -- encountered and skipped, or some error situation, such as an
1509 -- illegal character, is encountered.
1511 <<Scan_Next_Character
>>
1514 -- Skip past blanks, loop is opened up for speed
1516 while Source
(Scan_Ptr
) = ' ' loop
1517 if Source
(Scan_Ptr
+ 1) /= ' ' then
1518 Scan_Ptr
:= Scan_Ptr
+ 1;
1522 if Source
(Scan_Ptr
+ 2) /= ' ' then
1523 Scan_Ptr
:= Scan_Ptr
+ 2;
1527 if Source
(Scan_Ptr
+ 3) /= ' ' then
1528 Scan_Ptr
:= Scan_Ptr
+ 3;
1532 if Source
(Scan_Ptr
+ 4) /= ' ' then
1533 Scan_Ptr
:= Scan_Ptr
+ 4;
1537 if Source
(Scan_Ptr
+ 5) /= ' ' then
1538 Scan_Ptr
:= Scan_Ptr
+ 5;
1542 if Source
(Scan_Ptr
+ 6) /= ' ' then
1543 Scan_Ptr
:= Scan_Ptr
+ 6;
1547 if Source
(Scan_Ptr
+ 7) /= ' ' then
1548 Scan_Ptr
:= Scan_Ptr
+ 7;
1552 Scan_Ptr
:= Scan_Ptr
+ 8;
1555 -- We are now at a non-blank character, which is the first character
1556 -- of the token we will scan, and hence the value of Token_Ptr.
1558 Token_Ptr
:= Scan_Ptr
;
1560 -- Here begins the main case statement which transfers control on the
1561 -- basis of the non-blank character we have encountered.
1563 case Source
(Scan_Ptr
) is
1565 -- Line terminator characters
1567 when CR | LF | FF | VT
=>
1568 goto Scan_Line_Terminator
;
1570 -- Horizontal tab, just skip past it
1577 Scan_Ptr
:= Scan_Ptr
+ 1;
1579 -- End of file character, treated as an end of file only if it is
1580 -- the last character in the buffer, otherwise it is ignored.
1583 if Scan_Ptr
= Source_Last
(Current_Source_File
) then
1593 Scan_Ptr
:= Scan_Ptr
+ 1;
1599 Accumulate_Checksum
('&');
1601 if Source
(Scan_Ptr
+ 1) = '&' then
1602 Error_Msg_S
-- CODEFIX
1603 ("'&'& should be `AND THEN`");
1604 Scan_Ptr
:= Scan_Ptr
+ 2;
1609 Scan_Ptr
:= Scan_Ptr
+ 1;
1610 Token
:= Tok_Ampersand
;
1615 if Ada_Version
< Ada_2020
then
1616 Error_Msg
("target_name is an Ada 2020 feature", Scan_Ptr
);
1617 Scan_Ptr
:= Scan_Ptr
+ 1;
1620 -- AI12-0125-03 : @ is target_name
1622 Accumulate_Checksum
('@');
1623 Scan_Ptr
:= Scan_Ptr
+ 1;
1624 Token
:= Tok_At_Sign
;
1628 -- Asterisk (can be multiplication operator or double asterisk which
1629 -- is the exponentiation compound delimiter).
1632 Accumulate_Checksum
('*');
1634 if Source
(Scan_Ptr
+ 1) = '*' then
1635 Accumulate_Checksum
('*');
1636 Scan_Ptr
:= Scan_Ptr
+ 2;
1637 Token
:= Tok_Double_Asterisk
;
1641 Scan_Ptr
:= Scan_Ptr
+ 1;
1642 Token
:= Tok_Asterisk
;
1646 -- Colon, which can either be an isolated colon, or part of an
1647 -- assignment compound delimiter.
1650 Accumulate_Checksum
(':');
1652 if Double_Char_Token
('=') then
1653 Token
:= Tok_Colon_Equal
;
1656 Style
.Check_Colon_Equal
;
1661 elsif Source
(Scan_Ptr
+ 1) = '-'
1662 and then Source
(Scan_Ptr
+ 2) /= '-'
1664 Token
:= Tok_Colon_Equal
;
1665 Error_Msg
-- CODEFIX
1666 (":- should be :=", Scan_Ptr
);
1667 Scan_Ptr
:= Scan_Ptr
+ 2;
1671 Scan_Ptr
:= Scan_Ptr
+ 1;
1684 Accumulate_Checksum
('(');
1685 Scan_Ptr
:= Scan_Ptr
+ 1;
1686 Token
:= Tok_Left_Paren
;
1689 Style
.Check_Left_Paren
;
1697 if Source
(Scan_Ptr
+ 1) = '"' then
1698 goto Scan_Wide_Character
;
1701 Error_Msg_S
("illegal character, replaced by ""(""");
1702 Scan_Ptr
:= Scan_Ptr
+ 1;
1703 Token
:= Tok_Left_Paren
;
1710 Error_Msg_S
("illegal character, replaced by ""(""");
1711 Scan_Ptr
:= Scan_Ptr
+ 1;
1712 Token
:= Tok_Left_Paren
;
1718 Accumulate_Checksum
(',');
1719 Scan_Ptr
:= Scan_Ptr
+ 1;
1728 -- Dot, which is either an isolated period, or part of a double dot
1729 -- compound delimiter sequence. We also check for the case of a
1730 -- digit following the period, to give a better error message.
1733 Accumulate_Checksum
('.');
1735 if Double_Char_Token
('.') then
1736 Token
:= Tok_Dot_Dot
;
1739 Style
.Check_Dot_Dot
;
1744 elsif Source
(Scan_Ptr
+ 1) in '0' .. '9' then
1745 Error_Msg_S
("numeric literal cannot start with point");
1746 Scan_Ptr
:= Scan_Ptr
+ 1;
1749 Scan_Ptr
:= Scan_Ptr
+ 1;
1754 -- Equal, which can either be an equality operator, or part of the
1755 -- arrow (=>) compound delimiter.
1758 Accumulate_Checksum
('=');
1760 if Double_Char_Token
('>') then
1764 Style
.Check_Arrow
(Inside_Depends
);
1769 elsif Source
(Scan_Ptr
+ 1) = '=' then
1770 Error_Msg_S
-- CODEFIX
1772 Scan_Ptr
:= Scan_Ptr
+ 1;
1775 Scan_Ptr
:= Scan_Ptr
+ 1;
1779 -- Greater than, which can be a greater than operator, greater than
1780 -- or equal operator, or first character of a right label bracket.
1783 Accumulate_Checksum
('>');
1785 if Double_Char_Token
('=') then
1786 Token
:= Tok_Greater_Equal
;
1789 elsif Double_Char_Token
('>') then
1790 Token
:= Tok_Greater_Greater
;
1794 Scan_Ptr
:= Scan_Ptr
+ 1;
1795 Token
:= Tok_Greater
;
1799 -- Less than, which can be a less than operator, less than or equal
1800 -- operator, or the first character of a left label bracket, or the
1801 -- first character of a box (<>) compound delimiter.
1804 Accumulate_Checksum
('<');
1806 if Double_Char_Token
('=') then
1807 Token
:= Tok_Less_Equal
;
1810 elsif Double_Char_Token
('>') then
1819 elsif Double_Char_Token
('<') then
1820 Token
:= Tok_Less_Less
;
1824 Scan_Ptr
:= Scan_Ptr
+ 1;
1829 -- Minus, which is either a subtraction operator, or the first
1830 -- character of double minus starting a comment
1832 when '-' => Minus_Case
: begin
1833 if Source
(Scan_Ptr
+ 1) = '>' then
1834 Error_Msg_S
("invalid token");
1835 Scan_Ptr
:= Scan_Ptr
+ 2;
1839 elsif Source
(Scan_Ptr
+ 1) /= '-' then
1840 Accumulate_Checksum
('-');
1841 Scan_Ptr
:= Scan_Ptr
+ 1;
1847 else -- Source (Scan_Ptr + 1) = '-' then
1849 Style
.Check_Comment
;
1852 Scan_Ptr
:= Scan_Ptr
+ 2;
1854 -- If we are in preprocessor mode with Replace_In_Comments set,
1855 -- then we return the "--" as a token on its own.
1857 if Replace_In_Comments
then
1858 Token
:= Tok_Comment
;
1862 -- Otherwise scan out the comment
1864 Start_Of_Comment
:= Scan_Ptr
;
1866 -- Loop to scan comment (this loop runs more than once only if
1867 -- a horizontal tab or other non-graphic character is scanned)
1870 -- Scan to non graphic character (opened up for speed)
1872 -- Note that we just eat left brackets, which means that
1873 -- bracket notation cannot be used for end of line
1874 -- characters in comments. This seems a reasonable choice,
1875 -- since no one would ever use brackets notation in a real
1876 -- program in this situation, and if we allow brackets
1877 -- notation, we forbid some valid comments which contain a
1878 -- brackets sequence that happens to match an end of line
1882 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1883 Scan_Ptr
:= Scan_Ptr
+ 1;
1884 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1885 Scan_Ptr
:= Scan_Ptr
+ 1;
1886 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1887 Scan_Ptr
:= Scan_Ptr
+ 1;
1888 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1889 Scan_Ptr
:= Scan_Ptr
+ 1;
1890 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1891 Scan_Ptr
:= Scan_Ptr
+ 1;
1894 -- Keep going if horizontal tab
1896 if Source
(Scan_Ptr
) = HT
then
1901 Scan_Ptr
:= Scan_Ptr
+ 1;
1903 -- Terminate scan of comment if line terminator
1905 elsif Source
(Scan_Ptr
) in Line_Terminator
then
1908 -- Terminate scan of comment if end of file encountered
1909 -- (embedded EOF character or real last character in file)
1911 elsif Source
(Scan_Ptr
) = EOF
then
1914 -- If we have a wide character, we have to scan it out,
1915 -- because it might be a legitimate line terminator
1917 elsif Start_Of_Wide_Character
then
1919 Wptr
: constant Source_Ptr
:= Scan_Ptr
;
1924 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1926 -- If not well formed wide character, then just skip
1927 -- past it and ignore it.
1930 Scan_Ptr
:= Wptr
+ 1;
1932 -- If UTF_32 terminator, terminate comment scan
1934 elsif Is_UTF_32_Line_Terminator
(UTF_32
(Code
)) then
1940 -- Keep going if character in 80-FF range, or is ESC. These
1941 -- characters are allowed in comments by RM-2.1(1), 2.7(2).
1942 -- They are allowed even in Ada 83 mode according to the
1943 -- approved AI. ESC was added to the AI in June 93.
1945 elsif Source
(Scan_Ptr
) in Upper_Half_Character
1946 or else Source
(Scan_Ptr
) = ESC
1948 Scan_Ptr
:= Scan_Ptr
+ 1;
1950 -- Otherwise we have an illegal comment character, ignore
1951 -- this error in relaxed semantics mode.
1954 if Relaxed_RM_Semantics
then
1955 Scan_Ptr
:= Scan_Ptr
+ 1;
1957 Error_Illegal_Character
;
1962 -- Note that, except when comments are tokens, we do NOT
1963 -- execute a return here, instead we fall through to reexecute
1964 -- the scan loop to look for a token.
1966 if Comment_Is_Token
then
1967 Name_Len
:= Integer (Scan_Ptr
- Start_Of_Comment
);
1968 Name_Buffer
(1 .. Name_Len
) :=
1969 String (Source
(Start_Of_Comment
.. Scan_Ptr
- 1));
1970 Comment_Id
:= Name_Find
;
1971 Token
:= Tok_Comment
;
1975 -- If the SPARK restriction is set for this unit, then generate
1976 -- a token Tok_SPARK_Hide for a SPARK HIDE directive.
1978 if Restriction_Check_Required
(SPARK_05
)
1979 and then Source
(Start_Of_Comment
) = '#'
1982 Scan_SPARK_Ptr
: Source_Ptr
;
1985 Scan_SPARK_Ptr
:= Start_Of_Comment
+ 1;
1989 while Source
(Scan_SPARK_Ptr
) = ' '
1990 or else Source
(Scan_SPARK_Ptr
) = HT
1992 Scan_SPARK_Ptr
:= Scan_SPARK_Ptr
+ 1;
1995 -- Recognize HIDE directive. SPARK input cannot be
1996 -- encoded as wide characters, so only deal with
1997 -- lower/upper case.
1999 if (Source
(Scan_SPARK_Ptr
) = 'h'
2000 or else Source
(Scan_SPARK_Ptr
) = 'H')
2001 and then (Source
(Scan_SPARK_Ptr
+ 1) = 'i'
2002 or else Source
(Scan_SPARK_Ptr
+ 1) = 'I')
2003 and then (Source
(Scan_SPARK_Ptr
+ 2) = 'd'
2004 or else Source
(Scan_SPARK_Ptr
+ 2) = 'D')
2005 and then (Source
(Scan_SPARK_Ptr
+ 3) = 'e'
2006 or else Source
(Scan_SPARK_Ptr
+ 3) = 'E')
2007 and then (Source
(Scan_SPARK_Ptr
+ 4) = ' '
2008 or else Source
(Scan_SPARK_Ptr
+ 4) = HT
)
2010 Token
:= Tok_SPARK_Hide
;
2018 -- Double quote or percent starting a string literal
2025 -- Apostrophe. This can either be the start of a character literal,
2026 -- or an isolated apostrophe used in a qualified expression or an
2027 -- attribute. In the following:
2029 -- A := CHARACTER'('A');
2031 -- the first apostrophe is treated as an isolated apostrophe, and the
2032 -- second one is treated as the start of the character literal 'A'.
2033 -- Note that RM-2.2(7) does not require a separator between "'" and
2034 -- "(" in the above, so we cannot use lookahead to distinguish the
2035 -- cases; we use look-back instead. Analysis of the grammar shows
2036 -- that some tokens can be followed by an apostrophe, and some by a
2037 -- character literal, but none by both. Some cannot be followed by
2038 -- either, so it doesn't matter what we do in those cases, except to
2039 -- get good error behavior.
2041 when ''' => Char_Literal_Case
: declare
2046 Accumulate_Checksum
(''');
2047 Scan_Ptr
:= Scan_Ptr
+ 1;
2049 -- Distinguish between apostrophe and character literal. It's an
2050 -- apostrophe if the previous token is one of the following.
2051 -- Reserved words are included for things like A.all'Address and
2052 -- T'Digits'Img. Strings literals are included for things like
2053 -- "abs"'Address. Other literals are included to give better error
2054 -- behavior for illegal cases like 123'Img.
2056 -- In Ada 2020, a target name (i.e. @) is a valid prefix of an
2057 -- attribute, and functions like a name.
2059 if Prev_Token
= Tok_All
2060 or else Prev_Token
= Tok_At_Sign
2061 or else Prev_Token
= Tok_Delta
2062 or else Prev_Token
= Tok_Digits
2063 or else Prev_Token
= Tok_Identifier
2064 or else Prev_Token
= Tok_Project
2065 or else Prev_Token
= Tok_Right_Paren
2066 or else Prev_Token
in Token_Class_Literal
2068 Token
:= Tok_Apostrophe
;
2071 Style
.Check_Apostrophe
;
2076 -- Otherwise the apostrophe starts a character literal
2079 -- Case of wide character literal
2081 if Start_Of_Wide_Character
then
2083 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2084 Accumulate_Checksum
(Code
);
2087 Error_Illegal_Wide_Character
;
2088 Code
:= Character'Pos (' ');
2090 -- In Ada 95 mode we allow any wide character in a character
2091 -- literal, but in Ada 2005, the set of characters allowed
2092 -- is restricted to graphic characters.
2094 elsif Ada_Version
>= Ada_2005
2095 and then Is_UTF_32_Non_Graphic
(UTF_32
(Code
))
2097 Error_Msg
-- CODEFIX????
2098 ("(Ada 2005) non-graphic character not permitted " &
2099 "in character literal", Wptr
);
2102 if Source
(Scan_Ptr
) /= ''' then
2103 Error_Msg_S
("missing apostrophe");
2105 Scan_Ptr
:= Scan_Ptr
+ 1;
2108 -- If we do not find a closing quote in the expected place then
2109 -- assume that we have a misguided attempt at a string literal.
2111 -- However, if previous token is RANGE, then we return an
2112 -- apostrophe instead since this gives better error recovery
2114 elsif Source
(Scan_Ptr
+ 1) /= ''' then
2115 if Prev_Token
= Tok_Range
then
2116 Token
:= Tok_Apostrophe
;
2120 Scan_Ptr
:= Scan_Ptr
- 1;
2122 ("strings are delimited by double quote character");
2128 -- Otherwise we have a (non-wide) character literal
2131 Accumulate_Checksum
(Source
(Scan_Ptr
));
2133 if Source
(Scan_Ptr
) not in Graphic_Character
then
2134 if Source
(Scan_Ptr
) in Upper_Half_Character
then
2135 if Ada_Version
= Ada_83
then
2136 Error_Illegal_Character
;
2140 Error_Illegal_Character
;
2144 Code
:= Get_Char_Code
(Source
(Scan_Ptr
));
2145 Scan_Ptr
:= Scan_Ptr
+ 2;
2148 -- Fall through here with Scan_Ptr updated past the closing
2149 -- quote, and Code set to the Char_Code value for the literal
2151 Accumulate_Checksum
(''');
2152 Token
:= Tok_Char_Literal
;
2153 Set_Character_Literal_Name
(Code
);
2154 Token_Name
:= Name_Find
;
2155 Character_Code
:= Code
;
2159 end Char_Literal_Case
;
2161 -- Right parenthesis
2164 Accumulate_Checksum
(')');
2165 Scan_Ptr
:= Scan_Ptr
+ 1;
2166 Token
:= Tok_Right_Paren
;
2169 Style
.Check_Right_Paren
;
2174 -- Right bracket or right brace, treated as right paren
2177 Error_Msg_S
("illegal character, replaced by "")""");
2178 Scan_Ptr
:= Scan_Ptr
+ 1;
2179 Token
:= Tok_Right_Paren
;
2182 -- Slash (can be division operator or first character of not equal)
2185 Accumulate_Checksum
('/');
2187 if Double_Char_Token
('=') then
2188 Token
:= Tok_Not_Equal
;
2191 Scan_Ptr
:= Scan_Ptr
+ 1;
2199 Accumulate_Checksum
(';');
2200 Scan_Ptr
:= Scan_Ptr
+ 1;
2201 Token
:= Tok_Semicolon
;
2204 Style
.Check_Semicolon
;
2211 when '|' => Vertical_Bar_Case
: begin
2212 Accumulate_Checksum
('|');
2214 -- Special check for || to give nice message
2216 if Source
(Scan_Ptr
+ 1) = '|' then
2217 Error_Msg_S
-- CODEFIX
2218 ("""'|'|"" should be `OR ELSE`");
2219 Scan_Ptr
:= Scan_Ptr
+ 2;
2224 Scan_Ptr
:= Scan_Ptr
+ 1;
2225 Token
:= Tok_Vertical_Bar
;
2228 Style
.Check_Vertical_Bar
;
2234 end Vertical_Bar_Case
;
2236 -- Exclamation, replacement character for vertical bar
2238 when '!' => Exclamation_Case
: begin
2239 Accumulate_Checksum
('!');
2241 if Source
(Scan_Ptr
+ 1) = '=' then
2242 Error_Msg_S
-- CODEFIX
2243 ("'!= should be /=");
2244 Scan_Ptr
:= Scan_Ptr
+ 2;
2245 Token
:= Tok_Not_Equal
;
2249 Scan_Ptr
:= Scan_Ptr
+ 1;
2250 Token
:= Tok_Vertical_Bar
;
2254 end Exclamation_Case
;
2258 when '+' => Plus_Case
: begin
2259 Accumulate_Checksum
('+');
2260 Scan_Ptr
:= Scan_Ptr
+ 1;
2265 -- Digits starting a numeric literal
2269 -- First a bit of a scan ahead to see if we have a case of an
2270 -- identifier starting with a digit (remembering exponent case).
2273 C
: constant Character := Source
(Scan_Ptr
+ 1);
2276 -- OK literal if digit followed by digit or underscore
2278 if C
in '0' .. '9' or else C
= '_' then
2281 -- OK literal if digit not followed by identifier char
2283 elsif not Identifier_Char
(C
) then
2286 -- OK literal if digit followed by e/E followed by digit/sign.
2287 -- We also allow underscore after the E, which is an error, but
2288 -- better handled by Nlit than deciding this is an identifier.
2290 elsif (C
= 'e' or else C
= 'E')
2291 and then (Source
(Scan_Ptr
+ 2) in '0' .. '9'
2292 or else Source
(Scan_Ptr
+ 2) = '+'
2293 or else Source
(Scan_Ptr
+ 2) = '-'
2294 or else Source
(Scan_Ptr
+ 2) = '_')
2298 -- Here we have what really looks like an identifier that
2299 -- starts with a digit, so give error msg.
2302 Error_Msg_S
("identifier may not start with digit");
2304 Underline_Found
:= False;
2305 Name_Buffer
(1) := Source
(Scan_Ptr
);
2306 Accumulate_Checksum
(Name_Buffer
(1));
2307 Scan_Ptr
:= Scan_Ptr
+ 1;
2308 goto Scan_Identifier
;
2312 -- Here we have an OK integer literal
2316 -- Check for proper delimiter, ignoring other format characters
2318 Skip_Other_Format_Characters
;
2320 if Identifier_Char
(Source
(Scan_Ptr
)) then
2322 ("delimiter required between literal and identifier");
2328 -- Lower case letters
2332 Underline_Found
:= False;
2333 Name_Buffer
(1) := Source
(Scan_Ptr
);
2334 Accumulate_Checksum
(Name_Buffer
(1));
2335 Scan_Ptr
:= Scan_Ptr
+ 1;
2336 goto Scan_Identifier
;
2338 -- Upper case letters
2342 Underline_Found
:= False;
2344 Character'Val (Character'Pos (Source
(Scan_Ptr
)) + 32);
2345 Accumulate_Checksum
(Name_Buffer
(1));
2346 Scan_Ptr
:= Scan_Ptr
+ 1;
2347 goto Scan_Identifier
;
2349 -- Underline character
2352 if Special_Characters
('_') then
2353 Token_Ptr
:= Scan_Ptr
;
2354 Scan_Ptr
:= Scan_Ptr
+ 1;
2355 Token
:= Tok_Special
;
2356 Special_Character
:= '_';
2360 Error_Msg_S
("identifier cannot start with underline");
2362 Name_Buffer
(1) := '_';
2363 Scan_Ptr
:= Scan_Ptr
+ 1;
2364 Underline_Found
:= False;
2365 goto Scan_Identifier
;
2367 -- Space (not possible, because we scanned past blanks)
2370 raise Program_Error
;
2372 -- Characters in top half of ASCII 8-bit chart
2374 when Upper_Half_Character
=>
2376 -- Wide character case
2378 if Upper_Half_Encoding
then
2379 goto Scan_Wide_Character
;
2381 -- Otherwise we have OK Latin-1 character
2384 -- Upper half characters may possibly be identifier letters
2385 -- but can never be digits, so Identifier_Char can be used to
2386 -- test for a valid start of identifier character.
2388 if Identifier_Char
(Source
(Scan_Ptr
)) then
2390 Underline_Found
:= False;
2391 goto Scan_Identifier
;
2393 Error_Illegal_Character
;
2399 -- ESC character, possible start of identifier if wide characters
2400 -- using ESC encoding are allowed in identifiers, which we can
2401 -- tell by looking at the Identifier_Char flag for ESC, which is
2402 -- only true if these conditions are met. In Ada 2005 mode, may
2403 -- also be valid UTF_32 space or line terminator character.
2405 if Identifier_Char
(ESC
) then
2407 goto Scan_Wide_Character
;
2409 Error_Illegal_Character
;
2412 -- Invalid control characters
2441 Error_Illegal_Character
;
2443 -- Invalid graphic characters
2444 -- Note that '@' is handled elsewhere, because following AI12-125
2445 -- it denotes the target_name of an assignment.
2447 when '#' |
'$' |
'?' |
'`' |
'\' |
'^' |
'~' =>
2449 -- If Set_Special_Character has been called for this character,
2450 -- set Scans.Special_Character and return a Special token.
2452 if Special_Characters
(Source
(Scan_Ptr
)) then
2453 Token_Ptr
:= Scan_Ptr
;
2454 Token
:= Tok_Special
;
2455 Special_Character
:= Source
(Scan_Ptr
);
2456 Scan_Ptr
:= Scan_Ptr
+ 1;
2459 -- Check for something looking like a preprocessor directive
2461 elsif Source
(Scan_Ptr
) = '#'
2462 and then (Source
(Scan_Ptr
+ 1 .. Scan_Ptr
+ 2) = "if"
2464 Source
(Scan_Ptr
+ 1 .. Scan_Ptr
+ 5) = "elsif"
2466 Source
(Scan_Ptr
+ 1 .. Scan_Ptr
+ 4) = "else"
2468 Source
(Scan_Ptr
+ 1 .. Scan_Ptr
+ 3) = "end")
2471 ("preprocessor directive ignored, preprocessor not active");
2473 -- Skip to end of line
2476 if Source
(Scan_Ptr
) in Graphic_Character
2478 Source
(Scan_Ptr
) = HT
2480 Scan_Ptr
:= Scan_Ptr
+ 1;
2482 -- Done if line terminator or EOF
2484 elsif Source
(Scan_Ptr
) in Line_Terminator
2486 Source
(Scan_Ptr
) = EOF
2490 -- If we have a wide character, we have to scan it out,
2491 -- because it might be a legitimate line terminator
2493 elsif Start_Of_Wide_Character
then
2495 Wptr
: constant Source_Ptr
:= Scan_Ptr
;
2500 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2502 -- If not well formed wide character, then just skip
2503 -- past it and ignore it.
2506 Scan_Ptr
:= Wptr
+ 1;
2508 -- If UTF_32 terminator, terminate comment scan
2510 elsif Is_UTF_32_Line_Terminator
(UTF_32
(Code
)) then
2516 -- Else keep going (don't worry about bad comment chars
2517 -- in this context, we just want to find the end of line.
2520 Scan_Ptr
:= Scan_Ptr
+ 1;
2524 -- Otherwise, this is an illegal character
2527 Error_Illegal_Character
;
2530 -- End switch on non-blank character
2534 -- End loop past format effectors. The exit from this loop is by
2535 -- executing a return statement following completion of token scan
2536 -- (control never falls out of this loop to the code that follows).
2540 pragma Assert
(False);
2542 -- Wide_Character scanning routine. On entry we have encountered the
2543 -- initial character of a wide character sequence.
2545 <<Scan_Wide_Character
>>
2553 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2555 -- If bad wide character, signal error and continue scan
2558 Error_Illegal_Wide_Character
;
2559 goto Scan_Next_Character
;
2562 Cat
:= Get_Category
(UTF_32
(Code
));
2564 -- If OK letter, reset scan ptr and go scan identifier
2566 if Is_UTF_32_Letter
(Cat
) then
2569 Underline_Found
:= False;
2570 goto Scan_Identifier
;
2572 -- If OK wide space, ignore and keep scanning (we do not include
2573 -- any ignored spaces in checksum)
2575 elsif Is_UTF_32_Space
(Cat
) then
2576 goto Scan_Next_Character
;
2578 -- If other format character, ignore and keep scanning (again we
2579 -- do not include in the checksum) (this is for AI-0079).
2581 elsif Is_UTF_32_Other
(Cat
) then
2582 goto Scan_Next_Character
;
2584 -- If OK wide line terminator, terminate current line
2586 elsif Is_UTF_32_Line_Terminator
(UTF_32
(Code
)) then
2588 goto Scan_Line_Terminator
;
2590 -- Punctuation is an error (at start of identifier)
2592 elsif Is_UTF_32_Punctuation
(Cat
) then
2593 Error_Msg
("identifier cannot start with punctuation", Wptr
);
2596 Underline_Found
:= False;
2597 goto Scan_Identifier
;
2599 -- Mark character is an error (at start of identifier)
2601 elsif Is_UTF_32_Mark
(Cat
) then
2602 Error_Msg
("identifier cannot start with mark character", Wptr
);
2605 Underline_Found
:= False;
2606 goto Scan_Identifier
;
2608 -- Extended digit character is an error. Could be bad start of
2609 -- identifier or bad literal. Not worth doing too much to try to
2610 -- distinguish these cases, but we will do a little bit.
2612 elsif Is_UTF_32_Digit
(Cat
) then
2614 ("identifier cannot start with digit character", Wptr
);
2617 Underline_Found
:= False;
2618 goto Scan_Identifier
;
2620 -- All other wide characters are illegal here
2623 Error_Illegal_Wide_Character
;
2624 goto Scan_Next_Character
;
2628 -- Routine to scan line terminator. On entry Scan_Ptr points to a
2629 -- character which is one of FF,LR,CR,VT, or one of the wide characters
2630 -- that is treated as a line terminator.
2632 <<Scan_Line_Terminator
>>
2634 -- Check line too long
2638 -- Set Token_Ptr, if End_Of_Line is a token, for the case when it is
2641 if End_Of_Line_Is_Token
then
2642 Token_Ptr
:= Scan_Ptr
;
2649 Skip_Line_Terminators
(Scan_Ptr
, Physical
);
2651 -- If we are at start of physical line, update scan pointers to
2652 -- reflect the start of the new line.
2655 Current_Line_Start
:= Scan_Ptr
;
2656 Start_Column
:= Set_Start_Column
;
2657 First_Non_Blank_Location
:= Scan_Ptr
;
2659 -- If End_Of_Line is a token, we return it as it is a
2662 if End_Of_Line_Is_Token
then
2663 Token
:= Tok_End_Of_Line
;
2669 goto Scan_Next_Character
;
2671 -- Identifier scanning routine. On entry, some initial characters of
2672 -- the identifier may have already been stored in Name_Buffer. If so,
2673 -- Name_Len has the number of characters stored, otherwise Name_Len is
2674 -- set to zero on entry. Underline_Found is also set False on entry.
2678 -- This loop scans as fast as possible past lower half letters and
2679 -- digits, which we expect to be the most common characters.
2682 if Source
(Scan_Ptr
) in 'a' .. 'z'
2683 or else Source
(Scan_Ptr
) in '0' .. '9'
2685 Name_Buffer
(Name_Len
+ 1) := Source
(Scan_Ptr
);
2686 Accumulate_Checksum
(Source
(Scan_Ptr
));
2688 elsif Source
(Scan_Ptr
) in 'A' .. 'Z' then
2689 Name_Buffer
(Name_Len
+ 1) :=
2690 Character'Val (Character'Pos (Source
(Scan_Ptr
)) + 32);
2691 Accumulate_Checksum
(Name_Buffer
(Name_Len
+ 1));
2697 Underline_Found
:= False;
2698 Scan_Ptr
:= Scan_Ptr
+ 1;
2699 Name_Len
:= Name_Len
+ 1;
2702 -- If we fall through, then we have encountered either an underline
2703 -- character, or an extended identifier character (i.e. one from the
2704 -- upper half), or a wide character, or an identifier terminator. The
2705 -- initial test speeds us up in the most common case where we have
2706 -- an identifier terminator. Note that ESC is an identifier character
2707 -- only if a wide character encoding method that uses ESC encoding
2708 -- is active, so if we find an ESC character we know that we have a
2711 if Identifier_Char
(Source
(Scan_Ptr
))
2712 or else (Source
(Scan_Ptr
) in Upper_Half_Character
2713 and then Upper_Half_Encoding
)
2715 -- Case of underline
2717 if Source
(Scan_Ptr
) = '_' then
2718 Accumulate_Checksum
('_');
2720 if Underline_Found
then
2721 Error_No_Double_Underline
;
2723 Underline_Found
:= True;
2724 Name_Len
:= Name_Len
+ 1;
2725 Name_Buffer
(Name_Len
) := '_';
2728 Scan_Ptr
:= Scan_Ptr
+ 1;
2729 goto Scan_Identifier
;
2731 -- Upper half character
2733 elsif Source
(Scan_Ptr
) in Upper_Half_Character
2734 and then not Upper_Half_Encoding
2736 Accumulate_Checksum
(Source
(Scan_Ptr
));
2737 Store_Encoded_Character
2738 (Get_Char_Code
(Fold_Lower
(Source
(Scan_Ptr
))));
2739 Scan_Ptr
:= Scan_Ptr
+ 1;
2740 Underline_Found
:= False;
2741 goto Scan_Identifier
;
2743 -- Left bracket not followed by a quote terminates an identifier.
2744 -- This is an error, but we don't want to give a junk error msg
2745 -- about wide characters in this case.
2747 elsif Source
(Scan_Ptr
) = '['
2748 and then Source
(Scan_Ptr
+ 1) /= '"'
2752 -- We know we have a wide character encoding here (the current
2753 -- character is either ESC, left bracket, or an upper half
2754 -- character depending on the encoding method).
2757 -- Scan out the wide character and insert the appropriate
2758 -- encoding into the name table entry for the identifier.
2768 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2770 -- If error, signal error
2773 Error_Illegal_Wide_Character
;
2775 -- If the character scanned is a normal identifier
2776 -- character, then we treat it that way.
2778 elsif In_Character_Range
(Code
)
2779 and then Identifier_Char
(Get_Character
(Code
))
2781 Chr
:= Get_Character
(Code
);
2782 Accumulate_Checksum
(Chr
);
2783 Store_Encoded_Character
2784 (Get_Char_Code
(Fold_Lower
(Chr
)));
2785 Underline_Found
:= False;
2787 -- Here if not a normal identifier character
2790 Cat
:= Get_Category
(UTF_32
(Code
));
2792 -- Wide character in Unicode category "Other, Format"
2793 -- is not accepted in an identifier. This is because it
2794 -- it is considered a security risk (AI-0091).
2796 -- However, it is OK for such a character to appear at
2797 -- the end of an identifier.
2799 if Is_UTF_32_Other
(Cat
) then
2800 if not Identifier_Char
(Source
(Scan_Ptr
)) then
2801 goto Scan_Identifier_Complete
;
2804 ("identifier cannot contain other_format "
2805 & "character", Wptr
);
2806 goto Scan_Identifier
;
2809 -- Wide character in category Separator,Space terminates
2811 elsif Is_UTF_32_Space
(Cat
) then
2812 goto Scan_Identifier_Complete
;
2815 -- Here if wide character is part of the identifier
2817 -- Make sure we are allowing wide characters in
2818 -- identifiers. Note that we allow wide character
2819 -- notation for an OK identifier character. This in
2820 -- particular allows bracket or other notation to be
2821 -- used for upper half letters.
2823 -- Wide characters are always allowed in Ada 2005
2825 if Identifier_Character_Set
/= 'w'
2826 and then Ada_Version
< Ada_2005
2829 ("wide character not allowed in identifier", Wptr
);
2832 -- If OK letter, store it folding to upper case. Note
2833 -- that we include the folded letter in the checksum.
2835 if Is_UTF_32_Letter
(Cat
) then
2837 Char_Code
(UTF_32_To_Upper_Case
(UTF_32
(Code
)));
2838 Accumulate_Checksum
(Code
);
2839 Store_Encoded_Character
(Code
);
2840 Underline_Found
:= False;
2842 -- If OK extended digit or mark, then store it
2844 elsif Is_UTF_32_Digit
(Cat
)
2845 or else Is_UTF_32_Mark
(Cat
)
2847 Accumulate_Checksum
(Code
);
2848 Store_Encoded_Character
(Code
);
2849 Underline_Found
:= False;
2851 -- Wide punctuation is also stored, but counts as an
2852 -- underline character for error checking purposes.
2854 elsif Is_UTF_32_Punctuation
(Cat
) then
2855 Accumulate_Checksum
(Code
);
2857 if Underline_Found
then
2859 Cend
: constant Source_Ptr
:= Scan_Ptr
;
2862 Error_No_Double_Underline
;
2867 Store_Encoded_Character
(Code
);
2868 Underline_Found
:= True;
2871 -- Any other wide character is not acceptable
2875 ("invalid wide character in identifier", Wptr
);
2879 goto Scan_Identifier
;
2884 -- Scan of identifier is complete. The identifier is stored in
2885 -- Name_Buffer, and Scan_Ptr points past the last character.
2887 <<Scan_Identifier_Complete
>>
2888 Token_Name
:= Name_Find
;
2890 -- Check for identifier ending with underline or punctuation char
2892 if Underline_Found
then
2893 Underline_Found
:= False;
2895 if Source
(Scan_Ptr
- 1) = '_' then
2897 ("identifier cannot end with underline", Scan_Ptr
- 1);
2900 ("identifier cannot end with punctuation character", Wptr
);
2904 -- We will assume it is an identifier, not a keyword, so that the
2905 -- checksum is independent of the Ada version.
2907 Token
:= Tok_Identifier
;
2909 -- Here is where we check if it was a keyword
2911 if Is_Keyword_Name
(Token_Name
) then
2912 if Opt
.Checksum_GNAT_6_3
then
2913 Token
:= Token_Type
'Val (Get_Name_Table_Byte
(Token_Name
));
2915 if Checksum_Accumulate_Token_Checksum
then
2916 if Checksum_GNAT_5_03
then
2917 Accumulate_Token_Checksum_GNAT_5_03
;
2919 Accumulate_Token_Checksum_GNAT_6_3
;
2924 Accumulate_Token_Checksum
;
2925 Token
:= Token_Type
'Val (Get_Name_Table_Byte
(Token_Name
));
2928 -- Keyword style checks
2932 -- Deal with possible style check for non-lower case keyword,
2933 -- but we don't treat ACCESS, DELTA, DIGITS, RANGE as keywords
2934 -- for this purpose if they appear as attribute designators.
2935 -- Actually we only check the first character for speed.
2937 -- Ada 2005 (AI-284): Do not apply the style check in case of
2938 -- "pragma Interface"
2940 -- Ada 2005 (AI-340): Do not apply the style check in case of
2943 if Source
(Token_Ptr
) <= 'Z'
2944 and then (Prev_Token
/= Tok_Apostrophe
2946 (Token
/= Tok_Access
and then
2947 Token
/= Tok_Delta
and then
2948 Token
/= Tok_Digits
and then
2949 Token
/= Tok_Mod
and then
2950 Token
/= Tok_Range
))
2951 and then (Token
/= Tok_Interface
2953 (Token
= Tok_Interface
2954 and then Prev_Token
/= Tok_Pragma
))
2956 Style
.Non_Lower_Case_Keyword
;
2959 -- Check THEN/ELSE style rules. These do not apply to AND THEN
2960 -- or OR ELSE, and do not apply in if expressions.
2962 if (Token
= Tok_Then
and then Prev_Token
/= Tok_And
)
2964 (Token
= Tok_Else
and then Prev_Token
/= Tok_Or
)
2966 if Inside_If_Expression
= 0 then
2967 Style
.Check_Separate_Stmt_Lines
;
2972 -- We must reset Token_Name since this is not an identifier and
2973 -- if we leave Token_Name set, the parser gets confused because
2974 -- it thinks it is dealing with an identifier instead of the
2975 -- corresponding keyword.
2977 Token_Name
:= No_Name
;
2980 -- It is an identifier after all
2983 if Checksum_Accumulate_Token_Checksum
then
2984 Accumulate_Token_Checksum
;
2992 --------------------------
2993 -- Set_Comment_As_Token --
2994 --------------------------
2996 procedure Set_Comment_As_Token
(Value
: Boolean) is
2998 Comment_Is_Token
:= Value
;
2999 end Set_Comment_As_Token
;
3001 ------------------------------
3002 -- Set_End_Of_Line_As_Token --
3003 ------------------------------
3005 procedure Set_End_Of_Line_As_Token
(Value
: Boolean) is
3007 End_Of_Line_Is_Token
:= Value
;
3008 end Set_End_Of_Line_As_Token
;
3010 ---------------------------
3011 -- Set_Special_Character --
3012 ---------------------------
3014 procedure Set_Special_Character
(C
: Character) is
3017 when '#' |
'$' |
'_' |
'?' |
'@' |
'`' |
'\' |
'^' |
'~' =>
3018 Special_Characters
(C
) := True;
3023 end Set_Special_Character
;
3025 ----------------------
3026 -- Set_Start_Column --
3027 ----------------------
3029 -- Note: it seems at first glance a little expensive to compute this value
3030 -- for every source line (since it is certainly not used for all source
3031 -- lines). On the other hand, it doesn't take much more work to skip past
3032 -- the initial white space on the line counting the columns than it would
3033 -- to scan past the white space using the standard scanning circuits.
3035 function Set_Start_Column
return Column_Number
is
3036 Start_Column
: Column_Number
:= 0;
3039 -- Outer loop scans past horizontal tab characters
3043 -- Inner loop scans past blanks as fast as possible, bumping Scan_Ptr
3044 -- past the blanks and adjusting Start_Column to account for them.
3047 if Source
(Scan_Ptr
) = ' ' then
3048 if Source
(Scan_Ptr
+ 1) = ' ' then
3049 if Source
(Scan_Ptr
+ 2) = ' ' then
3050 if Source
(Scan_Ptr
+ 3) = ' ' then
3051 if Source
(Scan_Ptr
+ 4) = ' ' then
3052 if Source
(Scan_Ptr
+ 5) = ' ' then
3053 if Source
(Scan_Ptr
+ 6) = ' ' then
3054 Scan_Ptr
:= Scan_Ptr
+ 7;
3055 Start_Column
:= Start_Column
+ 7;
3057 Scan_Ptr
:= Scan_Ptr
+ 6;
3058 Start_Column
:= Start_Column
+ 6;
3062 Scan_Ptr
:= Scan_Ptr
+ 5;
3063 Start_Column
:= Start_Column
+ 5;
3067 Scan_Ptr
:= Scan_Ptr
+ 4;
3068 Start_Column
:= Start_Column
+ 4;
3072 Scan_Ptr
:= Scan_Ptr
+ 3;
3073 Start_Column
:= Start_Column
+ 3;
3077 Scan_Ptr
:= Scan_Ptr
+ 2;
3078 Start_Column
:= Start_Column
+ 2;
3082 Scan_Ptr
:= Scan_Ptr
+ 1;
3083 Start_Column
:= Start_Column
+ 1;
3089 end loop Blanks_Loop
;
3091 -- Outer loop keeps going only if a horizontal tab follows
3093 if Source
(Scan_Ptr
) = HT
then
3098 Scan_Ptr
:= Scan_Ptr
+ 1;
3099 Start_Column
:= (Start_Column
/ 8) * 8 + 8;
3105 return Start_Column
;
3107 -- A constraint error can happen only if we have a compiler with checks on
3108 -- and a line with a ludicrous number of tabs or spaces at the start. In
3109 -- such a case, we really don't care if Start_Column is right or not.
3112 when Constraint_Error
=>
3113 return Start_Column
;
3114 end Set_Start_Column
;