public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-247] [Ada] Remove repeated conversions between Source_Ptr and Int Date: Tue, 10 May 2022 08:22:44 +0000 (GMT) [thread overview] Message-ID: <20220510082244.13DC83838001@sourceware.org> (raw) https://gcc.gnu.org/g:45c4d9193dd33013522ff7e7f8f90f77d20cb7be commit r13-247-g45c4d9193dd33013522ff7e7f8f90f77d20cb7be Author: Piotr Trojanek <trojanek@adacore.com> Date: Thu Jan 20 18:05:39 2022 +0100 [Ada] Remove repeated conversions between Source_Ptr and Int Both Source_Ptr and Int are integer types (and even happen to have equal ranges). Their values can be calculated without converting back-and-forth, e.g.: Int (Loc1) - Int (Loc2) can be written simply as: Int (Loc1 - Loc2) Code cleanup related to handling of references to unset objects. Offending occurrences found with various invocations of grep. gcc/ada/ * par-ch10.adb, scng.adb, sem_res.adb, sinfo-utils.adb, treepr.adb: Simplify calculations with Source_Ptr and Loc values. Diff: --- gcc/ada/par-ch10.adb | 2 +- gcc/ada/scng.adb | 6 +----- gcc/ada/sem_res.adb | 4 ++-- gcc/ada/sinfo-utils.adb | 4 ++-- gcc/ada/treepr.adb | 2 +- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/gcc/ada/par-ch10.adb b/gcc/ada/par-ch10.adb index 901ad17115e..613be37fe75 100644 --- a/gcc/ada/par-ch10.adb +++ b/gcc/ada/par-ch10.adb @@ -1194,7 +1194,7 @@ package body Ch10 is Write_Int (Int (Line)); Write_Str (", file offset "); - Write_Int (Int (Loc) - Int (Source_First (Sind))); + Write_Int (Int (Loc - Source_First (Sind))); end Unit_Location; end Ch10; diff --git a/gcc/ada/scng.adb b/gcc/ada/scng.adb index 676a4f2898c..c50a41e94dc 100644 --- a/gcc/ada/scng.adb +++ b/gcc/ada/scng.adb @@ -130,11 +130,7 @@ package body Scng is procedure Check_End_Of_Line is Len : constant Int := - Int (Scan_Ptr) - - Int (Current_Line_Start) - - Wide_Char_Byte_Count; - - -- Start of processing for Check_End_Of_Line + Int (Scan_Ptr - Current_Line_Start) - Wide_Char_Byte_Count; begin if Style_Check then diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index a59ffe70be0..125366b4973 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -11754,7 +11754,7 @@ package body Sem_Res is Error_Msg ("literal out of range of type Standard.Character", - Source_Ptr (Int (Loc) + J)); + Loc + Source_Ptr (J)); return; end if; end loop; @@ -11783,7 +11783,7 @@ package body Sem_Res is Error_Msg ("literal out of range of type Standard.Wide_Character", - Source_Ptr (Int (Loc) + J)); + Loc + Source_Ptr (J)); return; end if; end loop; diff --git a/gcc/ada/sinfo-utils.adb b/gcc/ada/sinfo-utils.adb index 121a0398f4a..35288916b8a 100644 --- a/gcc/ada/sinfo-utils.adb +++ b/gcc/ada/sinfo-utils.adb @@ -191,7 +191,7 @@ package body Sinfo.Utils is function End_Location (N : Node_Id) return Source_Ptr is L : constant Valid_Uint := End_Span (N); begin - return Source_Ptr (Int (Sloc (N)) + UI_To_Int (L)); + return Sloc (N) + Source_Ptr (UI_To_Int (L)); end End_Location; -------------------- @@ -214,7 +214,7 @@ package body Sinfo.Utils is procedure Set_End_Location (N : Node_Id; S : Source_Ptr) is begin Set_End_Span (N, - UI_From_Int (Int (S) - Int (Sloc (N)))); + UI_From_Int (Int (S - Sloc (N)))); end Set_End_Location; -------------------------- diff --git a/gcc/ada/treepr.adb b/gcc/ada/treepr.adb index 2faf3f85656..3173668d82a 100644 --- a/gcc/ada/treepr.adb +++ b/gcc/ada/treepr.adb @@ -1229,7 +1229,7 @@ package body Treepr is else Sfile := Get_Source_File_Index (Sloc (N)); - Print_Int (Int (Sloc (N)) - Int (Source_Text (Sfile)'First)); + Print_Int (Int (Sloc (N) - Source_Text (Sfile)'First)); Write_Str (" "); Write_Location (Sloc (N)); end if;
reply other threads:[~2022-05-10 8:22 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=20220510082244.13DC83838001@sourceware.org \ --to=pmderodat@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /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: linkBe 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).