diff options
author | Bob Duff <duff@adacore.com> | 2022-06-21 09:50:06 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2022-07-12 12:24:11 +0000 |
commit | 2148f2996ae76a7773eb7d8e30c02bd036ec7b3c (patch) | |
tree | 7aaa816d7c8d7e80b59386ddc2efda9f4ad8e39a /gcc/ada/scng.adb | |
parent | fe6f256d5ba85a588493a489af1bdbe8087e368a (diff) | |
download | gcc-2148f2996ae76a7773eb7d8e30c02bd036ec7b3c.zip gcc-2148f2996ae76a7773eb7d8e30c02bd036ec7b3c.tar.gz gcc-2148f2996ae76a7773eb7d8e30c02bd036ec7b3c.tar.bz2 |
[Ada] Clean up scanner
This patch removes some obsolete code in the scanner and related files,
and corrects some comments. Tok_Special is used only by the
preprocessor, and uses only the two characters '#' and '$'.
It might be simpler to have a single flag indicating we're scanning for
preprocessing, instead of the Special_Characters array and the
End_Of_Line_Is_Token flag, but that's for another day.
gcc/ada/
* scans.ads: Fix obsolete comments about Tok_Special, and give
Special_Character a predicate assuring it is one of the two
characters used in preprocessing.
* scng.ads: Clean up comments.
* scng.adb: Clean up handling of Tok_Special. Remove comment
about '@' (target_name), which doesn't seem very helpful.
Set_Special_Character will now blow up if given anything other
than '#' and '$', because of the predicate on Special_Character;
it's not clear why it used to say "when others => null;".
Remove Comment_Is_Token, which is not used.
* scn.ads: Remove commented-out use clause. Remove redundant
comment.
* ali-util.adb: Use "is null" for do-nothing procedures.
* gprep.adb (Post_Scan): Use "is null".
Diffstat (limited to 'gcc/ada/scng.adb')
-rw-r--r-- | gcc/ada/scng.adb | 93 |
1 files changed, 13 insertions, 80 deletions
diff --git a/gcc/ada/scng.adb b/gcc/ada/scng.adb index cd10d1d..f2cf413 100644 --- a/gcc/ada/scng.adb +++ b/gcc/ada/scng.adb @@ -29,7 +29,6 @@ with Errout; use Errout; with Hostparm; use Hostparm; with Namet; use Namet; with Opt; use Opt; -with Scans; use Scans; with Sinput; use Sinput; with Snames; use Snames; with Stringt; use Stringt; @@ -53,9 +52,6 @@ package body Scng is Special_Characters : array (Character) of Boolean := (others => False); -- For characters that are Special token, the value is True - Comment_Is_Token : Boolean := False; - -- True if comments are tokens - End_Of_Line_Is_Token : Boolean := False; -- True if End_Of_Line is a token @@ -259,9 +255,6 @@ package body Scng is procedure Scan is - Start_Of_Comment : Source_Ptr; - -- Record start of comment position - Underline_Found : Boolean; -- During scanning of an identifier, set to True if last character -- scanned was an underline or other punctuation character. This @@ -1609,10 +1602,6 @@ package body Scng is return; end if; - -- Otherwise scan out the comment - - Start_Of_Comment := Scan_Ptr; - -- Loop to scan comment (this loop runs more than once only if -- a horizontal tab or other non-graphic character is scanned) @@ -1711,18 +1700,8 @@ package body Scng is end if; end loop; - -- Note that, except when comments are tokens, we do NOT - -- execute a return here, instead we fall through to reexecute - -- the scan loop to look for a token. - - if Comment_Is_Token then - Name_Len := Integer (Scan_Ptr - Start_Of_Comment); - Name_Buffer (1 .. Name_Len) := - String (Source (Start_Of_Comment .. Scan_Ptr - 1)); - Comment_Id := Name_Find; - Token := Tok_Comment; - return; - end if; + -- Note that we do not return here; instead we fall through to + -- reexecute the scan loop to look for a token. end if; end Minus_Case; @@ -2072,14 +2051,6 @@ package body Scng is -- Underline character when '_' => - if Special_Characters ('_') then - Token_Ptr := Scan_Ptr; - Scan_Ptr := Scan_Ptr + 1; - Token := Tok_Special; - Special_Character := '_'; - return; - end if; - Error_Msg_S ("identifier cannot start with underline"); Name_Len := 1; Name_Buffer (1) := '_'; @@ -2132,42 +2103,19 @@ package body Scng is Error_Illegal_Character; end if; - -- Invalid control characters - - when ACK - | ASCII.SO - | BEL - | BS - | CAN - | DC1 - | DC2 - | DC3 - | DC4 - | DEL - | DLE - | EM - | ENQ - | EOT - | ETB - | ETX - | FS - | GS - | NAK - | NUL - | RS - | SI - | SOH - | STX - | SYN - | US + -- Illegal characters + + when ACK | ASCII.SO | BEL | BS | CAN | DC1 | DC2 | DC3 | DC4 | DEL + | DLE | EM | ENQ | EOT | ETB | ETX | FS | GS | NAK | NUL | RS | SI + | SOH | STX | SYN | US + | '?' | '`' | '\' | '^' | '~' => Error_Illegal_Character; - -- Invalid graphic characters - -- Note that '@' is handled elsewhere, because following AI12-125 - -- it denotes the target_name of an assignment. + -- Special preprocessor characters. If Set_Special_Character has been + -- called, return a Special token. Otherwise give an error. - when '#' | '$' | '?' | '`' | '\' | '^' | '~' => + when Special_Preprocessor_Character => -- If Set_Special_Character has been called for this character, -- set Scans.Special_Character and return a Special token. @@ -2710,15 +2658,6 @@ package body Scng is end if; end Scan; - -------------------------- - -- Set_Comment_As_Token -- - -------------------------- - - procedure Set_Comment_As_Token (Value : Boolean) is - begin - Comment_Is_Token := Value; - end Set_Comment_As_Token; - ------------------------------ -- Set_End_Of_Line_As_Token -- ------------------------------ @@ -2732,15 +2671,9 @@ package body Scng is -- Set_Special_Character -- --------------------------- - procedure Set_Special_Character (C : Character) is + procedure Set_Special_Character (C : Special_Preprocessor_Character) is begin - case C is - when '#' | '$' | '_' | '?' | '@' | '`' | '\' | '^' | '~' => - Special_Characters (C) := True; - - when others => - null; - end case; + Special_Characters (C) := True; end Set_Special_Character; ---------------------- |