1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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.
174 | Tok_Double_Asterisk
178 | Tok_Greater_Greater
181 | Tok_Integer_Literal
195 | Tok_Operator_Symbol
212 (System
.CRC32
.CRC32
(Checksum
),
213 Character'Val (Token_Type
'Pos (Token
)));
217 (System
.CRC32
.CRC32
(Checksum
),
218 Character'Val (Token_Type
'Pos (Tok_Identifier
)));
240 | Tok_External_As_List
278 (System
.CRC32
.CRC32
(Checksum
),
279 Character'Val (Token_Type
'Pos (Token_Type
'Pred (Token
))));
281 end Accumulate_Token_Checksum_GNAT_6_3
;
283 -----------------------------------------
284 -- Accumulate_Token_Checksum_GNAT_5_03 --
285 -----------------------------------------
287 procedure Accumulate_Token_Checksum_GNAT_5_03
is
289 -- Individual values of Token_Type are used, instead of subranges, so
290 -- that additions or suppressions of enumerated values in type
291 -- Token_Type are detected by the compiler.
316 | Tok_Double_Asterisk
320 | Tok_Greater_Greater
323 | Tok_Integer_Literal
334 | Tok_Operator_Symbol
347 (System
.CRC32
.CRC32
(Checksum
),
348 Character'Val (Token_Type
'Pos (Token
)));
356 (System
.CRC32
.CRC32
(Checksum
),
357 Character'Val (Token_Type
'Pos (Tok_Identifier
)));
367 (System
.CRC32
.CRC32
(Checksum
),
368 Character'Val (Token_Type
'Pos (Token
) - 1));
404 (System
.CRC32
.CRC32
(Checksum
),
405 Character'Val (Token_Type
'Pos (Token
) - 2));
415 | Tok_External_As_List
431 (System
.CRC32
.CRC32
(Checksum
),
432 Character'Val (Token_Type
'Pos (Token
) - 4));
434 end Accumulate_Token_Checksum_GNAT_5_03
;
436 -----------------------
437 -- Check_End_Of_Line --
438 -----------------------
440 procedure Check_End_Of_Line
is
441 Len
: constant Int
:=
443 Int
(Current_Line_Start
) -
444 Wide_Char_Byte_Count
;
446 -- Start of processing for Check_End_Of_Line
450 Style
.Check_Line_Terminator
(Len
);
453 -- Deal with checking maximum line length
455 if Style_Check
and Style_Check_Max_Line_Length
then
456 Style
.Check_Line_Max_Length
(Len
);
458 -- If style checking is inactive, check maximum line length against
461 elsif Len
> Max_Line_Length
then
463 ("this line is too long",
464 Current_Line_Start
+ Source_Ptr
(Max_Line_Length
));
467 -- Now one more checking circuit. Normally we are only enforcing a limit
468 -- of physical characters, with tabs counting as one character. But if
469 -- after tab expansion we would have a total line length that exceeded
470 -- 32766, that would really cause trouble, because column positions
471 -- would exceed the maximum we allow for a column count. Note: the limit
472 -- is 32766 rather than 32767, since we use a value of 32767 for special
473 -- purposes (see Sinput). Now we really do not want to go messing with
474 -- tabs in the normal case, so what we do is to check for a line that
475 -- has more than 4096 physical characters. Any shorter line could not
476 -- be a problem, even if it was all tabs.
485 Ptr
:= Current_Line_Start
;
487 exit when Ptr
= Scan_Ptr
;
489 if Source
(Ptr
) = ASCII
.HT
then
490 Col
:= (Col
- 1 + 8) / 8 * 8 + 1;
497 ("this line is longer than 32766 characters",
499 raise Unrecoverable_Error
;
507 -- Reset wide character byte count for next line
509 Wide_Char_Byte_Count
:= 0;
510 end Check_End_Of_Line
;
512 ----------------------------
513 -- Determine_Token_Casing --
514 ----------------------------
516 function Determine_Token_Casing
return Casing_Type
is
518 return Determine_Casing
(Source
(Token_Ptr
.. Scan_Ptr
- 1));
519 end Determine_Token_Casing
;
521 -------------------------
522 -- Initialize_Checksum --
523 -------------------------
525 procedure Initialize_Checksum
is
527 System
.CRC32
.Initialize
(System
.CRC32
.CRC32
(Checksum
));
528 end Initialize_Checksum
;
530 ------------------------
531 -- Initialize_Scanner --
532 ------------------------
534 procedure Initialize_Scanner
(Index
: Source_File_Index
) is
536 -- Establish reserved words
538 Scans
.Initialize_Ada_Keywords
;
540 -- Initialize scan control variables
542 Current_Source_File
:= Index
;
543 Source
:= Source_Text
(Current_Source_File
);
544 Scan_Ptr
:= Source_First
(Current_Source_File
);
546 Token_Ptr
:= Scan_Ptr
;
547 Current_Line_Start
:= Scan_Ptr
;
549 Token_Name
:= No_Name
;
550 Start_Column
:= Set_Start_Column
;
551 First_Non_Blank_Location
:= Scan_Ptr
;
554 Wide_Char_Byte_Count
:= 0;
556 -- Do not call Scan, otherwise the License stuff does not work in Scn
558 end Initialize_Scanner
;
560 ------------------------------
561 -- Reset_Special_Characters --
562 ------------------------------
564 procedure Reset_Special_Characters
is
566 Special_Characters
:= (others => False);
567 end Reset_Special_Characters
;
575 Start_Of_Comment
: Source_Ptr
;
576 -- Record start of comment position
578 Underline_Found
: Boolean;
579 -- During scanning of an identifier, set to True if last character
580 -- scanned was an underline or other punctuation character. This
581 -- is used to flag the error of two underlines/punctuations in a
582 -- row or ending an identifier with a underline/punctuation. Here
583 -- punctuation means any UTF_32 character in the Unicode category
584 -- Punctuation,Connector.
587 -- Used to remember start of last wide character scanned
589 function Double_Char_Token
(C
: Character) return Boolean;
590 -- This function is used for double character tokens like := or <>. It
591 -- checks if the character following Source (Scan_Ptr) is C, and if so
592 -- bumps Scan_Ptr past the pair of characters and returns True. A space
593 -- between the two characters is also recognized with an appropriate
594 -- error message being issued. If C is not present, False is returned.
595 -- Note that Double_Char_Token can only be used for tokens defined in
596 -- the Ada syntax (it's use for error cases like && is not appropriate
597 -- since we do not want a junk message for a case like &-space-&).
599 procedure Error_Illegal_Character
;
600 -- Give illegal character error, Scan_Ptr points to character. On
601 -- return, Scan_Ptr is bumped past the illegal character.
603 procedure Error_Illegal_Wide_Character
;
604 -- Give illegal wide character message. On return, Scan_Ptr is bumped
605 -- past the illegal character, which may still leave us pointing to
606 -- junk, not much we can do if the escape sequence is messed up.
608 procedure Error_No_Double_Underline
;
609 -- Signal error of two underline or punctuation characters in a row.
610 -- Called with Scan_Ptr pointing to second underline/punctuation char.
613 -- This is the procedure for scanning out numeric literals. On entry,
614 -- Scan_Ptr points to the digit that starts the numeric literal (the
615 -- checksum for this character has not been accumulated yet). On return
616 -- Scan_Ptr points past the last character of the numeric literal, Token
617 -- and Token_Node are set appropriately, and the checksum is updated.
620 -- This is the procedure for scanning out string literals. On entry,
621 -- Scan_Ptr points to the opening string quote (the checksum for this
622 -- character has not been accumulated yet). On return Scan_Ptr points
623 -- past the closing quote of the string literal, Token and Token_Node
624 -- are set appropriately, and the checksum is updated.
626 procedure Skip_Other_Format_Characters
;
627 -- Skips past any "other format" category characters at the current
628 -- cursor location (does not skip past spaces or any other characters).
630 function Start_Of_Wide_Character
return Boolean;
631 -- Returns True if the scan pointer is pointing to the start of a wide
632 -- character sequence, does not modify the scan pointer in any case.
634 -----------------------
635 -- Double_Char_Token --
636 -----------------------
638 function Double_Char_Token
(C
: Character) return Boolean is
640 if Source
(Scan_Ptr
+ 1) = C
then
641 Accumulate_Checksum
(C
);
642 Scan_Ptr
:= Scan_Ptr
+ 2;
645 elsif Source
(Scan_Ptr
+ 1) = ' '
646 and then Source
(Scan_Ptr
+ 2) = C
648 Scan_Ptr
:= Scan_Ptr
+ 1;
649 Error_Msg_S
-- CODEFIX
650 ("no space allowed here");
651 Scan_Ptr
:= Scan_Ptr
+ 2;
657 end Double_Char_Token
;
659 -----------------------------
660 -- Error_Illegal_Character --
661 -----------------------------
663 procedure Error_Illegal_Character
is
665 Error_Msg_S
("illegal character");
666 Scan_Ptr
:= Scan_Ptr
+ 1;
667 end Error_Illegal_Character
;
669 ----------------------------------
670 -- Error_Illegal_Wide_Character --
671 ----------------------------------
673 procedure Error_Illegal_Wide_Character
is
675 Scan_Ptr
:= Scan_Ptr
+ 1;
676 Error_Msg
("illegal wide character", Wptr
);
677 end Error_Illegal_Wide_Character
;
679 -------------------------------
680 -- Error_No_Double_Underline --
681 -------------------------------
683 procedure Error_No_Double_Underline
is
685 Underline_Found
:= False;
687 -- There are four cases, and we special case the messages
689 if Source
(Scan_Ptr
) = '_' then
690 if Source
(Scan_Ptr
- 1) = '_' then
691 Error_Msg_S
-- CODEFIX
692 ("two consecutive underlines not permitted");
694 Error_Msg_S
("underline cannot follow punctuation character");
698 if Source
(Scan_Ptr
- 1) = '_' then
699 Error_Msg_S
("punctuation character cannot follow underline");
702 ("two consecutive punctuation characters not permitted");
705 end Error_No_Double_Underline
;
714 -- Current source program character
716 Base_Char
: Character;
717 -- Either # or : (character at start of based number)
723 -- Value of base in Uint format
726 -- Value of integer scanned by Scan_Integer in Uint format
729 -- Value of integer in numeric value being scanned
732 -- Scale value for real literal
735 -- Scale in Uint format
737 Exponent_Is_Negative
: Boolean;
738 -- Set true for negative exponent
740 Extended_Digit_Value
: Int
;
741 -- Extended digit value
743 Point_Scanned
: Boolean;
744 -- Flag for decimal point scanned in numeric literal
746 -----------------------
747 -- Local Subprograms --
748 -----------------------
750 procedure Error_Digit_Expected
;
751 -- Signal error of bad digit, Scan_Ptr points to the location at
752 -- which the digit was expected on input, and is unchanged on return.
754 procedure Scan_Integer
;
755 -- Scan integer literal. On entry, Scan_Ptr points to a digit, on
756 -- exit Scan_Ptr points past the last character of the integer.
758 -- For each digit encountered, UI_Int_Value is multiplied by 10, and
759 -- the value of the digit added to the result. In addition, the value
760 -- in Scale is decremented by one for each actual digit scanned.
762 --------------------------
763 -- Error_Digit_Expected --
764 --------------------------
766 procedure Error_Digit_Expected
is
768 Error_Msg_S
("digit expected");
769 end Error_Digit_Expected
;
775 procedure Scan_Integer
is
777 -- Next character scanned
780 C
:= Source
(Scan_Ptr
);
782 -- Loop through digits (allowing underlines)
785 Accumulate_Checksum
(C
);
787 UI_Int_Value
* 10 + (Character'Pos (C
) - Character'Pos ('0'));
788 Scan_Ptr
:= Scan_Ptr
+ 1;
790 C
:= Source
(Scan_Ptr
);
792 -- Case of underline encountered
796 -- We do not accumulate the '_' in the checksum, so that
797 -- 1_234 is equivalent to 1234, and does not trigger
798 -- compilation for "minimal recompilation" (gnatmake -m).
801 Scan_Ptr
:= Scan_Ptr
+ 1;
802 C
:= Source
(Scan_Ptr
);
804 Error_No_Double_Underline
;
807 if C
not in '0' .. '9' then
808 Error_Digit_Expected
;
813 exit when C
not in '0' .. '9';
818 -- Start of processing for Nlit
823 UI_Int_Value
:= Uint_0
;
824 Based_Literal_Uses_Colon
:= False;
827 Point_Scanned
:= False;
828 UI_Num_Value
:= UI_Int_Value
;
830 -- Various possibilities now for continuing the literal are period,
831 -- E/e (for exponent), or :/# (for based literal).
834 C
:= Source
(Scan_Ptr
);
838 -- Scan out point, but do not scan past .. which is a range
839 -- sequence, and must not be eaten up scanning a numeric literal.
841 while C
= '.' and then Source
(Scan_Ptr
+ 1) /= '.' loop
842 Accumulate_Checksum
('.');
844 if Point_Scanned
then
845 Error_Msg_S
("duplicate point ignored");
848 Point_Scanned
:= True;
849 Scan_Ptr
:= Scan_Ptr
+ 1;
850 C
:= Source
(Scan_Ptr
);
852 if C
not in '0' .. '9' then
854 ("real literal cannot end with point", Scan_Ptr
- 1);
857 UI_Num_Value
:= UI_Int_Value
;
861 -- Based literal case. The base is the value we already scanned.
862 -- In the case of colon, we insist that the following character
863 -- is indeed an extended digit or a period. This catches a number
864 -- of common errors, as well as catching the well known tricky
865 -- bug otherwise arising from "x : integer range 1 .. 10:= 6;"
868 or else (C
= ':' and then
869 (Source
(Scan_Ptr
+ 1) = '.'
871 Source
(Scan_Ptr
+ 1) in '0' .. '9'
873 Source
(Scan_Ptr
+ 1) in 'A' .. 'Z'
875 Source
(Scan_Ptr
+ 1) in 'a' .. 'z'))
877 Accumulate_Checksum
(C
);
879 UI_Base
:= UI_Int_Value
;
881 if Base_Char
= ':' then
882 Based_Literal_Uses_Colon
:= True;
885 if UI_Base
< 2 or else UI_Base
> 16 then
886 Error_Msg_SC
("base not 2-16");
890 Base
:= UI_To_Int
(UI_Base
);
891 Scan_Ptr
:= Scan_Ptr
+ 1;
893 -- Scan out extended integer [. integer]
895 C
:= Source
(Scan_Ptr
);
896 UI_Int_Value
:= Uint_0
;
900 if C
in '0' .. '9' then
901 Accumulate_Checksum
(C
);
902 Extended_Digit_Value
:=
903 Int
'(Character'Pos (C)) - Int'(Character'Pos ('0'));
905 elsif C
in 'A' .. 'F' then
906 Accumulate_Checksum
(Character'Val (Character'Pos (C
) + 32));
907 Extended_Digit_Value
:=
908 Int
'(Character'Pos (C)) - Int'(Character'Pos ('A')) + 10;
910 elsif C
in 'a' .. 'f' then
911 Accumulate_Checksum
(C
);
912 Extended_Digit_Value
:=
913 Int
'(Character'Pos (C)) - Int'(Character'Pos ('a')) + 10;
916 Error_Msg_S
("extended digit expected");
920 if Extended_Digit_Value
>= Base
then
921 Error_Msg_S
("digit '>= base");
924 UI_Int_Value
:= UI_Int_Value
* UI_Base
+ Extended_Digit_Value
;
926 Scan_Ptr
:= Scan_Ptr
+ 1;
927 C
:= Source
(Scan_Ptr
);
931 Accumulate_Checksum
('_');
932 Scan_Ptr
:= Scan_Ptr
+ 1;
933 C
:= Source
(Scan_Ptr
);
935 Error_No_Double_Underline
;
939 Accumulate_Checksum
('.');
941 if Point_Scanned
then
942 Error_Msg_S
("duplicate point ignored");
945 Scan_Ptr
:= Scan_Ptr
+ 1;
946 C
:= Source
(Scan_Ptr
);
947 Point_Scanned
:= True;
950 elsif C
= Base_Char
then
951 Accumulate_Checksum
(C
);
952 Scan_Ptr
:= Scan_Ptr
+ 1;
955 elsif C
= '#' or else C
= ':' then
956 Error_Msg_S
("based number delimiters must match");
957 Scan_Ptr
:= Scan_Ptr
+ 1;
960 elsif not Identifier_Char
(C
) then
961 if Base_Char
= '#' then
962 Error_Msg_S
-- CODEFIX
965 Error_Msg_S
-- CODEFIX
974 UI_Num_Value
:= UI_Int_Value
;
979 if not Point_Scanned
then
983 UI_Scale
:= UI_From_Int
(Scale
);
986 if Source
(Scan_Ptr
) = 'e' or else Source
(Scan_Ptr
) = 'E' then
987 Accumulate_Checksum
('e');
988 Scan_Ptr
:= Scan_Ptr
+ 1;
989 Exponent_Is_Negative
:= False;
991 if Source
(Scan_Ptr
) = '+' then
992 Accumulate_Checksum
('+');
993 Scan_Ptr
:= Scan_Ptr
+ 1;
995 elsif Source
(Scan_Ptr
) = '-' then
996 Accumulate_Checksum
('-');
998 if not Point_Scanned
then
1000 ("negative exponent not allowed for integer literal");
1002 Exponent_Is_Negative
:= True;
1005 Scan_Ptr
:= Scan_Ptr
+ 1;
1008 UI_Int_Value
:= Uint_0
;
1010 if Source
(Scan_Ptr
) in '0' .. '9' then
1013 Error_Digit_Expected
;
1016 if Exponent_Is_Negative
then
1017 UI_Scale
:= UI_Scale
- UI_Int_Value
;
1019 UI_Scale
:= UI_Scale
+ UI_Int_Value
;
1023 -- Case of real literal to be returned
1025 if Point_Scanned
then
1026 Token
:= Tok_Real_Literal
;
1027 Real_Literal_Value
:=
1028 UR_From_Components
(
1029 Num
=> UI_Num_Value
,
1033 -- Case of integer literal to be returned
1036 Token
:= Tok_Integer_Literal
;
1038 if UI_Scale
= 0 then
1039 Int_Literal_Value
:= UI_Num_Value
;
1041 -- Avoid doing possibly expensive calculations in cases like
1042 -- parsing 163E800_000# when semantics will not be done anyway.
1043 -- This is especially useful when parsing garbled input.
1045 elsif Operating_Mode
/= Check_Syntax
1046 and then (Serious_Errors_Detected
= 0 or else Try_Semantics
)
1048 Int_Literal_Value
:= UI_Num_Value
* UI_Base
** UI_Scale
;
1051 Int_Literal_Value
:= No_Uint
;
1055 if Checksum_Accumulate_Token_Checksum
then
1056 Accumulate_Token_Checksum
;
1068 Delimiter
: Character;
1069 -- Delimiter (first character of string)
1072 -- Current source program character
1075 -- Current character code value
1078 -- Error flag for Scan_Wide call
1080 String_Start
: Source_Ptr
;
1081 -- Point to first character of string
1083 procedure Error_Bad_String_Char
;
1084 -- Signal bad character in string/character literal. On entry
1085 -- Scan_Ptr points to the improper character encountered during the
1086 -- scan. Scan_Ptr is not modified, so it still points to the bad
1087 -- character on return.
1089 procedure Error_Unterminated_String
;
1090 -- Procedure called if a line terminator character is encountered
1091 -- during scanning a string, meaning that the string is not properly
1094 procedure Set_String
;
1095 -- Procedure used to distinguish between string and operator symbol.
1096 -- On entry the string has been scanned out, and its characters start
1097 -- at Token_Ptr and end one character before Scan_Ptr. On exit Token
1098 -- is set to Tok_String_Literal/Tok_Operator_Symbol as appropriate,
1099 -- and Token_Node is appropriately initialized. In addition, in the
1100 -- operator symbol case, Token_Name is appropriately set, and the
1101 -- flags [Wide_]Wide_Character_Found are set appropriately.
1103 ---------------------------
1104 -- Error_Bad_String_Char --
1105 ---------------------------
1107 procedure Error_Bad_String_Char
is
1108 C
: constant Character := Source
(Scan_Ptr
);
1112 Error_Msg_S
("horizontal tab not allowed in string");
1114 elsif C
= VT
or else C
= FF
then
1115 Error_Msg_S
("format effector not allowed in string");
1117 elsif C
in Upper_Half_Character
then
1118 Error_Msg_S
("(Ada 83) upper half character not allowed");
1121 Error_Msg_S
("control character not allowed in string");
1123 end Error_Bad_String_Char
;
1125 -------------------------------
1126 -- Error_Unterminated_String --
1127 -------------------------------
1129 procedure Error_Unterminated_String
is
1133 -- An interesting little refinement. Consider the following
1136 -- A := "this is an unterminated string;
1137 -- A := "this is an unterminated string &
1138 -- P(A, "this is a parameter that didn't get terminated);
1139 -- P("this is a parameter that didn't get terminated, A);
1141 -- We fiddle a little to do slightly better placement in these
1142 -- cases also if there is white space at the end of the line we
1143 -- place the flag at the start of this white space, not at the
1144 -- end. Note that we only have to test for blanks, since tabs
1145 -- aren't allowed in strings in the first place and would have
1146 -- caused an error message.
1148 -- Two more cases that we treat specially are:
1150 -- A := "this string uses the wrong terminator'
1151 -- A := "this string uses the wrong terminator' &
1153 -- In these cases we give a different error message as well
1155 -- We actually reposition the scan pointer to the point where we
1156 -- place the flag in these cases, since it seems a better bet on
1157 -- the original intention.
1159 while Source
(Scan_Ptr
- 1) = ' '
1160 or else Source
(Scan_Ptr
- 1) = '&'
1162 Scan_Ptr
:= Scan_Ptr
- 1;
1163 Unstore_String_Char
;
1166 -- Check for case of incorrect string terminator, but single quote
1167 -- is not considered incorrect if the opening terminator misused
1168 -- a single quote (error message already given).
1171 and then Source
(Scan_Ptr
- 1) = '''
1173 Unstore_String_Char
;
1175 ("incorrect string terminator character", Scan_Ptr
- 1);
1179 -- Backup over semicolon or right-paren/semicolon sequence
1181 if Source
(Scan_Ptr
- 1) = ';' then
1182 Scan_Ptr
:= Scan_Ptr
- 1;
1183 Unstore_String_Char
;
1185 if Source
(Scan_Ptr
- 1) = ')' then
1186 Scan_Ptr
:= Scan_Ptr
- 1;
1187 Unstore_String_Char
;
1191 -- See if there is a comma in the string, if so, guess that
1192 -- the first comma terminates the string.
1195 while S
< Scan_Ptr
loop
1196 if Source
(S
) = ',' then
1197 while Scan_Ptr
> S
loop
1198 Scan_Ptr
:= Scan_Ptr
- 1;
1199 Unstore_String_Char
;
1208 -- Now we have adjusted the scan pointer, give message
1210 Error_Msg_S
-- CODEFIX
1211 ("missing string quote");
1212 end Error_Unterminated_String
;
1218 procedure Set_String
is
1219 Slen
: constant Int
:= Int
(Scan_Ptr
- Token_Ptr
- 2);
1225 -- Token_Name is currently set to Error_Name. The following
1226 -- section of code resets Token_Name to the proper Name_Op_xx
1227 -- value if the string is a valid operator symbol, otherwise it is
1228 -- left set to Error_Name.
1231 C1
:= Source
(Token_Ptr
+ 1);
1235 Token_Name
:= Name_Op_Eq
;
1238 Token_Name
:= Name_Op_Gt
;
1241 Token_Name
:= Name_Op_Lt
;
1244 Token_Name
:= Name_Op_Add
;
1247 Token_Name
:= Name_Op_Subtract
;
1250 Token_Name
:= Name_Op_Concat
;
1253 Token_Name
:= Name_Op_Multiply
;
1256 Token_Name
:= Name_Op_Divide
;
1263 C1
:= Source
(Token_Ptr
+ 1);
1264 C2
:= Source
(Token_Ptr
+ 2);
1266 if C1
= '*' and then C2
= '*' then
1267 Token_Name
:= Name_Op_Expon
;
1272 Token_Name
:= Name_Op_Ne
;
1274 Token_Name
:= Name_Op_Le
;
1276 Token_Name
:= Name_Op_Ge
;
1279 elsif (C1
= 'O' or else C1
= 'o') and then -- OR
1280 (C2
= 'R' or else C2
= 'r')
1282 Token_Name
:= Name_Op_Or
;
1286 C1
:= Source
(Token_Ptr
+ 1);
1287 C2
:= Source
(Token_Ptr
+ 2);
1288 C3
:= Source
(Token_Ptr
+ 3);
1290 if (C1
= 'A' or else C1
= 'a') and then -- AND
1291 (C2
= 'N' or else C2
= 'n') and then
1292 (C3
= 'D' or else C3
= 'd')
1294 Token_Name
:= Name_Op_And
;
1296 elsif (C1
= 'A' or else C1
= 'a') and then -- ABS
1297 (C2
= 'B' or else C2
= 'b') and then
1298 (C3
= 'S' or else C3
= 's')
1300 Token_Name
:= Name_Op_Abs
;
1302 elsif (C1
= 'M' or else C1
= 'm') and then -- MOD
1303 (C2
= 'O' or else C2
= 'o') and then
1304 (C3
= 'D' or else C3
= 'd')
1306 Token_Name
:= Name_Op_Mod
;
1308 elsif (C1
= 'N' or else C1
= 'n') and then -- NOT
1309 (C2
= 'O' or else C2
= 'o') and then
1310 (C3
= 'T' or else C3
= 't')
1312 Token_Name
:= Name_Op_Not
;
1314 elsif (C1
= 'R' or else C1
= 'r') and then -- REM
1315 (C2
= 'E' or else C2
= 'e') and then
1316 (C3
= 'M' or else C3
= 'm')
1318 Token_Name
:= Name_Op_Rem
;
1320 elsif (C1
= 'X' or else C1
= 'x') and then -- XOR
1321 (C2
= 'O' or else C2
= 'o') and then
1322 (C3
= 'R' or else C3
= 'r')
1324 Token_Name
:= Name_Op_Xor
;
1329 -- If it is an operator symbol, then Token_Name is set. If it is
1330 -- some other string value, then Token_Name still contains
1333 if Token_Name
= Error_Name
then
1334 Token
:= Tok_String_Literal
;
1337 Token
:= Tok_Operator_Symbol
;
1341 -- Start of processing for Slit
1344 -- On entry, Scan_Ptr points to the opening character of the string
1345 -- which is either a percent, double quote, or apostrophe (single
1346 -- quote). The latter case is an error detected by the character
1349 String_Start
:= Scan_Ptr
;
1351 Delimiter
:= Source
(Scan_Ptr
);
1352 Accumulate_Checksum
(Delimiter
);
1355 Wide_Character_Found
:= False;
1356 Wide_Wide_Character_Found
:= False;
1357 Scan_Ptr
:= Scan_Ptr
+ 1;
1359 -- Loop to scan out characters of string literal
1362 C
:= Source
(Scan_Ptr
);
1364 if C
= Delimiter
then
1365 Accumulate_Checksum
(C
);
1366 Scan_Ptr
:= Scan_Ptr
+ 1;
1367 exit when Source
(Scan_Ptr
) /= Delimiter
;
1368 Code
:= Get_Char_Code
(C
);
1369 Accumulate_Checksum
(C
);
1370 Scan_Ptr
:= Scan_Ptr
+ 1;
1373 if C
= '"' and then Delimiter
= '%' then
1375 ("quote not allowed in percent delimited string");
1376 Code
:= Get_Char_Code
(C
);
1377 Scan_Ptr
:= Scan_Ptr
+ 1;
1379 elsif Start_Of_Wide_Character
then
1381 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1384 Error_Illegal_Wide_Character
;
1385 Code
:= Get_Char_Code
(' ');
1388 Accumulate_Checksum
(Code
);
1390 -- In Ada 95 mode we allow any wide characters in a string
1391 -- but in Ada 2005, the set of characters allowed has been
1392 -- restricted to graphic characters.
1394 if Ada_Version
>= Ada_2005
1395 and then Is_UTF_32_Non_Graphic
(UTF_32
(Code
))
1398 ("(Ada 2005) non-graphic character not permitted " &
1399 "in string literal", Wptr
);
1403 Accumulate_Checksum
(C
);
1405 if C
not in Graphic_Character
then
1406 if C
in Line_Terminator
then
1407 Error_Unterminated_String
;
1410 elsif C
in Upper_Half_Character
then
1411 if Ada_Version
= Ada_83
then
1412 Error_Bad_String_Char
;
1416 Error_Bad_String_Char
;
1420 Code
:= Get_Char_Code
(C
);
1421 Scan_Ptr
:= Scan_Ptr
+ 1;
1425 Store_String_Char
(Code
);
1427 if not In_Character_Range
(Code
) then
1428 if In_Wide_Character_Range
(Code
) then
1429 Wide_Character_Found
:= True;
1431 Wide_Wide_Character_Found
:= True;
1436 String_Literal_Id
:= End_String
;
1441 ----------------------------------
1442 -- Skip_Other_Format_Characters --
1443 ----------------------------------
1445 procedure Skip_Other_Format_Characters
is
1451 while Start_Of_Wide_Character
loop
1453 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1455 if not Is_UTF_32_Other
(UTF_32
(Code
)) then
1460 end Skip_Other_Format_Characters
;
1462 -----------------------------
1463 -- Start_Of_Wide_Character --
1464 -----------------------------
1466 function Start_Of_Wide_Character
return Boolean is
1467 C
: constant Character := Source
(Scan_Ptr
);
1470 -- ESC encoding method with ESC present
1473 and then Wide_Character_Encoding_Method
in WC_ESC_Encoding_Method
1477 -- Upper half character with upper half encoding
1479 elsif C
in Upper_Half_Character
and then Upper_Half_Encoding
then
1482 -- Brackets encoding
1485 and then Source
(Scan_Ptr
+ 1) = '"'
1486 and then Identifier_Char
(Source
(Scan_Ptr
+ 2))
1490 -- Not the start of a wide character
1495 end Start_Of_Wide_Character
;
1497 -- Start of processing for Scan
1500 Prev_Token
:= Token
;
1501 Prev_Token_Ptr
:= Token_Ptr
;
1502 Token_Name
:= Error_Name
;
1504 -- The following loop runs more than once only if a format effector
1505 -- (tab, vertical tab, form feed, line feed, carriage return) is
1506 -- encountered and skipped, or some error situation, such as an
1507 -- illegal character, is encountered.
1509 <<Scan_Next_Character
>>
1512 -- Skip past blanks, loop is opened up for speed
1514 while Source
(Scan_Ptr
) = ' ' loop
1515 if Source
(Scan_Ptr
+ 1) /= ' ' then
1516 Scan_Ptr
:= Scan_Ptr
+ 1;
1520 if Source
(Scan_Ptr
+ 2) /= ' ' then
1521 Scan_Ptr
:= Scan_Ptr
+ 2;
1525 if Source
(Scan_Ptr
+ 3) /= ' ' then
1526 Scan_Ptr
:= Scan_Ptr
+ 3;
1530 if Source
(Scan_Ptr
+ 4) /= ' ' then
1531 Scan_Ptr
:= Scan_Ptr
+ 4;
1535 if Source
(Scan_Ptr
+ 5) /= ' ' then
1536 Scan_Ptr
:= Scan_Ptr
+ 5;
1540 if Source
(Scan_Ptr
+ 6) /= ' ' then
1541 Scan_Ptr
:= Scan_Ptr
+ 6;
1545 if Source
(Scan_Ptr
+ 7) /= ' ' then
1546 Scan_Ptr
:= Scan_Ptr
+ 7;
1550 Scan_Ptr
:= Scan_Ptr
+ 8;
1553 -- We are now at a non-blank character, which is the first character
1554 -- of the token we will scan, and hence the value of Token_Ptr.
1556 Token_Ptr
:= Scan_Ptr
;
1558 -- Here begins the main case statement which transfers control on the
1559 -- basis of the non-blank character we have encountered.
1561 case Source
(Scan_Ptr
) is
1563 -- Line terminator characters
1565 when CR | LF | FF | VT
=>
1566 goto Scan_Line_Terminator
;
1568 -- Horizontal tab, just skip past it
1575 Scan_Ptr
:= Scan_Ptr
+ 1;
1577 -- End of file character, treated as an end of file only if it is
1578 -- the last character in the buffer, otherwise it is ignored.
1581 if Scan_Ptr
= Source_Last
(Current_Source_File
) then
1591 Scan_Ptr
:= Scan_Ptr
+ 1;
1597 Accumulate_Checksum
('&');
1599 if Source
(Scan_Ptr
+ 1) = '&' then
1600 Error_Msg_S
-- CODEFIX
1601 ("'&'& should be `AND THEN`");
1602 Scan_Ptr
:= Scan_Ptr
+ 2;
1607 Scan_Ptr
:= Scan_Ptr
+ 1;
1608 Token
:= Tok_Ampersand
;
1612 -- Asterisk (can be multiplication operator or double asterisk which
1613 -- is the exponentiation compound delimiter).
1616 Accumulate_Checksum
('*');
1618 if Source
(Scan_Ptr
+ 1) = '*' then
1619 Accumulate_Checksum
('*');
1620 Scan_Ptr
:= Scan_Ptr
+ 2;
1621 Token
:= Tok_Double_Asterisk
;
1625 Scan_Ptr
:= Scan_Ptr
+ 1;
1626 Token
:= Tok_Asterisk
;
1630 -- Colon, which can either be an isolated colon, or part of an
1631 -- assignment compound delimiter.
1634 Accumulate_Checksum
(':');
1636 if Double_Char_Token
('=') then
1637 Token
:= Tok_Colon_Equal
;
1640 Style
.Check_Colon_Equal
;
1645 elsif Source
(Scan_Ptr
+ 1) = '-'
1646 and then Source
(Scan_Ptr
+ 2) /= '-'
1648 Token
:= Tok_Colon_Equal
;
1649 Error_Msg
-- CODEFIX
1650 (":- should be :=", Scan_Ptr
);
1651 Scan_Ptr
:= Scan_Ptr
+ 2;
1655 Scan_Ptr
:= Scan_Ptr
+ 1;
1668 Accumulate_Checksum
('(');
1669 Scan_Ptr
:= Scan_Ptr
+ 1;
1670 Token
:= Tok_Left_Paren
;
1673 Style
.Check_Left_Paren
;
1681 if Source
(Scan_Ptr
+ 1) = '"' then
1682 goto Scan_Wide_Character
;
1685 Error_Msg_S
("illegal character, replaced by ""(""");
1686 Scan_Ptr
:= Scan_Ptr
+ 1;
1687 Token
:= Tok_Left_Paren
;
1694 Error_Msg_S
("illegal character, replaced by ""(""");
1695 Scan_Ptr
:= Scan_Ptr
+ 1;
1696 Token
:= Tok_Left_Paren
;
1702 Accumulate_Checksum
(',');
1703 Scan_Ptr
:= Scan_Ptr
+ 1;
1712 -- Dot, which is either an isolated period, or part of a double dot
1713 -- compound delimiter sequence. We also check for the case of a
1714 -- digit following the period, to give a better error message.
1717 Accumulate_Checksum
('.');
1719 if Double_Char_Token
('.') then
1720 Token
:= Tok_Dot_Dot
;
1723 Style
.Check_Dot_Dot
;
1728 elsif Source
(Scan_Ptr
+ 1) in '0' .. '9' then
1729 Error_Msg_S
("numeric literal cannot start with point");
1730 Scan_Ptr
:= Scan_Ptr
+ 1;
1733 Scan_Ptr
:= Scan_Ptr
+ 1;
1738 -- Equal, which can either be an equality operator, or part of the
1739 -- arrow (=>) compound delimiter.
1742 Accumulate_Checksum
('=');
1744 if Double_Char_Token
('>') then
1748 Style
.Check_Arrow
(Inside_Depends
);
1753 elsif Source
(Scan_Ptr
+ 1) = '=' then
1754 Error_Msg_S
-- CODEFIX
1756 Scan_Ptr
:= Scan_Ptr
+ 1;
1759 Scan_Ptr
:= Scan_Ptr
+ 1;
1763 -- Greater than, which can be a greater than operator, greater than
1764 -- or equal operator, or first character of a right label bracket.
1767 Accumulate_Checksum
('>');
1769 if Double_Char_Token
('=') then
1770 Token
:= Tok_Greater_Equal
;
1773 elsif Double_Char_Token
('>') then
1774 Token
:= Tok_Greater_Greater
;
1778 Scan_Ptr
:= Scan_Ptr
+ 1;
1779 Token
:= Tok_Greater
;
1783 -- Less than, which can be a less than operator, less than or equal
1784 -- operator, or the first character of a left label bracket, or the
1785 -- first character of a box (<>) compound delimiter.
1788 Accumulate_Checksum
('<');
1790 if Double_Char_Token
('=') then
1791 Token
:= Tok_Less_Equal
;
1794 elsif Double_Char_Token
('>') then
1803 elsif Double_Char_Token
('<') then
1804 Token
:= Tok_Less_Less
;
1808 Scan_Ptr
:= Scan_Ptr
+ 1;
1813 -- Minus, which is either a subtraction operator, or the first
1814 -- character of double minus starting a comment
1816 when '-' => Minus_Case
: begin
1817 if Source
(Scan_Ptr
+ 1) = '>' then
1818 Error_Msg_S
("invalid token");
1819 Scan_Ptr
:= Scan_Ptr
+ 2;
1823 elsif Source
(Scan_Ptr
+ 1) /= '-' then
1824 Accumulate_Checksum
('-');
1825 Scan_Ptr
:= Scan_Ptr
+ 1;
1831 else -- Source (Scan_Ptr + 1) = '-' then
1833 Style
.Check_Comment
;
1836 Scan_Ptr
:= Scan_Ptr
+ 2;
1838 -- If we are in preprocessor mode with Replace_In_Comments set,
1839 -- then we return the "--" as a token on its own.
1841 if Replace_In_Comments
then
1842 Token
:= Tok_Comment
;
1846 -- Otherwise scan out the comment
1848 Start_Of_Comment
:= Scan_Ptr
;
1850 -- Loop to scan comment (this loop runs more than once only if
1851 -- a horizontal tab or other non-graphic character is scanned)
1854 -- Scan to non graphic character (opened up for speed)
1856 -- Note that we just eat left brackets, which means that
1857 -- bracket notation cannot be used for end of line
1858 -- characters in comments. This seems a reasonable choice,
1859 -- since no one would ever use brackets notation in a real
1860 -- program in this situation, and if we allow brackets
1861 -- notation, we forbid some valid comments which contain a
1862 -- brackets sequence that happens to match an end of line
1866 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1867 Scan_Ptr
:= Scan_Ptr
+ 1;
1868 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1869 Scan_Ptr
:= Scan_Ptr
+ 1;
1870 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1871 Scan_Ptr
:= Scan_Ptr
+ 1;
1872 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1873 Scan_Ptr
:= Scan_Ptr
+ 1;
1874 exit when Source
(Scan_Ptr
) not in Graphic_Character
;
1875 Scan_Ptr
:= Scan_Ptr
+ 1;
1878 -- Keep going if horizontal tab
1880 if Source
(Scan_Ptr
) = HT
then
1885 Scan_Ptr
:= Scan_Ptr
+ 1;
1887 -- Terminate scan of comment if line terminator
1889 elsif Source
(Scan_Ptr
) in Line_Terminator
then
1892 -- Terminate scan of comment if end of file encountered
1893 -- (embedded EOF character or real last character in file)
1895 elsif Source
(Scan_Ptr
) = EOF
then
1898 -- If we have a wide character, we have to scan it out,
1899 -- because it might be a legitimate line terminator
1901 elsif Start_Of_Wide_Character
then
1903 Wptr
: constant Source_Ptr
:= Scan_Ptr
;
1908 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
1910 -- If not well formed wide character, then just skip
1911 -- past it and ignore it.
1914 Scan_Ptr
:= Wptr
+ 1;
1916 -- If UTF_32 terminator, terminate comment scan
1918 elsif Is_UTF_32_Line_Terminator
(UTF_32
(Code
)) then
1924 -- Keep going if character in 80-FF range, or is ESC. These
1925 -- characters are allowed in comments by RM-2.1(1), 2.7(2).
1926 -- They are allowed even in Ada 83 mode according to the
1927 -- approved AI. ESC was added to the AI in June 93.
1929 elsif Source
(Scan_Ptr
) in Upper_Half_Character
1930 or else Source
(Scan_Ptr
) = ESC
1932 Scan_Ptr
:= Scan_Ptr
+ 1;
1934 -- Otherwise we have an illegal comment character, ignore
1935 -- this error in relaxed semantics mode.
1938 if Relaxed_RM_Semantics
then
1939 Scan_Ptr
:= Scan_Ptr
+ 1;
1941 Error_Illegal_Character
;
1946 -- Note that, except when comments are tokens, we do NOT
1947 -- execute a return here, instead we fall through to reexecute
1948 -- the scan loop to look for a token.
1950 if Comment_Is_Token
then
1951 Name_Len
:= Integer (Scan_Ptr
- Start_Of_Comment
);
1952 Name_Buffer
(1 .. Name_Len
) :=
1953 String (Source
(Start_Of_Comment
.. Scan_Ptr
- 1));
1954 Comment_Id
:= Name_Find
;
1955 Token
:= Tok_Comment
;
1959 -- If the SPARK restriction is set for this unit, then generate
1960 -- a token Tok_SPARK_Hide for a SPARK HIDE directive.
1962 if Restriction_Check_Required
(SPARK_05
)
1963 and then Source
(Start_Of_Comment
) = '#'
1966 Scan_SPARK_Ptr
: Source_Ptr
;
1969 Scan_SPARK_Ptr
:= Start_Of_Comment
+ 1;
1973 while Source
(Scan_SPARK_Ptr
) = ' '
1974 or else Source
(Scan_SPARK_Ptr
) = HT
1976 Scan_SPARK_Ptr
:= Scan_SPARK_Ptr
+ 1;
1979 -- Recognize HIDE directive. SPARK input cannot be
1980 -- encoded as wide characters, so only deal with
1981 -- lower/upper case.
1983 if (Source
(Scan_SPARK_Ptr
) = 'h'
1984 or else Source
(Scan_SPARK_Ptr
) = 'H')
1985 and then (Source
(Scan_SPARK_Ptr
+ 1) = 'i'
1986 or else Source
(Scan_SPARK_Ptr
+ 1) = 'I')
1987 and then (Source
(Scan_SPARK_Ptr
+ 2) = 'd'
1988 or else Source
(Scan_SPARK_Ptr
+ 2) = 'D')
1989 and then (Source
(Scan_SPARK_Ptr
+ 3) = 'e'
1990 or else Source
(Scan_SPARK_Ptr
+ 3) = 'E')
1991 and then (Source
(Scan_SPARK_Ptr
+ 4) = ' '
1992 or else Source
(Scan_SPARK_Ptr
+ 4) = HT
)
1994 Token
:= Tok_SPARK_Hide
;
2002 -- Double quote or percent starting a string literal
2009 -- Apostrophe. This can either be the start of a character literal,
2010 -- or an isolated apostrophe used in a qualified expression or an
2011 -- attribute. In the following:
2013 -- A := CHARACTER'('A');
2015 -- the first apostrophe is treated as an isolated apostrophe, and the
2016 -- second one is treated as the start of the character literal 'A'.
2017 -- Note that RM-2.2(7) does not require a separator between "'" and
2018 -- "(" in the above, so we cannot use lookahead to distinguish the
2019 -- cases; we use look-back instead. Analysis of the grammar shows
2020 -- that some tokens can be followed by an apostrophe, and some by a
2021 -- character literal, but none by both. Some cannot be followed by
2022 -- either, so it doesn't matter what we do in those cases, except to
2023 -- get good error behavior.
2025 when ''' => Char_Literal_Case
: declare
2030 Accumulate_Checksum
(''');
2031 Scan_Ptr
:= Scan_Ptr
+ 1;
2033 -- Distinguish between apostrophe and character literal. It's an
2034 -- apostrophe if the previous token is one of the following.
2035 -- Reserved words are included for things like A.all'Address and
2036 -- T'Digits'Img. Strings literals are included for things like
2037 -- "abs"'Address. Other literals are included to give better error
2038 -- behavior for illegal cases like 123'Img.
2040 if Prev_Token
= Tok_Identifier
2041 or else Prev_Token
= Tok_Right_Paren
2042 or else Prev_Token
= Tok_All
2043 or else Prev_Token
= Tok_Delta
2044 or else Prev_Token
= Tok_Digits
2045 or else Prev_Token
= Tok_Project
2046 or else Prev_Token
in Token_Class_Literal
2048 Token
:= Tok_Apostrophe
;
2051 Style
.Check_Apostrophe
;
2056 -- Otherwise the apostrophe starts a character literal
2059 -- Case of wide character literal
2061 if Start_Of_Wide_Character
then
2063 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2064 Accumulate_Checksum
(Code
);
2067 Error_Illegal_Wide_Character
;
2068 Code
:= Character'Pos (' ');
2070 -- In Ada 95 mode we allow any wide character in a character
2071 -- literal, but in Ada 2005, the set of characters allowed
2072 -- is restricted to graphic characters.
2074 elsif Ada_Version
>= Ada_2005
2075 and then Is_UTF_32_Non_Graphic
(UTF_32
(Code
))
2077 Error_Msg
-- CODEFIX????
2078 ("(Ada 2005) non-graphic character not permitted " &
2079 "in character literal", Wptr
);
2082 if Source
(Scan_Ptr
) /= ''' then
2083 Error_Msg_S
("missing apostrophe");
2085 Scan_Ptr
:= Scan_Ptr
+ 1;
2088 -- If we do not find a closing quote in the expected place then
2089 -- assume that we have a misguided attempt at a string literal.
2091 -- However, if previous token is RANGE, then we return an
2092 -- apostrophe instead since this gives better error recovery
2094 elsif Source
(Scan_Ptr
+ 1) /= ''' then
2095 if Prev_Token
= Tok_Range
then
2096 Token
:= Tok_Apostrophe
;
2100 Scan_Ptr
:= Scan_Ptr
- 1;
2102 ("strings are delimited by double quote character");
2108 -- Otherwise we have a (non-wide) character literal
2111 Accumulate_Checksum
(Source
(Scan_Ptr
));
2113 if Source
(Scan_Ptr
) not in Graphic_Character
then
2114 if Source
(Scan_Ptr
) in Upper_Half_Character
then
2115 if Ada_Version
= Ada_83
then
2116 Error_Illegal_Character
;
2120 Error_Illegal_Character
;
2124 Code
:= Get_Char_Code
(Source
(Scan_Ptr
));
2125 Scan_Ptr
:= Scan_Ptr
+ 2;
2128 -- Fall through here with Scan_Ptr updated past the closing
2129 -- quote, and Code set to the Char_Code value for the literal
2131 Accumulate_Checksum
(''');
2132 Token
:= Tok_Char_Literal
;
2133 Set_Character_Literal_Name
(Code
);
2134 Token_Name
:= Name_Find
;
2135 Character_Code
:= Code
;
2139 end Char_Literal_Case
;
2141 -- Right parenthesis
2144 Accumulate_Checksum
(')');
2145 Scan_Ptr
:= Scan_Ptr
+ 1;
2146 Token
:= Tok_Right_Paren
;
2149 Style
.Check_Right_Paren
;
2154 -- Right bracket or right brace, treated as right paren
2157 Error_Msg_S
("illegal character, replaced by "")""");
2158 Scan_Ptr
:= Scan_Ptr
+ 1;
2159 Token
:= Tok_Right_Paren
;
2162 -- Slash (can be division operator or first character of not equal)
2165 Accumulate_Checksum
('/');
2167 if Double_Char_Token
('=') then
2168 Token
:= Tok_Not_Equal
;
2171 Scan_Ptr
:= Scan_Ptr
+ 1;
2179 Accumulate_Checksum
(';');
2180 Scan_Ptr
:= Scan_Ptr
+ 1;
2181 Token
:= Tok_Semicolon
;
2184 Style
.Check_Semicolon
;
2191 when '|' => Vertical_Bar_Case
: begin
2192 Accumulate_Checksum
('|');
2194 -- Special check for || to give nice message
2196 if Source
(Scan_Ptr
+ 1) = '|' then
2197 Error_Msg_S
-- CODEFIX
2198 ("""'|'|"" should be `OR ELSE`");
2199 Scan_Ptr
:= Scan_Ptr
+ 2;
2204 Scan_Ptr
:= Scan_Ptr
+ 1;
2205 Token
:= Tok_Vertical_Bar
;
2208 Style
.Check_Vertical_Bar
;
2214 end Vertical_Bar_Case
;
2216 -- Exclamation, replacement character for vertical bar
2218 when '!' => Exclamation_Case
: begin
2219 Accumulate_Checksum
('!');
2221 if Source
(Scan_Ptr
+ 1) = '=' then
2222 Error_Msg_S
-- CODEFIX
2223 ("'!= should be /=");
2224 Scan_Ptr
:= Scan_Ptr
+ 2;
2225 Token
:= Tok_Not_Equal
;
2229 Scan_Ptr
:= Scan_Ptr
+ 1;
2230 Token
:= Tok_Vertical_Bar
;
2234 end Exclamation_Case
;
2238 when '+' => Plus_Case
: begin
2239 Accumulate_Checksum
('+');
2240 Scan_Ptr
:= Scan_Ptr
+ 1;
2245 -- Digits starting a numeric literal
2249 -- First a bit of a scan ahead to see if we have a case of an
2250 -- identifier starting with a digit (remembering exponent case).
2253 C
: constant Character := Source
(Scan_Ptr
+ 1);
2256 -- OK literal if digit followed by digit or underscore
2258 if C
in '0' .. '9' or else C
= '_' then
2261 -- OK literal if digit not followed by identifier char
2263 elsif not Identifier_Char
(C
) then
2266 -- OK literal if digit followed by e/E followed by digit/sign.
2267 -- We also allow underscore after the E, which is an error, but
2268 -- better handled by Nlit than deciding this is an identifier.
2270 elsif (C
= 'e' or else C
= 'E')
2271 and then (Source
(Scan_Ptr
+ 2) in '0' .. '9'
2272 or else Source
(Scan_Ptr
+ 2) = '+'
2273 or else Source
(Scan_Ptr
+ 2) = '-'
2274 or else Source
(Scan_Ptr
+ 2) = '_')
2278 -- Here we have what really looks like an identifier that
2279 -- starts with a digit, so give error msg.
2282 Error_Msg_S
("identifier may not start with digit");
2284 Underline_Found
:= False;
2285 Name_Buffer
(1) := Source
(Scan_Ptr
);
2286 Accumulate_Checksum
(Name_Buffer
(1));
2287 Scan_Ptr
:= Scan_Ptr
+ 1;
2288 goto Scan_Identifier
;
2292 -- Here we have an OK integer literal
2296 -- Check for proper delimiter, ignoring other format characters
2298 Skip_Other_Format_Characters
;
2300 if Identifier_Char
(Source
(Scan_Ptr
)) then
2302 ("delimiter required between literal and identifier");
2308 -- Lower case letters
2312 Underline_Found
:= False;
2313 Name_Buffer
(1) := Source
(Scan_Ptr
);
2314 Accumulate_Checksum
(Name_Buffer
(1));
2315 Scan_Ptr
:= Scan_Ptr
+ 1;
2316 goto Scan_Identifier
;
2318 -- Upper case letters
2322 Underline_Found
:= False;
2324 Character'Val (Character'Pos (Source
(Scan_Ptr
)) + 32);
2325 Accumulate_Checksum
(Name_Buffer
(1));
2326 Scan_Ptr
:= Scan_Ptr
+ 1;
2327 goto Scan_Identifier
;
2329 -- Underline character
2332 if Special_Characters
('_') then
2333 Token_Ptr
:= Scan_Ptr
;
2334 Scan_Ptr
:= Scan_Ptr
+ 1;
2335 Token
:= Tok_Special
;
2336 Special_Character
:= '_';
2340 Error_Msg_S
("identifier cannot start with underline");
2342 Name_Buffer
(1) := '_';
2343 Scan_Ptr
:= Scan_Ptr
+ 1;
2344 Underline_Found
:= False;
2345 goto Scan_Identifier
;
2347 -- Space (not possible, because we scanned past blanks)
2350 raise Program_Error
;
2352 -- Characters in top half of ASCII 8-bit chart
2354 when Upper_Half_Character
=>
2356 -- Wide character case
2358 if Upper_Half_Encoding
then
2359 goto Scan_Wide_Character
;
2361 -- Otherwise we have OK Latin-1 character
2364 -- Upper half characters may possibly be identifier letters
2365 -- but can never be digits, so Identifier_Char can be used to
2366 -- test for a valid start of identifier character.
2368 if Identifier_Char
(Source
(Scan_Ptr
)) then
2370 Underline_Found
:= False;
2371 goto Scan_Identifier
;
2373 Error_Illegal_Character
;
2379 -- ESC character, possible start of identifier if wide characters
2380 -- using ESC encoding are allowed in identifiers, which we can
2381 -- tell by looking at the Identifier_Char flag for ESC, which is
2382 -- only true if these conditions are met. In Ada 2005 mode, may
2383 -- also be valid UTF_32 space or line terminator character.
2385 if Identifier_Char
(ESC
) then
2387 goto Scan_Wide_Character
;
2389 Error_Illegal_Character
;
2392 -- Invalid control characters
2421 Error_Illegal_Character
;
2423 -- Invalid graphic characters
2425 when '#' |
'$' |
'?' |
'@' |
'`' |
'\' |
'^' |
'~' =>
2427 -- If Set_Special_Character has been called for this character,
2428 -- set Scans.Special_Character and return a Special token.
2430 if Special_Characters
(Source
(Scan_Ptr
)) then
2431 Token_Ptr
:= Scan_Ptr
;
2432 Token
:= Tok_Special
;
2433 Special_Character
:= Source
(Scan_Ptr
);
2434 Scan_Ptr
:= Scan_Ptr
+ 1;
2437 -- Check for something looking like a preprocessor directive
2439 elsif Source
(Scan_Ptr
) = '#'
2440 and then (Source
(Scan_Ptr
+ 1 .. Scan_Ptr
+ 2) = "if"
2442 Source
(Scan_Ptr
+ 1 .. Scan_Ptr
+ 5) = "elsif"
2444 Source
(Scan_Ptr
+ 1 .. Scan_Ptr
+ 4) = "else"
2446 Source
(Scan_Ptr
+ 1 .. Scan_Ptr
+ 3) = "end")
2449 ("preprocessor directive ignored, preprocessor not active");
2451 -- Skip to end of line
2454 if Source
(Scan_Ptr
) in Graphic_Character
2456 Source
(Scan_Ptr
) = HT
2458 Scan_Ptr
:= Scan_Ptr
+ 1;
2460 -- Done if line terminator or EOF
2462 elsif Source
(Scan_Ptr
) in Line_Terminator
2464 Source
(Scan_Ptr
) = EOF
2468 -- If we have a wide character, we have to scan it out,
2469 -- because it might be a legitimate line terminator
2471 elsif Start_Of_Wide_Character
then
2473 Wptr
: constant Source_Ptr
:= Scan_Ptr
;
2478 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2480 -- If not well formed wide character, then just skip
2481 -- past it and ignore it.
2484 Scan_Ptr
:= Wptr
+ 1;
2486 -- If UTF_32 terminator, terminate comment scan
2488 elsif Is_UTF_32_Line_Terminator
(UTF_32
(Code
)) then
2494 -- Else keep going (don't worry about bad comment chars
2495 -- in this context, we just want to find the end of line.
2498 Scan_Ptr
:= Scan_Ptr
+ 1;
2502 -- Otherwise, this is an illegal character
2505 Error_Illegal_Character
;
2508 -- End switch on non-blank character
2512 -- End loop past format effectors. The exit from this loop is by
2513 -- executing a return statement following completion of token scan
2514 -- (control never falls out of this loop to the code which follows)
2518 -- Wide_Character scanning routine. On entry we have encountered the
2519 -- initial character of a wide character sequence.
2521 <<Scan_Wide_Character
>>
2529 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2531 -- If bad wide character, signal error and continue scan
2534 Error_Illegal_Wide_Character
;
2535 goto Scan_Next_Character
;
2538 Cat
:= Get_Category
(UTF_32
(Code
));
2540 -- If OK letter, reset scan ptr and go scan identifier
2542 if Is_UTF_32_Letter
(Cat
) then
2545 Underline_Found
:= False;
2546 goto Scan_Identifier
;
2548 -- If OK wide space, ignore and keep scanning (we do not include
2549 -- any ignored spaces in checksum)
2551 elsif Is_UTF_32_Space
(Cat
) then
2552 goto Scan_Next_Character
;
2554 -- If other format character, ignore and keep scanning (again we
2555 -- do not include in the checksum) (this is for AI-0079).
2557 elsif Is_UTF_32_Other
(Cat
) then
2558 goto Scan_Next_Character
;
2560 -- If OK wide line terminator, terminate current line
2562 elsif Is_UTF_32_Line_Terminator
(UTF_32
(Code
)) then
2564 goto Scan_Line_Terminator
;
2566 -- Punctuation is an error (at start of identifier)
2568 elsif Is_UTF_32_Punctuation
(Cat
) then
2569 Error_Msg
("identifier cannot start with punctuation", Wptr
);
2572 Underline_Found
:= False;
2573 goto Scan_Identifier
;
2575 -- Mark character is an error (at start of identifier)
2577 elsif Is_UTF_32_Mark
(Cat
) then
2578 Error_Msg
("identifier cannot start with mark character", Wptr
);
2581 Underline_Found
:= False;
2582 goto Scan_Identifier
;
2584 -- Extended digit character is an error. Could be bad start of
2585 -- identifier or bad literal. Not worth doing too much to try to
2586 -- distinguish these cases, but we will do a little bit.
2588 elsif Is_UTF_32_Digit
(Cat
) then
2590 ("identifier cannot start with digit character", Wptr
);
2593 Underline_Found
:= False;
2594 goto Scan_Identifier
;
2596 -- All other wide characters are illegal here
2599 Error_Illegal_Wide_Character
;
2600 goto Scan_Next_Character
;
2604 -- Routine to scan line terminator. On entry Scan_Ptr points to a
2605 -- character which is one of FF,LR,CR,VT, or one of the wide characters
2606 -- that is treated as a line terminator.
2608 <<Scan_Line_Terminator
>>
2610 -- Check line too long
2614 -- Set Token_Ptr, if End_Of_Line is a token, for the case when it is
2617 if End_Of_Line_Is_Token
then
2618 Token_Ptr
:= Scan_Ptr
;
2625 Skip_Line_Terminators
(Scan_Ptr
, Physical
);
2627 -- If we are at start of physical line, update scan pointers to
2628 -- reflect the start of the new line.
2631 Current_Line_Start
:= Scan_Ptr
;
2632 Start_Column
:= Set_Start_Column
;
2633 First_Non_Blank_Location
:= Scan_Ptr
;
2635 -- If End_Of_Line is a token, we return it as it is a
2638 if End_Of_Line_Is_Token
then
2639 Token
:= Tok_End_Of_Line
;
2645 goto Scan_Next_Character
;
2647 -- Identifier scanning routine. On entry, some initial characters of
2648 -- the identifier may have already been stored in Name_Buffer. If so,
2649 -- Name_Len has the number of characters stored, otherwise Name_Len is
2650 -- set to zero on entry. Underline_Found is also set False on entry.
2654 -- This loop scans as fast as possible past lower half letters and
2655 -- digits, which we expect to be the most common characters.
2658 if Source
(Scan_Ptr
) in 'a' .. 'z'
2659 or else Source
(Scan_Ptr
) in '0' .. '9'
2661 Name_Buffer
(Name_Len
+ 1) := Source
(Scan_Ptr
);
2662 Accumulate_Checksum
(Source
(Scan_Ptr
));
2664 elsif Source
(Scan_Ptr
) in 'A' .. 'Z' then
2665 Name_Buffer
(Name_Len
+ 1) :=
2666 Character'Val (Character'Pos (Source
(Scan_Ptr
)) + 32);
2667 Accumulate_Checksum
(Name_Buffer
(Name_Len
+ 1));
2673 Underline_Found
:= False;
2674 Scan_Ptr
:= Scan_Ptr
+ 1;
2675 Name_Len
:= Name_Len
+ 1;
2678 -- If we fall through, then we have encountered either an underline
2679 -- character, or an extended identifier character (i.e. one from the
2680 -- upper half), or a wide character, or an identifier terminator. The
2681 -- initial test speeds us up in the most common case where we have
2682 -- an identifier terminator. Note that ESC is an identifier character
2683 -- only if a wide character encoding method that uses ESC encoding
2684 -- is active, so if we find an ESC character we know that we have a
2687 if Identifier_Char
(Source
(Scan_Ptr
))
2688 or else (Source
(Scan_Ptr
) in Upper_Half_Character
2689 and then Upper_Half_Encoding
)
2691 -- Case of underline
2693 if Source
(Scan_Ptr
) = '_' then
2694 Accumulate_Checksum
('_');
2696 if Underline_Found
then
2697 Error_No_Double_Underline
;
2699 Underline_Found
:= True;
2700 Name_Len
:= Name_Len
+ 1;
2701 Name_Buffer
(Name_Len
) := '_';
2704 Scan_Ptr
:= Scan_Ptr
+ 1;
2705 goto Scan_Identifier
;
2707 -- Upper half character
2709 elsif Source
(Scan_Ptr
) in Upper_Half_Character
2710 and then not Upper_Half_Encoding
2712 Accumulate_Checksum
(Source
(Scan_Ptr
));
2713 Store_Encoded_Character
2714 (Get_Char_Code
(Fold_Lower
(Source
(Scan_Ptr
))));
2715 Scan_Ptr
:= Scan_Ptr
+ 1;
2716 Underline_Found
:= False;
2717 goto Scan_Identifier
;
2719 -- Left bracket not followed by a quote terminates an identifier.
2720 -- This is an error, but we don't want to give a junk error msg
2721 -- about wide characters in this case.
2723 elsif Source
(Scan_Ptr
) = '['
2724 and then Source
(Scan_Ptr
+ 1) /= '"'
2728 -- We know we have a wide character encoding here (the current
2729 -- character is either ESC, left bracket, or an upper half
2730 -- character depending on the encoding method).
2733 -- Scan out the wide character and insert the appropriate
2734 -- encoding into the name table entry for the identifier.
2744 Scan_Wide
(Source
, Scan_Ptr
, Code
, Err
);
2746 -- If error, signal error
2749 Error_Illegal_Wide_Character
;
2751 -- If the character scanned is a normal identifier
2752 -- character, then we treat it that way.
2754 elsif In_Character_Range
(Code
)
2755 and then Identifier_Char
(Get_Character
(Code
))
2757 Chr
:= Get_Character
(Code
);
2758 Accumulate_Checksum
(Chr
);
2759 Store_Encoded_Character
2760 (Get_Char_Code
(Fold_Lower
(Chr
)));
2761 Underline_Found
:= False;
2763 -- Here if not a normal identifier character
2766 Cat
:= Get_Category
(UTF_32
(Code
));
2768 -- Wide character in Unicode category "Other, Format"
2769 -- is not accepted in an identifier. This is because it
2770 -- it is considered a security risk (AI-0091).
2772 -- However, it is OK for such a character to appear at
2773 -- the end of an identifier.
2775 if Is_UTF_32_Other
(Cat
) then
2776 if not Identifier_Char
(Source
(Scan_Ptr
)) then
2777 goto Scan_Identifier_Complete
;
2780 ("identifier cannot contain other_format "
2781 & "character", Wptr
);
2782 goto Scan_Identifier
;
2785 -- Wide character in category Separator,Space terminates
2787 elsif Is_UTF_32_Space
(Cat
) then
2788 goto Scan_Identifier_Complete
;
2791 -- Here if wide character is part of the identifier
2793 -- Make sure we are allowing wide characters in
2794 -- identifiers. Note that we allow wide character
2795 -- notation for an OK identifier character. This in
2796 -- particular allows bracket or other notation to be
2797 -- used for upper half letters.
2799 -- Wide characters are always allowed in Ada 2005
2801 if Identifier_Character_Set
/= 'w'
2802 and then Ada_Version
< Ada_2005
2805 ("wide character not allowed in identifier", Wptr
);
2808 -- If OK letter, store it folding to upper case. Note
2809 -- that we include the folded letter in the checksum.
2811 if Is_UTF_32_Letter
(Cat
) then
2813 Char_Code
(UTF_32_To_Upper_Case
(UTF_32
(Code
)));
2814 Accumulate_Checksum
(Code
);
2815 Store_Encoded_Character
(Code
);
2816 Underline_Found
:= False;
2818 -- If OK extended digit or mark, then store it
2820 elsif Is_UTF_32_Digit
(Cat
)
2821 or else Is_UTF_32_Mark
(Cat
)
2823 Accumulate_Checksum
(Code
);
2824 Store_Encoded_Character
(Code
);
2825 Underline_Found
:= False;
2827 -- Wide punctuation is also stored, but counts as an
2828 -- underline character for error checking purposes.
2830 elsif Is_UTF_32_Punctuation
(Cat
) then
2831 Accumulate_Checksum
(Code
);
2833 if Underline_Found
then
2835 Cend
: constant Source_Ptr
:= Scan_Ptr
;
2838 Error_No_Double_Underline
;
2843 Store_Encoded_Character
(Code
);
2844 Underline_Found
:= True;
2847 -- Any other wide character is not acceptable
2851 ("invalid wide character in identifier", Wptr
);
2855 goto Scan_Identifier
;
2860 -- Scan of identifier is complete. The identifier is stored in
2861 -- Name_Buffer, and Scan_Ptr points past the last character.
2863 <<Scan_Identifier_Complete
>>
2864 Token_Name
:= Name_Find
;
2866 -- Check for identifier ending with underline or punctuation char
2868 if Underline_Found
then
2869 Underline_Found
:= False;
2871 if Source
(Scan_Ptr
- 1) = '_' then
2873 ("identifier cannot end with underline", Scan_Ptr
- 1);
2876 ("identifier cannot end with punctuation character", Wptr
);
2880 -- We will assume it is an identifier, not a keyword, so that the
2881 -- checksum is independent of the Ada version.
2883 Token
:= Tok_Identifier
;
2885 -- Here is where we check if it was a keyword
2887 if Is_Keyword_Name
(Token_Name
) then
2888 if Opt
.Checksum_GNAT_6_3
then
2889 Token
:= Token_Type
'Val (Get_Name_Table_Byte
(Token_Name
));
2891 if Checksum_Accumulate_Token_Checksum
then
2892 if Checksum_GNAT_5_03
then
2893 Accumulate_Token_Checksum_GNAT_5_03
;
2895 Accumulate_Token_Checksum_GNAT_6_3
;
2900 Accumulate_Token_Checksum
;
2901 Token
:= Token_Type
'Val (Get_Name_Table_Byte
(Token_Name
));
2904 -- Keyword style checks
2908 -- Deal with possible style check for non-lower case keyword,
2909 -- but we don't treat ACCESS, DELTA, DIGITS, RANGE as keywords
2910 -- for this purpose if they appear as attribute designators.
2911 -- Actually we only check the first character for speed.
2913 -- Ada 2005 (AI-284): Do not apply the style check in case of
2914 -- "pragma Interface"
2916 -- Ada 2005 (AI-340): Do not apply the style check in case of
2919 if Source
(Token_Ptr
) <= 'Z'
2920 and then (Prev_Token
/= Tok_Apostrophe
2922 (Token
/= Tok_Access
and then
2923 Token
/= Tok_Delta
and then
2924 Token
/= Tok_Digits
and then
2925 Token
/= Tok_Mod
and then
2926 Token
/= Tok_Range
))
2927 and then (Token
/= Tok_Interface
2929 (Token
= Tok_Interface
2930 and then Prev_Token
/= Tok_Pragma
))
2932 Style
.Non_Lower_Case_Keyword
;
2935 -- Check THEN/ELSE style rules. These do not apply to AND THEN
2936 -- or OR ELSE, and do not apply in if expressions.
2938 if (Token
= Tok_Then
and then Prev_Token
/= Tok_And
)
2940 (Token
= Tok_Else
and then Prev_Token
/= Tok_Or
)
2942 if Inside_If_Expression
= 0 then
2943 Style
.Check_Separate_Stmt_Lines
;
2948 -- We must reset Token_Name since this is not an identifier and
2949 -- if we leave Token_Name set, the parser gets confused because
2950 -- it thinks it is dealing with an identifier instead of the
2951 -- corresponding keyword.
2953 Token_Name
:= No_Name
;
2956 -- It is an identifier after all
2959 if Checksum_Accumulate_Token_Checksum
then
2960 Accumulate_Token_Checksum
;
2968 --------------------------
2969 -- Set_Comment_As_Token --
2970 --------------------------
2972 procedure Set_Comment_As_Token
(Value
: Boolean) is
2974 Comment_Is_Token
:= Value
;
2975 end Set_Comment_As_Token
;
2977 ------------------------------
2978 -- Set_End_Of_Line_As_Token --
2979 ------------------------------
2981 procedure Set_End_Of_Line_As_Token
(Value
: Boolean) is
2983 End_Of_Line_Is_Token
:= Value
;
2984 end Set_End_Of_Line_As_Token
;
2986 ---------------------------
2987 -- Set_Special_Character --
2988 ---------------------------
2990 procedure Set_Special_Character
(C
: Character) is
2993 when '#' |
'$' |
'_' |
'?' |
'@' |
'`' |
'\' |
'^' |
'~' =>
2994 Special_Characters
(C
) := True;
2999 end Set_Special_Character
;
3001 ----------------------
3002 -- Set_Start_Column --
3003 ----------------------
3005 -- Note: it seems at first glance a little expensive to compute this value
3006 -- for every source line (since it is certainly not used for all source
3007 -- lines). On the other hand, it doesn't take much more work to skip past
3008 -- the initial white space on the line counting the columns than it would
3009 -- to scan past the white space using the standard scanning circuits.
3011 function Set_Start_Column
return Column_Number
is
3012 Start_Column
: Column_Number
:= 0;
3015 -- Outer loop scans past horizontal tab characters
3019 -- Inner loop scans past blanks as fast as possible, bumping Scan_Ptr
3020 -- past the blanks and adjusting Start_Column to account for them.
3023 if Source
(Scan_Ptr
) = ' ' then
3024 if Source
(Scan_Ptr
+ 1) = ' ' then
3025 if Source
(Scan_Ptr
+ 2) = ' ' then
3026 if Source
(Scan_Ptr
+ 3) = ' ' then
3027 if Source
(Scan_Ptr
+ 4) = ' ' then
3028 if Source
(Scan_Ptr
+ 5) = ' ' then
3029 if Source
(Scan_Ptr
+ 6) = ' ' then
3030 Scan_Ptr
:= Scan_Ptr
+ 7;
3031 Start_Column
:= Start_Column
+ 7;
3033 Scan_Ptr
:= Scan_Ptr
+ 6;
3034 Start_Column
:= Start_Column
+ 6;
3038 Scan_Ptr
:= Scan_Ptr
+ 5;
3039 Start_Column
:= Start_Column
+ 5;
3043 Scan_Ptr
:= Scan_Ptr
+ 4;
3044 Start_Column
:= Start_Column
+ 4;
3048 Scan_Ptr
:= Scan_Ptr
+ 3;
3049 Start_Column
:= Start_Column
+ 3;
3053 Scan_Ptr
:= Scan_Ptr
+ 2;
3054 Start_Column
:= Start_Column
+ 2;
3058 Scan_Ptr
:= Scan_Ptr
+ 1;
3059 Start_Column
:= Start_Column
+ 1;
3065 end loop Blanks_Loop
;
3067 -- Outer loop keeps going only if a horizontal tab follows
3069 if Source
(Scan_Ptr
) = HT
then
3074 Scan_Ptr
:= Scan_Ptr
+ 1;
3075 Start_Column
:= (Start_Column
/ 8) * 8 + 8;
3081 return Start_Column
;
3083 -- A constraint error can happen only if we have a compiler with checks on
3084 -- and a line with a ludicrous number of tabs or spaces at the start. In
3085 -- such a case, we really don't care if Start_Column is right or not.
3088 when Constraint_Error
=>
3089 return Start_Column
;
3090 end Set_Start_Column
;