public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Replace variables with constants in expanded code for task names
@ 2022-05-10  8:20 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-05-10  8:20 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

[-- Attachment #1: Type: text/plain, Size: 467 bytes --]

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.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

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

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2509 bytes --]

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -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)));



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-10  8:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10  8:20 [Ada] Replace variables with constants in expanded code for task names Pierre-Marie de Rodat

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).