Implement the 'Valid_Value attribute for enumeration types. Currently, 'Valid_Value is not supported for types in Standard, because they do not have image/value tables. Currently, there are no 'Valid_Wide_Image or 'Valid_Wide_Wide_Image attributes.
Tested on x86_64-pc-linux-gnu, committed on trunk 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.
patch.diff.gz
Description: application/gzip