Ada Fixes Differences between 'Img and 'Image for Enumeration Types.
The Ada compiler now ensures 'Img behaves like 'Image for enumeration types when using Put_Image, and folds more aggressively.
The Ada compiler now ensures that the 'Img attribute behaves consistently with the 'Image attribute for enumeration types, as documented in the GNAT Reference Manual. This change resolves inconsistencies and implements more aggressive folding, improving performance. The implementation factors out a new procedure, Fold_Compile_Time_Known_Enumeration_Image, to handle folding of 'Img and 'Image for compile-time known values of enumeration types, excluding character types, when Put_Image is not required.
In Details
The Ada language's 'Img and 'Image attributes provide string representations of values. This commit modifies sem_attr.adb to ensure 'Img behaves like 'Image for enumeration types when Put_Image is involved. The change also introduces more aggressive folding, attempting to evaluate 'Img and 'Image at compile time for known enumeration values, which can improve code generation.
For Context
In Ada, the 'Img and 'Image attributes convert values into strings. This commit aligns the behavior of these attributes for enumeration types (user-defined types with a fixed set of values) when a specific formatting function, Put_Image, is used. By ensuring consistent behavior and performing more calculations at compile time, this change can improve the performance and predictability of Ada programs.