aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_attr.adb
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2024-03-22 14:50:15 +0100
committerMarc Poulhiès <poulhies@adacore.com>2024-05-20 09:47:03 +0200
commit9edbaab0f6eb83351ef65e5bc0e427a415e04915 (patch)
tree59b629afbab333a094cd3479feff5fcf472eb461 /gcc/ada/sem_attr.adb
parentfbe275e2458458ad517645d64619d3aac4467cf1 (diff)
downloadgcc-9edbaab0f6eb83351ef65e5bc0e427a415e04915.zip
gcc-9edbaab0f6eb83351ef65e5bc0e427a415e04915.tar.gz
gcc-9edbaab0f6eb83351ef65e5bc0e427a415e04915.tar.bz2
ada: Fix static 'Img for enumeration type with Discard_Names
Fix a short-circuit folding of 'Img for enumeration type, which wrongly ignored Discard_Names and exposed enumeration literals. gcc/ada/ * sem_attr.adb (Eval_Attribute): Handle enumeration type with Discard_Names.
Diffstat (limited to 'gcc/ada/sem_attr.adb')
-rw-r--r--gcc/ada/sem_attr.adb19
1 files changed, 16 insertions, 3 deletions
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 96f216c..2b22cf1 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -8221,13 +8221,26 @@ package body Sem_Attr is
then
declare
Lit : constant Entity_Id := Expr_Value_E (P);
+ Typ : constant Entity_Id := Etype (Entity (P));
Str : String_Id;
begin
Start_String;
- Get_Unqualified_Decoded_Name_String (Chars (Lit));
- Set_Casing (All_Upper_Case);
- Store_String_Chars (Name_Buffer (1 .. Name_Len));
+
+ -- If Discard_Names is in effect for the type, then we emit the
+ -- numeric representation of the prefix literal 'Pos attribute,
+ -- prefixed with a single space.
+
+ if Discard_Names (Typ) then
+ UI_Image (Enumeration_Pos (Lit), Decimal);
+ Store_String_Char (' ');
+ Store_String_Chars (UI_Image_Buffer (1 .. UI_Image_Length));
+ else
+ Get_Unqualified_Decoded_Name_String (Chars (Lit));
+ Set_Casing (All_Upper_Case);
+ Store_String_Chars (Name_Buffer (1 .. Name_Len));
+ end if;
+
Str := End_String;
Rewrite (N, Make_String_Literal (Loc, Strval => Str));