From patchwork Tue Jul 12 12:25:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 55943 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 91220382C160 for ; Tue, 12 Jul 2022 12:25:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 91220382C160 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657628743; bh=A8J7LJJR9NnM0FBdrAjvHhwLBtjTJOYfMZdrHtz0Wkk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=QgbAHZGrdFtmoXLjaPEMBBxyJr39OHbsLFvgorQLUc1+0TnTNjAWcn1yj2jjUCOv0 xfHDMnLNvjzBTInHyDFDkYTVVf9ePmZscgejM8UbzDBQ5znk7DVR7PQB0D9XYCDjlN ZAk5wHL1tF5fI6dq+uVTKJ6LFL7liCH9Jc7GIjIQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id 21B84385AC09 for ; Tue, 12 Jul 2022 12:25:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 21B84385AC09 Received: by mail-ed1-x52c.google.com with SMTP id y4so9882837edc.4 for ; Tue, 12 Jul 2022 05:25:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=A8J7LJJR9NnM0FBdrAjvHhwLBtjTJOYfMZdrHtz0Wkk=; b=b4qnGBpUjUIC5ZJeSacjZG4cwIYQkSVymad4c09wi2JMAEWx445JX6Fv29xJpcL2HE XYhV9gzZznLNdPUxIndYZ9J2ciqcniPm/8k3yQ3OSGNglsIMyoIv9p6nQDszrgy93n8A xNgAQrPnyNs3dfCXyxdgE8tuwCUsFvlYkxJ7/pMduyq7bNeubsFdsTNwXp/j8JY4kBy4 TldqI0i0B3pjVIjWu9Cr/gptfdJWG7ARnkby9BEXX11Hfux8eHZsWM8TyYmFzVAzE/iU BrjXQUOenpXhvh15WvEKQQUcfGOX+1U4w1vFj7cUnvliBdJq0DjsUAQwThn9TDxQ7GRb Lemw== X-Gm-Message-State: AJIora8TRjlaxU6KXz2MZnAGTxkmmqiBjoxfzaFdwAONw7Puioyaa4wG s/sb/tWdeyxhYk/475LNz0C2XtlhQR1Uqg== X-Google-Smtp-Source: AGRyM1teF3LbyhlL0Jzj4ExJs5lfOR5omxxaMZ/Bhvk5zvYJV2Ltr/5f83yvDj8uGuYvglS/ziPK0g== X-Received: by 2002:a05:6402:1389:b0:43a:ceea:93fd with SMTP id b9-20020a056402138900b0043aceea93fdmr16601217edv.64.1657628709902; Tue, 12 Jul 2022 05:25:09 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id d18-20020a170906345200b007052b183d51sm3741700ejb.132.2022.07.12.05.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 05:25:09 -0700 (PDT) Date: Tue, 12 Jul 2022 12:25:08 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Clean up scanner Message-ID: <20220712122508.GA3404573@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Bob Duff Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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. Tested on x86_64-pc-linux-gnu, committed on trunk 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". diff --git a/gcc/ada/ali-util.adb b/gcc/ada/ali-util.adb --- a/gcc/ada/ali-util.adb +++ b/gcc/ada/ali-util.adb @@ -42,15 +42,12 @@ package body ALI.Util is -- empty, because we don't want to report any errors when computing -- a source checksum. - procedure Post_Scan; + procedure Post_Scan is null; - procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr); - - procedure Error_Msg_S (Msg : String); - - procedure Error_Msg_SC (Msg : String); - - procedure Error_Msg_SP (Msg : String); + procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is null; + procedure Error_Msg_S (Msg : String) is null; + procedure Error_Msg_SC (Msg : String) is null; + procedure Error_Msg_SP (Msg : String) is null; -- Instantiation of Styleg, needed to instantiate Scng @@ -85,47 +82,6 @@ package body ALI.Util is return Checksum1 = Checksum2 and then Checksum1 /= Checksum_Error; end Checksums_Match; - --------------- - -- Error_Msg -- - --------------- - - procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is - pragma Warnings (Off, Msg); - pragma Warnings (Off, Flag_Location); - begin - null; - end Error_Msg; - - ----------------- - -- Error_Msg_S -- - ----------------- - - procedure Error_Msg_S (Msg : String) is - pragma Warnings (Off, Msg); - begin - null; - end Error_Msg_S; - - ------------------ - -- Error_Msg_SC -- - ------------------ - - procedure Error_Msg_SC (Msg : String) is - pragma Warnings (Off, Msg); - begin - null; - end Error_Msg_SC; - - ------------------ - -- Error_Msg_SP -- - ------------------ - - procedure Error_Msg_SP (Msg : String) is - pragma Warnings (Off, Msg); - begin - null; - end Error_Msg_SP; - ----------------------- -- Get_File_Checksum -- ----------------------- @@ -192,15 +148,6 @@ package body ALI.Util is Interfaces.Reset; end Initialize_ALI_Source; - --------------- - -- Post_Scan -- - --------------- - - procedure Post_Scan is - begin - null; - end Post_Scan; - ---------------------- -- Read_Withed_ALIs -- ---------------------- diff --git a/gcc/ada/gprep.adb b/gcc/ada/gprep.adb --- a/gcc/ada/gprep.adb +++ b/gcc/ada/gprep.adb @@ -93,8 +93,8 @@ package body GPrep is procedure Display_Copyright; -- Display the copyright notice - procedure Post_Scan; - -- Null procedure, needed by instantiation of Scng below + procedure Post_Scan is null; + -- Needed by instantiation of Scng below package Scanner is new Scng (Post_Scan, @@ -327,15 +327,6 @@ package body GPrep is New_Line (Outfile.all); end New_EOL_To_Outfile; - --------------- - -- Post_Scan -- - --------------- - - procedure Post_Scan is - begin - null; - end Post_Scan; - ---------------------------- -- Preprocess_Infile_Name -- ---------------------------- diff --git a/gcc/ada/scans.ads b/gcc/ada/scans.ads --- a/gcc/ada/scans.ads +++ b/gcc/ada/scans.ads @@ -210,15 +210,11 @@ package Scans is Tok_End_Of_Line, -- Represents an end of line. Not used during normal compilation scans - -- where end of line is ignored. Active for preprocessor scanning and - -- also when scanning project files (where it is needed because of ???) + -- where end of line is ignored. Active for preprocessor scanning. Tok_Special, - -- AI12-0125-03 : target name as abbreviation for LHS - - -- Otherwise used only in preprocessor scanning (to represent one of - -- the characters '#', '$', '?', '@', '`', '\', '^', '~', or '_'. The - -- character value itself is stored in Scans.Special_Character. + -- Special character used by the preprocessor. The character itself is + -- stored in Special_Character below. No_Token); -- No_Token is used for initializing Token values to indicate that @@ -466,12 +462,9 @@ package Scans is -- character found (i.e. a character that does not fit in Character or -- Wide_Character). - Special_Character : Character; - -- AI12-0125-03 : '@' as target name is handled elsewhere. - -- Valid only when Token = Tok_Special. Returns one of the characters - -- '#', '$', '?', '`', '\', '^', '~', or '_'. - -- - -- Why only this set? What about wide characters??? + subtype Special_Preprocessor_Character is Character with + Predicate => Special_Preprocessor_Character in '#' | '$'; + Special_Character : Special_Preprocessor_Character; Comment_Id : Name_Id := No_Name; -- Valid only when Token = Tok_Comment. Store the string that follows diff --git a/gcc/ada/scn.ads b/gcc/ada/scn.ads --- a/gcc/ada/scn.ads +++ b/gcc/ada/scn.ads @@ -29,7 +29,7 @@ with Casing; use Casing; with Errout; use Errout; with Scng; -with Style; -- use Style; +with Style; with Types; use Types; package Scn is @@ -75,9 +75,5 @@ package Scn is Style => Style.Style_Inst); procedure Scan renames Scanner.Scan; - -- Scan scans out the next token, and advances the scan state accordingly - -- (see package Scans for details). If the scan encounters an illegal - -- token, then an error message is issued pointing to the bad character, - -- and Scan returns a reasonable substitute token of some kind. end Scn; diff --git a/gcc/ada/scng.adb b/gcc/ada/scng.adb --- 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; ---------------------- diff --git a/gcc/ada/scng.ads b/gcc/ada/scng.ads --- a/gcc/ada/scng.ads +++ b/gcc/ada/scng.ads @@ -23,11 +23,11 @@ -- -- ------------------------------------------------------------------------------ --- This package contains a generic lexical analyzer. This is used for scanning --- Ada source files or text files with an Ada-like syntax, such as project --- files. It is instantiated in Scn and Prj.Err. +-- This is a generic lexical analyzer, used for scanning Ada source files, and +-- also for preprocessor files. with Casing; use Casing; +with Scans; use Scans; with Styleg; with Types; use Types; @@ -68,33 +68,27 @@ package Scng is -- Scan scans out the next token, and advances the scan state accordingly -- (see package Scan_State for details). If the scan encounters an illegal -- token, then an error message is issued pointing to the bad character, - -- and Scan returns a reasonable substitute token of some kind. - -- For tokens Char_Literal, Identifier, Real_Literal, Integer_Literal, - -- String_Literal and Operator_Symbol, Post_Scan is called after scanning. + -- and Scan returns a reasonable substitute token. For tokens Char_Literal, + -- Identifier, Real_Literal, Integer_Literal, String_Literal and + -- Operator_Symbol, Post_Scan is called after scanning. function Determine_Token_Casing return Casing_Type; pragma Inline (Determine_Token_Casing); -- Determines the casing style of the current token, which is -- either a keyword or an identifier. See also package Casing. - procedure Set_Special_Character (C : Character); - -- Indicate that one of the following character '#', '$', '?', '`', - -- '\', '^', '_' or '~', when found is a Special token. - -- AI12-0125-03 : target name (ES) is not in this list because '@' is - -- handled as a special token as abbreviation of LHS of assignment. + procedure Set_Special_Character (C : Special_Preprocessor_Character); + -- Called when the preprocessor is active to indicate that Scan should + -- return a Special token for C. procedure Reset_Special_Characters; - -- Indicate that there is no characters that are Special tokens., which + -- Indicate that there are no characters that are Special tokens, which -- is the default. procedure Set_End_Of_Line_As_Token (Value : Boolean); -- Indicate if End_Of_Line is a token or not. -- By default, End_Of_Line is not a token. - procedure Set_Comment_As_Token (Value : Boolean); - -- Indicate if a comment is a token or not. - -- By default, a comment is not a token. - function Set_Start_Column return Column_Number; -- This routine is called with Scan_Ptr pointing to the first character -- of a line. On exit, Scan_Ptr is advanced to the first non-blank