From patchwork Thu Jul 8 13:49:51 2021 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: 1502263 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=haTDTW/o; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GLHjY4shDz9sRf for ; Thu, 8 Jul 2021 23:50:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 88482398B8A7 for ; Thu, 8 Jul 2021 13:50:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id 6C38B3893642 for ; Thu, 8 Jul 2021 13:49:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6C38B3893642 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-lf1-x12d.google.com with SMTP id y42so15828068lfa.3 for ; Thu, 08 Jul 2021 06:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=hF/KzmSHIhNmey9BJILjXIftczYmLGAwRo+IKdMmmAI=; b=haTDTW/oWEuLMloMzu4FGIRJSuOZ2yi7TgwvOKRcHerU08gvH2GpEf90fEiJe6OymV ZepjQxO8SDT9c5OHFHvEL/cv8lQgYtDMLREu3GQ2YTcUemvdyx3h69hiXZtfVSchT58V qsh4fOj4norgItDERGCLGS8+NN9nUpzR0mjRplKqXCfueeA0fFcLQU/7M0bEe6Afnbmu UQ0on2TI9pUdXKZNx2Boc2osz2qRQMrratEagE/+AizPxvm1SdgOEIJcf/cWAC1lHB7W 9K9PV6asIrd+Z8pmeaS/vYz/lbuix3sho8dMOycgE41xmKYYE/gdvFDBJZYIUn381xxY oodw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=hF/KzmSHIhNmey9BJILjXIftczYmLGAwRo+IKdMmmAI=; b=KD36KGEBjph9DG6Y92b+Ksalf4/dBqpxJ+xL6ehllh1uolqZYkMf9awrEWZ4hyXfI7 6mF08cRxw5mrUj+G9DuCvKeF2I3vlAIslyEqYXz9zMia8X4t9C0rMtCQl2/OibaEuUll syoCJZntOMWUoXG9nsxd/XWDhUAVgRnasQ3bI5vjFAx/kQdy6jXfOIGxyE6DTP0uuapa hDGod32YPMxJ1ns3eXwgdi/aneO2xxSnf81URe7JbccmTR/Q23N9GmP5rYCqEKb2RurD BpMMvDOzFZuypoIaFznfbvGcRWxcFL8DmiRUqgW8bjcVXZGxYb79OUKgd8ejsTdm5fLj TG5A== X-Gm-Message-State: AOAM533Ydi8YN44gm6r5GvBRWkfKlK+rBBcAtNlp6uVmnud22plu0z/n C1blZXXPzUpDExWttIPsxLeqqcqiJSjKdw== X-Google-Smtp-Source: ABdhPJwYUis6OiJ0bFvxUTDGVzxokwuUonSopQn0G6vEVI210vk2ZJmG+hv6NtAY8wfEFZS0VsyOqg== X-Received: by 2002:a19:8c07:: with SMTP id o7mr18865856lfd.637.1625752192872; Thu, 08 Jul 2021 06:49:52 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id k13sm202784lfv.64.2021.07.08.06.49.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jul 2021 06:49:52 -0700 (PDT) Date: Thu, 8 Jul 2021 13:49:51 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Simplify string manipulation related to preprocessing Message-ID: <20210708134951.GA2465446@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, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Cc: Piotr Trojanek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Code cleanup; semantics is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sinput-l.adb (Load_File): Simplify foreword manipulation with concatenation; similar for filename with preprocessed output. diff --git a/gcc/ada/sinput-l.adb b/gcc/ada/sinput-l.adb --- a/gcc/ada/sinput-l.adb +++ b/gcc/ada/sinput-l.adb @@ -551,19 +551,10 @@ package body Sinput.L is Set_Source_File_Index_Table (X); if Opt.List_Preprocessing_Symbols then - Get_Name_String (N); - declare - Foreword : String (1 .. Foreword_Start'Length + - Name_Len + Foreword_End'Length); - + Foreword : constant String := + Foreword_Start & Get_Name_String (N) & Foreword_End; begin - Foreword (1 .. Foreword_Start'Length) := Foreword_Start; - Foreword (Foreword_Start'Length + 1 .. - Foreword_Start'Length + Name_Len) := - Name_Buffer (1 .. Name_Len); - Foreword (Foreword'Last - Foreword_End'Length + 1 .. - Foreword'Last) := Foreword_End; Prep.List_Symbols (Foreword); end; end if; @@ -654,14 +645,13 @@ package body Sinput.L is NB : Integer; Status : Boolean; - begin - Get_Name_String (N); - Add_Str_To_Name_Buffer (Prep_Suffix); + Prep_Filename : constant String := + Get_Name_String (N) & Prep_Suffix; - Delete_File (Name_Buffer (1 .. Name_Len), Status); + begin + Delete_File (Prep_Filename, Status); - FD := - Create_New_File (Name_Buffer (1 .. Name_Len), Text); + FD := Create_New_File (Prep_Filename, Text); Status := FD /= Invalid_FD;