]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Use bounded string buffer in Get_Unit_Name
authorPiotr Trojanek <trojanek@adacore.com>
Tue, 11 May 2021 10:16:14 +0000 (12:16 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 7 Jul 2021 16:23:16 +0000 (16:23 +0000)
gcc/ada/

* uname.adb (Get_Unit_Name): Simplify with a bounded string
buffer; also, this addresses a ??? comment about the max length
being exceeded.

gcc/ada/uname.adb

index 23911802a6f0f62f913f1f534caebe703be044d0..18cb6d1a32956960905f80a828f24d3d2868af92 100644 (file)
@@ -177,13 +177,8 @@ package body Uname is
 
    function Get_Unit_Name (N : Node_Id) return Unit_Name_Type is
 
-      Unit_Name_Buffer : String (1 .. Hostparm.Max_Name_Length);
-      --  Buffer used to build name of unit. Note that we cannot use the
-      --  Name_Buffer in package Name_Table because we use it to read
-      --  component names.
-
-      Unit_Name_Length : Natural := 0;
-      --  Length of name stored in Unit_Name_Buffer
+      Unit_Name_Buffer : Bounded_String;
+      --  Buffer used to build name of unit
 
       Node : Node_Id;
       --  Program unit node
@@ -206,9 +201,7 @@ package body Uname is
 
       procedure Add_Char (C : Character) is
       begin
-         --  Should really check for max length exceeded here???
-         Unit_Name_Length := Unit_Name_Length + 1;
-         Unit_Name_Buffer (Unit_Name_Length) := C;
+         Append (Unit_Name_Buffer, C);
       end Add_Char;
 
       --------------
@@ -217,11 +210,7 @@ package body Uname is
 
       procedure Add_Name (Name : Name_Id) is
       begin
-         Get_Name_String (Name);
-
-         for J in 1 .. Name_Len loop
-            Add_Char (Name_Buffer (J));
-         end loop;
+         Append (Unit_Name_Buffer, Name);
       end Add_Name;
 
       -------------------
@@ -414,11 +403,7 @@ package body Uname is
             raise Program_Error;
       end case;
 
-      Name_Buffer (1 .. Unit_Name_Length) :=
-        Unit_Name_Buffer (1 .. Unit_Name_Length);
-      Name_Len := Unit_Name_Length;
-      return Name_Find;
-
+      return Name_Find (Unit_Name_Buffer);
    end Get_Unit_Name;
 
    --------------------------