]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix SFN_Patterns documentation comment
authorRonan Desplanques <desplanques@adacore.com>
Mon, 3 Feb 2025 13:22:22 +0000 (14:22 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 5 Jun 2025 08:18:38 +0000 (10:18 +0200)
The documentation comment under SFN_Patterns was misleading. This patch
fixes it and also fixes Get_Default_File_Name which assumed the comment
was correct.

gcc/ada/ChangeLog:

* fname-uf.adb: Fix documentation comment.
(Get_Default_File_Name): Fix indices of default patterns.

gcc/ada/fname-uf.adb

index 39a09c4ce1331425afea45b56d37d5c2559a9fa6..ec22ad7a3d2aef037a734f4fd80829ac9c6a79d5 100644 (file)
@@ -90,8 +90,9 @@ package body Fname.UF is
      Table_Initial        => 10,
      Table_Increment      => 100,
      Table_Name           => "SFN_Patterns");
-   --  Table recording calls to Set_File_Name_Pattern. Note that the first two
-   --  entries are set to represent the standard GNAT rules for file naming.
+   --  Table recording calls to Set_File_Name_Pattern. Note that the last two
+   --  entries are set to represent the standard GNAT rules for file naming;
+   --  that invariant is maintained by Set_File_Name_Pattern.
 
    procedure Instantiate_SFN_Pattern
      (Pattern   : SFN_Pattern_Entry;
@@ -178,6 +179,8 @@ package body Fname.UF is
    ---------------------------
 
    function Get_Default_File_Name (Uname : Unit_Name_Type) return String is
+      L : constant Int := SFN_Patterns.Last;
+
       Buf : Bounded_String;
 
       Pattern : SFN_Pattern_Entry;
@@ -185,10 +188,10 @@ package body Fname.UF is
       Get_Unit_Name_String (Buf, Uname, False);
 
       if Is_Spec_Name (Uname) then
-         Pattern := SFN_Patterns.Table (1);
+         Pattern := SFN_Patterns.Table (L - 1);
       else
          pragma Assert (Is_Body_Name (Uname));
-         Pattern := SFN_Patterns.Table (2);
+         Pattern := SFN_Patterns.Table (L);
       end if;
 
       Instantiate_SFN_Pattern (Pattern, Buf);