[Ada] Implement 'Valid_Value attribute
authorBob Duff <duff@adacore.com>
Wed, 31 Mar 2021 12:00:59 +0000 (08:00 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 21 Jun 2021 10:45:12 +0000 (06:45 -0400)
commit336438b6d225c3a5f28d57fd766e36f53faf8f3e
tree4d9c8a37c32c67c6121686a39ed3a053d7b79556
parent7f34e744c0bdb8b3f767463f290a32bc671bfcc8
[Ada] Implement 'Valid_Value attribute

gcc/ada/

* libgnat/s-valuen.ads, libgnat/s-valuen.adb
(Value_Enumeration_Pos): New function to compute the 'Pos of the
enumeration literal for a given String.  Return a special value
instead of raising an exception on invalid input. Called by both
Valid_Enumeration_Image and Value_Enumeration.
(Valid_Enumeration_Image): Return a Boolean indicating whether
the String is a valid Image for the given enumeration type.
(Value_Enumeration): Implement in terms of
Value_Enumeration_Pos.
* libgnat/s-vaenu8.ads, libgnat/s-vaen16.ads,
libgnat/s-vaen32.ads: Rename Valid_Enumeration_Image from the
instances.
* libgnat/s-valuti.ads: Correct documentation (it was not true
for the null string).
* libgnat/s-valuti.adb (Normalize_String): Do not raise
Constraint_Error for the null string, nor strings containing
nothing but blanks, so that Valid_Enumeration_Image can return
False in these cases, rather than raising an exception.
* rtsfind.ads (RE_Value_Enumeration_8, RE_Value_Enumeration_16,
RE_Value_Enumeration_32): New functions.
(RTE_Available): Improve comment (E doesn't have to be a
subprogram, although that's the usual case).
* sem_attr.adb (nalid_Value): Semantic analysis for new
attribute.
* exp_attr.adb: Call Expand_Valid_Value_Attribute for new
attribute.
* exp_imgv.ads, exp_imgv.adb (Expand_Valid_Value_Attribute): New
procedure to expand Valid_Value into a call to
Valid_Enumeration_Image_NN.
(Expand_Value_Attribute): Misc code cleanups.  Remove two ???
mark comments. RTE_Available won't work here.  For one thing,
RTE_Available (X) shouldn't be called until the compiler has
decided to make use of X (see comments on RTE_Available), and in
this case we're trying to AVOID calling something.
* snames.ads-tmpl: New attribute name.
* doc/gnat_rm/implementation_defined_attributes.rst: Document
new attribute.
* gnat_rm.texi: Regenerate.
15 files changed:
gcc/ada/doc/gnat_rm/implementation_defined_attributes.rst
gcc/ada/exp_attr.adb
gcc/ada/exp_imgv.adb
gcc/ada/exp_imgv.ads
gcc/ada/gnat_rm.texi
gcc/ada/libgnat/s-vaen16.ads
gcc/ada/libgnat/s-vaen32.ads
gcc/ada/libgnat/s-vaenu8.ads
gcc/ada/libgnat/s-valuen.adb
gcc/ada/libgnat/s-valuen.ads
gcc/ada/libgnat/s-valuti.adb
gcc/ada/libgnat/s-valuti.ads
gcc/ada/rtsfind.ads
gcc/ada/sem_attr.adb
gcc/ada/snames.ads-tmpl