From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 2DCB33849AD0 for ; Fri, 17 May 2024 08:32:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2DCB33849AD0 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2DCB33849AD0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715934767; cv=none; b=xeTR5C2Aruax433o8klBO3Lc7WlA/3DWWltnbogiSidpVsLswdjPvCNx8LlujxR/TgI7ns65jwvylnNWJzes35IDI6q1MB5cTiz1G5f5M0GXDvq+epBpv/U7i8XtRZK8B1VkQX09DkKq1Pn9LQKis68e1/zUXH4Uv37XKMDBpOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715934767; c=relaxed/simple; bh=sJ2rfKFRoRaYh62R9yK3tA7tMHtCvGl6PAH0XXBTXnc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bHBeqqCvQgwT7gcBDttitoszE+E+u2Bp1dQ2/VkqPLzY0ilJ2oSv7imkgkNcEBF8YmSSvjWPorEmaU5nOLBnO8brROnmyPj6IH3gsYgVs2NHZuovI5swxGgCeBZO5zUIiQdeBb3CE5AN0SWkLZqSy3NmFVWDEXY1GLPiPhuy5LU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-51f174e316eso394623e87.0 for ; Fri, 17 May 2024 01:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1715934750; x=1716539550; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qQQTf2M5Lu2b7aNiiKOc5bQfVz16HYHZKrm7CyFUB6Q=; b=dU8e/54WdjYW4HQXHeC2tl3TDa4smgm48l1TgMPO3+U0cNNqEg234PALusJMnxWVb4 1LHoO3+T5XE+IKjGUi3DcRG2IRZr9s0JSIQ0Yyq2goIbDTA3upHipK0xyCFz/qDtijjk WXj6xFUkIyLfI/Y82SX/NI1uJHpmSlPVgnBxFRPD6X3Utpb0fS/wjdPC1uJ1gxePk8Ed +eao66OTZwSBLDBg/tXSQmpn1mUFTds9t2XfqFsFIeyE51E/77rJE7auC03AGcxIoliR zuXhVNjbRTJLri1CX3Pe2N35HTwgetzHbtnVbhoWuSgPg2IZ0ZtR17D7HKTpbaIM/llX /d4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715934750; x=1716539550; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qQQTf2M5Lu2b7aNiiKOc5bQfVz16HYHZKrm7CyFUB6Q=; b=sWbkqJnib81ze9ofzWOR4NFOde8ENbMb9G4rPtgI7ojjny8SMYBG3R3wLtdUhq5+d2 4W9ChPIlAxo79AlwZJj8Kj8kkKSof54mMSKD1AvmppkX6OhutE9AmJh+5EMT0JK35KR9 Kw4moYXe4Af682vggpxfT2jnhvXzbvVq+AVQ+8rqU/iNRgtXNh1sSC0K7E5rLShNsHBg KfvYV341iat7BUksiSR+T7EsTEadlARxtL8WugrM0Lyu8k5j23bgoKSDXDBnT81v5slD 03M1109Y0WmZrhjy+WeWyKP5fHrqLXT41bq1NYiO2pqfDf4ck5NoSJrPIlB15pKMRLxw K4ig== X-Gm-Message-State: AOJu0YxZmxFKryH5/dUyYtEw9F4MxkhN+t9CZEHWVYpI9jUCdsJ4Duit gKApZVPKdDoEePuEq7IyVbB6CeJ3nDA3luW1caO5Bb7C2Y544StPdSQQS9xVUTsR9XOkulC2bd8 = X-Google-Smtp-Source: AGHT+IFq5GTcPW8Zaq+4oRhWSgq7OA3uoekgsjuwqHqNwYdEdebj0r9tGeVs+j8RY4HojJOuiUXmPw== X-Received: by 2002:a05:6512:3f10:b0:51f:3ae6:7440 with SMTP id 2adb3069b0e04-5220fe78a45mr19165135e87.42.1715934750654; Fri, 17 May 2024 01:32:30 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:de37:8b1c:1f33:2610]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-420273cff03sm75197045e9.26.2024.05.17.01.32.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 01:32:30 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [COMMITTED 14/35] ada: gnatbind-related cleanups Date: Fri, 17 May 2024 10:31:46 +0200 Message-ID: <20240517083207.130391-14-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240517083207.130391-1-poulhies@adacore.com> References: <20240517083207.130391-1-poulhies@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Bob Duff This patch cleans up some things noticed while working on gnatbind. No change in behavior yet. gcc/ada/ * ali-util.adb (Read_Withed_ALIs): Minor reformatting. * bindo-units.adb (Corresponding_Body): Add assert. (Corresponding_Spec): Likewise. * uname.adb: Clean up assertions, use available functions. Get_Spec_Name/Get_Body_Name can assert that N obeys the conventions for Unit_Name_Type (end in "%s" or "%b"). Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/ali-util.adb | 4 +-- gcc/ada/bindo-units.adb | 8 ++++-- gcc/ada/uname.adb | 61 ++++++++++++++--------------------------- 3 files changed, 28 insertions(+), 45 deletions(-) diff --git a/gcc/ada/ali-util.adb b/gcc/ada/ali-util.adb index fe0af74086c..61dddb94e85 100644 --- a/gcc/ada/ali-util.adb +++ b/gcc/ada/ali-util.adb @@ -161,9 +161,7 @@ package body ALI.Util is -- Process all dependent units for U in ALIs.Table (Id).First_Unit .. ALIs.Table (Id).Last_Unit loop - for - W in Units.Table (U).First_With .. Units.Table (U).Last_With - loop + for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop Afile := Withs.Table (W).Afile; -- Only process if not a generic (Afile /= No_File) and if diff --git a/gcc/ada/bindo-units.adb b/gcc/ada/bindo-units.adb index 0fbe8e9d381..0acc6612270 100644 --- a/gcc/ada/bindo-units.adb +++ b/gcc/ada/bindo-units.adb @@ -103,7 +103,9 @@ package body Bindo.Units is begin pragma Assert (U_Rec.Utype = Is_Spec); - return U_Id - 1; + return Result : constant Unit_Id := U_Id - 1 do + pragma Assert (ALI.Units.Table (Result).Utype = Is_Body); + end return; end Corresponding_Body; ------------------------ @@ -117,7 +119,9 @@ package body Bindo.Units is begin pragma Assert (U_Rec.Utype = Is_Body); - return U_Id + 1; + return Result : constant Unit_Id := U_Id + 1 do + pragma Assert (ALI.Units.Table (Result).Utype = Is_Spec); + end return; end Corresponding_Spec; ------------------------ diff --git a/gcc/ada/uname.adb b/gcc/ada/uname.adb index 08574784173..dbb08b88cfd 100644 --- a/gcc/ada/uname.adb +++ b/gcc/ada/uname.adb @@ -50,14 +50,8 @@ package body Uname is Buffer : Bounded_String; begin Append (Buffer, N); - - pragma Assert - (Buffer.Length > 2 - and then Buffer.Chars (Buffer.Length - 1) = '%' - and then Buffer.Chars (Buffer.Length) = 's'); - + pragma Assert (Is_Spec_Name (N)); Buffer.Chars (Buffer.Length) := 'b'; - return Name_Find (Buffer); end Get_Body_Name; @@ -160,14 +154,8 @@ package body Uname is Buffer : Bounded_String; begin Append (Buffer, N); - - pragma Assert - (Buffer.Length > 2 - and then Buffer.Chars (Buffer.Length - 1) = '%' - and then Buffer.Chars (Buffer.Length) = 'b'); - + pragma Assert (Is_Body_Name (N)); Buffer.Chars (Buffer.Length) := 's'; - return Name_Find (Buffer); end Get_Spec_Name; @@ -416,6 +404,9 @@ package body Uname is Suffix : Boolean := True) is begin + pragma Assert (Buf.Chars (1) /= '"'); + pragma Assert (Is_Body_Name (N) or else Is_Spec_Name (N)); + Buf.Length := 0; Append_Decoded (Buf, N); @@ -424,17 +415,11 @@ package body Uname is -- (lower case) 's'/'b', and before appending (lower case) "spec" or -- "body". - pragma Assert (Buf.Length >= 3); - pragma Assert (Buf.Chars (1) /= '"'); - pragma Assert (Buf.Chars (Buf.Length) in 's' | 'b'); - declare S : constant String := (if Buf.Chars (Buf.Length) = 's' then " (spec)" else " (body)"); begin - Buf.Length := Buf.Length - 1; -- remove 's' or 'b' - pragma Assert (Buf.Chars (Buf.Length) = '%'); - Buf.Length := Buf.Length - 1; -- remove '%' + Buf.Length := Buf.Length - 2; -- remove "%s" or "%b" Set_Casing (Buf, Identifier_Casing (Source_Index (Main_Unit))); if Suffix then @@ -474,9 +459,9 @@ package body Uname is Buffer : Bounded_String; begin Append (Buffer, N); - return Buffer.Length > 2 - and then Buffer.Chars (Buffer.Length - 1) = '%' - and then Buffer.Chars (Buffer.Length) = 'b'; + pragma Assert + (Buffer.Length > 2 and then Buffer.Chars (Buffer.Length - 1) = '%'); + return Buffer.Chars (Buffer.Length) = 'b'; end Is_Body_Name; ------------------- @@ -535,10 +520,7 @@ package body Uname is System : constant String := "system"; begin - if Name = Ada - or else Name = Interfaces - or else Name = System - then + if Name in Ada | Interfaces | System then return True; end if; @@ -555,15 +537,14 @@ package body Uname is -- The following are the predefined renamings - return - Name = "calendar" - or else Name = "machine_code" - or else Name = "unchecked_conversion" - or else Name = "unchecked_deallocation" - or else Name = "direct_io" - or else Name = "io_exceptions" - or else Name = "sequential_io" - or else Name = "text_io"; + return Name in "calendar" + | "machine_code" + | "unchecked_conversion" + | "unchecked_deallocation" + | "direct_io" + | "io_exceptions" + | "sequential_io" + | "text_io"; end Is_Predefined_Unit_Name; ------------------ @@ -574,9 +555,9 @@ package body Uname is Buffer : Bounded_String; begin Append (Buffer, N); - return Buffer.Length > 2 - and then Buffer.Chars (Buffer.Length - 1) = '%' - and then Buffer.Chars (Buffer.Length) = 's'; + pragma Assert + (Buffer.Length > 2 and then Buffer.Chars (Buffer.Length - 1) = '%'); + return Buffer.Chars (Buffer.Length) = 's'; end Is_Spec_Name; ----------------------- -- 2.43.2