public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Bob Duff <duff@adacore.com>
Subject: [COMMITTED 14/35] ada: gnatbind-related cleanups
Date: Fri, 17 May 2024 10:31:46 +0200	[thread overview]
Message-ID: <20240517083207.130391-14-poulhies@adacore.com> (raw)
In-Reply-To: <20240517083207.130391-1-poulhies@adacore.com>

From: Bob Duff <duff@adacore.com>

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


  parent reply	other threads:[~2024-05-17  8:32 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-17  8:31 [COMMITTED 01/35] ada: Add support for 'Object_Size to pragma Compile_Time_{Warning,Error} Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 02/35] ada: Small cleanup in aggregate expansion code Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 03/35] ada: Remove superfluous Relocate_Node calls Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 04/35] ada: Fix checking range constraints within composite types Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 05/35] ada: Check subtype to avoid a precondition failure Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 06/35] ada: Fix probable copy/paste error Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 07/35] ada: Tune detection of unconstrained and tagged items in Depends contract Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 08/35] ada: Allow private items with unknown discriminants as Depends inputs Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 09/35] ada: Simplify code for private types with unknown discriminants Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 10/35] ada: Only record types with discriminants can be unconstrained Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 11/35] ada: Fix Constraint_Error on mutable assignment Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 12/35] ada: Fix crash caused by missing New_Copy_tree Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 13/35] ada: Make raise-gcc.c compatible with Clang Marc Poulhiès
2024-05-17  8:31 ` Marc Poulhiès [this message]
2024-05-17  8:31 ` [COMMITTED 15/35] ada: correction to gnatbind-related cleanups Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 16/35] ada: Fix containers' Reference_Preserving_Key functions' memory leaks Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 17/35] ada: Update docs for Resolve_Null_Array_Aggregate Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 18/35] ada: gnatbind: subprogram spec no longer exists Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 19/35] ada: Couple of adjustments coming from aliasing considerations Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 20/35] ada: Expose utility routine for processing of Depends contracts in SPARK Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 21/35] ada: Fix others error message location Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 22/35] ada: Clarify code for aggregate warnings Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 23/35] ada: Disable Equivalent_Array_Aggregate optimization if predicates involved Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 24/35] ada: Do not query the modification time of a special file Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 25/35] ada: Fix for validity checking and conditional evaluation of 'Old Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 26/35] ada: Factor out duplicated code in bodies of System.Task_Primitives.Operations Marc Poulhiès
2024-05-17  8:31 ` [COMMITTED 27/35] ada: Bug in computing local restrictions inherited from enclosing scopes Marc Poulhiès
2024-05-17  8:32 ` [COMMITTED 28/35] ada: Document secondary usage of Materialize_Entity flag Marc Poulhiès
2024-05-17  8:32 ` [COMMITTED 29/35] ada: Replace spinlocks with fully-fledged locks in finalization collections Marc Poulhiès
2024-05-17  8:32 ` [COMMITTED 30/35] ada: Further adjustments coming from aliasing considerations Marc Poulhiès
2024-05-17  8:32 ` [COMMITTED 31/35] ada: Restore dependency on System.OS_Interface in System.Task_Primitives Marc Poulhiès
2024-05-17  8:32 ` [COMMITTED 32/35] ada: Improve test for unprocessed preprocessor directives Marc Poulhiès
2024-05-17  8:32 ` [COMMITTED 33/35] ada: Start the initialization of the tasking runtime earlier Marc Poulhiès
2024-05-17  8:32 ` [COMMITTED 34/35] ada: Remove outdated workaround in aggregate expansion Marc Poulhiès
2024-05-17  8:32 ` [COMMITTED 35/35] ada: Improve deriving initial sizes for container aggregates Marc Poulhiès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240517083207.130391-14-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=duff@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).