1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Errout; use Errout;
32 with Exp_Ch7; use Exp_Ch7;
33 with Exp_Util; use Exp_Util;
34 with Hostparm; use Hostparm;
35 with Inline; use Inline;
37 with Namet; use Namet;
38 with Nlists; use Nlists;
39 with Nmake; use Nmake;
41 with Rtsfind; use Rtsfind;
42 with Restrict; use Restrict;
43 with Rident; use Rident;
45 with Sem_Ch5; use Sem_Ch5;
46 with Sem_Ch8; use Sem_Ch8;
47 with Sem_Res; use Sem_Res;
48 with Sem_Util; use Sem_Util;
49 with Sinfo; use Sinfo;
50 with Sinput; use Sinput;
51 with Snames; use Snames;
52 with Stand; use Stand;
53 with Stringt; use Stringt;
54 with Targparm; use Targparm;
55 with Tbuild; use Tbuild;
56 with Uintp; use Uintp;
57 with Uname; use Uname;
59 package body Exp_Ch11 is
62 -- This list gathers the values SDn'Unrestricted_Access used to
63 -- construct the unit exception table. It is set to Empty_List if
64 -- there are no subprogram descriptors.
66 -----------------------
67 -- Local Subprograms --
68 -----------------------
70 procedure Expand_Exception_Handler_Tables (HSS : Node_Id);
71 -- Subsidiary procedure called by Expand_Exception_Handlers if zero
72 -- cost exception handling is installed for this target. Replaces the
73 -- exception handler structure with appropriate labeled code and tables
74 -- that allow the zero cost exception handling circuits to find the
75 -- correct handler (see unit Ada.Exceptions for details).
77 procedure Generate_Subprogram_Descriptor
82 -- Procedure called to generate a subprogram descriptor. N is the
83 -- subprogram body node or, in the case of an imported subprogram, is
84 -- Empty, and Spec is the entity of the sunprogram. For details of the
85 -- required structure, see package System.Exceptions. The generated
86 -- subprogram descriptor is appended to Slist. Loc provides the
87 -- source location to be used for the generated descriptor.
89 ---------------------------
90 -- Expand_At_End_Handler --
91 ---------------------------
93 -- For a handled statement sequence that has a cleanup (At_End_Proc
94 -- field set), an exception handler of the following form is required:
101 -- Note: this exception handler is treated rather specially by
102 -- subsequent expansion in two respects:
104 -- The normal call to Undefer_Abort is omitted
105 -- The raise call does not do Defer_Abort
107 -- This is because the current tasking code seems to assume that
108 -- the call to the cleanup routine that is made from an exception
109 -- handler for the abort signal is called with aborts deferred.
111 -- This expansion is only done if we have front end exception handling.
112 -- If we have back end exception handling, then the AT END handler is
113 -- left alone, and cleanups (including the exceptional case) are handled
116 -- In the front end case, the exception handler described above handles
117 -- the exceptional case. The AT END handler is left in the generated tree
118 -- and the code generator (e.g. gigi) must still handle proper generation
119 -- of cleanup calls for the non-exceptional case.
121 procedure Expand_At_End_Handler (HSS : Node_Id; Block : Node_Id) is
122 Clean : constant Entity_Id := Entity (At_End_Proc (HSS));
123 Loc : constant Source_Ptr := Sloc (Clean);
128 pragma Assert (Present (Clean));
129 pragma Assert (No (Exception_Handlers (HSS)));
131 -- Don't expand if back end exception handling active
133 if Exception_Mechanism = Back_End_ZCX_Exceptions then
137 -- Don't expand an At End handler if we have already had configurable
138 -- run-time violations, since likely this will just be a matter of
139 -- generating useless cascaded messages
141 if Configurable_Run_Time_Violations > 0 then
145 if Restriction_Active (No_Exception_Handlers) then
149 if Present (Block) then
154 Make_Others_Choice (Loc);
155 Set_All_Others (Ohandle);
158 Make_Procedure_Call_Statement (Loc,
159 Name => New_Occurrence_Of (Clean, Loc)),
160 Make_Raise_Statement (Loc));
162 Set_Exception_Handlers (HSS, New_List (
163 Make_Exception_Handler (Loc,
164 Exception_Choices => New_List (Ohandle),
165 Statements => Stmnts)));
167 Analyze_List (Stmnts, Suppress => All_Checks);
168 Expand_Exception_Handlers (HSS);
170 if Present (Block) then
173 end Expand_At_End_Handler;
175 -------------------------------------
176 -- Expand_Exception_Handler_Tables --
177 -------------------------------------
179 -- See Ada.Exceptions specification for full details of the data
180 -- structures that we need to construct here. As an example of the
181 -- transformation that is required, given the structure:
198 -- We transform this into:
220 -- HR2 : constant Handler_Record := (
224 -- Handler => L5'Address);
226 -- HR3 : constant Handler_Record := (
230 -- Handler => L4'Address);
236 -- HR1 : constant Handler_Record := (
240 -- Handler => L4'Address);
243 -- The exception handlers in the transformed version are marked with the
244 -- Zero_Cost_Handling flag set, and all gigi does in this case is simply
245 -- to put the handler code somewhere. It can optionally be put inline
246 -- between the goto L3 and the label <<L3>> (which is why we generate
247 -- that goto in the first place).
249 procedure Expand_Exception_Handler_Tables (HSS : Node_Id) is
250 Loc : constant Source_Ptr := Sloc (HSS);
251 Handlrs : constant List_Id := Exception_Handlers (HSS);
252 Stms : constant List_Id := Statements (HSS);
256 -- This is the list to which handlers are to be appended. It is
257 -- either the list for the enclosing subprogram, or the enclosing
258 -- selective accept statement (which will turn into a subprogram
259 -- during expansion later on).
261 L1 : constant Entity_Id :=
262 Make_Defining_Identifier (Loc,
263 Chars => New_Internal_Name ('L'));
265 L2 : constant Entity_Id :=
266 Make_Defining_Identifier (Loc,
267 Chars => New_Internal_Name ('L'));
276 Subp_Entity : Entity_Id;
277 -- This is the entity for the subprogram (or library level package)
278 -- to which the handler record is to be attached for later reference
279 -- in a subprogram descriptor for this entity.
281 procedure Append_To_Stms (N : Node_Id);
282 -- Append given statement to the end of the statements of the
283 -- handled sequence of statements and analyze it in place.
285 function Inside_Selective_Accept return Boolean;
286 -- This function is called if we are inside the scope of an entry
287 -- or task. It checks if the handler is appearing in the context
288 -- of a selective accept statement. If so, Hlist is set to
289 -- temporarily park the handlers in the N_Accept_Alternative.
290 -- node. They will subsequently be moved to the procedure entity
291 -- for the procedure built for this alternative. The statements that
292 -- follow the Accept within the alternative are not inside the Accept
293 -- for purposes of this test, and handlers that may appear within
294 -- them belong in the enclosing task procedure.
297 -- Sets the handler list corresponding to Subp_Entity
303 procedure Append_To_Stms (N : Node_Id) is
305 Insert_After_And_Analyze (Last (Stms), N);
306 Set_Exception_Junk (N);
309 -----------------------------
310 -- Inside_Selective_Accept --
311 -----------------------------
313 function Inside_Selective_Accept return Boolean is
315 Curr : Node_Id := HSS;
318 Parnt := Parent (HSS);
319 while Nkind (Parnt) /= N_Compilation_Unit loop
320 if Nkind (Parnt) = N_Accept_Alternative
321 and then Curr = Accept_Statement (Parnt)
323 if Present (Accept_Handler_Records (Parnt)) then
324 Hlist := Accept_Handler_Records (Parnt);
327 Set_Accept_Handler_Records (Parnt, Hlist);
333 Parnt := Parent (Parnt);
338 end Inside_Selective_Accept;
344 procedure Set_Hlist is
346 -- Never try to inline a subprogram with exception handlers
348 Set_Is_Inlined (Subp_Entity, False);
350 if Present (Subp_Entity)
351 and then Present (Handler_Records (Subp_Entity))
353 Hlist := Handler_Records (Subp_Entity);
356 Set_Handler_Records (Subp_Entity, Hlist);
360 -- Start of processing for Expand_Exception_Handler_Tables
363 -- Nothing to do if this handler has already been processed
365 if Zero_Cost_Handling (HSS) then
369 Set_Zero_Cost_Handling (HSS);
371 -- Find the parent subprogram or package scope containing this
372 -- exception frame. This should always find a real package or
373 -- subprogram. If it does not it will stop at Standard, but
374 -- this cannot legitimately occur.
376 -- We only stop at library level packages, for inner packages
377 -- we always attach handlers to the containing procedure.
379 Subp_Entity := Current_Scope;
382 -- Never need tables expanded inside a generic template
384 if Is_Generic_Unit (Subp_Entity) then
387 -- Stop if we reached containing subprogram. Go to protected
388 -- subprogram if there is one defined.
390 elsif Ekind (Subp_Entity) = E_Function
391 or else Ekind (Subp_Entity) = E_Procedure
393 if Present (Protected_Body_Subprogram (Subp_Entity)) then
394 Subp_Entity := Protected_Body_Subprogram (Subp_Entity);
400 -- Case of within an entry
402 elsif Is_Entry (Subp_Entity) then
404 -- Protected entry, use corresponding body subprogram
406 if Present (Protected_Body_Subprogram (Subp_Entity)) then
407 Subp_Entity := Protected_Body_Subprogram (Subp_Entity);
411 -- Check if we are within a selective accept alternative
413 elsif Inside_Selective_Accept then
415 -- As a side effect, Inside_Selective_Accept set Hlist,
416 -- in much the same manner as Set_Hlist, except that
417 -- the list involved was the one for the selective accept.
422 -- Case of within library level package
424 elsif Ekind (Subp_Entity) = E_Package
425 and then Is_Compilation_Unit (Subp_Entity)
427 if Is_Body_Name (Unit_Name (Get_Code_Unit (HSS))) then
428 Subp_Entity := Body_Entity (Subp_Entity);
436 elsif Ekind (Subp_Entity) = E_Task_Type then
438 -- Check if we are within a selective accept alternative
440 if Inside_Selective_Accept then
442 -- As a side effect, Inside_Selective_Accept set Hlist,
443 -- in much the same manner as Set_Hlist, except that the
444 -- list involved was the one for the selective accept.
448 -- Stop if we reached task type with task body procedure,
449 -- use the task body procedure.
451 elsif Present (Get_Task_Body_Procedure (Subp_Entity)) then
452 Subp_Entity := Get_Task_Body_Procedure (Subp_Entity);
458 -- If we fall through, keep looking
460 Subp_Entity := Scope (Subp_Entity);
463 pragma Assert (Subp_Entity /= Standard_Standard);
465 -- Analyze standard labels
467 Analyze_Label_Entity (L1);
468 Analyze_Label_Entity (L2);
470 Insert_Before_And_Analyze (First (Stms),
472 Identifier => New_Occurrence_Of (L1, Loc)));
473 Set_Exception_Junk (First (Stms));
477 Identifier => New_Occurrence_Of (L2, Loc)));
479 -- Loop through exception handlers
481 Handler := First_Non_Pragma (Handlrs);
482 while Present (Handler) loop
483 Set_Zero_Cost_Handling (Handler);
485 -- Add label at start of handler, and goto at the end
488 Make_Defining_Identifier (Loc,
489 Chars => New_Internal_Name ('L'));
491 Analyze_Label_Entity (Lnn);
495 Identifier => New_Occurrence_Of (Lnn, Loc));
496 Set_Exception_Junk (Item);
497 Insert_Before_And_Analyze (First (Statements (Handler)), Item);
499 -- Loop through choices
501 Choice := First (Exception_Choices (Handler));
502 while Present (Choice) loop
504 -- Others (or all others) choice
506 if Nkind (Choice) = N_Others_Choice then
507 if All_Others (Choice) then
508 E_Id := New_Occurrence_Of (RTE (RE_All_Others_Id), Loc);
510 E_Id := New_Occurrence_Of (RTE (RE_Others_Id), Loc);
513 -- Special case of VMS_Exception. Not clear what we will do
514 -- eventually here if and when we implement zero cost exceptions
515 -- on VMS. But at least for now, don't blow up trying to take
516 -- a garbage code address for such an exception.
518 elsif Is_VMS_Exception (Entity (Choice)) then
519 E_Id := New_Occurrence_Of (RTE (RE_Null_Id), Loc);
521 -- Normal case of specific exception choice
525 Make_Attribute_Reference (Loc,
526 Prefix => New_Occurrence_Of (Entity (Choice), Loc),
527 Attribute_Name => Name_Identity);
531 Make_Defining_Identifier (Loc,
532 Chars => New_Internal_Name ('H'));
535 Make_Attribute_Reference (Loc,
536 Prefix => New_Occurrence_Of (HR_Ent, Loc),
537 Attribute_Name => Name_Unrestricted_Access);
539 -- Now we need to add the entry for the new handler record to
540 -- the list of handler records for the current subprogram.
542 -- Normally we end up generating the handler records in exactly
543 -- the right order. Here right order means innermost first,
544 -- since the table will be searched sequentially. Since we
545 -- generally expand from outside to inside, the order is just
546 -- what we want, and we need to append the new entry to the
549 -- However, there are exceptions, notably in the case where
550 -- a generic body is inserted later on. See for example the
551 -- case of ACVC test C37213J, which has the following form:
553 -- generic package x ... end x;
564 -- package q is new x;
571 -- In this case, we will expand exception handler (2) first,
572 -- since the expansion of (1) is delayed till later when the
573 -- generic body is inserted. But (1) belongs before (2) in
576 -- Note that scopes are not totally ordered, because two
577 -- scopes can be in parallel blocks, so that it does not
578 -- matter what order these entries appear in. An ordering
579 -- relation exists if one scope is inside another, and what
580 -- we really want is some partial ordering.
582 -- A simple, not very efficient, but adequate algorithm to
583 -- achieve this partial ordering is to search the list for
584 -- the first entry containing the given scope, and put the
585 -- new entry just before it.
588 New_Scop : constant Entity_Id := Current_Scope;
592 Ent := First (Hlist);
594 -- If all searched, then we can just put the new
595 -- entry at the end of the list (it actually does
596 -- not matter where we put it in this case).
599 Append_To (Hlist, HL_Ref);
602 -- If the current scope is within the scope of the
603 -- entry then insert the entry before to retain the
604 -- proper order as per above discussion.
606 -- Note that for equal entries, we just keep going,
607 -- which is fine, the entry will end up at the end
608 -- of the list where it belongs.
611 (New_Scop, Scope (Entity (Prefix (Ent))))
613 Insert_Before (Ent, HL_Ref);
616 -- Otherwise keep looking
625 Make_Object_Declaration (Loc,
626 Defining_Identifier => HR_Ent,
627 Constant_Present => True,
628 Aliased_Present => True,
630 New_Occurrence_Of (RTE (RE_Handler_Record), Loc),
634 Expressions => New_List (
635 Make_Attribute_Reference (Loc, -- Lo
636 Prefix => New_Occurrence_Of (L1, Loc),
637 Attribute_Name => Name_Address),
639 Make_Attribute_Reference (Loc, -- Hi
640 Prefix => New_Occurrence_Of (L2, Loc),
641 Attribute_Name => Name_Address),
645 Make_Attribute_Reference (Loc,
646 Prefix => New_Occurrence_Of (Lnn, Loc), -- Handler
647 Attribute_Name => Name_Address))));
649 Set_Handler_List_Entry (Item, HL_Ref);
650 Set_Exception_Junk (Item);
651 Insert_After_And_Analyze (Last (Statements (Handler)), Item);
652 Set_Is_Statically_Allocated (HR_Ent);
654 -- If this is a late insertion (from body instance) it is being
655 -- inserted in the component list of an already analyzed aggre-
656 -- gate, and must be analyzed explicitly.
658 Analyze_And_Resolve (HL_Ref, RTE (RE_Handler_Record_Ptr));
663 Next_Non_Pragma (Handler);
665 end Expand_Exception_Handler_Tables;
667 -------------------------------
668 -- Expand_Exception_Handlers --
669 -------------------------------
671 procedure Expand_Exception_Handlers (HSS : Node_Id) is
672 Handlrs : constant List_Id := Exception_Handlers (HSS);
675 Others_Choice : Boolean;
678 procedure Prepend_Call_To_Handler
680 Args : List_Id := No_List);
681 -- Routine to prepend a call to the procedure referenced by Proc at
682 -- the start of the handler code for the current Handler.
684 -----------------------------
685 -- Prepend_Call_To_Handler --
686 -----------------------------
688 procedure Prepend_Call_To_Handler
690 Args : List_Id := No_List)
692 Ent : constant Entity_Id := RTE (Proc);
695 -- If we have no Entity, then we are probably in no run time mode
696 -- or some weird error has occured. In either case do do nothing!
698 if Present (Ent) then
700 Call : constant Node_Id :=
701 Make_Procedure_Call_Statement (Loc,
702 Name => New_Occurrence_Of (RTE (Proc), Loc),
703 Parameter_Associations => Args);
706 Prepend_To (Statements (Handler), Call);
707 Analyze (Call, Suppress => All_Checks);
710 end Prepend_Call_To_Handler;
712 -- Start of processing for Expand_Exception_Handlers
715 -- Loop through handlers
717 Handler := First_Non_Pragma (Handlrs);
718 Handler_Loop : while Present (Handler) loop
719 Loc := Sloc (Handler);
721 -- Remove source handler if gnat debug flag N is set
723 if Debug_Flag_Dot_X and then Comes_From_Source (Handler) then
725 H : constant Node_Id := Handler;
727 Next_Non_Pragma (Handler);
729 goto Continue_Handler_Loop;
733 -- If an exception occurrence is present, then we must declare it
734 -- and initialize it from the value stored in the TSD
737 -- name : Exception_Occurrence;
740 -- Save_Occurrence (name, Get_Current_Excep.all)
744 if Present (Choice_Parameter (Handler)) then
746 Cparm : constant Entity_Id := Choice_Parameter (Handler);
747 Clc : constant Source_Ptr := Sloc (Cparm);
752 Make_Procedure_Call_Statement (Loc,
754 New_Occurrence_Of (RTE (RE_Save_Occurrence), Loc),
755 Parameter_Associations => New_List (
756 New_Occurrence_Of (Cparm, Clc),
757 Make_Explicit_Dereference (Loc,
758 Make_Function_Call (Loc,
759 Name => Make_Explicit_Dereference (Loc,
761 (RTE (RE_Get_Current_Excep), Loc))))));
763 Mark_Rewrite_Insertion (Save);
764 Prepend (Save, Statements (Handler));
767 Make_Object_Declaration (Clc,
768 Defining_Identifier => Cparm,
771 (RTE (RE_Exception_Occurrence), Clc));
772 Set_No_Initialization (Obj_Decl, True);
775 Make_Exception_Handler (Loc,
776 Exception_Choices => Exception_Choices (Handler),
778 Statements => New_List (
779 Make_Block_Statement (Loc,
780 Declarations => New_List (Obj_Decl),
781 Handled_Statement_Sequence =>
782 Make_Handled_Sequence_Of_Statements (Loc,
783 Statements => Statements (Handler))))));
785 Analyze_List (Statements (Handler), Suppress => All_Checks);
789 -- The processing at this point is rather different for the
790 -- JVM case, so we completely separate the processing.
792 -- For the JVM case, we unconditionally call Update_Exception,
793 -- passing a call to the intrinsic function Current_Target_Exception
794 -- (see JVM version of Ada.Exceptions in 4jexcept.adb for details).
796 if Hostparm.Java_VM then
798 Arg : constant Node_Id :=
799 Make_Function_Call (Loc,
800 Name => New_Occurrence_Of
801 (RTE (RE_Current_Target_Exception), Loc));
803 Prepend_Call_To_Handler (RE_Update_Exception, New_List (Arg));
806 -- For the normal case, we have to worry about the state of abort
807 -- deferral. Generally, we defer abort during runtime handling of
808 -- exceptions. When control is passed to the handler, then in the
809 -- normal case we undefer aborts. In any case this entire handling
810 -- is relevant only if aborts are allowed!
812 elsif Abort_Allowed then
814 -- There are some special cases in which we do not do the
815 -- undefer. In particular a finalization (AT END) handler
816 -- wants to operate with aborts still deferred.
818 -- We also suppress the call if this is the special handler
819 -- for Abort_Signal, since if we are aborting, we want to keep
820 -- aborts deferred (one abort is enough thank you very much :-)
822 -- If abort really needs to be deferred the expander must add
823 -- this call explicitly, see Exp_Ch9.Expand_N_Asynchronous_Select.
826 Nkind (First (Exception_Choices (Handler))) = N_Others_Choice;
829 or else Entity (First (Exception_Choices (Handler))) /=
833 and then All_Others (First (Exception_Choices (Handler))))
834 and then Abort_Allowed
836 Prepend_Call_To_Handler (RE_Abort_Undefer);
840 Next_Non_Pragma (Handler);
842 <<Continue_Handler_Loop>>
844 end loop Handler_Loop;
846 -- If all handlers got removed by gnatdN, then remove the list
849 and then Is_Empty_List (Exception_Handlers (HSS))
851 Set_Exception_Handlers (HSS, No_List);
854 -- The last step for expanding exception handlers is to expand the
855 -- exception tables if zero cost exception handling is active.
857 if Exception_Mechanism = Front_End_ZCX_Exceptions then
858 Expand_Exception_Handler_Tables (HSS);
860 end Expand_Exception_Handlers;
862 ------------------------------------
863 -- Expand_N_Exception_Declaration --
864 ------------------------------------
867 -- exceptE : constant String := "A.B.EXCEP"; -- static data
868 -- except : exception_data := (
869 -- Handled_By_Other => False,
871 -- Name_Length => exceptE'Length,
872 -- Full_Name => exceptE'Address,
873 -- HTable_Ptr => null,
875 -- Raise_Hook => null,
878 -- (protecting test only needed if not at library level)
880 -- exceptF : Boolean := True -- static data
883 -- Register_Exception (except'Unchecked_Access);
886 procedure Expand_N_Exception_Declaration (N : Node_Id) is
887 Loc : constant Source_Ptr := Sloc (N);
888 Id : constant Entity_Id := Defining_Identifier (N);
889 L : List_Id := New_List;
892 Name_Exname : constant Name_Id := New_External_Name (Chars (Id), 'E');
893 Exname : constant Node_Id :=
894 Make_Defining_Identifier (Loc, Name_Exname);
897 -- There is no expansion needed when compiling for the JVM since the
898 -- JVM has a built-in exception mechanism. See 4jexcept.ads for details.
900 if Hostparm.Java_VM then
904 -- Definition of the external name: nam : constant String := "A.B.NAME";
907 Make_Object_Declaration (Loc,
908 Defining_Identifier => Exname,
909 Constant_Present => True,
910 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
911 Expression => Make_String_Literal (Loc, Full_Qualified_Name (Id))));
913 Set_Is_Statically_Allocated (Exname);
915 -- Create the aggregate list for type Standard.Exception_Type:
916 -- Handled_By_Other component: False
918 Append_To (L, New_Occurrence_Of (Standard_False, Loc));
920 -- Lang component: 'A'
923 Make_Character_Literal (Loc,
925 Char_Literal_Value => UI_From_Int (Character'Pos ('A'))));
927 -- Name_Length component: Nam'Length
930 Make_Attribute_Reference (Loc,
931 Prefix => New_Occurrence_Of (Exname, Loc),
932 Attribute_Name => Name_Length));
934 -- Full_Name component: Standard.A_Char!(Nam'Address)
936 Append_To (L, Unchecked_Convert_To (Standard_A_Char,
937 Make_Attribute_Reference (Loc,
938 Prefix => New_Occurrence_Of (Exname, Loc),
939 Attribute_Name => Name_Address)));
941 -- HTable_Ptr component: null
943 Append_To (L, Make_Null (Loc));
945 -- Import_Code component: 0
947 Append_To (L, Make_Integer_Literal (Loc, 0));
949 -- Raise_Hook component: null
951 Append_To (L, Make_Null (Loc));
953 Set_Expression (N, Make_Aggregate (Loc, Expressions => L));
954 Analyze_And_Resolve (Expression (N), Etype (Id));
956 -- Register_Exception (except'Unchecked_Access);
958 if not Restriction_Active (No_Exception_Handlers)
959 and then not Restriction_Active (No_Exception_Registration)
962 Make_Procedure_Call_Statement (Loc,
963 Name => New_Occurrence_Of (RTE (RE_Register_Exception), Loc),
964 Parameter_Associations => New_List (
965 Unchecked_Convert_To (RTE (RE_Exception_Data_Ptr),
966 Make_Attribute_Reference (Loc,
967 Prefix => New_Occurrence_Of (Id, Loc),
968 Attribute_Name => Name_Unrestricted_Access)))));
970 Set_Register_Exception_Call (Id, First (L));
972 if not Is_Library_Level_Entity (Id) then
973 Flag_Id := Make_Defining_Identifier (Loc,
974 New_External_Name (Chars (Id), 'F'));
977 Make_Object_Declaration (Loc,
978 Defining_Identifier => Flag_Id,
980 New_Occurrence_Of (Standard_Boolean, Loc),
982 New_Occurrence_Of (Standard_True, Loc)));
984 Set_Is_Statically_Allocated (Flag_Id);
987 Make_Assignment_Statement (Loc,
988 Name => New_Occurrence_Of (Flag_Id, Loc),
989 Expression => New_Occurrence_Of (Standard_False, Loc)));
991 Insert_After_And_Analyze (N,
992 Make_Implicit_If_Statement (N,
993 Condition => New_Occurrence_Of (Flag_Id, Loc),
994 Then_Statements => L));
997 Insert_List_After_And_Analyze (N, L);
1001 end Expand_N_Exception_Declaration;
1003 ---------------------------------------------
1004 -- Expand_N_Handled_Sequence_Of_Statements --
1005 ---------------------------------------------
1007 procedure Expand_N_Handled_Sequence_Of_Statements (N : Node_Id) is
1009 if Present (Exception_Handlers (N))
1010 and then not Restriction_Active (No_Exception_Handlers)
1012 Expand_Exception_Handlers (N);
1015 -- The following code needs comments ???
1017 if Nkind (Parent (N)) /= N_Package_Body
1018 and then Nkind (Parent (N)) /= N_Accept_Statement
1019 and then not Delay_Cleanups (Current_Scope)
1021 Expand_Cleanup_Actions (Parent (N));
1023 Set_First_Real_Statement (N, First (Statements (N)));
1026 end Expand_N_Handled_Sequence_Of_Statements;
1028 -------------------------------------
1029 -- Expand_N_Raise_Constraint_Error --
1030 -------------------------------------
1032 -- The only processing required is to adjust the condition to deal
1033 -- with the C/Fortran boolean case. This may well not be necessary,
1034 -- as all such conditions are generated by the expander and probably
1035 -- are all standard boolean, but who knows what strange optimization
1036 -- in future may require this adjustment!
1038 procedure Expand_N_Raise_Constraint_Error (N : Node_Id) is
1040 Adjust_Condition (Condition (N));
1041 end Expand_N_Raise_Constraint_Error;
1043 ----------------------------------
1044 -- Expand_N_Raise_Program_Error --
1045 ----------------------------------
1047 -- The only processing required is to adjust the condition to deal
1048 -- with the C/Fortran boolean case. This may well not be necessary,
1049 -- as all such conditions are generated by the expander and probably
1050 -- are all standard boolean, but who knows what strange optimization
1051 -- in future may require this adjustment!
1053 procedure Expand_N_Raise_Program_Error (N : Node_Id) is
1055 Adjust_Condition (Condition (N));
1056 end Expand_N_Raise_Program_Error;
1058 ------------------------------
1059 -- Expand_N_Raise_Statement --
1060 ------------------------------
1062 procedure Expand_N_Raise_Statement (N : Node_Id) is
1063 Loc : constant Source_Ptr := Sloc (N);
1069 -- If a string expression is present, then the raise statement is
1070 -- converted to a call:
1072 -- Raise_Exception (exception-name'Identity, string);
1074 -- and there is nothing else to do
1076 if Present (Expression (N)) then
1078 Make_Procedure_Call_Statement (Loc,
1079 Name => New_Occurrence_Of (RTE (RE_Raise_Exception), Loc),
1080 Parameter_Associations => New_List (
1081 Make_Attribute_Reference (Loc,
1083 Attribute_Name => Name_Identity),
1089 -- Remaining processing is for the case where no string expression
1092 -- There is no expansion needed for statement "raise <exception>;" when
1093 -- compiling for the JVM since the JVM has a built-in exception
1094 -- mechanism. However we need the keep the expansion for "raise;"
1095 -- statements. See 4jexcept.ads for details.
1097 if Present (Name (N)) and then Hostparm.Java_VM then
1101 -- Don't expand a raise statement that does not come from source
1102 -- if we have already had configurable run-time violations, since
1103 -- most likely it will be junk cascaded nonsense.
1105 if Configurable_Run_Time_Violations > 0
1106 and then not Comes_From_Source (N)
1111 -- Convert explicit raise of Program_Error, Constraint_Error, and
1112 -- Storage_Error into the corresponding raise (in High_Integrity_Mode
1113 -- all other raises will get normal expansion and be disallowed,
1114 -- but this is also faster in all modes).
1116 if Present (Name (N)) and then Nkind (Name (N)) = N_Identifier then
1117 if Entity (Name (N)) = Standard_Constraint_Error then
1119 Make_Raise_Constraint_Error (Loc,
1120 Reason => CE_Explicit_Raise));
1124 elsif Entity (Name (N)) = Standard_Program_Error then
1126 Make_Raise_Program_Error (Loc,
1127 Reason => PE_Explicit_Raise));
1131 elsif Entity (Name (N)) = Standard_Storage_Error then
1133 Make_Raise_Storage_Error (Loc,
1134 Reason => SE_Explicit_Raise));
1140 -- Case of name present, in this case we expand raise name to
1142 -- Raise_Exception (name'Identity, location_string);
1144 -- where location_string identifies the file/line of the raise
1146 if Present (Name (N)) then
1148 Id : Entity_Id := Entity (Name (N));
1151 Build_Location_String (Loc);
1153 -- If the exception is a renaming, use the exception that it
1154 -- renames (which might be a predefined exception, e.g.).
1156 if Present (Renamed_Object (Id)) then
1157 Id := Renamed_Object (Id);
1160 -- Build a C-compatible string in case of no exception handlers,
1161 -- since this is what the last chance handler is expecting.
1163 if Restriction_Active (No_Exception_Handlers) then
1165 -- Generate an empty message if configuration pragma
1166 -- Suppress_Exception_Locations is set for this unit.
1168 if Opt.Exception_Locations_Suppressed then
1171 Name_Len := Name_Len + 1;
1174 Name_Buffer (Name_Len) := ASCII.NUL;
1177 if Opt.Exception_Locations_Suppressed then
1181 Str := String_From_Name_Buffer;
1183 -- For VMS exceptions, convert the raise into a call to
1184 -- lib$stop so it will be handled by __gnat_error_handler.
1186 if Is_VMS_Exception (Id) then
1188 Excep_Image : String_Id;
1192 if Present (Interface_Name (Id)) then
1193 Excep_Image := Strval (Interface_Name (Id));
1195 Get_Name_String (Chars (Id));
1197 Excep_Image := String_From_Name_Buffer;
1200 if Exception_Code (Id) /= No_Uint then
1202 Make_Integer_Literal (Loc, Exception_Code (Id));
1205 Unchecked_Convert_To (Standard_Integer,
1206 Make_Function_Call (Loc,
1207 Name => New_Occurrence_Of
1208 (RTE (RE_Import_Value), Loc),
1209 Parameter_Associations => New_List
1210 (Make_String_Literal (Loc,
1211 Strval => Excep_Image))));
1215 Make_Procedure_Call_Statement (Loc,
1217 New_Occurrence_Of (RTE (RE_Lib_Stop), Loc),
1218 Parameter_Associations => New_List (Cond)));
1219 Analyze_And_Resolve (Cond, Standard_Integer);
1222 -- Not VMS exception case, convert raise to call to the
1223 -- Raise_Exception routine.
1227 Make_Procedure_Call_Statement (Loc,
1228 Name => New_Occurrence_Of (RTE (RE_Raise_Exception), Loc),
1229 Parameter_Associations => New_List (
1230 Make_Attribute_Reference (Loc,
1232 Attribute_Name => Name_Identity),
1233 Make_String_Literal (Loc,
1238 -- Case of no name present (reraise). We rewrite the raise to:
1240 -- Reraise_Occurrence_Always (EO);
1242 -- where EO is the current exception occurrence. If the current handler
1243 -- does not have a choice parameter specification, then we provide one.
1246 -- Find innermost enclosing exception handler (there must be one,
1247 -- since the semantics has already verified that this raise statement
1248 -- is valid, and a raise with no arguments is only permitted in the
1249 -- context of an exception handler.
1251 Ehand := Parent (N);
1252 while Nkind (Ehand) /= N_Exception_Handler loop
1253 Ehand := Parent (Ehand);
1256 -- Make exception choice parameter if none present. Note that we do
1257 -- not need to put the entity on the entity chain, since no one will
1258 -- be referencing this entity by normal visibility methods.
1260 if No (Choice_Parameter (Ehand)) then
1261 E := Make_Defining_Identifier (Loc, New_Internal_Name ('E'));
1262 Set_Choice_Parameter (Ehand, E);
1263 Set_Ekind (E, E_Variable);
1264 Set_Etype (E, RTE (RE_Exception_Occurrence));
1265 Set_Scope (E, Current_Scope);
1268 -- Now rewrite the raise as a call to Reraise. A special case arises
1269 -- if this raise statement occurs in the context of a handler for
1270 -- all others (i.e. an at end handler). in this case we avoid
1271 -- the call to defer abort, cleanup routines are expected to be
1272 -- called in this case with aborts deferred.
1275 Ech : constant Node_Id := First (Exception_Choices (Ehand));
1279 if Nkind (Ech) = N_Others_Choice
1280 and then All_Others (Ech)
1282 Ent := RTE (RE_Reraise_Occurrence_No_Defer);
1284 Ent := RTE (RE_Reraise_Occurrence_Always);
1288 Make_Procedure_Call_Statement (Loc,
1289 Name => New_Occurrence_Of (Ent, Loc),
1290 Parameter_Associations => New_List (
1291 New_Occurrence_Of (Choice_Parameter (Ehand), Loc))));
1296 end Expand_N_Raise_Statement;
1298 ----------------------------------
1299 -- Expand_N_Raise_Storage_Error --
1300 ----------------------------------
1302 -- The only processing required is to adjust the condition to deal
1303 -- with the C/Fortran boolean case. This may well not be necessary,
1304 -- as all such conditions are generated by the expander and probably
1305 -- are all standard boolean, but who knows what strange optimization
1306 -- in future may require this adjustment!
1308 procedure Expand_N_Raise_Storage_Error (N : Node_Id) is
1310 Adjust_Condition (Condition (N));
1311 end Expand_N_Raise_Storage_Error;
1313 ------------------------------
1314 -- Expand_N_Subprogram_Info --
1315 ------------------------------
1317 procedure Expand_N_Subprogram_Info (N : Node_Id) is
1318 Loc : constant Source_Ptr := Sloc (N);
1321 -- For now, we replace an Expand_N_Subprogram_Info node with an
1322 -- attribute reference that gives the address of the procedure.
1323 -- This is because gigi does not yet recognize this node, and
1324 -- for the initial targets, this is the right value anyway.
1327 Make_Attribute_Reference (Loc,
1328 Prefix => Identifier (N),
1329 Attribute_Name => Name_Code_Address));
1331 Analyze_And_Resolve (N, RTE (RE_Code_Loc));
1332 end Expand_N_Subprogram_Info;
1334 ------------------------------------
1335 -- Generate_Subprogram_Descriptor --
1336 ------------------------------------
1338 procedure Generate_Subprogram_Descriptor
1353 if Exception_Mechanism /= Front_End_ZCX_Exceptions then
1357 if Restriction_Active (No_Exception_Handlers) then
1361 -- Suppress descriptor if we are not generating code. This happens
1362 -- in the case of a -gnatc -gnatt compilation where we force generics
1363 -- to be generated, but we still don't want exception tables.
1365 if Operating_Mode /= Generate_Code then
1369 -- Suppress descriptor if we are in No_Exceptions restrictions mode,
1370 -- since we can never propagate exceptions in any case in this mode.
1371 -- The same consideration applies for No_Exception_Handlers (which
1372 -- is also set in High_Integrity_Mode).
1374 if Restriction_Active (No_Exceptions)
1375 or Restriction_Active (No_Exception_Handlers)
1380 -- Suppress descriptor if we are inside a generic. There are two
1381 -- ways that we can tell that, depending on what is going on. If
1382 -- we are actually inside the processing for a generic right now,
1383 -- then Expander_Active will be reset. If we are outside the
1384 -- generic, then we will see the generic entity.
1386 if not Expander_Active then
1390 -- Suppress descriptor is subprogram is marked as eliminated, for
1391 -- example if this is a subprogram created to analyze a default
1392 -- expression with potential side effects. Ditto if it is nested
1393 -- within an eliminated subprogram, for example a cleanup action.
1400 while Scop /= Standard_Standard loop
1401 if Is_Generic_Unit (Scop) or else Is_Eliminated (Scop) then
1405 Scop := Scope (Scop);
1409 -- Suppress descriptor for original protected subprogram (we will
1410 -- be called again later to generate the descriptor for the actual
1411 -- protected body subprogram.) This does not apply to barrier
1412 -- functions which are there own protected subprogram.
1414 if Is_Subprogram (Spec)
1415 and then Present (Protected_Body_Subprogram (Spec))
1416 and then Protected_Body_Subprogram (Spec) /= Spec
1421 -- Suppress descriptors for packages unless they have at least one
1422 -- handler. The binder will generate the dummy (no handler) descriptors
1423 -- for elaboration procedures. We can't do it here, because we don't
1424 -- know if an elaboration routine does in fact exist.
1426 -- If there is at least one handler for the package spec or body
1427 -- then most certainly an elaboration routine must exist, so we
1428 -- can safely reference it.
1430 if (Nkind (N) = N_Package_Declaration
1432 Nkind (N) = N_Package_Body)
1433 and then No (Handler_Records (Spec))
1438 -- Suppress all subprogram descriptors for the file System.Exceptions.
1439 -- We similarly suppress subprogram descriptors for Ada.Exceptions.
1440 -- These are all init procs for types which cannot raise exceptions.
1441 -- The reason this is done is that otherwise we get embarassing
1442 -- elaboration dependencies.
1444 Get_Name_String (Unit_File_Name (Current_Sem_Unit));
1446 if Name_Buffer (1 .. 12) = "s-except.ads"
1448 Name_Buffer (1 .. 12) = "a-except.ads"
1453 -- Similarly, we need to suppress entries for System.Standard_Library,
1454 -- since otherwise we get elaboration circularities. Again, this would
1455 -- better be done with a Suppress_Initialization pragma :-)
1457 if Name_Buffer (1 .. 11) = "s-stalib.ad" then
1461 -- For now, also suppress entries for s-stoele because we have
1462 -- some kind of unexplained error there ???
1464 if Name_Buffer (1 .. 11) = "s-stoele.ad" then
1468 -- And also for g-htable, because it cannot raise exceptions,
1469 -- and generates some kind of elaboration order problem.
1471 if Name_Buffer (1 .. 11) = "g-htable.ad" then
1475 -- Suppress subprogram descriptor if already generated. This happens
1476 -- in the case of late generation from Delay_Subprogram_Descriptors
1477 -- beging set (where there is more than one instantiation in the list)
1479 if Has_Subprogram_Descriptor (Spec) then
1482 Set_Has_Subprogram_Descriptor (Spec);
1485 -- Never generate descriptors for inlined bodies
1487 if Analyzing_Inlined_Bodies then
1491 -- Here we definitely are going to generate a subprogram descriptor
1494 Hnum : Nat := Homonym_Number (Spec);
1502 Make_Defining_Identifier (Loc,
1503 Chars => New_External_Name (Chars (Spec), "SD", Hnum));
1506 if No (Handler_Records (Spec)) then
1510 Hrc := Handler_Records (Spec);
1511 Numh := List_Length (Hrc);
1516 -- We need a static subtype for the declaration of the subprogram
1517 -- descriptor. For the case of 0-3 handlers we can use one of the
1518 -- predefined subtypes in System.Exceptions. For more handlers,
1519 -- we build our own subtype here.
1523 Dtyp := RTE (RE_Subprogram_Descriptor_0);
1526 Dtyp := RTE (RE_Subprogram_Descriptor_1);
1529 Dtyp := RTE (RE_Subprogram_Descriptor_2);
1532 Dtyp := RTE (RE_Subprogram_Descriptor_3);
1536 Make_Defining_Identifier (Loc,
1537 Chars => New_Internal_Name ('T'));
1539 -- Set the constructed type as global, since we will be
1540 -- referencing the object that is of this type globally
1542 Set_Is_Statically_Allocated (Dtyp);
1545 Make_Subtype_Declaration (Loc,
1546 Defining_Identifier => Dtyp,
1547 Subtype_Indication =>
1548 Make_Subtype_Indication (Loc,
1550 New_Occurrence_Of (RTE (RE_Subprogram_Descriptor), Loc),
1552 Make_Index_Or_Discriminant_Constraint (Loc,
1553 Constraints => New_List (
1554 Make_Integer_Literal (Loc, Numh)))));
1556 Append (Decl, Slist);
1558 -- We analyze the descriptor for the subprogram and package
1559 -- case, but not for the imported subprogram case (it will
1560 -- be analyzed when the freeze entity actions are analyzed.
1566 Set_Exception_Junk (Decl);
1569 -- Prepare the code address entry for the table entry. For the normal
1570 -- case of being within a procedure, this is simply:
1574 -- where P is the procedure, but for the package case, it is
1576 -- P'Elab_Body'Code_Address
1577 -- P'Elab_Spec'Code_Address
1579 -- for the body and spec respectively. Note that we do our own
1580 -- analysis of these attribute references, because we know in this
1581 -- case that the prefix of ELab_Body/Spec is a visible package,
1582 -- which can be referenced directly instead of using the general
1583 -- case expansion for these attributes.
1585 if Ekind (Spec) = E_Package then
1587 Make_Attribute_Reference (Loc,
1588 Prefix => New_Occurrence_Of (Spec, Loc),
1589 Attribute_Name => Name_Elab_Spec);
1590 Set_Etype (Code, Standard_Void_Type);
1591 Set_Analyzed (Code);
1593 elsif Ekind (Spec) = E_Package_Body then
1595 Make_Attribute_Reference (Loc,
1596 Prefix => New_Occurrence_Of (Spec_Entity (Spec), Loc),
1597 Attribute_Name => Name_Elab_Body);
1598 Set_Etype (Code, Standard_Void_Type);
1599 Set_Analyzed (Code);
1602 Code := New_Occurrence_Of (Spec, Loc);
1606 Make_Attribute_Reference (Loc,
1608 Attribute_Name => Name_Code_Address);
1610 Set_Etype (Code, RTE (RE_Address));
1611 Set_Analyzed (Code);
1613 -- Now we can build the subprogram descriptor
1616 Make_Object_Declaration (Loc,
1617 Defining_Identifier => Ent,
1618 Constant_Present => True,
1619 Aliased_Present => True,
1620 Object_Definition => New_Occurrence_Of (Dtyp, Loc),
1623 Make_Aggregate (Loc,
1624 Expressions => New_List (
1625 Make_Integer_Literal (Loc, Numh), -- Num_Handlers
1631 -- Make_Subprogram_Info (Loc, -- Subprogram_Info
1633 -- New_Occurrence_Of (Spec, Loc)),
1635 New_Copy_Tree (Code),
1637 Make_Aggregate (Loc, -- Handler_Records
1638 Expressions => Hrc))));
1640 Set_Exception_Junk (Sdes);
1641 Set_Is_Subprogram_Descriptor (Sdes);
1643 Append (Sdes, Slist);
1645 -- We analyze the descriptor for the subprogram and package case,
1646 -- but not for the imported subprogram case (it will be analyzed
1647 -- when the freeze entity actions are analyzed.
1653 -- We can now pop the scope used for analyzing the descriptor
1657 -- We need to set the descriptor as statically allocated, since
1658 -- it will be referenced from the unit exception table.
1660 Set_Is_Statically_Allocated (Ent);
1662 -- Append the resulting descriptor to the list. We do this only
1663 -- if we are in the main unit. You might think that we could
1664 -- simply skip generating the descriptors completely if we are
1665 -- not in the main unit, but in fact this is not the case, since
1666 -- we have problems with inconsistent serial numbers for internal
1667 -- names if we do this.
1669 if In_Extended_Main_Code_Unit (Spec) then
1671 Make_Attribute_Reference (Loc,
1672 Prefix => New_Occurrence_Of (Ent, Loc),
1673 Attribute_Name => Name_Unrestricted_Access));
1675 Unit_Exception_Table_Present := True;
1678 end Generate_Subprogram_Descriptor;
1680 ------------------------------------------------------------
1681 -- Generate_Subprogram_Descriptor_For_Imported_Subprogram --
1682 ------------------------------------------------------------
1684 procedure Generate_Subprogram_Descriptor_For_Imported_Subprogram
1689 Generate_Subprogram_Descriptor (Empty, Sloc (Spec), Spec, Slist);
1690 end Generate_Subprogram_Descriptor_For_Imported_Subprogram;
1692 ------------------------------------------------
1693 -- Generate_Subprogram_Descriptor_For_Package --
1694 ------------------------------------------------
1696 procedure Generate_Subprogram_Descriptor_For_Package
1703 -- If N is empty with prior errors, ignore
1705 if Total_Errors_Detected /= 0 and then No (N) then
1709 -- Do not generate if no exceptions
1711 if Restriction_Active (No_Exception_Handlers) then
1715 -- Otherwise generate descriptor
1717 Adecl := Aux_Decls_Node (Parent (N));
1719 if No (Actions (Adecl)) then
1720 Set_Actions (Adecl, New_List);
1723 Generate_Subprogram_Descriptor (N, Sloc (N), Spec, Actions (Adecl));
1724 end Generate_Subprogram_Descriptor_For_Package;
1726 ---------------------------------------------------
1727 -- Generate_Subprogram_Descriptor_For_Subprogram --
1728 ---------------------------------------------------
1730 procedure Generate_Subprogram_Descriptor_For_Subprogram
1735 -- If we have no subprogram body and prior errors, ignore
1737 if Total_Errors_Detected /= 0 and then No (N) then
1741 -- Do not generate if no exceptions
1743 if Restriction_Active (No_Exception_Handlers) then
1747 -- Else generate descriptor
1750 HSS : constant Node_Id := Handled_Statement_Sequence (N);
1753 if No (Exception_Handlers (HSS)) then
1754 Generate_Subprogram_Descriptor
1755 (N, Sloc (N), Spec, Statements (HSS));
1757 Generate_Subprogram_Descriptor
1759 Spec, Statements (Last (Exception_Handlers (HSS))));
1762 end Generate_Subprogram_Descriptor_For_Subprogram;
1764 -----------------------------------
1765 -- Generate_Unit_Exception_Table --
1766 -----------------------------------
1768 -- The only remaining thing to generate here is to generate the
1769 -- reference to the subprogram descriptor chain. See Ada.Exceptions
1770 -- for details of required data structures.
1772 procedure Generate_Unit_Exception_Table is
1773 Loc : constant Source_Ptr := No_Location;
1777 Next_Ent : Entity_Id;
1781 -- Nothing to be done if zero length exceptions not active
1783 if Exception_Mechanism /= Front_End_ZCX_Exceptions then
1787 -- Nothing to do if no exceptions
1789 if Restriction_Active (No_Exception_Handlers) then
1793 -- Remove any entries from SD_List that correspond to eliminated
1796 Ent := First (SD_List);
1797 while Present (Ent) loop
1798 Next_Ent := Next (Ent);
1799 if Is_Eliminated (Scope (Entity (Prefix (Ent)))) then
1800 Remove (Ent); -- After this, there is no Next (Ent) anymore
1806 -- Nothing to do if no unit exception table present.
1807 -- An empty table can result from subprogram elimination,
1808 -- in such a case, eliminate the exception table itself.
1810 if Is_Empty_List (SD_List) then
1811 Unit_Exception_Table_Present := False;
1815 -- Do not generate table in a generic
1817 if Inside_A_Generic then
1821 -- Generate the unit exception table
1823 -- subtype Tnn is Subprogram_Descriptors_Record (Num);
1824 -- __gnat_unitname__SDP : aliased constant Tnn :=
1826 -- (sub1'unrestricted_access,
1827 -- sub2'unrestricted_access,
1829 -- subNum'unrestricted_access));
1831 Num := List_Length (SD_List);
1834 Make_Defining_Identifier (Loc,
1835 Chars => New_Internal_Name ('T'));
1837 Insert_Library_Level_Action (
1838 Make_Subtype_Declaration (Loc,
1839 Defining_Identifier => Stent,
1840 Subtype_Indication =>
1841 Make_Subtype_Indication (Loc,
1844 (RTE (RE_Subprogram_Descriptors_Record), Loc),
1846 Make_Index_Or_Discriminant_Constraint (Loc,
1847 Constraints => New_List (
1848 Make_Integer_Literal (Loc, Num))))));
1850 Set_Is_Statically_Allocated (Stent);
1852 Get_External_Unit_Name_String (Unit_Name (Main_Unit));
1853 Name_Buffer (1 + 7 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len);
1854 Name_Buffer (1 .. 7) := "__gnat_";
1855 Name_Len := Name_Len + 7;
1856 Add_Str_To_Name_Buffer ("__SDP");
1859 Make_Defining_Identifier (Loc,
1860 Chars => Name_Find);
1862 Get_Name_String (Chars (Ent));
1863 Set_Interface_Name (Ent,
1864 Make_String_Literal (Loc, Strval => String_From_Name_Buffer));
1867 Make_Object_Declaration (Loc,
1868 Defining_Identifier => Ent,
1869 Object_Definition => New_Occurrence_Of (Stent, Loc),
1870 Constant_Present => True,
1871 Aliased_Present => True,
1873 Make_Aggregate (Loc,
1875 Make_Integer_Literal (Loc, List_Length (SD_List)),
1877 Make_Aggregate (Loc,
1878 Expressions => SD_List))));
1880 Insert_Library_Level_Action (Decl);
1882 Set_Is_Exported (Ent, True);
1883 Set_Is_Public (Ent, True);
1884 Set_Is_Statically_Allocated (Ent, True);
1886 Get_Name_String (Chars (Ent));
1887 Set_Interface_Name (Ent,
1888 Make_String_Literal (Loc,
1889 Strval => String_From_Name_Buffer));
1891 end Generate_Unit_Exception_Table;
1897 procedure Initialize is
1899 SD_List := Empty_List;
1902 ----------------------
1903 -- Is_Non_Ada_Error --
1904 ----------------------
1906 function Is_Non_Ada_Error (E : Entity_Id) return Boolean is
1908 if not OpenVMS_On_Target then
1912 Get_Name_String (Chars (E));
1914 -- Note: it is a little irregular for the body of exp_ch11 to know
1915 -- the details of the encoding scheme for names, but on the other
1916 -- hand, gigi knows them, and this is for gigi's benefit anyway!
1918 if Name_Buffer (1 .. 30) /= "system__aux_dec__non_ada_error" then
1923 end Is_Non_Ada_Error;
1925 ----------------------------
1926 -- Remove_Handler_Entries --
1927 ----------------------------
1929 procedure Remove_Handler_Entries (N : Node_Id) is
1930 function Check_Handler_Entry (N : Node_Id) return Traverse_Result;
1931 -- This function checks one node for a possible reference to a
1932 -- handler entry that must be deleted. it always returns OK.
1934 function Remove_All_Handler_Entries is new
1935 Traverse_Func (Check_Handler_Entry);
1936 -- This defines the traversal operation
1938 Discard : Traverse_Result;
1939 pragma Warnings (Off, Discard);
1941 function Check_Handler_Entry (N : Node_Id) return Traverse_Result is
1943 if Nkind (N) = N_Object_Declaration then
1945 if Present (Handler_List_Entry (N)) then
1946 Remove (Handler_List_Entry (N));
1947 Delete_Tree (Handler_List_Entry (N));
1948 Set_Handler_List_Entry (N, Empty);
1950 elsif Is_Subprogram_Descriptor (N) then
1955 SDN := First (SD_List);
1956 while Present (SDN) loop
1957 if Defining_Identifier (N) = Entity (Prefix (SDN)) then
1970 end Check_Handler_Entry;
1972 -- Start of processing for Remove_Handler_Entries
1975 if Exception_Mechanism = Front_End_ZCX_Exceptions then
1976 Discard := Remove_All_Handler_Entries (N);
1978 end Remove_Handler_Entries;