PR c++/11509
[official-gcc.git] / gcc / ada / sem.adb
blobd6d8a547043d761fef2f06f4213b31da42358431
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
10 -- --
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. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Debug; use Debug;
29 with Debug_A; use Debug_A;
30 with Einfo; use Einfo;
31 with Errout; use Errout;
32 with Expander; use Expander;
33 with Fname; use Fname;
34 with HLO; use HLO;
35 with Lib; use Lib;
36 with Lib.Load; use Lib.Load;
37 with Nlists; use Nlists;
38 with Opt; use Opt;
39 with Sem_Attr; use Sem_Attr;
40 with Sem_Ch2; use Sem_Ch2;
41 with Sem_Ch3; use Sem_Ch3;
42 with Sem_Ch4; use Sem_Ch4;
43 with Sem_Ch5; use Sem_Ch5;
44 with Sem_Ch6; use Sem_Ch6;
45 with Sem_Ch7; use Sem_Ch7;
46 with Sem_Ch8; use Sem_Ch8;
47 with Sem_Ch9; use Sem_Ch9;
48 with Sem_Ch10; use Sem_Ch10;
49 with Sem_Ch11; use Sem_Ch11;
50 with Sem_Ch12; use Sem_Ch12;
51 with Sem_Ch13; use Sem_Ch13;
52 with Sem_Prag; use Sem_Prag;
53 with Sem_Util; use Sem_Util;
54 with Sinfo; use Sinfo;
55 with Stand; use Stand;
56 with Uintp; use Uintp;
58 pragma Warnings (Off, Sem_Util);
59 -- Suppress warnings of unused with for Sem_Util (used only in asserts)
61 package body Sem is
63 Outer_Generic_Scope : Entity_Id := Empty;
64 -- Global reference to the outer scope that is generic. In a non
65 -- generic context, it is empty. At the moment, it is only used
66 -- for avoiding freezing of external references in generics.
68 -------------
69 -- Analyze --
70 -------------
72 procedure Analyze (N : Node_Id) is
73 begin
74 Debug_A_Entry ("analyzing ", N);
76 -- Immediate return if already analyzed
78 if Analyzed (N) then
79 Debug_A_Exit ("analyzing ", N, " (done, analyzed already)");
80 return;
81 end if;
83 Current_Error_Node := N;
85 -- Otherwise processing depends on the node kind
87 case Nkind (N) is
89 when N_Abort_Statement =>
90 Analyze_Abort_Statement (N);
92 when N_Abstract_Subprogram_Declaration =>
93 Analyze_Abstract_Subprogram_Declaration (N);
95 when N_Accept_Alternative =>
96 Analyze_Accept_Alternative (N);
98 when N_Accept_Statement =>
99 Analyze_Accept_Statement (N);
101 when N_Aggregate =>
102 Analyze_Aggregate (N);
104 when N_Allocator =>
105 Analyze_Allocator (N);
107 when N_And_Then =>
108 Analyze_Short_Circuit (N);
110 when N_Assignment_Statement =>
111 Analyze_Assignment (N);
113 when N_Asynchronous_Select =>
114 Analyze_Asynchronous_Select (N);
116 when N_At_Clause =>
117 Analyze_At_Clause (N);
119 when N_Attribute_Reference =>
120 Analyze_Attribute (N);
122 when N_Attribute_Definition_Clause =>
123 Analyze_Attribute_Definition_Clause (N);
125 when N_Block_Statement =>
126 Analyze_Block_Statement (N);
128 when N_Case_Statement =>
129 Analyze_Case_Statement (N);
131 when N_Character_Literal =>
132 Analyze_Character_Literal (N);
134 when N_Code_Statement =>
135 Analyze_Code_Statement (N);
137 when N_Compilation_Unit =>
138 Analyze_Compilation_Unit (N);
140 when N_Component_Declaration =>
141 Analyze_Component_Declaration (N);
143 when N_Conditional_Expression =>
144 Analyze_Conditional_Expression (N);
146 when N_Conditional_Entry_Call =>
147 Analyze_Conditional_Entry_Call (N);
149 when N_Delay_Alternative =>
150 Analyze_Delay_Alternative (N);
152 when N_Delay_Relative_Statement =>
153 Analyze_Delay_Relative (N);
155 when N_Delay_Until_Statement =>
156 Analyze_Delay_Until (N);
158 when N_Entry_Body =>
159 Analyze_Entry_Body (N);
161 when N_Entry_Body_Formal_Part =>
162 Analyze_Entry_Body_Formal_Part (N);
164 when N_Entry_Call_Alternative =>
165 Analyze_Entry_Call_Alternative (N);
167 when N_Entry_Declaration =>
168 Analyze_Entry_Declaration (N);
170 when N_Entry_Index_Specification =>
171 Analyze_Entry_Index_Specification (N);
173 when N_Enumeration_Representation_Clause =>
174 Analyze_Enumeration_Representation_Clause (N);
176 when N_Exception_Declaration =>
177 Analyze_Exception_Declaration (N);
179 when N_Exception_Renaming_Declaration =>
180 Analyze_Exception_Renaming (N);
182 when N_Exit_Statement =>
183 Analyze_Exit_Statement (N);
185 when N_Expanded_Name =>
186 Analyze_Expanded_Name (N);
188 when N_Explicit_Dereference =>
189 Analyze_Explicit_Dereference (N);
191 when N_Extension_Aggregate =>
192 Analyze_Aggregate (N);
194 when N_Formal_Object_Declaration =>
195 Analyze_Formal_Object_Declaration (N);
197 when N_Formal_Package_Declaration =>
198 Analyze_Formal_Package (N);
200 when N_Formal_Subprogram_Declaration =>
201 Analyze_Formal_Subprogram (N);
203 when N_Formal_Type_Declaration =>
204 Analyze_Formal_Type_Declaration (N);
206 when N_Free_Statement =>
207 Analyze_Free_Statement (N);
209 when N_Freeze_Entity =>
210 null; -- no semantic processing required
212 when N_Full_Type_Declaration =>
213 Analyze_Type_Declaration (N);
215 when N_Function_Call =>
216 Analyze_Function_Call (N);
218 when N_Function_Instantiation =>
219 Analyze_Function_Instantiation (N);
221 when N_Generic_Function_Renaming_Declaration =>
222 Analyze_Generic_Function_Renaming (N);
224 when N_Generic_Package_Declaration =>
225 Analyze_Generic_Package_Declaration (N);
227 when N_Generic_Package_Renaming_Declaration =>
228 Analyze_Generic_Package_Renaming (N);
230 when N_Generic_Procedure_Renaming_Declaration =>
231 Analyze_Generic_Procedure_Renaming (N);
233 when N_Generic_Subprogram_Declaration =>
234 Analyze_Generic_Subprogram_Declaration (N);
236 when N_Goto_Statement =>
237 Analyze_Goto_Statement (N);
239 when N_Handled_Sequence_Of_Statements =>
240 Analyze_Handled_Statements (N);
242 when N_Identifier =>
243 Analyze_Identifier (N);
245 when N_If_Statement =>
246 Analyze_If_Statement (N);
248 when N_Implicit_Label_Declaration =>
249 Analyze_Implicit_Label_Declaration (N);
251 when N_In =>
252 Analyze_Membership_Op (N);
254 when N_Incomplete_Type_Declaration =>
255 Analyze_Incomplete_Type_Decl (N);
257 when N_Indexed_Component =>
258 Analyze_Indexed_Component_Form (N);
260 when N_Integer_Literal =>
261 Analyze_Integer_Literal (N);
263 when N_Itype_Reference =>
264 Analyze_Itype_Reference (N);
266 when N_Label =>
267 Analyze_Label (N);
269 when N_Loop_Statement =>
270 Analyze_Loop_Statement (N);
272 when N_Not_In =>
273 Analyze_Membership_Op (N);
275 when N_Null =>
276 Analyze_Null (N);
278 when N_Null_Statement =>
279 Analyze_Null_Statement (N);
281 when N_Number_Declaration =>
282 Analyze_Number_Declaration (N);
284 when N_Object_Declaration =>
285 Analyze_Object_Declaration (N);
287 when N_Object_Renaming_Declaration =>
288 Analyze_Object_Renaming (N);
290 when N_Operator_Symbol =>
291 Analyze_Operator_Symbol (N);
293 when N_Op_Abs =>
294 Analyze_Unary_Op (N);
296 when N_Op_Add =>
297 Analyze_Arithmetic_Op (N);
299 when N_Op_And =>
300 Analyze_Logical_Op (N);
302 when N_Op_Concat =>
303 Analyze_Concatenation (N);
305 when N_Op_Divide =>
306 Analyze_Arithmetic_Op (N);
308 when N_Op_Eq =>
309 Analyze_Equality_Op (N);
311 when N_Op_Expon =>
312 Analyze_Arithmetic_Op (N);
314 when N_Op_Ge =>
315 Analyze_Comparison_Op (N);
317 when N_Op_Gt =>
318 Analyze_Comparison_Op (N);
320 when N_Op_Le =>
321 Analyze_Comparison_Op (N);
323 when N_Op_Lt =>
324 Analyze_Comparison_Op (N);
326 when N_Op_Minus =>
327 Analyze_Unary_Op (N);
329 when N_Op_Mod =>
330 Analyze_Arithmetic_Op (N);
332 when N_Op_Multiply =>
333 Analyze_Arithmetic_Op (N);
335 when N_Op_Ne =>
336 Analyze_Equality_Op (N);
338 when N_Op_Not =>
339 Analyze_Negation (N);
341 when N_Op_Or =>
342 Analyze_Logical_Op (N);
344 when N_Op_Plus =>
345 Analyze_Unary_Op (N);
347 when N_Op_Rem =>
348 Analyze_Arithmetic_Op (N);
350 when N_Op_Rotate_Left =>
351 Analyze_Arithmetic_Op (N);
353 when N_Op_Rotate_Right =>
354 Analyze_Arithmetic_Op (N);
356 when N_Op_Shift_Left =>
357 Analyze_Arithmetic_Op (N);
359 when N_Op_Shift_Right =>
360 Analyze_Arithmetic_Op (N);
362 when N_Op_Shift_Right_Arithmetic =>
363 Analyze_Arithmetic_Op (N);
365 when N_Op_Subtract =>
366 Analyze_Arithmetic_Op (N);
368 when N_Op_Xor =>
369 Analyze_Logical_Op (N);
371 when N_Or_Else =>
372 Analyze_Short_Circuit (N);
374 when N_Others_Choice =>
375 Analyze_Others_Choice (N);
377 when N_Package_Body =>
378 Analyze_Package_Body (N);
380 when N_Package_Body_Stub =>
381 Analyze_Package_Body_Stub (N);
383 when N_Package_Declaration =>
384 Analyze_Package_Declaration (N);
386 when N_Package_Instantiation =>
387 Analyze_Package_Instantiation (N);
389 when N_Package_Renaming_Declaration =>
390 Analyze_Package_Renaming (N);
392 when N_Package_Specification =>
393 Analyze_Package_Specification (N);
395 when N_Parameter_Association =>
396 Analyze_Parameter_Association (N);
398 when N_Pragma =>
399 Analyze_Pragma (N);
401 when N_Private_Extension_Declaration =>
402 Analyze_Private_Extension_Declaration (N);
404 when N_Private_Type_Declaration =>
405 Analyze_Private_Type_Declaration (N);
407 when N_Procedure_Call_Statement =>
408 Analyze_Procedure_Call (N);
410 when N_Procedure_Instantiation =>
411 Analyze_Procedure_Instantiation (N);
413 when N_Protected_Body =>
414 Analyze_Protected_Body (N);
416 when N_Protected_Body_Stub =>
417 Analyze_Protected_Body_Stub (N);
419 when N_Protected_Definition =>
420 Analyze_Protected_Definition (N);
422 when N_Protected_Type_Declaration =>
423 Analyze_Protected_Type (N);
425 when N_Qualified_Expression =>
426 Analyze_Qualified_Expression (N);
428 when N_Raise_Statement =>
429 Analyze_Raise_Statement (N);
431 when N_Raise_xxx_Error =>
432 Analyze_Raise_xxx_Error (N);
434 when N_Range =>
435 Analyze_Range (N);
437 when N_Range_Constraint =>
438 Analyze_Range (Range_Expression (N));
440 when N_Real_Literal =>
441 Analyze_Real_Literal (N);
443 when N_Record_Representation_Clause =>
444 Analyze_Record_Representation_Clause (N);
446 when N_Reference =>
447 Analyze_Reference (N);
449 when N_Requeue_Statement =>
450 Analyze_Requeue (N);
452 when N_Return_Statement =>
453 Analyze_Return_Statement (N);
455 when N_Selected_Component =>
456 Find_Selected_Component (N);
457 -- ??? why not Analyze_Selected_Component, needs comments
459 when N_Selective_Accept =>
460 Analyze_Selective_Accept (N);
462 when N_Single_Protected_Declaration =>
463 Analyze_Single_Protected (N);
465 when N_Single_Task_Declaration =>
466 Analyze_Single_Task (N);
468 when N_Slice =>
469 Analyze_Slice (N);
471 when N_String_Literal =>
472 Analyze_String_Literal (N);
474 when N_Subprogram_Body =>
475 Analyze_Subprogram_Body (N);
477 when N_Subprogram_Body_Stub =>
478 Analyze_Subprogram_Body_Stub (N);
480 when N_Subprogram_Declaration =>
481 Analyze_Subprogram_Declaration (N);
483 when N_Subprogram_Info =>
484 Analyze_Subprogram_Info (N);
486 when N_Subprogram_Renaming_Declaration =>
487 Analyze_Subprogram_Renaming (N);
489 when N_Subtype_Declaration =>
490 Analyze_Subtype_Declaration (N);
492 when N_Subtype_Indication =>
493 Analyze_Subtype_Indication (N);
495 when N_Subunit =>
496 Analyze_Subunit (N);
498 when N_Task_Body =>
499 Analyze_Task_Body (N);
501 when N_Task_Body_Stub =>
502 Analyze_Task_Body_Stub (N);
504 when N_Task_Definition =>
505 Analyze_Task_Definition (N);
507 when N_Task_Type_Declaration =>
508 Analyze_Task_Type (N);
510 when N_Terminate_Alternative =>
511 Analyze_Terminate_Alternative (N);
513 when N_Timed_Entry_Call =>
514 Analyze_Timed_Entry_Call (N);
516 when N_Triggering_Alternative =>
517 Analyze_Triggering_Alternative (N);
519 when N_Type_Conversion =>
520 Analyze_Type_Conversion (N);
522 when N_Unchecked_Expression =>
523 Analyze_Unchecked_Expression (N);
525 when N_Unchecked_Type_Conversion =>
526 Analyze_Unchecked_Type_Conversion (N);
528 when N_Use_Package_Clause =>
529 Analyze_Use_Package (N);
531 when N_Use_Type_Clause =>
532 Analyze_Use_Type (N);
534 when N_Validate_Unchecked_Conversion =>
535 null;
537 when N_Variant_Part =>
538 Analyze_Variant_Part (N);
540 when N_With_Clause =>
541 Analyze_With_Clause (N);
543 when N_With_Type_Clause =>
544 Analyze_With_Type_Clause (N);
546 -- A call to analyze the Empty node is an error, but most likely
547 -- it is an error caused by an attempt to analyze a malformed
548 -- piece of tree caused by some other error, so if there have
549 -- been any other errors, we just ignore it, otherwise it is
550 -- a real internal error which we complain about.
552 when N_Empty =>
553 pragma Assert (Serious_Errors_Detected /= 0);
554 null;
556 -- A call to analyze the error node is simply ignored, to avoid
557 -- causing cascaded errors (happens of course only in error cases)
559 when N_Error =>
560 null;
562 -- For the remaining node types, we generate compiler abort, because
563 -- these nodes are always analyzed within the Sem_Chn routines and
564 -- there should never be a case of making a call to the main Analyze
565 -- routine for these node kinds. For example, an N_Access_Definition
566 -- node appears only in the context of a type declaration, and is
567 -- processed by the analyze routine for type declarations.
569 when
570 N_Abortable_Part |
571 N_Access_Definition |
572 N_Access_Function_Definition |
573 N_Access_Procedure_Definition |
574 N_Access_To_Object_Definition |
575 N_Case_Statement_Alternative |
576 N_Compilation_Unit_Aux |
577 N_Component_Association |
578 N_Component_Clause |
579 N_Component_List |
580 N_Constrained_Array_Definition |
581 N_Decimal_Fixed_Point_Definition |
582 N_Defining_Character_Literal |
583 N_Defining_Identifier |
584 N_Defining_Operator_Symbol |
585 N_Defining_Program_Unit_Name |
586 N_Delta_Constraint |
587 N_Derived_Type_Definition |
588 N_Designator |
589 N_Digits_Constraint |
590 N_Discriminant_Association |
591 N_Discriminant_Specification |
592 N_Elsif_Part |
593 N_Entry_Call_Statement |
594 N_Enumeration_Type_Definition |
595 N_Exception_Handler |
596 N_Floating_Point_Definition |
597 N_Formal_Decimal_Fixed_Point_Definition |
598 N_Formal_Derived_Type_Definition |
599 N_Formal_Discrete_Type_Definition |
600 N_Formal_Floating_Point_Definition |
601 N_Formal_Modular_Type_Definition |
602 N_Formal_Ordinary_Fixed_Point_Definition |
603 N_Formal_Private_Type_Definition |
604 N_Formal_Signed_Integer_Type_Definition |
605 N_Function_Specification |
606 N_Generic_Association |
607 N_Index_Or_Discriminant_Constraint |
608 N_Iteration_Scheme |
609 N_Loop_Parameter_Specification |
610 N_Mod_Clause |
611 N_Modular_Type_Definition |
612 N_Ordinary_Fixed_Point_Definition |
613 N_Parameter_Specification |
614 N_Pragma_Argument_Association |
615 N_Procedure_Specification |
616 N_Real_Range_Specification |
617 N_Record_Definition |
618 N_Signed_Integer_Type_Definition |
619 N_Unconstrained_Array_Definition |
620 N_Unused_At_Start |
621 N_Unused_At_End |
622 N_Variant =>
624 raise Program_Error;
625 end case;
627 Debug_A_Exit ("analyzing ", N, " (done)");
629 -- Now that we have analyzed the node, we call the expander to
630 -- perform possible expansion. This is done only for nodes that
631 -- are not subexpressions, because in the case of subexpressions,
632 -- we don't have the type yet, and the expander will need to know
633 -- the type before it can do its job. For subexpression nodes, the
634 -- call to the expander happens in the Sem_Res.Resolve.
636 -- The Analyzed flag is also set at this point for non-subexpression
637 -- nodes (in the case of subexpression nodes, we can't set the flag
638 -- yet, since resolution and expansion have not yet been completed)
640 if Nkind (N) not in N_Subexpr then
641 Expand (N);
642 end if;
644 end Analyze;
646 -- Version with check(s) suppressed
648 procedure Analyze (N : Node_Id; Suppress : Check_Id) is
649 begin
650 if Suppress = All_Checks then
651 declare
652 Svg : constant Suppress_Record := Scope_Suppress;
654 begin
655 Scope_Suppress := (others => True);
656 Analyze (N);
657 Scope_Suppress := Svg;
658 end;
660 else
661 declare
662 Svg : constant Boolean := Get_Scope_Suppress (Suppress);
664 begin
665 Set_Scope_Suppress (Suppress, True);
666 Analyze (N);
667 Set_Scope_Suppress (Suppress, Svg);
668 end;
669 end if;
670 end Analyze;
672 ------------------
673 -- Analyze_List --
674 ------------------
676 procedure Analyze_List (L : List_Id) is
677 Node : Node_Id;
679 begin
680 Node := First (L);
681 while Present (Node) loop
682 Analyze (Node);
683 Next (Node);
684 end loop;
685 end Analyze_List;
687 -- Version with check(s) suppressed
689 procedure Analyze_List (L : List_Id; Suppress : Check_Id) is
690 begin
691 if Suppress = All_Checks then
692 declare
693 Svg : constant Suppress_Record := Scope_Suppress;
695 begin
696 Scope_Suppress := (others => True);
697 Analyze_List (L);
698 Scope_Suppress := Svg;
699 end;
701 else
702 declare
703 Svg : constant Boolean := Get_Scope_Suppress (Suppress);
705 begin
706 Set_Scope_Suppress (Suppress, True);
707 Analyze_List (L);
708 Set_Scope_Suppress (Suppress, Svg);
709 end;
710 end if;
711 end Analyze_List;
713 -------------------------
714 -- Enter_Generic_Scope --
715 -------------------------
717 procedure Enter_Generic_Scope (S : Entity_Id) is
718 begin
719 if No (Outer_Generic_Scope) then
720 Outer_Generic_Scope := S;
721 end if;
722 end Enter_Generic_Scope;
724 ------------------------
725 -- Exit_Generic_Scope --
726 ------------------------
728 procedure Exit_Generic_Scope (S : Entity_Id) is
729 begin
730 if S = Outer_Generic_Scope then
731 Outer_Generic_Scope := Empty;
732 end if;
733 end Exit_Generic_Scope;
735 -----------------------------
736 -- External_Ref_In_Generic --
737 -----------------------------
739 function External_Ref_In_Generic (E : Entity_Id) return Boolean is
740 begin
742 -- Entity is global if defined outside of current outer_generic_scope:
743 -- Either the entity has a smaller depth that the outer generic, or it
744 -- is in a different compilation unit.
746 return Present (Outer_Generic_Scope)
747 and then (Scope_Depth (Scope (E)) < Scope_Depth (Outer_Generic_Scope)
748 or else not In_Same_Source_Unit (E, Outer_Generic_Scope));
749 end External_Ref_In_Generic;
751 ------------------------
752 -- Get_Scope_Suppress --
753 ------------------------
755 function Get_Scope_Suppress (C : Check_Id) return Boolean is
756 S : Suppress_Record renames Scope_Suppress;
758 begin
759 case C is
760 when Access_Check => return S.Access_Checks;
761 when Accessibility_Check => return S.Accessibility_Checks;
762 when Discriminant_Check => return S.Discriminant_Checks;
763 when Division_Check => return S.Division_Checks;
764 when Elaboration_Check => return S.Discriminant_Checks;
765 when Index_Check => return S.Elaboration_Checks;
766 when Length_Check => return S.Discriminant_Checks;
767 when Overflow_Check => return S.Overflow_Checks;
768 when Range_Check => return S.Range_Checks;
769 when Storage_Check => return S.Storage_Checks;
770 when Tag_Check => return S.Tag_Checks;
771 when All_Checks =>
772 raise Program_Error;
773 end case;
774 end Get_Scope_Suppress;
776 ----------------
777 -- Initialize --
778 ----------------
780 procedure Initialize is
781 begin
782 Entity_Suppress.Init;
783 Scope_Stack.Init;
784 Unloaded_Subunits := False;
785 end Initialize;
787 ------------------------------
788 -- Insert_After_And_Analyze --
789 ------------------------------
791 procedure Insert_After_And_Analyze (N : Node_Id; M : Node_Id) is
792 Node : Node_Id;
794 begin
795 if Present (M) then
797 -- If we are not at the end of the list, then the easiest
798 -- coding is simply to insert before our successor
800 if Present (Next (N)) then
801 Insert_Before_And_Analyze (Next (N), M);
803 -- Case of inserting at the end of the list
805 else
806 -- Capture the Node_Id of the node to be inserted. This Node_Id
807 -- will still be the same after the insert operation.
809 Node := M;
810 Insert_After (N, M);
812 -- Now just analyze from the inserted node to the end of
813 -- the new list (note that this properly handles the case
814 -- where any of the analyze calls result in the insertion of
815 -- nodes after the analyzed node, expecting analysis).
817 while Present (Node) loop
818 Analyze (Node);
819 Mark_Rewrite_Insertion (Node);
820 Next (Node);
821 end loop;
822 end if;
823 end if;
825 end Insert_After_And_Analyze;
827 -- Version with check(s) suppressed
829 procedure Insert_After_And_Analyze
830 (N : Node_Id; M : Node_Id; Suppress : Check_Id)
832 begin
833 if Suppress = All_Checks then
834 declare
835 Svg : constant Suppress_Record := Scope_Suppress;
837 begin
838 Scope_Suppress := (others => True);
839 Insert_After_And_Analyze (N, M);
840 Scope_Suppress := Svg;
841 end;
843 else
844 declare
845 Svg : constant Boolean := Get_Scope_Suppress (Suppress);
847 begin
848 Set_Scope_Suppress (Suppress, True);
849 Insert_After_And_Analyze (N, M);
850 Set_Scope_Suppress (Suppress, Svg);
851 end;
852 end if;
853 end Insert_After_And_Analyze;
855 -------------------------------
856 -- Insert_Before_And_Analyze --
857 -------------------------------
859 procedure Insert_Before_And_Analyze (N : Node_Id; M : Node_Id) is
860 Node : Node_Id;
862 begin
863 if Present (M) then
865 -- Capture the Node_Id of the first list node to be inserted.
866 -- This will still be the first node after the insert operation,
867 -- since Insert_List_After does not modify the Node_Id values.
869 Node := M;
870 Insert_Before (N, M);
872 -- The insertion does not change the Id's of any of the nodes in
873 -- the list, and they are still linked, so we can simply loop from
874 -- the original first node until we meet the node before which the
875 -- insertion is occurring. Note that this properly handles the case
876 -- where any of the analyzed nodes insert nodes after themselves,
877 -- expecting them to get analyzed.
879 while Node /= N loop
880 Analyze (Node);
881 Mark_Rewrite_Insertion (Node);
882 Next (Node);
883 end loop;
884 end if;
886 end Insert_Before_And_Analyze;
888 -- Version with check(s) suppressed
890 procedure Insert_Before_And_Analyze
891 (N : Node_Id; M : Node_Id; Suppress : Check_Id)
893 begin
894 if Suppress = All_Checks then
895 declare
896 Svg : constant Suppress_Record := Scope_Suppress;
898 begin
899 Scope_Suppress := (others => True);
900 Insert_Before_And_Analyze (N, M);
901 Scope_Suppress := Svg;
902 end;
904 else
905 declare
906 Svg : constant Boolean := Get_Scope_Suppress (Suppress);
908 begin
909 Set_Scope_Suppress (Suppress, True);
910 Insert_Before_And_Analyze (N, M);
911 Set_Scope_Suppress (Suppress, Svg);
912 end;
913 end if;
914 end Insert_Before_And_Analyze;
916 -----------------------------------
917 -- Insert_List_After_And_Analyze --
918 -----------------------------------
920 procedure Insert_List_After_And_Analyze (N : Node_Id; L : List_Id) is
921 After : constant Node_Id := Next (N);
922 Node : Node_Id;
924 begin
925 if Is_Non_Empty_List (L) then
927 -- Capture the Node_Id of the first list node to be inserted.
928 -- This will still be the first node after the insert operation,
929 -- since Insert_List_After does not modify the Node_Id values.
931 Node := First (L);
932 Insert_List_After (N, L);
934 -- Now just analyze from the original first node until we get to
935 -- the successor of the original insertion point (which may be
936 -- Empty if the insertion point was at the end of the list). Note
937 -- that this properly handles the case where any of the analyze
938 -- calls result in the insertion of nodes after the analyzed
939 -- node (possibly calling this routine recursively).
941 while Node /= After loop
942 Analyze (Node);
943 Mark_Rewrite_Insertion (Node);
944 Next (Node);
945 end loop;
946 end if;
948 end Insert_List_After_And_Analyze;
950 -- Version with check(s) suppressed
952 procedure Insert_List_After_And_Analyze
953 (N : Node_Id; L : List_Id; Suppress : Check_Id)
955 begin
956 if Suppress = All_Checks then
957 declare
958 Svg : constant Suppress_Record := Scope_Suppress;
960 begin
961 Scope_Suppress := (others => True);
962 Insert_List_After_And_Analyze (N, L);
963 Scope_Suppress := Svg;
964 end;
966 else
967 declare
968 Svg : constant Boolean := Get_Scope_Suppress (Suppress);
970 begin
971 Set_Scope_Suppress (Suppress, True);
972 Insert_List_After_And_Analyze (N, L);
973 Set_Scope_Suppress (Suppress, Svg);
974 end;
975 end if;
976 end Insert_List_After_And_Analyze;
978 ------------------------------------
979 -- Insert_List_Before_And_Analyze --
980 ------------------------------------
982 procedure Insert_List_Before_And_Analyze (N : Node_Id; L : List_Id) is
983 Node : Node_Id;
985 begin
986 if Is_Non_Empty_List (L) then
988 -- Capture the Node_Id of the first list node to be inserted.
989 -- This will still be the first node after the insert operation,
990 -- since Insert_List_After does not modify the Node_Id values.
992 Node := First (L);
993 Insert_List_Before (N, L);
995 -- The insertion does not change the Id's of any of the nodes in
996 -- the list, and they are still linked, so we can simply loop from
997 -- the original first node until we meet the node before which the
998 -- insertion is occurring. Note that this properly handles the case
999 -- where any of the analyzed nodes insert nodes after themselves,
1000 -- expecting them to get analyzed.
1002 while Node /= N loop
1003 Analyze (Node);
1004 Mark_Rewrite_Insertion (Node);
1005 Next (Node);
1006 end loop;
1007 end if;
1009 end Insert_List_Before_And_Analyze;
1011 -- Version with check(s) suppressed
1013 procedure Insert_List_Before_And_Analyze
1014 (N : Node_Id; L : List_Id; Suppress : Check_Id)
1016 begin
1017 if Suppress = All_Checks then
1018 declare
1019 Svg : constant Suppress_Record := Scope_Suppress;
1021 begin
1022 Scope_Suppress := (others => True);
1023 Insert_List_Before_And_Analyze (N, L);
1024 Scope_Suppress := Svg;
1025 end;
1027 else
1028 declare
1029 Svg : constant Boolean := Get_Scope_Suppress (Suppress);
1031 begin
1032 Set_Scope_Suppress (Suppress, True);
1033 Insert_List_Before_And_Analyze (N, L);
1034 Set_Scope_Suppress (Suppress, Svg);
1035 end;
1036 end if;
1037 end Insert_List_Before_And_Analyze;
1039 ----------
1040 -- Lock --
1041 ----------
1043 procedure Lock is
1044 begin
1045 Entity_Suppress.Locked := True;
1046 Scope_Stack.Locked := True;
1047 Entity_Suppress.Release;
1048 Scope_Stack.Release;
1049 end Lock;
1051 ---------------
1052 -- Semantics --
1053 ---------------
1055 procedure Semantics (Comp_Unit : Node_Id) is
1057 -- The following locations save the corresponding global flags and
1058 -- variables so that they can be restored on completion. This is
1059 -- needed so that calls to Rtsfind start with the proper default
1060 -- values for these variables, and also that such calls do not
1061 -- disturb the settings for units being analyzed at a higher level.
1063 S_Full_Analysis : constant Boolean := Full_Analysis;
1064 S_In_Default_Expr : constant Boolean := In_Default_Expression;
1065 S_Inside_A_Generic : constant Boolean := Inside_A_Generic;
1066 S_New_Nodes_OK : constant Int := New_Nodes_OK;
1067 S_Outer_Gen_Scope : constant Entity_Id := Outer_Generic_Scope;
1068 S_Sem_Unit : constant Unit_Number_Type := Current_Sem_Unit;
1070 Save_Config_Switches : Config_Switches_Type;
1071 -- Variable used to save values of config switches while we analyze
1072 -- the new unit, to be restored on exit for proper recursive behavior.
1074 procedure Do_Analyze;
1075 -- Procedure to analyze the compilation unit. This is called more
1076 -- than once when the high level optimizer is activated.
1078 procedure Do_Analyze is
1079 begin
1080 Save_Scope_Stack;
1081 New_Scope (Standard_Standard);
1082 Scope_Suppress := Suppress_Options;
1083 Scope_Stack.Table
1084 (Scope_Stack.Last).Component_Alignment_Default := Calign_Default;
1085 Scope_Stack.Table
1086 (Scope_Stack.Last).Is_Active_Stack_Base := True;
1087 Outer_Generic_Scope := Empty;
1089 -- Now analyze the top level compilation unit node
1091 Analyze (Comp_Unit);
1093 -- Check for scope mismatch on exit from compilation
1095 pragma Assert (Current_Scope = Standard_Standard
1096 or else Comp_Unit = Cunit (Main_Unit));
1098 -- Then pop entry for Standard, and pop implicit types
1100 Pop_Scope;
1101 Restore_Scope_Stack;
1102 end Do_Analyze;
1104 -- Start of processing for Sem
1106 begin
1107 Compiler_State := Analyzing;
1108 Current_Sem_Unit := Get_Cunit_Unit_Number (Comp_Unit);
1110 Expander_Mode_Save_And_Set
1111 (Operating_Mode = Generate_Code or Debug_Flag_X);
1113 Full_Analysis := True;
1114 Inside_A_Generic := False;
1115 In_Default_Expression := False;
1117 Set_Comes_From_Source_Default (False);
1118 Save_Opt_Config_Switches (Save_Config_Switches);
1119 Set_Opt_Config_Switches
1120 (Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit)));
1122 -- Only do analysis of unit that has not already been analyzed
1124 if not Analyzed (Comp_Unit) then
1125 Initialize_Version (Current_Sem_Unit);
1126 if HLO_Active then
1127 Expander_Mode_Save_And_Set (False);
1128 New_Nodes_OK := 1;
1129 Do_Analyze;
1130 Reset_Analyzed_Flags (Comp_Unit);
1131 Expander_Mode_Restore;
1132 High_Level_Optimize (Comp_Unit);
1133 New_Nodes_OK := 0;
1134 end if;
1136 Do_Analyze;
1137 end if;
1139 -- Save indication of dynamic elaboration checks for ALI file
1141 Set_Dynamic_Elab (Current_Sem_Unit, Dynamic_Elaboration_Checks);
1143 -- Restore settings of saved switches to entry values
1145 Current_Sem_Unit := S_Sem_Unit;
1146 Full_Analysis := S_Full_Analysis;
1147 In_Default_Expression := S_In_Default_Expr;
1148 Inside_A_Generic := S_Inside_A_Generic;
1149 New_Nodes_OK := S_New_Nodes_OK;
1150 Outer_Generic_Scope := S_Outer_Gen_Scope;
1152 Restore_Opt_Config_Switches (Save_Config_Switches);
1153 Expander_Mode_Restore;
1155 end Semantics;
1157 ------------------------
1158 -- Set_Scope_Suppress --
1159 ------------------------
1161 procedure Set_Scope_Suppress (C : Check_Id; B : Boolean) is
1162 S : Suppress_Record renames Scope_Suppress;
1164 begin
1165 case C is
1166 when Access_Check => S.Access_Checks := B;
1167 when Accessibility_Check => S.Accessibility_Checks := B;
1168 when Discriminant_Check => S.Discriminant_Checks := B;
1169 when Division_Check => S.Division_Checks := B;
1170 when Elaboration_Check => S.Discriminant_Checks := B;
1171 when Index_Check => S.Elaboration_Checks := B;
1172 when Length_Check => S.Discriminant_Checks := B;
1173 when Overflow_Check => S.Overflow_Checks := B;
1174 when Range_Check => S.Range_Checks := B;
1175 when Storage_Check => S.Storage_Checks := B;
1176 when Tag_Check => S.Tag_Checks := B;
1177 when All_Checks =>
1178 raise Program_Error;
1179 end case;
1180 end Set_Scope_Suppress;
1182 end Sem;