From: Eric Botcazou <[email protected]>
The hook moniker is an obsolete reference to the previous implementation of
object finalization, which used hooks (and counters) to manage the objects.
gcc/ada/ChangeLog:
* exp_util.ads (Find_Hook_Context): Rename to...
(Find_Master_Context): ...this and alphabetize.
* exp_util.adb (Find_Master_Context): Rename to...
(Find_Master_Context): ...this and alphabetize.
* exp_ch4.adb (Insert_Conditional_Object_Declaration): Adjust to
above renaming.
(Process_Transients_In_Expression): Likewise.
Tested on x86_64-pc-linux-gnu (before the recent bootstrap breakage), committed
on master.
---
gcc/ada/exp_ch4.adb | 10 +-
gcc/ada/exp_util.adb | 297 +++++++++++++++++++++----------------------
gcc/ada/exp_util.ads | 14 +-
3 files changed, 159 insertions(+), 162 deletions(-)
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 1d167e01b8c..28d7f596777 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -13436,7 +13436,7 @@ package body Exp_Ch4 is
-- The master is the innermost enclosing non-transient construct
- Insert_Action (Find_Hook_Context (Expr), Master_Node_Decl);
+ Insert_Action (Find_Master_Context (Expr), Master_Node_Decl);
-- Propagate the relaxed finalization semantics
@@ -14896,7 +14896,7 @@ package body Exp_Ch4 is
Loc : constant Source_Ptr := Sloc (Obj_Decl);
Obj_Id : constant Entity_Id := Defining_Identifier (Obj_Decl);
- Hook_Context : constant Node_Id := Find_Hook_Context (Expr);
+ Master_Context : constant Node_Id := Find_Master_Context (Expr);
-- The node after which to insert deferred finalization actions. This
-- is usually the innermost enclosing non-transient construct.
@@ -14938,7 +14938,7 @@ package body Exp_Ch4 is
-- enclosing non-transient construct.
else
- Fin_Context := Hook_Context;
+ Fin_Context := Master_Context;
end if;
-- Create the declaration of the Master_Node for the object and
@@ -14948,7 +14948,7 @@ package body Exp_Ch4 is
Master_Node_Id := Make_Temporary (Loc, 'N');
Master_Node_Decl :=
Make_Master_Node_Declaration (Loc, Master_Node_Id, Obj_Id);
- Insert_Action (Hook_Context, Master_Node_Decl);
+ Insert_Action (Master_Context, Master_Node_Decl);
-- Generate the attachment of the object to the Master_Node
@@ -14968,7 +14968,7 @@ package body Exp_Ch4 is
-- Finalize the object after the context has been evaluated
- -- Note that the node returned by Find_Hook_Context above may be an
+ -- Note that the node returned by Find_Master_Context above may be an
-- operator, which is not a list member. We must locate the proper
-- node in the tree after which to insert the finalization call.
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 4dc4b03da68..f231dab2168 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -6771,6 +6771,153 @@ package body Exp_Util is
return Last_Init;
end Find_Last_Init;
+ -------------------------
+ -- Find_Master_Context --
+ -------------------------
+
+ function Find_Master_Context (N : Node_Id) return Node_Id is
+ Par : Node_Id;
+ Top : Node_Id;
+
+ Wrapped_Node : Node_Id;
+ -- Note: if we are in a transient scope, we want to reuse it as the
+ -- context for inserting actions, if possible. But if N is itself
+ -- part of the stored actions of the current transient scope, then
+ -- we need to insert at the appropriate (inner) location in the list.
+
+ begin
+ -- When the node is inside a case/if expression, the lifetime of any
+ -- temporary controlled object is extended. Find a suitable insertion
+ -- node by locating the topmost case or if expressions.
+
+ if Within_Conditional_Expression (N) then
+ Par := N;
+ Top := N;
+ while Present (Par) loop
+ if Nkind (Original_Node (Par)) in N_Case_Expression
+ | N_If_Expression
+ then
+ Top := Par;
+
+ elsif Nkind (Par) in N_Case_Statement
+ | N_If_Statement
+ and then From_Conditional_Expression (Par)
+ then
+ Top := Par;
+
+ -- Prevent the search from going too far
+
+ elsif Is_Body_Or_Package_Declaration (Par) then
+ exit;
+ end if;
+
+ Par := Parent (Par);
+ end loop;
+
+ -- The topmost case or if expression is now recovered, but it may
+ -- still not be the correct place to add generated code. Climb to
+ -- find a parent that is part of a declarative or statement list,
+ -- and is not a list of actuals in a call.
+
+ Par := Top;
+ while Present (Par) loop
+ if Is_List_Member (Par)
+ and then Nkind (Par) not in N_Component_Association
+ | N_Discriminant_Association
+ | N_Parameter_Association
+ | N_Pragma_Argument_Association
+ | N_Aggregate
+ | N_Delta_Aggregate
+ | N_Extension_Aggregate
+ | N_Elsif_Part
+ and then Nkind (Parent (Par)) not in N_Function_Call
+ | N_Procedure_Call_Statement
+ | N_Entry_Call_Statement
+ | N_Aggregate
+ | N_Delta_Aggregate
+ | N_Extension_Aggregate
+ then
+ return Par;
+
+ -- Prevent the search from going too far
+
+ elsif Is_Body_Or_Package_Declaration (Par) then
+ exit;
+ end if;
+
+ Par := Parent (Par);
+ end loop;
+
+ return Par;
+
+ else
+ Par := N;
+ while Present (Par) loop
+
+ -- Keep climbing past various operators
+
+ if Nkind (Parent (Par)) in N_Op
+ or else Nkind (Parent (Par)) in N_And_Then | N_Or_Else
+ then
+ Par := Parent (Par);
+ else
+ exit;
+ end if;
+ end loop;
+
+ Top := Par;
+
+ -- The node may be located in a pragma in which case return the
+ -- pragma itself:
+
+ -- pragma Precondition (... and then Ctrl_Func_Call ...);
+
+ -- Similar case occurs when the node is related to an object
+ -- declaration or assignment:
+
+ -- Obj [: Some_Typ] := ... and then Ctrl_Func_Call ...;
+
+ -- Another case to consider is when the node is part of a return
+ -- statement:
+
+ -- return ... and then Ctrl_Func_Call ...;
+
+ -- Another case is when the node acts as a formal in a procedure
+ -- call statement:
+
+ -- Proc (... and then Ctrl_Func_Call ...);
+
+ if Scope_Is_Transient then
+ Wrapped_Node := Node_To_Be_Wrapped;
+ else
+ Wrapped_Node := Empty;
+ end if;
+
+ while Present (Par) loop
+ if Par = Wrapped_Node
+ or else Nkind (Par) in N_Assignment_Statement
+ | N_Object_Declaration
+ | N_Pragma
+ | N_Procedure_Call_Statement
+ | N_Simple_Return_Statement
+ then
+ return Par;
+
+ -- Prevent the search from going too far
+
+ elsif Is_Body_Or_Package_Declaration (Par) then
+ exit;
+ end if;
+
+ Par := Parent (Par);
+ end loop;
+
+ -- Return the topmost short circuit operator
+
+ return Top;
+ end if;
+ end Find_Master_Context;
+
---------------------------
-- Find_Optional_Prim_Op --
---------------------------
@@ -6977,156 +7124,6 @@ package body Exp_Util is
end if;
end Find_Storage_Op;
- -----------------------
- -- Find_Hook_Context --
- -----------------------
-
- function Find_Hook_Context (N : Node_Id) return Node_Id is
- Par : Node_Id;
- Top : Node_Id;
-
- Wrapped_Node : Node_Id;
- -- Note: if we are in a transient scope, we want to reuse it as
- -- the context for actions insertion, if possible. But if N is itself
- -- part of the stored actions for the current transient scope,
- -- then we need to insert at the appropriate (inner) location in
- -- the not as an action on Node_To_Be_Wrapped.
-
- In_Cond_Expr : constant Boolean := Within_Conditional_Expression (N);
-
- begin
- -- When the node is inside a case/if expression, the lifetime of any
- -- temporary controlled object is extended. Find a suitable insertion
- -- node by locating the topmost case or if expressions.
-
- if In_Cond_Expr then
- Par := N;
- Top := N;
- while Present (Par) loop
- if Nkind (Original_Node (Par)) in N_Case_Expression
- | N_If_Expression
- then
- Top := Par;
-
- elsif Nkind (Par) in N_Case_Statement
- | N_If_Statement
- and then From_Conditional_Expression (Par)
- then
- Top := Par;
-
- -- Prevent the search from going too far
-
- elsif Is_Body_Or_Package_Declaration (Par) then
- exit;
- end if;
-
- Par := Parent (Par);
- end loop;
-
- -- The topmost case or if expression is now recovered, but it may
- -- still not be the correct place to add generated code. Climb to
- -- find a parent that is part of a declarative or statement list,
- -- and is not a list of actuals in a call.
-
- Par := Top;
- while Present (Par) loop
- if Is_List_Member (Par)
- and then Nkind (Par) not in N_Component_Association
- | N_Discriminant_Association
- | N_Parameter_Association
- | N_Pragma_Argument_Association
- | N_Aggregate
- | N_Delta_Aggregate
- | N_Extension_Aggregate
- | N_Elsif_Part
- and then Nkind (Parent (Par)) not in N_Function_Call
- | N_Procedure_Call_Statement
- | N_Entry_Call_Statement
- | N_Aggregate
- | N_Delta_Aggregate
- | N_Extension_Aggregate
- then
- return Par;
-
- -- Prevent the search from going too far
-
- elsif Is_Body_Or_Package_Declaration (Par) then
- exit;
- end if;
-
- Par := Parent (Par);
- end loop;
-
- return Par;
-
- else
- Par := N;
- while Present (Par) loop
-
- -- Keep climbing past various operators
-
- if Nkind (Parent (Par)) in N_Op
- or else Nkind (Parent (Par)) in N_And_Then | N_Or_Else
- then
- Par := Parent (Par);
- else
- exit;
- end if;
- end loop;
-
- Top := Par;
-
- -- The node may be located in a pragma in which case return the
- -- pragma itself:
-
- -- pragma Precondition (... and then Ctrl_Func_Call ...);
-
- -- Similar case occurs when the node is related to an object
- -- declaration or assignment:
-
- -- Obj [: Some_Typ] := ... and then Ctrl_Func_Call ...;
-
- -- Another case to consider is when the node is part of a return
- -- statement:
-
- -- return ... and then Ctrl_Func_Call ...;
-
- -- Another case is when the node acts as a formal in a procedure
- -- call statement:
-
- -- Proc (... and then Ctrl_Func_Call ...);
-
- if Scope_Is_Transient then
- Wrapped_Node := Node_To_Be_Wrapped;
- else
- Wrapped_Node := Empty;
- end if;
-
- while Present (Par) loop
- if Par = Wrapped_Node
- or else Nkind (Par) in N_Assignment_Statement
- | N_Object_Declaration
- | N_Pragma
- | N_Procedure_Call_Statement
- | N_Simple_Return_Statement
- then
- return Par;
-
- -- Prevent the search from going too far
-
- elsif Is_Body_Or_Package_Declaration (Par) then
- exit;
- end if;
-
- Par := Parent (Par);
- end loop;
-
- -- Return the topmost short circuit operator
-
- return Top;
- end if;
- end Find_Hook_Context;
-
-----------------------------------------
-- Flag_Interface_Pointer_Displacement --
-----------------------------------------
diff --git a/gcc/ada/exp_util.ads b/gcc/ada/exp_util.ads
index c866acd76b8..318225abd69 100644
--- a/gcc/ada/exp_util.ads
+++ b/gcc/ada/exp_util.ads
@@ -644,6 +644,13 @@ package Exp_Util is
-- Same as Find_Prim_Op but for the three controlled primitive operations,
-- and returns Empty if not found.
+ function Find_Master_Context (N : Node_Id) return Node_Id;
+ -- Determine a suitable node on which to attach actions related to N that
+ -- need to be performed immediately after the execution of N is complete.
+ -- In general this is the topmost expression or statement of which N is a
+ -- subexpression, but note that object declarations may be returned here,
+ -- although they are not master constructs in the language.
+
function Find_Optional_Prim_Op
(T : Entity_Id; Name : Name_Id) return Entity_Id;
function Find_Optional_Prim_Op
@@ -673,13 +680,6 @@ package Exp_Util is
-- indicating that the operation is defaulted in the aspect (can occur in
-- the case where the storage-model address type is System.Address).
- function Find_Hook_Context (N : Node_Id) return Node_Id;
- -- Determine a suitable node on which to attach actions related to N that
- -- need to be elaborated unconditionally. In general this is the topmost
- -- expression of which N is a subexpression, which in turn may or may not
- -- be evaluated, for example if N is the right operand of a short circuit
- -- operator.
-
procedure Flag_Interface_Pointer_Displacement (N : Node_Id);
-- If N is an N_Type_Conversion node then flag N to indicate that this
-- type conversion was internally added to force the displacement of the
--
2.51.0