Freeze_Before (P, Etype (Var));
end;
- -- For an expression of the form "for all/some X of F(...) => ...",
- -- where F(...) is a function call that returns on the secondary stack,
- -- we need to mark an enclosing scope as Uses_Sec_Stack. We must do
- -- this before expansion, which can obscure the tree. Note that we
- -- might be inside another quantified expression. Skip blocks and
- -- loops that were generated by expansion.
-
- if Present (Iterator_Specification (N))
- and then Nkind (Name (Iterator_Specification (N))) = N_Function_Call
- and then Needs_Secondary_Stack
- (Etype (Name (Iterator_Specification (N))))
- then
- declare
- Source_Scope : Entity_Id := Current_Scope;
- begin
- while Ekind (Source_Scope) in E_Block | E_Loop
- and then not Comes_From_Source (Source_Scope)
- loop
- Source_Scope := Scope (Source_Scope);
- end loop;
-
- Set_Uses_Sec_Stack (Source_Scope);
- Check_Restriction (No_Secondary_Stack, N);
- end;
- end if;
-
-- Create the declaration of the flag which tracks the status of the
-- quantified expression. Generate:
function Has_Sec_Stack_Call (N : Node_Id) return Boolean;
-- N is the node for an arbitrary construct. This function searches the
- -- construct N to see if any expressions within it contain function
- -- calls that use the secondary stack, returning True if any such call
- -- is found, and False otherwise.
+ -- construct N to see if it contains a function call that returns on the
+ -- secondary stack, returning True if any such call is found, and False
+ -- otherwise.
+
+ -- ??? The implementation invokes Sem_Util.Requires_Transient_Scope so it
+ -- will return True if N contains a function call that needs finalization,
+ -- in addition to the above specification. See Analyze_Loop_Statement for
+ -- a similar comment about this entanglement.
procedure Preanalyze_Range (R_Copy : Node_Id);
-- Determine expected type of range or domain of iteration of Ada 2012
Cont_Typ := Etype (Nam_Copy);
-- The iterator loop is traversing an array. This case does not
- -- require any transformation.
+ -- require any transformation, unless the name contains a call
+ -- that returns on the secondary stack since we need to release
+ -- the space allocated there.
- if Is_Array_Type (Cont_Typ) then
+ if Is_Array_Type (Cont_Typ)
+ and then not Has_Sec_Stack_Call (Nam_Copy)
+ then
null;
-- Otherwise unconditionally wrap the loop statement within