[Ada] Avoid unnecessary work when expanding 'Image into 'Put_Image

gcc/ada/

	* exp_imgv.adb (Expand_Image_Attribute): Move rewriting to
	attribute Put_Image to the beginning of expansion of attribute
	Image.
This commit is contained in:
Piotr Trojanek 2021-06-17 18:49:11 +02:00 committed by Pierre-Marie de Rodat
parent c03cae4e06
commit 86b228b87b
1 changed files with 10 additions and 9 deletions

View File

@ -1044,6 +1044,15 @@ package body Exp_Imgv is
return;
end if;
-- If Image should be transformed using Put_Image, then do so. See
-- Exp_Put_Image for details.
if Exp_Put_Image.Image_Should_Call_Put_Image (N) then
Rewrite (N, Exp_Put_Image.Build_Image_Call (N));
Analyze_And_Resolve (N, Standard_String, Suppress => All_Checks);
return;
end if;
Ptyp := Underlying_Type (Entity (Pref));
-- Ada 2022 allows 'Image on private types, so fetch the underlying
@ -1063,15 +1072,7 @@ package body Exp_Imgv is
Enum_Case := False;
-- If this is a case where Image should be transformed using Put_Image,
-- then do so. See Exp_Put_Image for details.
if Exp_Put_Image.Image_Should_Call_Put_Image (N) then
Rewrite (N, Exp_Put_Image.Build_Image_Call (N));
Analyze_And_Resolve (N, Standard_String, Suppress => All_Checks);
return;
elsif Rtyp = Standard_Boolean then
if Rtyp = Standard_Boolean then
-- Use inline expansion if the -gnatd_x switch is not passed to the
-- compiler. Otherwise expand into a call to the runtime.