[Ada] Postcondition checks performed before finalization
authorJustin Squirek <squirek@adacore.com>
Mon, 16 Nov 2020 14:08:51 +0000 (09:08 -0500)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 15 Dec 2020 11:41:56 +0000 (06:41 -0500)
commita1023434a8dd3ce2281a726d30ef370caa425252
tree96879e168c070a781a22b5670da318bf9bf47143
parent43852482cafa73da6408120722dcbe7ff6fd3ded
[Ada] Postcondition checks performed before finalization

gcc/ada/

* contracts.adb, contracts.ads (Build_Postconditions_Procedure):
Add declarations for Postcond_Enabled,
Result_Object_For_Postcondition, and
Return_Success_For_Postcond, and place all postconditions within
an if statement to control their execution for interactions when
cleanup actions get generated.
(Get_Postcond_Enabled): Created to fetch object declared to
handle new expansion of postconditions.
(Get_Result_Object_For_Postcond): Created to fetch object
declared to handle new expansion of postconditions.
(Get_Return_Success_For_Postcond): Created to fetch object
declared to handle new expansion of postconditions.
* einfo.adb, einfo.ads: Modify flag Stores_Attribute_Old_Prefix
to apply to constants, variables, and types.
* exp_ch6.adb (Add_Return): Add assignment to
Return_Success_For_Postcond.
(Expand_Non_Function_Return): Add assignment to
Return_Success_For_Postcond
(Expand_Simple_Function_Return): Add assignment to
Result_Object_For_Postcond and Return_Success_For_Postcond.
* exp_ch7.adb (Build_Finalization_Master): Mark finalization
masters which finalize types created store 'Old objects as
storing 'Old objects.
(Build_Finalizer): Created to generated a unified and special
expansion for finalization when postconditions are present.
(Build_Finalizer_Helper): Renamed Build_Finalizer and added
parameter to facilitate the creation of separate finalization
routines for 'Old objects and general objects.
(Create_Finalizer): Add condition for the insertion of the
finalizer spec to avoid malformed trees.
(Expand_Cleanup_Actions): Move _postconditions and related
declarations to the new declarative section.  Fix the loop to
properly stop at the subprogram declaration for the
postconditions procedure and exclude its body from being moved
to the new list of declarations to avoid freezing issues.
* exp_prag.adb (Expand_Attributes): Mark temporary created to
store 'Old objects as storing a 'Old attribute.
* sem_ch6.adb (Find_What_Applies_To): Remove strange exception
to postconditions when traversing the scope stack.
* sem_prag.adb (Find_Related_Declaration_Or_Body): Use the newly
created Enclosing_HSS function to find the HSS for a potentially
nested statement.
* sem_util.adb, sem_util.ads (Declare_Indirect_Temp): Mark types
created to store 'Old objects as storing 'Old attributes.
(Enclosing_HSS): Created to find the enclosing handled sequence
of statements for a given statement.
* snames.ads-tmpl: Add multiple names to aid in the expansion of
finalization and to control the evaluation of postconditions.
Including _finalization_controller, a new routine to centralize
finalization actions and postcondition evaluation.
12 files changed:
gcc/ada/contracts.adb
gcc/ada/contracts.ads
gcc/ada/einfo.adb
gcc/ada/einfo.ads
gcc/ada/exp_ch6.adb
gcc/ada/exp_ch7.adb
gcc/ada/exp_prag.adb
gcc/ada/sem_ch6.adb
gcc/ada/sem_prag.adb
gcc/ada/sem_util.adb
gcc/ada/sem_util.ads
gcc/ada/snames.ads-tmpl