]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Remove repeated conversions between Source_Ptr and Int
authorPiotr Trojanek <trojanek@adacore.com>
Thu, 20 Jan 2022 17:05:39 +0000 (18:05 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 10 May 2022 08:19:28 +0000 (08:19 +0000)
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.

gcc/ada/par-ch10.adb
gcc/ada/scng.adb
gcc/ada/sem_res.adb
gcc/ada/sinfo-utils.adb
gcc/ada/treepr.adb

index 901ad17115eff92d64517a7ae46c383fb1c67aee..613be37fe751839192871b55ef0a1b7d0c8db66b 100644 (file)
@@ -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;
index 676a4f2898ce9841a11fa6dd1e764240c1ed353f..c50a41e94dc3237451f5a777399ab39ae31330e5 100644 (file)
@@ -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
index a59ffe70be051f29caad882cbec18c533d2dbd27..125366b49737f5dbfcb32ab77ae1df715d506164 100644 (file)
@@ -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;
index 121a0398f4ae9779297ac69c35ee90cdf04c0ac3..35288916b8aff58dffba26b1c52d9d78a1463b33 100644 (file)
@@ -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;
 
    --------------------------
index 2faf3f85656e914dc553b0a3487a2682dbd34853..3173668d82a7dbf636f578cf959a87a4d85b2d9e 100644 (file)
@@ -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;