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: Piotr Trojanek <trojanek@adacore.com>
Subject: [COMMITTED] ada: Clean up unnecessary nesting in code for DLL libraries
Date: Mon,  7 Nov 2022 09:40:50 +0100	[thread overview]
Message-ID: <20221107084050.151435-1-poulhies@adacore.com> (raw)

From: Piotr Trojanek <trojanek@adacore.com>

Code cleanup; issue spotted while examining routines with No_ prefix.

gcc/ada/

	* mdll.ads (Build_Import_Library): Fix grammar in comment.
	* mdll.adb (Build_Import_Library): Directly execute code of a
	nested routine; rename No_Lib_Prefix to Strip_Lib_Prefix.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/mdll.adb | 68 ++++++++++++++++++------------------------------
 gcc/ada/mdll.ads |  4 +--
 2 files changed, 28 insertions(+), 44 deletions(-)

diff --git a/gcc/ada/mdll.adb b/gcc/ada/mdll.adb
index 2107994e5c0..88f8f96927c 100644
--- a/gcc/ada/mdll.adb
+++ b/gcc/ada/mdll.adb
@@ -448,57 +448,41 @@ package body MDLL is
      (Lib_Filename : String;
       Def_Filename : String)
    is
-      procedure Build_Import_Library (Lib_Filename : String);
-      --  Build an import library. This is to build only a .a library to link
-      --  against a DLL.
+      function Strip_Lib_Prefix (Filename : String) return String;
+      --  Return Filename without the lib prefix if present
 
-      --------------------------
-      -- Build_Import_Library --
-      --------------------------
-
-      procedure Build_Import_Library (Lib_Filename : String) is
-
-         function No_Lib_Prefix (Filename : String) return String;
-         --  Return Filename without the lib prefix if present
-
-         -------------------
-         -- No_Lib_Prefix --
-         -------------------
-
-         function No_Lib_Prefix (Filename : String) return String is
-         begin
-            if Filename (Filename'First .. Filename'First + 2) = "lib" then
-               return Filename (Filename'First + 3 .. Filename'Last);
-            else
-               return Filename;
-            end if;
-         end No_Lib_Prefix;
-
-         --  Local variables
-
-         Def_File      : String renames Def_Filename;
-         Dll_File      : constant String := Get_Dll_Name (Lib_Filename);
-         Base_Filename : constant String :=
-                           MDLL.Fil.Ext_To (No_Lib_Prefix (Lib_Filename));
-         Lib_File      : constant String := "lib" & Base_Filename & ".dll.a";
-
-      --  Start of processing for Build_Import_Library
+      ----------------------
+      -- Strip_Lib_Prefix --
+      ----------------------
 
+      function Strip_Lib_Prefix (Filename : String) return String is
       begin
-         if not Quiet then
-            Text_IO.Put_Line ("Building import library...");
-            Text_IO.Put_Line
-              ("make " & Lib_File & " to use dynamic library " & Dll_File);
+         if Filename (Filename'First .. Filename'First + 2) = "lib" then
+            return Filename (Filename'First + 3 .. Filename'Last);
+         else
+            return Filename;
          end if;
+      end Strip_Lib_Prefix;
 
-         Utl.Dlltool
-           (Def_File, Dll_File, Lib_File, Build_Import => True);
-      end Build_Import_Library;
+      --  Local variables
+
+      Def_File      : String renames Def_Filename;
+      Dll_File      : constant String := Get_Dll_Name (Lib_Filename);
+      Base_Filename : constant String :=
+                        MDLL.Fil.Ext_To (Strip_Lib_Prefix (Lib_Filename));
+      Lib_File      : constant String := "lib" & Base_Filename & ".dll.a";
 
    --  Start of processing for Build_Import_Library
 
    begin
-      Build_Import_Library (Lib_Filename);
+      if not Quiet then
+         Text_IO.Put_Line ("Building import library...");
+         Text_IO.Put_Line
+           ("make " & Lib_File & " to use dynamic library " & Dll_File);
+      end if;
+
+      Utl.Dlltool
+        (Def_File, Dll_File, Lib_File, Build_Import => True);
    end Build_Import_Library;
 
    ------------------
diff --git a/gcc/ada/mdll.ads b/gcc/ada/mdll.ads
index 110eb31b001..9f080c0cafe 100644
--- a/gcc/ada/mdll.ads
+++ b/gcc/ada/mdll.ads
@@ -74,7 +74,7 @@ package MDLL is
    procedure Build_Import_Library
      (Lib_Filename : String;
       Def_Filename : String);
-   --  Build an import library (.a) from a definition files. An import library
-   --  is needed to link against a DLL.
+   --  Build an import library (.a) from definition files. An import library is
+   --  needed to link against a DLL.
 
 end MDLL;
-- 
2.34.1


                 reply	other threads:[~2022-11-07  8:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20221107084050.151435-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=trojanek@adacore.com \
    /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).