[Ada] Replace variables with constants in expanded code for task names
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 19 Jan 2022 12:35:46 +0000 (13:35 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 10 May 2022 08:19:22 +0000 (08:19 +0000)
Using constants instead of variables is cleaner both in human-written
and auto-generated code.

Cleanup related to handling of character values in SPARK
counterexamples, which just like the code for names of tasks create
N_Character_Literal nodes.

gcc/ada/

* exp_util.adb (Build_Task_Array_Image): Declare expanded
objects as constants.
(Build_Task_Image_Prefix): Likewise.
(Build_Task_Record_Image): Likewise.

gcc/ada/exp_util.adb

index b3d1fdf..c28723c 100644 (file)
@@ -4049,11 +4049,13 @@ package body Exp_Util is
 
    --  function F return String is
    --     Pref : String renames Task_Name;
-   --     T1   : String := Index1'Image (Val1);
+   --     T1   : constant String := Index1'Image (Val1);
    --     ...
-   --     Tn   : String := Indexn'Image (Valn);
-   --     Len  : Integer := Pref'Length + T1'Length + ... + Tn'Length + n + 1;
+   --     Tn   : constant String := Indexn'Image (Valn);
+   --     Len  : constant Integer :=
+   --       Pref'Length + T1'Length + ... + Tn'Length + n + 1;
    --     --  Len includes commas and the end parentheses
+   --
    --     Res  : String (1 .. Len);
    --     Pos  : Integer := Pref'Length;
    --
@@ -4124,8 +4126,9 @@ package body Exp_Util is
          Append_To (Decls,
            Make_Object_Declaration (Loc,
              Defining_Identifier => Pref,
-             Object_Definition => New_Occurrence_Of (Standard_String, Loc),
-             Expression =>
+             Constant_Present    => True,
+             Object_Definition   => New_Occurrence_Of (Standard_String, Loc),
+             Expression          =>
                Make_String_Literal (Loc,
                  Strval => String_From_Name_Buffer)));
 
@@ -4148,6 +4151,7 @@ package body Exp_Util is
            Make_Object_Declaration (Loc,
              Defining_Identifier => T,
              Object_Definition   => New_Occurrence_Of (Standard_String, Loc),
+             Constant_Present    => True,
              Expression          =>
                Make_Attribute_Reference (Loc,
                  Attribute_Name => Name_Image,
@@ -4425,6 +4429,7 @@ package body Exp_Util is
       Append_To (Decls,
         Make_Object_Declaration (Loc,
           Defining_Identifier => Len,
+          Constant_Present    => True,
           Object_Definition   => New_Occurrence_Of (Standard_Integer, Loc),
           Expression          => Sum));
 
@@ -4530,7 +4535,8 @@ package body Exp_Util is
          Append_To (Decls,
            Make_Object_Declaration (Loc,
              Defining_Identifier => Pref,
-             Object_Definition => New_Occurrence_Of (Standard_String, Loc),
+             Constant_Present    => True,
+             Object_Definition   => New_Occurrence_Of (Standard_String, Loc),
              Expression =>
                Make_String_Literal (Loc,
                  Strval => String_From_Name_Buffer)));