1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2014-2017, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Debug
; use Debug
;
28 with Einfo
; use Einfo
;
29 with Elists
; use Elists
;
31 with Namet
; use Namet
;
32 with Nlists
; use Nlists
;
33 with Nmake
; use Nmake
;
35 with Output
; use Output
;
36 with Rtsfind
; use Rtsfind
;
38 with Sem_Aux
; use Sem_Aux
;
39 with Sem_Ch8
; use Sem_Ch8
;
40 with Sem_Mech
; use Sem_Mech
;
41 with Sem_Res
; use Sem_Res
;
42 with Sem_Util
; use Sem_Util
;
43 with Sinfo
; use Sinfo
;
44 with Sinput
; use Sinput
;
45 with Snames
; use Snames
;
46 with Tbuild
; use Tbuild
;
47 with Uintp
; use Uintp
;
49 package body Exp_Unst
is
51 -----------------------
52 -- Local Subprograms --
53 -----------------------
55 procedure Unnest_Subprogram
(Subp
: Entity_Id
; Subp_Body
: Node_Id
);
56 -- Subp is a library-level subprogram which has nested subprograms, and
57 -- Subp_Body is the corresponding N_Subprogram_Body node. This procedure
58 -- declares the AREC types and objects, adds assignments to the AREC record
59 -- as required, defines the xxxPTR types for uplevel referenced objects,
60 -- adds the ARECP parameter to all nested subprograms which need it, and
61 -- modifies all uplevel references appropriately.
67 -- Table to record calls within the nest being analyzed. These are the
68 -- calls which may need to have an AREC actual added. This table is built
69 -- new for each subprogram nest and cleared at the end of processing each
72 type Call_Entry
is record
77 -- Entity of the subprogram containing the call (can be at any level)
80 -- Entity of the subprogram called (always at level 2 or higher). Note
81 -- that in accordance with the basic rules of nesting, the level of To
82 -- is either less than or equal to the level of From, or one greater.
85 package Calls
is new Table
.Table
(
86 Table_Component_Type
=> Call_Entry
,
87 Table_Index_Type
=> Nat
,
90 Table_Increment
=> 200,
91 Table_Name
=> "Unnest_Calls");
92 -- Records each call within the outer subprogram and all nested subprograms
93 -- that are to other subprograms nested within the outer subprogram. These
94 -- are the calls that may need an additional parameter.
96 procedure Append_Unique_Call
(Call
: Call_Entry
);
97 -- Append a call entry to the Calls table. A check is made to see if the
98 -- table already contains this entry and if so it has no effect.
104 -- Table to record explicit uplevel references to objects (variables,
105 -- constants, formal parameters). These are the references that will
106 -- need rewriting to use the activation table (AREC) pointers. Also
107 -- included are implicit and explicit uplevel references to types, but
108 -- these do not get rewritten by the front end. This table is built new
109 -- for each subprogram nest and cleared at the end of processing each
112 type Uref_Entry
is record
114 -- The reference itself. For objects this is always an entity reference
115 -- and the referenced entity will have its Is_Uplevel_Referenced_Entity
116 -- flag set and will appear in the Uplevel_Referenced_Entities list of
117 -- the subprogram declaring this entity.
120 -- The Entity_Id of the uplevel referenced object or type
123 -- The entity for the subprogram immediately containing this entity
126 -- The entity for the subprogram containing the referenced entity. Note
127 -- that the level of Callee must be less than the level of Caller, since
128 -- this is an uplevel reference.
131 package Urefs
is new Table
.Table
(
132 Table_Component_Type
=> Uref_Entry
,
133 Table_Index_Type
=> Nat
,
134 Table_Low_Bound
=> 1,
135 Table_Initial
=> 100,
136 Table_Increment
=> 200,
137 Table_Name
=> "Unnest_Urefs");
139 ------------------------
140 -- Append_Unique_Call --
141 ------------------------
143 procedure Append_Unique_Call
(Call
: Call_Entry
) is
145 for J
in Calls
.First
.. Calls
.Last
loop
146 if Calls
.Table
(J
) = Call
then
152 end Append_Unique_Call
;
158 function Get_Level
(Subp
: Entity_Id
; Sub
: Entity_Id
) return Nat
is
170 S
:= Enclosing_Subprogram
(S
);
179 function Subp_Index
(Sub
: Entity_Id
) return SI_Type
is
180 E
: Entity_Id
:= Sub
;
183 pragma Assert
(Is_Subprogram
(E
));
185 if Subps_Index
(E
) = Uint_0
then
186 E
:= Ultimate_Alias
(E
);
188 if Ekind
(E
) = E_Function
189 and then Rewritten_For_C
(E
)
190 and then Present
(Corresponding_Procedure
(E
))
192 E
:= Corresponding_Procedure
(E
);
196 pragma Assert
(Subps_Index
(E
) /= Uint_0
);
197 return SI_Type
(UI_To_Int
(Subps_Index
(E
)));
200 -----------------------
201 -- Unnest_Subprogram --
202 -----------------------
204 procedure Unnest_Subprogram
(Subp
: Entity_Id
; Subp_Body
: Node_Id
) is
205 function AREC_Name
(J
: Pos
; S
: String) return Name_Id
;
206 -- Returns name for string ARECjS, where j is the decimal value of j
208 function Enclosing_Subp
(Subp
: SI_Type
) return SI_Type
;
209 -- Subp is the index of a subprogram which has a Lev greater than 1.
210 -- This function returns the index of the enclosing subprogram which
211 -- will have a Lev value one less than this.
213 function Img_Pos
(N
: Pos
) return String;
214 -- Return image of N without leading blank
219 Clist
: List_Id
) return Name_Id
;
220 -- This function returns the name to be used in the activation record to
221 -- reference the variable uplevel. Clist is the list of components that
222 -- have been created in the activation record so far. Normally the name
223 -- is just a copy of the Chars field of the entity. The exception is
224 -- when the name has already been used, in which case we suffix the name
225 -- with the index value Index to avoid duplication. This happens with
226 -- declare blocks and generic parameters at least.
232 function AREC_Name
(J
: Pos
; S
: String) return Name_Id
is
234 return Name_Find
("AREC" & Img_Pos
(J
) & S
);
241 function Enclosing_Subp
(Subp
: SI_Type
) return SI_Type
is
242 STJ
: Subp_Entry
renames Subps
.Table
(Subp
);
243 Ret
: constant SI_Type
:= Subp_Index
(Enclosing_Subprogram
(STJ
.Ent
));
245 pragma Assert
(STJ
.Lev
> 1);
246 pragma Assert
(Subps
.Table
(Ret
).Lev
= STJ
.Lev
- 1);
254 function Img_Pos
(N
: Pos
) return String is
255 Buf
: String (1 .. 20);
263 Buf
(Ptr
) := Character'Val (48 + NV
mod 10);
268 return Buf
(Ptr
+ 1 .. Buf
'Last);
278 Clist
: List_Id
) return Name_Id
287 elsif Chars
(Defining_Identifier
(C
)) = Chars
(Ent
) then
289 Name_Find
(Get_Name_String
(Chars
(Ent
)) & Img_Pos
(Index
));
296 -- Start of processing for Unnest_Subprogram
299 -- Nothing to do inside a generic (all processing is for instance)
301 if Inside_A_Generic
then
305 -- At least for now, do not unnest anything but main source unit
307 if not In_Extended_Main_Source_Unit
(Subp_Body
) then
311 -- This routine is called late, after the scope stack is gone. The
312 -- following creates a suitable dummy scope stack to be used for the
313 -- analyze/expand calls made from this routine.
317 -- First step, we must mark all nested subprograms that require a static
318 -- link (activation record) because either they contain explicit uplevel
319 -- references (as indicated by Is_Uplevel_Referenced_Entity being set at
320 -- this point), or they make calls to other subprograms in the same nest
321 -- that require a static link (in which case we set this flag).
323 -- This is a recursive definition, and to implement this, we have to
324 -- build a call graph for the set of nested subprograms, and then go
325 -- over this graph to implement recursively the invariant that if a
326 -- subprogram has a call to a subprogram requiring a static link, then
327 -- the calling subprogram requires a static link.
329 -- First populate the above tables
331 Subps_First
:= Subps
.Last
+ 1;
335 Build_Tables
: declare
336 Current_Subprogram
: Entity_Id
;
337 -- When we scan a subprogram body, we set Current_Subprogram to the
338 -- corresponding entity. This gets recursively saved and restored.
340 function Visit_Node
(N
: Node_Id
) return Traverse_Result
;
341 -- Visit a single node in Subp
347 procedure Visit
is new Traverse_Proc
(Visit_Node
);
348 -- Used to traverse the body of Subp, populating the tables
354 function Visit_Node
(N
: Node_Id
) return Traverse_Result
is
359 procedure Check_Static_Type
(T
: Entity_Id
; DT
: in out Boolean);
360 -- Given a type T, checks if it is a static type defined as a type
361 -- with no dynamic bounds in sight. If so, the only action is to
362 -- set Is_Static_Type True for T. If T is not a static type, then
363 -- all types with dynamic bounds associated with T are detected,
364 -- and their bounds are marked as uplevel referenced if not at the
365 -- library level, and DT is set True.
367 procedure Note_Uplevel_Ref
371 -- Called when we detect an explicit or implicit uplevel reference
372 -- from within Caller to entity E declared in Callee. E can be a
373 -- an object or a type.
375 -----------------------
376 -- Check_Static_Type --
377 -----------------------
379 procedure Check_Static_Type
(T
: Entity_Id
; DT
: in out Boolean) is
380 procedure Note_Uplevel_Bound
(N
: Node_Id
);
381 -- N is the bound of a dynamic type. This procedure notes that
382 -- this bound is uplevel referenced, it can handle references
383 -- to entities (typically _FIRST and _LAST entities), and also
384 -- attribute references of the form T'name (name is typically
385 -- FIRST or LAST) where T is the uplevel referenced bound.
387 ------------------------
388 -- Note_Uplevel_Bound --
389 ------------------------
391 procedure Note_Uplevel_Bound
(N
: Node_Id
) is
395 if Is_Entity_Name
(N
) then
396 if Present
(Entity
(N
)) then
399 Caller
=> Current_Subprogram
,
400 Callee
=> Enclosing_Subprogram
(Entity
(N
)));
405 elsif Nkind
(N
) = N_Attribute_Reference
then
406 Note_Uplevel_Bound
(Prefix
(N
));
408 end Note_Uplevel_Bound
;
410 -- Start of processing for Check_Static_Type
413 -- If already marked static, immediate return
415 if Is_Static_Type
(T
) then
419 -- If the type is at library level, always consider it static,
420 -- since such uplevel references are irrelevant.
422 if Is_Library_Level_Entity
(T
) then
423 Set_Is_Static_Type
(T
);
427 -- Otherwise figure out what the story is with this type
429 -- For a scalar type, check bounds
431 if Is_Scalar_Type
(T
) then
433 -- If both bounds static, then this is a static type
436 LB
: constant Node_Id
:= Type_Low_Bound
(T
);
437 UB
: constant Node_Id
:= Type_High_Bound
(T
);
440 if not Is_Static_Expression
(LB
) then
441 Note_Uplevel_Bound
(LB
);
445 if not Is_Static_Expression
(UB
) then
446 Note_Uplevel_Bound
(UB
);
451 -- For record type, check all components
453 elsif Is_Record_Type
(T
) then
457 C
:= First_Component_Or_Discriminant
(T
);
458 while Present
(C
) loop
459 Check_Static_Type
(Etype
(C
), DT
);
460 Next_Component_Or_Discriminant
(C
);
464 -- For array type, check index types and component type
466 elsif Is_Array_Type
(T
) then
470 Check_Static_Type
(Component_Type
(T
), DT
);
472 IX
:= First_Index
(T
);
473 while Present
(IX
) loop
474 Check_Static_Type
(Etype
(IX
), DT
);
479 -- For private type, examine whether full view is static
481 elsif Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
482 Check_Static_Type
(Full_View
(T
), DT
);
484 if Is_Static_Type
(Full_View
(T
)) then
485 Set_Is_Static_Type
(T
);
488 -- For now, ignore other types
495 Set_Is_Static_Type
(T
);
497 end Check_Static_Type
;
499 ----------------------
500 -- Note_Uplevel_Ref --
501 ----------------------
503 procedure Note_Uplevel_Ref
509 -- Nothing to do for static type
511 if Is_Static_Type
(E
) then
515 -- Nothing to do if Caller and Callee are the same
517 if Caller
= Callee
then
520 -- Callee may be a function that returns an array, and that has
521 -- been rewritten as a procedure. If caller is that procedure,
522 -- nothing to do either.
524 elsif Ekind
(Callee
) = E_Function
525 and then Rewritten_For_C
(Callee
)
526 and then Corresponding_Procedure
(Callee
) = Caller
531 -- We have a new uplevel referenced entity
533 -- All we do at this stage is to add the uplevel reference to
534 -- the table. It's too early to do anything else, since this
535 -- uplevel reference may come from an unreachable subprogram
536 -- in which case the entry will be deleted.
538 Urefs
.Append
((N
, E
, Caller
, Callee
));
539 end Note_Uplevel_Ref
;
541 -- Start of processing for Visit_Node
546 if Nkind_In
(N
, N_Procedure_Call_Statement
, N_Function_Call
)
548 -- We are only interested in direct calls, not indirect calls
549 -- (where Name (N) is an explicit dereference) at least for now!
551 and then Nkind
(Name
(N
)) in N_Has_Entity
553 Ent
:= Entity
(Name
(N
));
555 -- We are only interested in calls to subprograms nested
556 -- within Subp. Calls to Subp itself or to subprograms that
557 -- are outside the nested structure do not affect us.
559 if Scope_Within
(Ent
, Subp
) then
561 -- Ignore calls to imported routines
563 if Is_Imported
(Ent
) then
566 -- Here we have a call to keep and analyze
569 -- Both caller and callee must be subprograms
571 if Is_Subprogram
(Ent
) then
572 Append_Unique_Call
((N
, Current_Subprogram
, Ent
));
577 -- Record a 'Access as a (potential) call
579 elsif Nkind
(N
) = N_Attribute_Reference
then
581 Attr
: constant Attribute_Id
:=
582 Get_Attribute_Id
(Attribute_Name
(N
));
585 when Attribute_Access
586 | Attribute_Unchecked_Access
587 | Attribute_Unrestricted_Access
589 Ent
:= Entity
(Prefix
(N
));
591 -- We are only interested in calls to subprograms
592 -- nested within Subp.
594 if Scope_Within
(Ent
, Subp
) then
595 if Is_Imported
(Ent
) then
598 elsif Is_Subprogram
(Ent
) then
600 ((N
, Current_Subprogram
, Ent
));
609 -- Record a subprogram. We record a subprogram body that acts as
610 -- a spec. Otherwise we record a subprogram declaration, providing
611 -- that it has a corresponding body we can get hold of. The case
612 -- of no corresponding body being available is ignored for now.
614 elsif Nkind
(N
) = N_Subprogram_Body
then
615 Ent
:= Unique_Defining_Entity
(N
);
617 -- Ignore generic subprogram
619 if Is_Generic_Subprogram
(Ent
) then
623 -- Make new entry in subprogram table if not already made
626 L
: constant Nat
:= Get_Level
(Subp
, Ent
);
634 Declares_AREC
=> False,
643 Set_Subps_Index
(Ent
, UI_From_Int
(Subps
.Last
));
646 -- We make a recursive call to scan the subprogram body, so
647 -- that we can save and restore Current_Subprogram.
650 Save_CS
: constant Entity_Id
:= Current_Subprogram
;
654 Current_Subprogram
:= Ent
;
658 Decl
:= First
(Declarations
(N
));
659 while Present
(Decl
) loop
666 Visit
(Handled_Statement_Sequence
(N
));
668 -- Restore current subprogram setting
670 Current_Subprogram
:= Save_CS
;
673 -- Now at this level, return skipping the subprogram body
674 -- descendants, since we already took care of them!
678 -- Record an uplevel reference
680 elsif Nkind
(N
) in N_Has_Entity
and then Present
(Entity
(N
)) then
683 -- Only interested in entities declared within our nest
685 if not Is_Library_Level_Entity
(Ent
)
686 and then Scope_Within_Or_Same
(Scope
(Ent
), Subp
)
688 -- Skip entities defined in inlined subprograms
690 and then Chars
(Enclosing_Subprogram
(Ent
)) /= Name_uParent
693 -- Constants and variables are interesting
695 (Ekind_In
(Ent
, E_Constant
, E_Variable
)
697 -- Formals are interesting, but not if being used as mere
698 -- names of parameters for name notation calls.
703 (Nkind
(Parent
(N
)) = N_Parameter_Association
704 and then Selector_Name
(Parent
(N
)) = N
))
706 -- Types other than known Is_Static types are interesting
708 or else (Is_Type
(Ent
)
709 and then not Is_Static_Type
(Ent
)))
711 -- Here we have a possible interesting uplevel reference
713 if Is_Type
(Ent
) then
715 DT
: Boolean := False;
718 Check_Static_Type
(Ent
, DT
);
720 if Is_Static_Type
(Ent
) then
726 Caller
:= Current_Subprogram
;
727 Callee
:= Enclosing_Subprogram
(Ent
);
729 if Callee
/= Caller
and then not Is_Static_Type
(Ent
) then
730 Note_Uplevel_Ref
(Ent
, Caller
, Callee
);
734 -- If we have a body stub, visit the associated subunit
736 elsif Nkind
(N
) in N_Body_Stub
then
737 Visit
(Library_Unit
(N
));
739 -- Skip generic declarations
741 elsif Nkind
(N
) in N_Generic_Declaration
then
744 -- Skip generic package body
746 elsif Nkind
(N
) = N_Package_Body
747 and then Present
(Corresponding_Spec
(N
))
748 and then Ekind
(Corresponding_Spec
(N
)) = E_Generic_Package
753 -- Fall through to continue scanning children of this node
758 -- Start of processing for Build_Tables
761 -- Traverse the body to get subprograms, calls and uplevel references
766 -- Now do the first transitive closure which determines which
767 -- subprograms in the nest are actually reachable.
769 Reachable_Closure
: declare
773 Subps
.Table
(Subps_First
).Reachable
:= True;
775 -- We use a simple minded algorithm as follows (obviously this can
776 -- be done more efficiently, using one of the standard algorithms
777 -- for efficient transitive closure computation, but this is simple
778 -- and most likely fast enough that its speed does not matter).
780 -- Repeatedly scan the list of calls. Any time we find a call from
781 -- A to B, where A is reachable, but B is not, then B is reachable,
782 -- and note that we have made a change by setting Modified True. We
783 -- repeat this until we make a pass with no modifications.
787 Inner
: for J
in Calls
.First
.. Calls
.Last
loop
789 CTJ
: Call_Entry
renames Calls
.Table
(J
);
791 SINF
: constant SI_Type
:= Subp_Index
(CTJ
.Caller
);
792 SINT
: constant SI_Type
:= Subp_Index
(CTJ
.Callee
);
794 SUBF
: Subp_Entry
renames Subps
.Table
(SINF
);
795 SUBT
: Subp_Entry
renames Subps
.Table
(SINT
);
798 if SUBF
.Reachable
and then not SUBT
.Reachable
then
799 SUBT
.Reachable
:= True;
805 exit Outer
when not Modified
;
807 end Reachable_Closure
;
809 -- Remove calls from unreachable subprograms
816 for J
in Calls
.First
.. Calls
.Last
loop
818 CTJ
: Call_Entry
renames Calls
.Table
(J
);
820 SINF
: constant SI_Type
:= Subp_Index
(CTJ
.Caller
);
821 SINT
: constant SI_Type
:= Subp_Index
(CTJ
.Callee
);
823 SUBF
: Subp_Entry
renames Subps
.Table
(SINF
);
824 SUBT
: Subp_Entry
renames Subps
.Table
(SINT
);
827 if SUBF
.Reachable
then
828 pragma Assert
(SUBT
.Reachable
);
829 New_Index
:= New_Index
+ 1;
830 Calls
.Table
(New_Index
) := Calls
.Table
(J
);
835 Calls
.Set_Last
(New_Index
);
838 -- Remove uplevel references from unreachable subprograms
845 for J
in Urefs
.First
.. Urefs
.Last
loop
847 URJ
: Uref_Entry
renames Urefs
.Table
(J
);
849 SINF
: constant SI_Type
:= Subp_Index
(URJ
.Caller
);
850 SINT
: constant SI_Type
:= Subp_Index
(URJ
.Callee
);
852 SUBF
: Subp_Entry
renames Subps
.Table
(SINF
);
853 SUBT
: Subp_Entry
renames Subps
.Table
(SINT
);
858 -- Keep reachable reference
860 if SUBF
.Reachable
then
861 New_Index
:= New_Index
+ 1;
862 Urefs
.Table
(New_Index
) := Urefs
.Table
(J
);
864 -- And since we know we are keeping this one, this is a good
865 -- place to fill in information for a good reference.
867 -- Mark all enclosing subprograms need to declare AREC
871 S
:= Enclosing_Subprogram
(S
);
873 -- if we are at the top level, as can happen with
874 -- references to formals in aspects of nested subprogram
875 -- declarations, there are no further subprograms to
876 -- mark as requiring activation records.
879 Subps
.Table
(Subp_Index
(S
)).Declares_AREC
:= True;
880 exit when S
= URJ
.Callee
;
883 -- Add to list of uplevel referenced entities for Callee.
884 -- We do not add types to this list, only actual references
885 -- to objects that will be referenced uplevel, and we use
886 -- the flag Is_Uplevel_Referenced_Entity to avoid making
887 -- duplicate entries in the list.
889 if not Is_Uplevel_Referenced_Entity
(URJ
.Ent
) then
890 Set_Is_Uplevel_Referenced_Entity
(URJ
.Ent
);
892 if not Is_Type
(URJ
.Ent
) then
893 Append_New_Elmt
(URJ
.Ent
, SUBT
.Uents
);
897 -- And set uplevel indication for caller
899 if SUBT
.Lev
< SUBF
.Uplevel_Ref
then
900 SUBF
.Uplevel_Ref
:= SUBT
.Lev
;
906 Urefs
.Set_Last
(New_Index
);
909 -- Remove unreachable subprograms from Subps table. Note that we do
910 -- this after eliminating entries from the other two tables, since
911 -- those elimination steps depend on referencing the Subps table.
917 New_SI
:= Subps_First
- 1;
918 for J
in Subps_First
.. Subps
.Last
loop
920 STJ
: Subp_Entry
renames Subps
.Table
(J
);
925 -- Subprogram is reachable, copy and reset index
927 if STJ
.Reachable
then
928 New_SI
:= New_SI
+ 1;
929 Subps
.Table
(New_SI
) := STJ
;
930 Set_Subps_Index
(STJ
.Ent
, UI_From_Int
(New_SI
));
932 -- Subprogram is not reachable
935 -- Clear index, since no longer active
937 Set_Subps_Index
(Subps
.Table
(J
).Ent
, Uint_0
);
939 -- Output debug information if -gnatd.3 set
941 if Debug_Flag_Dot_3
then
942 Write_Str
("Eliminate ");
943 Write_Name
(Chars
(Subps
.Table
(J
).Ent
));
945 Write_Location
(Sloc
(Subps
.Table
(J
).Ent
));
946 Write_Str
(" (not referenced)");
950 -- Rewrite declaration and body to null statements
952 Spec
:= Corresponding_Spec
(STJ
.Bod
);
954 if Present
(Spec
) then
955 Decl
:= Parent
(Declaration_Node
(Spec
));
956 Rewrite
(Decl
, Make_Null_Statement
(Sloc
(Decl
)));
959 Rewrite
(STJ
.Bod
, Make_Null_Statement
(Sloc
(STJ
.Bod
)));
964 Subps
.Set_Last
(New_SI
);
967 -- Now it is time for the second transitive closure, which follows calls
968 -- and makes sure that A calls B, and B has uplevel references, then A
969 -- is also marked as having uplevel references.
971 Closure_Uplevel
: declare
975 -- We use a simple minded algorithm as follows (obviously this can
976 -- be done more efficiently, using one of the standard algorithms
977 -- for efficient transitive closure computation, but this is simple
978 -- and most likely fast enough that its speed does not matter).
980 -- Repeatedly scan the list of calls. Any time we find a call from
981 -- A to B, where B has uplevel references, make sure that A is marked
982 -- as having at least the same level of uplevel referencing.
986 Inner2
: for J
in Calls
.First
.. Calls
.Last
loop
988 CTJ
: Call_Entry
renames Calls
.Table
(J
);
989 SINF
: constant SI_Type
:= Subp_Index
(CTJ
.Caller
);
990 SINT
: constant SI_Type
:= Subp_Index
(CTJ
.Callee
);
991 SUBF
: Subp_Entry
renames Subps
.Table
(SINF
);
992 SUBT
: Subp_Entry
renames Subps
.Table
(SINT
);
994 if SUBT
.Lev
> SUBT
.Uplevel_Ref
995 and then SUBF
.Uplevel_Ref
> SUBT
.Uplevel_Ref
997 SUBF
.Uplevel_Ref
:= SUBT
.Uplevel_Ref
;
1003 exit Outer2
when not Modified
;
1005 end Closure_Uplevel
;
1007 -- We have one more step before the tables are complete. An uplevel
1008 -- call from subprogram A to subprogram B where subprogram B has uplevel
1009 -- references is in effect an uplevel reference, and must arrange for
1010 -- the proper activation link to be passed.
1012 for J
in Calls
.First
.. Calls
.Last
loop
1014 CTJ
: Call_Entry
renames Calls
.Table
(J
);
1016 SINF
: constant SI_Type
:= Subp_Index
(CTJ
.Caller
);
1017 SINT
: constant SI_Type
:= Subp_Index
(CTJ
.Callee
);
1019 SUBF
: Subp_Entry
renames Subps
.Table
(SINF
);
1020 SUBT
: Subp_Entry
renames Subps
.Table
(SINT
);
1025 -- If callee has uplevel references
1027 if SUBT
.Uplevel_Ref
< SUBT
.Lev
1029 -- And this is an uplevel call
1031 and then SUBT
.Lev
< SUBF
.Lev
1033 -- We need to arrange for finding the uplink
1037 A
:= Enclosing_Subprogram
(A
);
1038 Subps
.Table
(Subp_Index
(A
)).Declares_AREC
:= True;
1039 exit when A
= CTJ
.Callee
;
1041 -- In any case exit when we get to the outer level. This
1042 -- happens in some odd cases with generics (in particular
1043 -- sem_ch3.adb does not compile without this kludge ???).
1051 -- The tables are now complete, so we can record the last index in the
1052 -- Subps table for later reference in Cprint.
1054 Subps
.Table
(Subps_First
).Last
:= Subps
.Last
;
1056 -- Next step, create the entities for code we will insert. We do this
1057 -- at the start so that all the entities are defined, regardless of the
1058 -- order in which we do the code insertions.
1060 Create_Entities
: for J
in Subps_First
.. Subps
.Last
loop
1062 STJ
: Subp_Entry
renames Subps
.Table
(J
);
1063 Loc
: constant Source_Ptr
:= Sloc
(STJ
.Bod
);
1066 -- First we create the ARECnF entity for the additional formal for
1067 -- all subprograms which need an activation record passed.
1069 if STJ
.Uplevel_Ref
< STJ
.Lev
then
1071 Make_Defining_Identifier
(Loc
, Chars
=> AREC_Name
(J
, "F"));
1074 -- Define the AREC entities for the activation record if needed
1076 if STJ
.Declares_AREC
then
1078 Make_Defining_Identifier
(Loc
, AREC_Name
(J
, ""));
1080 Make_Defining_Identifier
(Loc
, AREC_Name
(J
, "T"));
1082 Make_Defining_Identifier
(Loc
, AREC_Name
(J
, "PT"));
1084 Make_Defining_Identifier
(Loc
, AREC_Name
(J
, "P"));
1086 -- Define uplink component entity if inner nesting case
1088 if Present
(STJ
.ARECnF
) then
1090 Make_Defining_Identifier
(Loc
, AREC_Name
(J
, "U"));
1094 end loop Create_Entities
;
1096 -- Loop through subprograms
1099 Addr
: constant Entity_Id
:= RTE
(RE_Address
);
1102 for J
in Subps_First
.. Subps
.Last
loop
1104 STJ
: Subp_Entry
renames Subps
.Table
(J
);
1107 -- First add the extra formal if needed. This applies to all
1108 -- nested subprograms that require an activation record to be
1109 -- passed, as indicated by ARECnF being defined.
1111 if Present
(STJ
.ARECnF
) then
1113 -- Here we need the extra formal. We do the expansion and
1114 -- analysis of this manually, since it is fairly simple,
1115 -- and it is not obvious how we can get what we want if we
1116 -- try to use the normal Analyze circuit.
1118 Add_Extra_Formal
: declare
1119 Encl
: constant SI_Type
:= Enclosing_Subp
(J
);
1120 STJE
: Subp_Entry
renames Subps
.Table
(Encl
);
1121 -- Index and Subp_Entry for enclosing routine
1123 Form
: constant Entity_Id
:= STJ
.ARECnF
;
1124 -- The formal to be added. Note that n here is one less
1125 -- than the level of the subprogram itself (STJ.Ent).
1127 procedure Add_Form_To_Spec
(F
: Entity_Id
; S
: Node_Id
);
1128 -- S is an N_Function/Procedure_Specification node, and F
1129 -- is the new entity to add to this subprogramn spec as
1130 -- the last Extra_Formal.
1132 ----------------------
1133 -- Add_Form_To_Spec --
1134 ----------------------
1136 procedure Add_Form_To_Spec
(F
: Entity_Id
; S
: Node_Id
) is
1137 Sub
: constant Entity_Id
:= Defining_Entity
(S
);
1141 -- Case of at least one Extra_Formal is present, set
1142 -- ARECnF as the new last entry in the list.
1144 if Present
(Extra_Formals
(Sub
)) then
1145 Ent
:= Extra_Formals
(Sub
);
1146 while Present
(Extra_Formal
(Ent
)) loop
1147 Ent
:= Extra_Formal
(Ent
);
1150 Set_Extra_Formal
(Ent
, F
);
1152 -- No Extra formals present
1155 Set_Extra_Formals
(Sub
, F
);
1156 Ent
:= Last_Formal
(Sub
);
1158 if Present
(Ent
) then
1159 Set_Extra_Formal
(Ent
, F
);
1162 end Add_Form_To_Spec
;
1164 -- Start of processing for Add_Extra_Formal
1167 -- Decorate the new formal entity
1169 Set_Scope
(Form
, STJ
.Ent
);
1170 Set_Ekind
(Form
, E_In_Parameter
);
1171 Set_Etype
(Form
, STJE
.ARECnPT
);
1172 Set_Mechanism
(Form
, By_Copy
);
1173 Set_Never_Set_In_Source
(Form
, True);
1174 Set_Analyzed
(Form
, True);
1175 Set_Comes_From_Source
(Form
, False);
1177 -- Case of only body present
1179 if Acts_As_Spec
(STJ
.Bod
) then
1180 Add_Form_To_Spec
(Form
, Specification
(STJ
.Bod
));
1182 -- Case of separate spec
1185 Add_Form_To_Spec
(Form
, Parent
(STJ
.Ent
));
1187 end Add_Extra_Formal
;
1190 -- Processing for subprograms that declare an activation record
1192 if Present
(STJ
.ARECn
) then
1194 -- Local declarations for one such subprogram
1197 Loc
: constant Source_Ptr
:= Sloc
(STJ
.Bod
);
1201 Decl_ARECnT
: Node_Id
;
1202 Decl_ARECnPT
: Node_Id
;
1203 Decl_ARECn
: Node_Id
;
1204 Decl_ARECnP
: Node_Id
;
1205 -- Declaration nodes for the AREC entities we build
1207 Decl_Assign
: Node_Id
;
1208 -- Assigment to set uplink, Empty if none
1211 -- List of new declarations we create
1214 -- Build list of component declarations for ARECnT
1216 Clist
:= Empty_List
;
1218 -- If we are in a subprogram that has a static link that
1219 -- is passed in (as indicated by ARECnF being defined),
1220 -- then include ARECnU : ARECmPT where ARECmPT comes from
1221 -- the level one higher than the current level, and the
1222 -- entity ARECnPT comes from the enclosing subprogram.
1224 if Present
(STJ
.ARECnF
) then
1227 renames Subps
.Table
(Enclosing_Subp
(J
));
1230 Make_Component_Declaration
(Loc
,
1231 Defining_Identifier
=> STJ
.ARECnU
,
1232 Component_Definition
=>
1233 Make_Component_Definition
(Loc
,
1234 Subtype_Indication
=>
1235 New_Occurrence_Of
(STJE
.ARECnPT
, Loc
))));
1239 -- Add components for uplevel referenced entities
1241 if Present
(STJ
.Uents
) then
1247 -- 1's origin of index in list of elements. This is
1248 -- used to uniquify names if needed in Upref_Name.
1251 Elmt
:= First_Elmt
(STJ
.Uents
);
1253 while Present
(Elmt
) loop
1254 Uent
:= Node
(Elmt
);
1258 Make_Defining_Identifier
(Loc
,
1259 Chars
=> Upref_Name
(Uent
, Indx
, Clist
));
1261 Set_Activation_Record_Component
1265 Make_Component_Declaration
(Loc
,
1266 Defining_Identifier
=> Comp
,
1267 Component_Definition
=>
1268 Make_Component_Definition
(Loc
,
1269 Subtype_Indication
=>
1270 New_Occurrence_Of
(Addr
, Loc
))));
1277 -- Now we can insert the AREC declarations into the body
1279 -- type ARECnT is record .. end record;
1280 -- pragma Suppress_Initialization (ARECnT);
1282 -- Note that we need to set the Suppress_Initialization
1283 -- flag after Decl_ARECnT has been analyzed.
1286 Make_Full_Type_Declaration
(Loc
,
1287 Defining_Identifier
=> STJ
.ARECnT
,
1289 Make_Record_Definition
(Loc
,
1291 Make_Component_List
(Loc
,
1292 Component_Items
=> Clist
)));
1293 Decls
:= New_List
(Decl_ARECnT
);
1295 -- type ARECnPT is access all ARECnT;
1298 Make_Full_Type_Declaration
(Loc
,
1299 Defining_Identifier
=> STJ
.ARECnPT
,
1301 Make_Access_To_Object_Definition
(Loc
,
1302 All_Present
=> True,
1303 Subtype_Indication
=>
1304 New_Occurrence_Of
(STJ
.ARECnT
, Loc
)));
1305 Append_To
(Decls
, Decl_ARECnPT
);
1307 -- ARECn : aliased ARECnT;
1310 Make_Object_Declaration
(Loc
,
1311 Defining_Identifier
=> STJ
.ARECn
,
1312 Aliased_Present
=> True,
1313 Object_Definition
=>
1314 New_Occurrence_Of
(STJ
.ARECnT
, Loc
));
1315 Append_To
(Decls
, Decl_ARECn
);
1317 -- ARECnP : constant ARECnPT := ARECn'Access;
1320 Make_Object_Declaration
(Loc
,
1321 Defining_Identifier
=> STJ
.ARECnP
,
1322 Constant_Present
=> True,
1323 Object_Definition
=>
1324 New_Occurrence_Of
(STJ
.ARECnPT
, Loc
),
1326 Make_Attribute_Reference
(Loc
,
1328 New_Occurrence_Of
(STJ
.ARECn
, Loc
),
1329 Attribute_Name
=> Name_Access
));
1330 Append_To
(Decls
, Decl_ARECnP
);
1332 -- If we are in a subprogram that has a static link that
1333 -- is passed in (as indicated by ARECnF being defined),
1334 -- then generate ARECn.ARECmU := ARECmF where m is
1335 -- one less than the current level to set the uplink.
1337 if Present
(STJ
.ARECnF
) then
1339 Make_Assignment_Statement
(Loc
,
1341 Make_Selected_Component
(Loc
,
1343 New_Occurrence_Of
(STJ
.ARECn
, Loc
),
1345 New_Occurrence_Of
(STJ
.ARECnU
, Loc
)),
1347 New_Occurrence_Of
(STJ
.ARECnF
, Loc
));
1348 Append_To
(Decls
, Decl_Assign
);
1351 Decl_Assign
:= Empty
;
1354 Prepend_List_To
(Declarations
(STJ
.Bod
), Decls
);
1356 -- Analyze the newly inserted declarations. Note that we
1357 -- do not need to establish the whole scope stack, since
1358 -- we have already set all entity fields (so there will
1359 -- be no searching of upper scopes to resolve names). But
1360 -- we do set the scope of the current subprogram, so that
1361 -- newly created entities go in the right entity chain.
1363 -- We analyze with all checks suppressed (since we do
1364 -- not expect any exceptions).
1366 Push_Scope
(STJ
.Ent
);
1367 Analyze
(Decl_ARECnT
, Suppress
=> All_Checks
);
1369 -- Note that we need to call Set_Suppress_Initialization
1370 -- after Decl_ARECnT has been analyzed, but before
1371 -- analyzing Decl_ARECnP so that the flag is properly
1372 -- taking into account.
1374 Set_Suppress_Initialization
(STJ
.ARECnT
);
1376 Analyze
(Decl_ARECnPT
, Suppress
=> All_Checks
);
1377 Analyze
(Decl_ARECn
, Suppress
=> All_Checks
);
1378 Analyze
(Decl_ARECnP
, Suppress
=> All_Checks
);
1380 if Present
(Decl_Assign
) then
1381 Analyze
(Decl_Assign
, Suppress
=> All_Checks
);
1386 -- Next step, for each uplevel referenced entity, add
1387 -- assignment operations to set the component in the
1388 -- activation record.
1390 if Present
(STJ
.Uents
) then
1395 Elmt
:= First_Elmt
(STJ
.Uents
);
1396 while Present
(Elmt
) loop
1398 Ent
: constant Entity_Id
:= Node
(Elmt
);
1399 Loc
: constant Source_Ptr
:= Sloc
(Ent
);
1400 Dec
: constant Node_Id
:=
1401 Declaration_Node
(Ent
);
1406 -- For parameters, we insert the assignment
1407 -- right after the declaration of ARECnP.
1408 -- For all other entities, we insert
1409 -- the assignment immediately after
1410 -- the declaration of the entity.
1412 -- Note: we don't need to mark the entity
1413 -- as being aliased, because the address
1414 -- attribute will mark it as Address_Taken,
1415 -- and that is good enough.
1417 if Is_Formal
(Ent
) then
1423 -- Build and insert the assignment:
1424 -- ARECn.nam := nam'Address
1427 Make_Assignment_Statement
(Loc
,
1429 Make_Selected_Component
(Loc
,
1431 New_Occurrence_Of
(STJ
.ARECn
, Loc
),
1434 (Activation_Record_Component
1439 Make_Attribute_Reference
(Loc
,
1441 New_Occurrence_Of
(Ent
, Loc
),
1442 Attribute_Name
=> Name_Address
));
1444 Insert_After
(Ins
, Asn
);
1446 -- Analyze the assignment statement. We do
1447 -- not need to establish the relevant scope
1448 -- stack entries here, because we have
1449 -- already set the correct entity references,
1450 -- so no name resolution is required, and no
1451 -- new entities are created, so we don't even
1452 -- need to set the current scope.
1454 -- We analyze with all checks suppressed
1455 -- (since we do not expect any exceptions).
1457 Analyze
(Asn
, Suppress
=> All_Checks
);
1470 -- Next step, process uplevel references. This has to be done in a
1471 -- separate pass, after completing the processing in Sub_Loop because we
1472 -- need all the AREC declarations generated, inserted, and analyzed so
1473 -- that the uplevel references can be successfully analyzed.
1475 Uplev_Refs
: for J
in Urefs
.First
.. Urefs
.Last
loop
1477 UPJ
: Uref_Entry
renames Urefs
.Table
(J
);
1480 -- Ignore type references, these are implicit references that do
1481 -- not need rewriting (e.g. the appearence in a conversion).
1483 if Is_Type
(UPJ
.Ent
) then
1487 -- Also ignore uplevel references to bounds of types that come
1488 -- from the original type reference.
1490 if Is_Entity_Name
(UPJ
.Ref
)
1491 and then Present
(Entity
(UPJ
.Ref
))
1492 and then Is_Type
(Entity
(UPJ
.Ref
))
1497 -- Rewrite one reference
1499 Rewrite_One_Ref
: declare
1500 Loc
: constant Source_Ptr
:= Sloc
(UPJ
.Ref
);
1501 -- Source location for the reference
1503 Typ
: constant Entity_Id
:= Etype
(UPJ
.Ent
);
1504 -- The type of the referenced entity
1506 Atyp
: constant Entity_Id
:= Get_Actual_Subtype
(UPJ
.Ref
);
1507 -- The actual subtype of the reference
1509 RS_Caller
: constant SI_Type
:= Subp_Index
(UPJ
.Caller
);
1510 -- Subp_Index for caller containing reference
1512 STJR
: Subp_Entry
renames Subps
.Table
(RS_Caller
);
1513 -- Subp_Entry for subprogram containing reference
1515 RS_Callee
: constant SI_Type
:= Subp_Index
(UPJ
.Callee
);
1516 -- Subp_Index for subprogram containing referenced entity
1518 STJE
: Subp_Entry
renames Subps
.Table
(RS_Callee
);
1519 -- Subp_Entry for subprogram containing referenced entity
1526 -- Ignore if no ARECnF entity for enclosing subprogram which
1527 -- probably happens as a result of not properly treating
1528 -- instance bodies. To be examined ???
1530 -- If this test is omitted, then the compilation of freeze.adb
1531 -- and inline.adb fail in unnesting mode.
1533 if No
(STJR
.ARECnF
) then
1537 -- Push the current scope, so that the pointer type Tnn, and
1538 -- any subsidiary entities resulting from the analysis of the
1539 -- rewritten reference, go in the right entity chain.
1541 Push_Scope
(STJR
.Ent
);
1543 -- Now we need to rewrite the reference. We have a reference
1544 -- from level STJR.Lev to level STJE.Lev. The general form of
1545 -- the rewritten reference for entity X is:
1547 -- Typ'Deref (ARECaF.ARECbU.ARECcU.ARECdU....ARECm.X)
1549 -- where a,b,c,d .. m =
1550 -- STJR.Lev - 1, STJR.Lev - 2, .. STJE.Lev
1552 pragma Assert
(STJR
.Lev
> STJE
.Lev
);
1554 -- Compute the prefix of X. Here are examples to make things
1555 -- clear (with parens to show groupings, the prefix is
1556 -- everything except the .X at the end).
1558 -- level 2 to level 1
1562 -- level 3 to level 1
1564 -- (AREC2F.AREC1U).X
1566 -- level 4 to level 1
1568 -- ((AREC3F.AREC2U).AREC1U).X
1570 -- level 6 to level 2
1572 -- (((AREC5F.AREC4U).AREC3U).AREC2U).X
1574 -- In the above, ARECnF and ARECnU are pointers, so there are
1575 -- explicit dereferences required for these occurrences.
1578 Make_Explicit_Dereference
(Loc
,
1579 Prefix
=> New_Occurrence_Of
(STJR
.ARECnF
, Loc
));
1581 for L
in STJE
.Lev
.. STJR
.Lev
- 2 loop
1582 SI
:= Enclosing_Subp
(SI
);
1584 Make_Explicit_Dereference
(Loc
,
1586 Make_Selected_Component
(Loc
,
1589 New_Occurrence_Of
(Subps
.Table
(SI
).ARECnU
, Loc
)));
1592 -- Get activation record component (must exist)
1594 Comp
:= Activation_Record_Component
(UPJ
.Ent
);
1595 pragma Assert
(Present
(Comp
));
1597 -- Do the replacement
1600 Make_Attribute_Reference
(Loc
,
1601 Prefix
=> New_Occurrence_Of
(Atyp
, Loc
),
1602 Attribute_Name
=> Name_Deref
,
1603 Expressions
=> New_List
(
1604 Make_Selected_Component
(Loc
,
1607 New_Occurrence_Of
(Comp
, Loc
)))));
1609 -- Analyze and resolve the new expression. We do not need to
1610 -- establish the relevant scope stack entries here, because we
1611 -- have already set all the correct entity references, so no
1612 -- name resolution is needed. We have already set the current
1613 -- scope, so that any new entities created will be in the right
1616 -- We analyze with all checks suppressed (since we do not
1617 -- expect any exceptions)
1619 Analyze_And_Resolve
(UPJ
.Ref
, Typ
, Suppress
=> All_Checks
);
1621 end Rewrite_One_Ref
;
1626 end loop Uplev_Refs
;
1628 -- Finally, loop through all calls adding extra actual for the
1629 -- activation record where it is required.
1631 Adjust_Calls
: for J
in Calls
.First
.. Calls
.Last
loop
1633 -- Process a single call, we are only interested in a call to a
1634 -- subprogram that actually needs a pointer to an activation record,
1635 -- as indicated by the ARECnF entity being set. This excludes the
1636 -- top level subprogram, and any subprogram not having uplevel refs.
1638 Adjust_One_Call
: declare
1639 CTJ
: Call_Entry
renames Calls
.Table
(J
);
1640 STF
: Subp_Entry
renames Subps
.Table
(Subp_Index
(CTJ
.Caller
));
1641 STT
: Subp_Entry
renames Subps
.Table
(Subp_Index
(CTJ
.Callee
));
1643 Loc
: constant Source_Ptr
:= Sloc
(CTJ
.N
);
1651 if Present
(STT
.ARECnF
)
1652 and then Nkind
(CTJ
.N
) /= N_Attribute_Reference
1655 -- CTJ.N is a call to a subprogram which may require a pointer
1656 -- to an activation record. The subprogram containing the call
1657 -- is CTJ.From and the subprogram being called is CTJ.To, so we
1658 -- have a call from level STF.Lev to level STT.Lev.
1660 -- There are three possibilities:
1662 -- For a call to the same level, we just pass the activation
1663 -- record passed to the calling subprogram.
1665 if STF
.Lev
= STT
.Lev
then
1666 Extra
:= New_Occurrence_Of
(STF
.ARECnF
, Loc
);
1668 -- For a call that goes down a level, we pass a pointer to the
1669 -- activation record constructed within the caller (which may
1670 -- be the outer-level subprogram, but also may be a more deeply
1673 elsif STT
.Lev
= STF
.Lev
+ 1 then
1674 Extra
:= New_Occurrence_Of
(STF
.ARECnP
, Loc
);
1676 -- Otherwise we must have an upcall (STT.Lev < STF.LEV),
1677 -- since it is not possible to do a downcall of more than
1680 -- For a call from level STF.Lev to level STT.Lev, we
1681 -- have to find the activation record needed by the
1682 -- callee. This is as follows:
1684 -- ARECaF.ARECbU.ARECcU....ARECm
1686 -- where a,b,c .. m =
1687 -- STF.Lev - 1, STF.Lev - 2, STF.Lev - 3 .. STT.Lev
1690 pragma Assert
(STT
.Lev
< STF
.Lev
);
1692 Extra
:= New_Occurrence_Of
(STF
.ARECnF
, Loc
);
1693 SubX
:= Subp_Index
(CTJ
.Caller
);
1694 for K
in reverse STT
.Lev
.. STF
.Lev
- 1 loop
1695 SubX
:= Enclosing_Subp
(SubX
);
1697 Make_Selected_Component
(Loc
,
1701 (Subps
.Table
(SubX
).ARECnU
, Loc
));
1705 -- Extra is the additional parameter to be added. Build a
1706 -- parameter association that we can append to the actuals.
1709 Make_Parameter_Association
(Loc
,
1711 New_Occurrence_Of
(STT
.ARECnF
, Loc
),
1712 Explicit_Actual_Parameter
=> Extra
);
1714 if No
(Parameter_Associations
(CTJ
.N
)) then
1715 Set_Parameter_Associations
(CTJ
.N
, Empty_List
);
1718 Append
(ExtraP
, Parameter_Associations
(CTJ
.N
));
1720 -- We need to deal with the actual parameter chain as well. The
1721 -- newly added parameter is always the last actual.
1723 Act
:= First_Named_Actual
(CTJ
.N
);
1726 Set_First_Named_Actual
(CTJ
.N
, Extra
);
1728 -- Here we must follow the chain and append the new entry
1737 PAN
:= Parent
(Act
);
1738 pragma Assert
(Nkind
(PAN
) = N_Parameter_Association
);
1739 NNA
:= Next_Named_Actual
(PAN
);
1742 Set_Next_Named_Actual
(PAN
, Extra
);
1751 -- Analyze and resolve the new actual. We do not need to
1752 -- establish the relevant scope stack entries here, because
1753 -- we have already set all the correct entity references, so
1754 -- no name resolution is needed.
1756 -- We analyze with all checks suppressed (since we do not
1757 -- expect any exceptions, and also we temporarily turn off
1758 -- Unested_Subprogram_Mode to avoid trying to mark uplevel
1759 -- references (not needed at this stage, and in fact causes
1760 -- a bit of recursive chaos).
1762 Opt
.Unnest_Subprogram_Mode
:= False;
1764 (Extra
, Etype
(STT
.ARECnF
), Suppress
=> All_Checks
);
1765 Opt
.Unnest_Subprogram_Mode
:= True;
1767 end Adjust_One_Call
;
1768 end loop Adjust_Calls
;
1771 end Unnest_Subprogram
;
1773 ------------------------
1774 -- Unnest_Subprograms --
1775 ------------------------
1777 procedure Unnest_Subprograms
(N
: Node_Id
) is
1778 function Search_Subprograms
(N
: Node_Id
) return Traverse_Result
;
1779 -- Tree visitor that search for outer level procedures with nested
1780 -- subprograms and invokes Unnest_Subprogram()
1782 ------------------------
1783 -- Search_Subprograms --
1784 ------------------------
1786 function Search_Subprograms
(N
: Node_Id
) return Traverse_Result
is
1788 if Nkind_In
(N
, N_Subprogram_Body
, N_Subprogram_Body_Stub
) then
1790 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(N
);
1793 -- We are only interested in subprograms (not generic
1794 -- subprograms), that have nested subprograms.
1796 if Is_Subprogram
(Spec_Id
)
1797 and then Has_Nested_Subprogram
(Spec_Id
)
1798 and then Is_Library_Level_Entity
(Spec_Id
)
1800 Unnest_Subprogram
(Spec_Id
, N
);
1806 end Search_Subprograms
;
1812 procedure Do_Search
is new Traverse_Proc
(Search_Subprograms
);
1813 -- Subtree visitor instantiation
1815 -- Start of processing for Unnest_Subprograms
1818 if not Opt
.Unnest_Subprogram_Mode
then
1823 end Unnest_Subprograms
;