[Ada] Improve support for casing on types with controlled parts
authorSteve Baird <baird@adacore.com>
Fri, 5 Nov 2021 22:22:05 +0000 (15:22 -0700)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 1 Dec 2021 10:24:42 +0000 (10:24 +0000)
commitbb2fc099e28c6e0fc3f77598c514fa6ec72d846d
tree32125e9ef4a86d75953b9001c2722254d9cb9a99
parentbe6bb3fc57e2af376e5c18eeca51119e87a55ee3
[Ada] Improve support for casing on types with controlled parts

gcc/ada/

* sem_case.adb (Check_Bindings): Provide a second strategy for
implementing bindings and choose which strategy to use for a
given binding. The previous approach was to introduce a new
object and assign the bound value to the object.  The new
approach is to introduce a renaming of a dereference of an
access value that references the appropriate subcomponent, so no
copies are made.  The original strategy is still used if the
type of the object is elementary.  When the renaming approach is
used, the initialization of the access value is not generated
until expansion. Until this missing initialization is added, the
tree looks like a known-at-compile-time dereference of a null
access value: Temp : Some_Access_Type; Obj : Designated_Type
renames Temp.all; This leads to problems, so a bogus initial
value is provided here and then later deleted during expansion.
(Check_Composite_Case_Selector): Disallow a case selector
expression that requires finalization. Note that it is ok if the
selector's type requires finalization, as long as the expression
itself doesn't have any "newly constructed" parts.
* exp_ch5.adb (Pattern_Match): Detect the case where analysis of
a general (i.e., composite selector type) case statement chose
to implement a binding as a renaming rather than by making a
copy. In that case, generate the assignments to initialize the
access-valued object whose designated value is later renamed
(and remove the bogus initial value for that object that was
added during analysis).
* sem_util.ads, sem_util.adb: Add new function
Is_Newly_Constructed corresponding to RM 4.4 term.
gcc/ada/exp_ch5.adb
gcc/ada/sem_case.adb
gcc/ada/sem_util.adb
gcc/ada/sem_util.ads