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.
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;
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
Error_Msg
("literal out of range of type Standard.Character",
- Source_Ptr (Int (Loc) + J));
+ Loc + Source_Ptr (J));
return;
end if;
end loop;
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;
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;
--------------------
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;
--------------------------
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;