PR tree-optimization/19853
[official-gcc.git] / gcc / ada / sem.adb
blobe242bc9399305ecf315167c66f55cdd717f82141
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2004, 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 -- Otherwise processing depends on the node kind
85 case Nkind (N) is
87 when N_Abort_Statement =>
88 Analyze_Abort_Statement (N);
90 when N_Abstract_Subprogram_Declaration =>
91 Analyze_Abstract_Subprogram_Declaration (N);
93 when N_Accept_Alternative =>
94 Analyze_Accept_Alternative (N);
96 when N_Accept_Statement =>
97 Analyze_Accept_Statement (N);
99 when N_Aggregate =>
100 Analyze_Aggregate (N);
102 when N_Allocator =>
103 Analyze_Allocator (N);
105 when N_And_Then =>
106 Analyze_Short_Circuit (N);
108 when N_Assignment_Statement =>
109 Analyze_Assignment (N);
111 when N_Asynchronous_Select =>
112 Analyze_Asynchronous_Select (N);
114 when N_At_Clause =>
115 Analyze_At_Clause (N);
117 when N_Attribute_Reference =>
118 Analyze_Attribute (N);
120 when N_Attribute_Definition_Clause =>
121 Analyze_Attribute_Definition_Clause (N);
123 when N_Block_Statement =>
124 Analyze_Block_Statement (N);
126 when N_Case_Statement =>
127 Analyze_Case_Statement (N);
129 when N_Character_Literal =>
130 Analyze_Character_Literal (N);
132 when N_Code_Statement =>
133 Analyze_Code_Statement (N);
135 when N_Compilation_Unit =>
136 Analyze_Compilation_Unit (N);
138 when N_Component_Declaration =>
139 Analyze_Component_Declaration (N);
141 when N_Conditional_Expression =>
142 Analyze_Conditional_Expression (N);
144 when N_Conditional_Entry_Call =>
145 Analyze_Conditional_Entry_Call (N);
147 when N_Delay_Alternative =>
148 Analyze_Delay_Alternative (N);
150 when N_Delay_Relative_Statement =>
151 Analyze_Delay_Relative (N);
153 when N_Delay_Until_Statement =>
154 Analyze_Delay_Until (N);
156 when N_Entry_Body =>
157 Analyze_Entry_Body (N);
159 when N_Entry_Body_Formal_Part =>
160 Analyze_Entry_Body_Formal_Part (N);
162 when N_Entry_Call_Alternative =>
163 Analyze_Entry_Call_Alternative (N);
165 when N_Entry_Declaration =>
166 Analyze_Entry_Declaration (N);
168 when N_Entry_Index_Specification =>
169 Analyze_Entry_Index_Specification (N);
171 when N_Enumeration_Representation_Clause =>
172 Analyze_Enumeration_Representation_Clause (N);
174 when N_Exception_Declaration =>
175 Analyze_Exception_Declaration (N);
177 when N_Exception_Renaming_Declaration =>
178 Analyze_Exception_Renaming (N);
180 when N_Exit_Statement =>
181 Analyze_Exit_Statement (N);
183 when N_Expanded_Name =>
184 Analyze_Expanded_Name (N);
186 when N_Explicit_Dereference =>
187 Analyze_Explicit_Dereference (N);
189 when N_Extension_Aggregate =>
190 Analyze_Aggregate (N);
192 when N_Formal_Object_Declaration =>
193 Analyze_Formal_Object_Declaration (N);
195 when N_Formal_Package_Declaration =>
196 Analyze_Formal_Package (N);
198 when N_Formal_Subprogram_Declaration =>
199 Analyze_Formal_Subprogram (N);
201 when N_Formal_Type_Declaration =>
202 Analyze_Formal_Type_Declaration (N);
204 when N_Free_Statement =>
205 Analyze_Free_Statement (N);
207 when N_Freeze_Entity =>
208 null; -- no semantic processing required
210 when N_Full_Type_Declaration =>
211 Analyze_Type_Declaration (N);
213 when N_Function_Call =>
214 Analyze_Function_Call (N);
216 when N_Function_Instantiation =>
217 Analyze_Function_Instantiation (N);
219 when N_Generic_Function_Renaming_Declaration =>
220 Analyze_Generic_Function_Renaming (N);
222 when N_Generic_Package_Declaration =>
223 Analyze_Generic_Package_Declaration (N);
225 when N_Generic_Package_Renaming_Declaration =>
226 Analyze_Generic_Package_Renaming (N);
228 when N_Generic_Procedure_Renaming_Declaration =>
229 Analyze_Generic_Procedure_Renaming (N);
231 when N_Generic_Subprogram_Declaration =>
232 Analyze_Generic_Subprogram_Declaration (N);
234 when N_Goto_Statement =>
235 Analyze_Goto_Statement (N);
237 when N_Handled_Sequence_Of_Statements =>
238 Analyze_Handled_Statements (N);
240 when N_Identifier =>
241 Analyze_Identifier (N);
243 when N_If_Statement =>
244 Analyze_If_Statement (N);
246 when N_Implicit_Label_Declaration =>
247 Analyze_Implicit_Label_Declaration (N);
249 when N_In =>
250 Analyze_Membership_Op (N);
252 when N_Incomplete_Type_Declaration =>
253 Analyze_Incomplete_Type_Decl (N);
255 when N_Indexed_Component =>
256 Analyze_Indexed_Component_Form (N);
258 when N_Integer_Literal =>
259 Analyze_Integer_Literal (N);
261 when N_Itype_Reference =>
262 Analyze_Itype_Reference (N);
264 when N_Label =>
265 Analyze_Label (N);
267 when N_Loop_Statement =>
268 Analyze_Loop_Statement (N);
270 when N_Not_In =>
271 Analyze_Membership_Op (N);
273 when N_Null =>
274 Analyze_Null (N);
276 when N_Null_Statement =>
277 Analyze_Null_Statement (N);
279 when N_Number_Declaration =>
280 Analyze_Number_Declaration (N);
282 when N_Object_Declaration =>
283 Analyze_Object_Declaration (N);
285 when N_Object_Renaming_Declaration =>
286 Analyze_Object_Renaming (N);
288 when N_Operator_Symbol =>
289 Analyze_Operator_Symbol (N);
291 when N_Op_Abs =>
292 Analyze_Unary_Op (N);
294 when N_Op_Add =>
295 Analyze_Arithmetic_Op (N);
297 when N_Op_And =>
298 Analyze_Logical_Op (N);
300 when N_Op_Concat =>
301 Analyze_Concatenation (N);
303 when N_Op_Divide =>
304 Analyze_Arithmetic_Op (N);
306 when N_Op_Eq =>
307 Analyze_Equality_Op (N);
309 when N_Op_Expon =>
310 Analyze_Arithmetic_Op (N);
312 when N_Op_Ge =>
313 Analyze_Comparison_Op (N);
315 when N_Op_Gt =>
316 Analyze_Comparison_Op (N);
318 when N_Op_Le =>
319 Analyze_Comparison_Op (N);
321 when N_Op_Lt =>
322 Analyze_Comparison_Op (N);
324 when N_Op_Minus =>
325 Analyze_Unary_Op (N);
327 when N_Op_Mod =>
328 Analyze_Arithmetic_Op (N);
330 when N_Op_Multiply =>
331 Analyze_Arithmetic_Op (N);
333 when N_Op_Ne =>
334 Analyze_Equality_Op (N);
336 when N_Op_Not =>
337 Analyze_Negation (N);
339 when N_Op_Or =>
340 Analyze_Logical_Op (N);
342 when N_Op_Plus =>
343 Analyze_Unary_Op (N);
345 when N_Op_Rem =>
346 Analyze_Arithmetic_Op (N);
348 when N_Op_Rotate_Left =>
349 Analyze_Arithmetic_Op (N);
351 when N_Op_Rotate_Right =>
352 Analyze_Arithmetic_Op (N);
354 when N_Op_Shift_Left =>
355 Analyze_Arithmetic_Op (N);
357 when N_Op_Shift_Right =>
358 Analyze_Arithmetic_Op (N);
360 when N_Op_Shift_Right_Arithmetic =>
361 Analyze_Arithmetic_Op (N);
363 when N_Op_Subtract =>
364 Analyze_Arithmetic_Op (N);
366 when N_Op_Xor =>
367 Analyze_Logical_Op (N);
369 when N_Or_Else =>
370 Analyze_Short_Circuit (N);
372 when N_Others_Choice =>
373 Analyze_Others_Choice (N);
375 when N_Package_Body =>
376 Analyze_Package_Body (N);
378 when N_Package_Body_Stub =>
379 Analyze_Package_Body_Stub (N);
381 when N_Package_Declaration =>
382 Analyze_Package_Declaration (N);
384 when N_Package_Instantiation =>
385 Analyze_Package_Instantiation (N);
387 when N_Package_Renaming_Declaration =>
388 Analyze_Package_Renaming (N);
390 when N_Package_Specification =>
391 Analyze_Package_Specification (N);
393 when N_Parameter_Association =>
394 Analyze_Parameter_Association (N);
396 when N_Pragma =>
397 Analyze_Pragma (N);
399 when N_Private_Extension_Declaration =>
400 Analyze_Private_Extension_Declaration (N);
402 when N_Private_Type_Declaration =>
403 Analyze_Private_Type_Declaration (N);
405 when N_Procedure_Call_Statement =>
406 Analyze_Procedure_Call (N);
408 when N_Procedure_Instantiation =>
409 Analyze_Procedure_Instantiation (N);
411 when N_Protected_Body =>
412 Analyze_Protected_Body (N);
414 when N_Protected_Body_Stub =>
415 Analyze_Protected_Body_Stub (N);
417 when N_Protected_Definition =>
418 Analyze_Protected_Definition (N);
420 when N_Protected_Type_Declaration =>
421 Analyze_Protected_Type (N);
423 when N_Qualified_Expression =>
424 Analyze_Qualified_Expression (N);
426 when N_Raise_Statement =>
427 Analyze_Raise_Statement (N);
429 when N_Raise_xxx_Error =>
430 Analyze_Raise_xxx_Error (N);
432 when N_Range =>
433 Analyze_Range (N);
435 when N_Range_Constraint =>
436 Analyze_Range (Range_Expression (N));
438 when N_Real_Literal =>
439 Analyze_Real_Literal (N);
441 when N_Record_Representation_Clause =>
442 Analyze_Record_Representation_Clause (N);
444 when N_Reference =>
445 Analyze_Reference (N);
447 when N_Requeue_Statement =>
448 Analyze_Requeue (N);
450 when N_Return_Statement =>
451 Analyze_Return_Statement (N);
453 when N_Selected_Component =>
454 Find_Selected_Component (N);
455 -- ??? why not Analyze_Selected_Component, needs comments
457 when N_Selective_Accept =>
458 Analyze_Selective_Accept (N);
460 when N_Single_Protected_Declaration =>
461 Analyze_Single_Protected (N);
463 when N_Single_Task_Declaration =>
464 Analyze_Single_Task (N);
466 when N_Slice =>
467 Analyze_Slice (N);
469 when N_String_Literal =>
470 Analyze_String_Literal (N);
472 when N_Subprogram_Body =>
473 Analyze_Subprogram_Body (N);
475 when N_Subprogram_Body_Stub =>
476 Analyze_Subprogram_Body_Stub (N);
478 when N_Subprogram_Declaration =>
479 Analyze_Subprogram_Declaration (N);
481 when N_Subprogram_Info =>
482 Analyze_Subprogram_Info (N);
484 when N_Subprogram_Renaming_Declaration =>
485 Analyze_Subprogram_Renaming (N);
487 when N_Subtype_Declaration =>
488 Analyze_Subtype_Declaration (N);
490 when N_Subtype_Indication =>
491 Analyze_Subtype_Indication (N);
493 when N_Subunit =>
494 Analyze_Subunit (N);
496 when N_Task_Body =>
497 Analyze_Task_Body (N);
499 when N_Task_Body_Stub =>
500 Analyze_Task_Body_Stub (N);
502 when N_Task_Definition =>
503 Analyze_Task_Definition (N);
505 when N_Task_Type_Declaration =>
506 Analyze_Task_Type (N);
508 when N_Terminate_Alternative =>
509 Analyze_Terminate_Alternative (N);
511 when N_Timed_Entry_Call =>
512 Analyze_Timed_Entry_Call (N);
514 when N_Triggering_Alternative =>
515 Analyze_Triggering_Alternative (N);
517 when N_Type_Conversion =>
518 Analyze_Type_Conversion (N);
520 when N_Unchecked_Expression =>
521 Analyze_Unchecked_Expression (N);
523 when N_Unchecked_Type_Conversion =>
524 Analyze_Unchecked_Type_Conversion (N);
526 when N_Use_Package_Clause =>
527 Analyze_Use_Package (N);
529 when N_Use_Type_Clause =>
530 Analyze_Use_Type (N);
532 when N_Validate_Unchecked_Conversion =>
533 null;
535 when N_Variant_Part =>
536 Analyze_Variant_Part (N);
538 when N_With_Clause =>
539 Analyze_With_Clause (N);
541 when N_With_Type_Clause =>
542 Analyze_With_Type_Clause (N);
544 -- A call to analyze the Empty node is an error, but most likely
545 -- it is an error caused by an attempt to analyze a malformed
546 -- piece of tree caused by some other error, so if there have
547 -- been any other errors, we just ignore it, otherwise it is
548 -- a real internal error which we complain about.
550 when N_Empty =>
551 pragma Assert (Serious_Errors_Detected /= 0);
552 null;
554 -- A call to analyze the error node is simply ignored, to avoid
555 -- causing cascaded errors (happens of course only in error cases)
557 when N_Error =>
558 null;
560 -- For the remaining node types, we generate compiler abort, because
561 -- these nodes are always analyzed within the Sem_Chn routines and
562 -- there should never be a case of making a call to the main Analyze
563 -- routine for these node kinds. For example, an N_Access_Definition
564 -- node appears only in the context of a type declaration, and is
565 -- processed by the analyze routine for type declarations.
567 when
568 N_Abortable_Part |
569 N_Access_Definition |
570 N_Access_Function_Definition |
571 N_Access_Procedure_Definition |
572 N_Access_To_Object_Definition |
573 N_Case_Statement_Alternative |
574 N_Compilation_Unit_Aux |
575 N_Component_Association |
576 N_Component_Clause |
577 N_Component_Definition |
578 N_Component_List |
579 N_Constrained_Array_Definition |
580 N_Decimal_Fixed_Point_Definition |
581 N_Defining_Character_Literal |
582 N_Defining_Identifier |
583 N_Defining_Operator_Symbol |
584 N_Defining_Program_Unit_Name |
585 N_Delta_Constraint |
586 N_Derived_Type_Definition |
587 N_Designator |
588 N_Digits_Constraint |
589 N_Discriminant_Association |
590 N_Discriminant_Specification |
591 N_Elsif_Part |
592 N_Entry_Call_Statement |
593 N_Enumeration_Type_Definition |
594 N_Exception_Handler |
595 N_Floating_Point_Definition |
596 N_Formal_Decimal_Fixed_Point_Definition |
597 N_Formal_Derived_Type_Definition |
598 N_Formal_Discrete_Type_Definition |
599 N_Formal_Floating_Point_Definition |
600 N_Formal_Modular_Type_Definition |
601 N_Formal_Ordinary_Fixed_Point_Definition |
602 N_Formal_Private_Type_Definition |
603 N_Formal_Signed_Integer_Type_Definition |
604 N_Function_Specification |
605 N_Generic_Association |
606 N_Index_Or_Discriminant_Constraint |
607 N_Iteration_Scheme |
608 N_Loop_Parameter_Specification |
609 N_Mod_Clause |
610 N_Modular_Type_Definition |
611 N_Ordinary_Fixed_Point_Definition |
612 N_Parameter_Specification |
613 N_Pragma_Argument_Association |
614 N_Procedure_Specification |
615 N_Real_Range_Specification |
616 N_Record_Definition |
617 N_Signed_Integer_Type_Definition |
618 N_Unconstrained_Array_Definition |
619 N_Unused_At_Start |
620 N_Unused_At_End |
621 N_Variant =>
623 raise Program_Error;
624 end case;
626 Debug_A_Exit ("analyzing ", N, " (done)");
628 -- Now that we have analyzed the node, we call the expander to
629 -- perform possible expansion. This is done only for nodes that
630 -- are not subexpressions, because in the case of subexpressions,
631 -- we don't have the type yet, and the expander will need to know
632 -- the type before it can do its job. For subexpression nodes, the
633 -- call to the expander happens in the Sem_Res.Resolve.
635 -- The Analyzed flag is also set at this point for non-subexpression
636 -- nodes (in the case of subexpression nodes, we can't set the flag
637 -- yet, since resolution and expansion have not yet been completed)
639 if Nkind (N) not in N_Subexpr then
640 Expand (N);
641 end if;
642 end Analyze;
644 -- Version with check(s) suppressed
646 procedure Analyze (N : Node_Id; Suppress : Check_Id) is
647 begin
648 if Suppress = All_Checks then
649 declare
650 Svg : constant Suppress_Array := Scope_Suppress;
652 begin
653 Scope_Suppress := (others => True);
654 Analyze (N);
655 Scope_Suppress := Svg;
656 end;
658 else
659 declare
660 Svg : constant Boolean := Scope_Suppress (Suppress);
662 begin
663 Scope_Suppress (Suppress) := True;
664 Analyze (N);
665 Scope_Suppress (Suppress) := Svg;
666 end;
667 end if;
668 end Analyze;
670 ------------------
671 -- Analyze_List --
672 ------------------
674 procedure Analyze_List (L : List_Id) is
675 Node : Node_Id;
677 begin
678 Node := First (L);
679 while Present (Node) loop
680 Analyze (Node);
681 Next (Node);
682 end loop;
683 end Analyze_List;
685 -- Version with check(s) suppressed
687 procedure Analyze_List (L : List_Id; Suppress : Check_Id) is
688 begin
689 if Suppress = All_Checks then
690 declare
691 Svg : constant Suppress_Array := Scope_Suppress;
693 begin
694 Scope_Suppress := (others => True);
695 Analyze_List (L);
696 Scope_Suppress := Svg;
697 end;
699 else
700 declare
701 Svg : constant Boolean := Scope_Suppress (Suppress);
703 begin
704 Scope_Suppress (Suppress) := True;
705 Analyze_List (L);
706 Scope_Suppress (Suppress) := Svg;
707 end;
708 end if;
709 end Analyze_List;
711 --------------------------
712 -- Copy_Suppress_Status --
713 --------------------------
715 procedure Copy_Suppress_Status
716 (C : Check_Id;
717 From : Entity_Id;
718 To : Entity_Id)
720 begin
721 if not Checks_May_Be_Suppressed (From) then
722 return;
723 end if;
725 -- First search the local entity suppress table, we search this in
726 -- reverse order so that we get the innermost entry that applies to
727 -- this case if there are nested entries. Note that for the purpose
728 -- of this procedure we are ONLY looking for entries corresponding
729 -- to a two-argument Suppress, where the second argument matches From.
731 for J in
732 reverse Local_Entity_Suppress.First .. Local_Entity_Suppress.Last
733 loop
734 declare
735 R : Entity_Check_Suppress_Record
736 renames Local_Entity_Suppress.Table (J);
738 begin
739 if R.Entity = From
740 and then (R.Check = All_Checks or else R.Check = C)
741 then
742 if R.Suppress then
743 Set_Checks_May_Be_Suppressed (To, True);
744 Local_Entity_Suppress.Append
745 ((Entity => To,
746 Check => C,
747 Suppress => True));
748 return;
749 end if;
750 end if;
751 end;
752 end loop;
754 -- Now search the global entity suppress table for a matching entry
755 -- We also search this in reverse order so that if there are multiple
756 -- pragmas for the same entity, the last one applies.
758 for J in
759 reverse Global_Entity_Suppress.First .. Global_Entity_Suppress.Last
760 loop
761 declare
762 R : Entity_Check_Suppress_Record
763 renames Global_Entity_Suppress.Table (J);
765 begin
766 if R.Entity = From
767 and then (R.Check = All_Checks or else R.Check = C)
768 then
769 if R.Suppress then
770 Set_Checks_May_Be_Suppressed (To, True);
771 Local_Entity_Suppress.Append
772 ((Entity => To,
773 Check => C,
774 Suppress => True));
775 end if;
776 end if;
777 end;
778 end loop;
779 end Copy_Suppress_Status;
781 -------------------------
782 -- Enter_Generic_Scope --
783 -------------------------
785 procedure Enter_Generic_Scope (S : Entity_Id) is
786 begin
787 if No (Outer_Generic_Scope) then
788 Outer_Generic_Scope := S;
789 end if;
790 end Enter_Generic_Scope;
792 ------------------------
793 -- Exit_Generic_Scope --
794 ------------------------
796 procedure Exit_Generic_Scope (S : Entity_Id) is
797 begin
798 if S = Outer_Generic_Scope then
799 Outer_Generic_Scope := Empty;
800 end if;
801 end Exit_Generic_Scope;
803 -----------------------
804 -- Explicit_Suppress --
805 -----------------------
807 function Explicit_Suppress (E : Entity_Id; C : Check_Id) return Boolean is
808 begin
809 if not Checks_May_Be_Suppressed (E) then
810 return False;
812 else
813 for J in
814 reverse Global_Entity_Suppress.First .. Global_Entity_Suppress.Last
815 loop
816 declare
817 R : Entity_Check_Suppress_Record
818 renames Global_Entity_Suppress.Table (J);
820 begin
821 if R.Entity = E
822 and then (R.Check = All_Checks or else R.Check = C)
823 then
824 return R.Suppress;
825 end if;
826 end;
827 end loop;
829 return False;
830 end if;
831 end Explicit_Suppress;
833 -----------------------------
834 -- External_Ref_In_Generic --
835 -----------------------------
837 function External_Ref_In_Generic (E : Entity_Id) return Boolean is
838 Scop : Entity_Id;
840 begin
841 -- Entity is global if defined outside of current outer_generic_scope:
842 -- Either the entity has a smaller depth that the outer generic, or it
843 -- is in a different compilation unit, or it is defined within a unit
844 -- in the same compilation, that is not within the outer_generic.
846 if No (Outer_Generic_Scope) then
847 return False;
849 elsif Scope_Depth (Scope (E)) < Scope_Depth (Outer_Generic_Scope)
850 or else not In_Same_Source_Unit (E, Outer_Generic_Scope)
851 then
852 return True;
854 else
855 Scop := Scope (E);
857 while Present (Scop) loop
858 if Scop = Outer_Generic_Scope then
859 return False;
860 elsif Scope_Depth (Scop) < Scope_Depth (Outer_Generic_Scope) then
861 return True;
862 else
863 Scop := Scope (Scop);
864 end if;
865 end loop;
867 return True;
868 end if;
869 end External_Ref_In_Generic;
871 ----------------
872 -- Initialize --
873 ----------------
875 procedure Initialize is
876 begin
877 Local_Entity_Suppress.Init;
878 Global_Entity_Suppress.Init;
879 Scope_Stack.Init;
880 Unloaded_Subunits := False;
881 end Initialize;
883 ------------------------------
884 -- Insert_After_And_Analyze --
885 ------------------------------
887 procedure Insert_After_And_Analyze (N : Node_Id; M : Node_Id) is
888 Node : Node_Id;
890 begin
891 if Present (M) then
893 -- If we are not at the end of the list, then the easiest
894 -- coding is simply to insert before our successor
896 if Present (Next (N)) then
897 Insert_Before_And_Analyze (Next (N), M);
899 -- Case of inserting at the end of the list
901 else
902 -- Capture the Node_Id of the node to be inserted. This Node_Id
903 -- will still be the same after the insert operation.
905 Node := M;
906 Insert_After (N, M);
908 -- Now just analyze from the inserted node to the end of
909 -- the new list (note that this properly handles the case
910 -- where any of the analyze calls result in the insertion of
911 -- nodes after the analyzed node, expecting analysis).
913 while Present (Node) loop
914 Analyze (Node);
915 Mark_Rewrite_Insertion (Node);
916 Next (Node);
917 end loop;
918 end if;
919 end if;
920 end Insert_After_And_Analyze;
922 -- Version with check(s) suppressed
924 procedure Insert_After_And_Analyze
925 (N : Node_Id;
926 M : Node_Id;
927 Suppress : Check_Id)
929 begin
930 if Suppress = All_Checks then
931 declare
932 Svg : constant Suppress_Array := Scope_Suppress;
934 begin
935 Scope_Suppress := (others => True);
936 Insert_After_And_Analyze (N, M);
937 Scope_Suppress := Svg;
938 end;
940 else
941 declare
942 Svg : constant Boolean := Scope_Suppress (Suppress);
944 begin
945 Scope_Suppress (Suppress) := True;
946 Insert_After_And_Analyze (N, M);
947 Scope_Suppress (Suppress) := Svg;
948 end;
949 end if;
950 end Insert_After_And_Analyze;
952 -------------------------------
953 -- Insert_Before_And_Analyze --
954 -------------------------------
956 procedure Insert_Before_And_Analyze (N : Node_Id; M : Node_Id) is
957 Node : Node_Id;
959 begin
960 if Present (M) then
962 -- Capture the Node_Id of the first list node to be inserted.
963 -- This will still be the first node after the insert operation,
964 -- since Insert_List_After does not modify the Node_Id values.
966 Node := M;
967 Insert_Before (N, M);
969 -- The insertion does not change the Id's of any of the nodes in
970 -- the list, and they are still linked, so we can simply loop from
971 -- the original first node until we meet the node before which the
972 -- insertion is occurring. Note that this properly handles the case
973 -- where any of the analyzed nodes insert nodes after themselves,
974 -- expecting them to get analyzed.
976 while Node /= N loop
977 Analyze (Node);
978 Mark_Rewrite_Insertion (Node);
979 Next (Node);
980 end loop;
981 end if;
982 end Insert_Before_And_Analyze;
984 -- Version with check(s) suppressed
986 procedure Insert_Before_And_Analyze
987 (N : Node_Id;
988 M : Node_Id;
989 Suppress : Check_Id)
991 begin
992 if Suppress = All_Checks then
993 declare
994 Svg : constant Suppress_Array := Scope_Suppress;
996 begin
997 Scope_Suppress := (others => True);
998 Insert_Before_And_Analyze (N, M);
999 Scope_Suppress := Svg;
1000 end;
1002 else
1003 declare
1004 Svg : constant Boolean := Scope_Suppress (Suppress);
1006 begin
1007 Scope_Suppress (Suppress) := True;
1008 Insert_Before_And_Analyze (N, M);
1009 Scope_Suppress (Suppress) := Svg;
1010 end;
1011 end if;
1012 end Insert_Before_And_Analyze;
1014 -----------------------------------
1015 -- Insert_List_After_And_Analyze --
1016 -----------------------------------
1018 procedure Insert_List_After_And_Analyze (N : Node_Id; L : List_Id) is
1019 After : constant Node_Id := Next (N);
1020 Node : Node_Id;
1022 begin
1023 if Is_Non_Empty_List (L) then
1025 -- Capture the Node_Id of the first list node to be inserted.
1026 -- This will still be the first node after the insert operation,
1027 -- since Insert_List_After does not modify the Node_Id values.
1029 Node := First (L);
1030 Insert_List_After (N, L);
1032 -- Now just analyze from the original first node until we get to
1033 -- the successor of the original insertion point (which may be
1034 -- Empty if the insertion point was at the end of the list). Note
1035 -- that this properly handles the case where any of the analyze
1036 -- calls result in the insertion of nodes after the analyzed
1037 -- node (possibly calling this routine recursively).
1039 while Node /= After loop
1040 Analyze (Node);
1041 Mark_Rewrite_Insertion (Node);
1042 Next (Node);
1043 end loop;
1044 end if;
1045 end Insert_List_After_And_Analyze;
1047 -- Version with check(s) suppressed
1049 procedure Insert_List_After_And_Analyze
1050 (N : Node_Id; L : List_Id; Suppress : Check_Id)
1052 begin
1053 if Suppress = All_Checks then
1054 declare
1055 Svg : constant Suppress_Array := Scope_Suppress;
1057 begin
1058 Scope_Suppress := (others => True);
1059 Insert_List_After_And_Analyze (N, L);
1060 Scope_Suppress := Svg;
1061 end;
1063 else
1064 declare
1065 Svg : constant Boolean := Scope_Suppress (Suppress);
1067 begin
1068 Scope_Suppress (Suppress) := True;
1069 Insert_List_After_And_Analyze (N, L);
1070 Scope_Suppress (Suppress) := Svg;
1071 end;
1072 end if;
1073 end Insert_List_After_And_Analyze;
1075 ------------------------------------
1076 -- Insert_List_Before_And_Analyze --
1077 ------------------------------------
1079 procedure Insert_List_Before_And_Analyze (N : Node_Id; L : List_Id) is
1080 Node : Node_Id;
1082 begin
1083 if Is_Non_Empty_List (L) then
1085 -- Capture the Node_Id of the first list node to be inserted.
1086 -- This will still be the first node after the insert operation,
1087 -- since Insert_List_After does not modify the Node_Id values.
1089 Node := First (L);
1090 Insert_List_Before (N, L);
1092 -- The insertion does not change the Id's of any of the nodes in
1093 -- the list, and they are still linked, so we can simply loop from
1094 -- the original first node until we meet the node before which the
1095 -- insertion is occurring. Note that this properly handles the case
1096 -- where any of the analyzed nodes insert nodes after themselves,
1097 -- expecting them to get analyzed.
1099 while Node /= N loop
1100 Analyze (Node);
1101 Mark_Rewrite_Insertion (Node);
1102 Next (Node);
1103 end loop;
1104 end if;
1105 end Insert_List_Before_And_Analyze;
1107 -- Version with check(s) suppressed
1109 procedure Insert_List_Before_And_Analyze
1110 (N : Node_Id; L : List_Id; Suppress : Check_Id)
1112 begin
1113 if Suppress = All_Checks then
1114 declare
1115 Svg : constant Suppress_Array := Scope_Suppress;
1117 begin
1118 Scope_Suppress := (others => True);
1119 Insert_List_Before_And_Analyze (N, L);
1120 Scope_Suppress := Svg;
1121 end;
1123 else
1124 declare
1125 Svg : constant Boolean := Scope_Suppress (Suppress);
1127 begin
1128 Scope_Suppress (Suppress) := True;
1129 Insert_List_Before_And_Analyze (N, L);
1130 Scope_Suppress (Suppress) := Svg;
1131 end;
1132 end if;
1133 end Insert_List_Before_And_Analyze;
1135 -------------------------
1136 -- Is_Check_Suppressed --
1137 -------------------------
1139 function Is_Check_Suppressed (E : Entity_Id; C : Check_Id) return Boolean is
1140 begin
1141 -- First search the local entity suppress table, we search this in
1142 -- reverse order so that we get the innermost entry that applies to
1143 -- this case if there are nested entries.
1145 for J in
1146 reverse Local_Entity_Suppress.First .. Local_Entity_Suppress.Last
1147 loop
1148 declare
1149 R : Entity_Check_Suppress_Record
1150 renames Local_Entity_Suppress.Table (J);
1152 begin
1153 if (R.Entity = Empty or else R.Entity = E)
1154 and then (R.Check = All_Checks or else R.Check = C)
1155 then
1156 return R.Suppress;
1157 end if;
1158 end;
1159 end loop;
1161 -- Now search the global entity suppress table for a matching entry
1162 -- We also search this in reverse order so that if there are multiple
1163 -- pragmas for the same entity, the last one applies (not clear what
1164 -- or whether the RM specifies this handling, but it seems reasonable).
1166 for J in
1167 reverse Global_Entity_Suppress.First .. Global_Entity_Suppress.Last
1168 loop
1169 declare
1170 R : Entity_Check_Suppress_Record
1171 renames Global_Entity_Suppress.Table (J);
1173 begin
1174 if R.Entity = E
1175 and then (R.Check = All_Checks or else R.Check = C)
1176 then
1177 return R.Suppress;
1178 end if;
1179 end;
1180 end loop;
1182 -- If we did not find a matching entry, then use the normal scope
1183 -- suppress value after all (actually this will be the global setting
1184 -- since it clearly was not overridden at any point)
1186 return Scope_Suppress (C);
1187 end Is_Check_Suppressed;
1189 ----------
1190 -- Lock --
1191 ----------
1193 procedure Lock is
1194 begin
1195 Local_Entity_Suppress.Locked := True;
1196 Global_Entity_Suppress.Locked := True;
1197 Scope_Stack.Locked := True;
1198 Local_Entity_Suppress.Release;
1199 Global_Entity_Suppress.Release;
1200 Scope_Stack.Release;
1201 end Lock;
1203 ---------------
1204 -- Semantics --
1205 ---------------
1207 procedure Semantics (Comp_Unit : Node_Id) is
1209 -- The following locations save the corresponding global flags and
1210 -- variables so that they can be restored on completion. This is
1211 -- needed so that calls to Rtsfind start with the proper default
1212 -- values for these variables, and also that such calls do not
1213 -- disturb the settings for units being analyzed at a higher level.
1215 S_Full_Analysis : constant Boolean := Full_Analysis;
1216 S_In_Default_Expr : constant Boolean := In_Default_Expression;
1217 S_Inside_A_Generic : constant Boolean := Inside_A_Generic;
1218 S_New_Nodes_OK : constant Int := New_Nodes_OK;
1219 S_Outer_Gen_Scope : constant Entity_Id := Outer_Generic_Scope;
1220 S_Sem_Unit : constant Unit_Number_Type := Current_Sem_Unit;
1222 Generic_Main : constant Boolean :=
1223 Nkind (Unit (Cunit (Main_Unit)))
1224 in N_Generic_Declaration;
1226 -- If the main unit is generic, every compiled unit, including its
1227 -- context, is compiled with expansion disabled.
1229 Save_Config_Switches : Config_Switches_Type;
1230 -- Variable used to save values of config switches while we analyze
1231 -- the new unit, to be restored on exit for proper recursive behavior.
1233 procedure Do_Analyze;
1234 -- Procedure to analyze the compilation unit. This is called more
1235 -- than once when the high level optimizer is activated.
1237 ----------------
1238 -- Do_Analyze --
1239 ----------------
1241 procedure Do_Analyze is
1242 begin
1243 Save_Scope_Stack;
1244 New_Scope (Standard_Standard);
1245 Scope_Suppress := Suppress_Options;
1246 Scope_Stack.Table
1247 (Scope_Stack.Last).Component_Alignment_Default := Calign_Default;
1248 Scope_Stack.Table
1249 (Scope_Stack.Last).Is_Active_Stack_Base := True;
1250 Outer_Generic_Scope := Empty;
1252 -- Now analyze the top level compilation unit node
1254 Analyze (Comp_Unit);
1256 -- Check for scope mismatch on exit from compilation
1258 pragma Assert (Current_Scope = Standard_Standard
1259 or else Comp_Unit = Cunit (Main_Unit));
1261 -- Then pop entry for Standard, and pop implicit types
1263 Pop_Scope;
1264 Restore_Scope_Stack;
1265 end Do_Analyze;
1267 -- Start of processing for Semantics
1269 begin
1270 Compiler_State := Analyzing;
1271 Current_Sem_Unit := Get_Cunit_Unit_Number (Comp_Unit);
1273 if Generic_Main then
1274 Expander_Mode_Save_And_Set (False);
1275 else
1276 Expander_Mode_Save_And_Set
1277 (Operating_Mode = Generate_Code or Debug_Flag_X);
1278 end if;
1280 Full_Analysis := True;
1281 Inside_A_Generic := False;
1282 In_Default_Expression := False;
1284 Set_Comes_From_Source_Default (False);
1285 Save_Opt_Config_Switches (Save_Config_Switches);
1286 Set_Opt_Config_Switches
1287 (Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit)));
1289 -- Only do analysis of unit that has not already been analyzed
1291 if not Analyzed (Comp_Unit) then
1292 Initialize_Version (Current_Sem_Unit);
1293 if HLO_Active then
1294 Expander_Mode_Save_And_Set (False);
1295 New_Nodes_OK := 1;
1296 Do_Analyze;
1297 Reset_Analyzed_Flags (Comp_Unit);
1298 Expander_Mode_Restore;
1299 High_Level_Optimize (Comp_Unit);
1300 New_Nodes_OK := 0;
1301 end if;
1303 Do_Analyze;
1304 end if;
1306 -- Save indication of dynamic elaboration checks for ALI file
1308 Set_Dynamic_Elab (Current_Sem_Unit, Dynamic_Elaboration_Checks);
1310 -- Restore settings of saved switches to entry values
1312 Current_Sem_Unit := S_Sem_Unit;
1313 Full_Analysis := S_Full_Analysis;
1314 In_Default_Expression := S_In_Default_Expr;
1315 Inside_A_Generic := S_Inside_A_Generic;
1316 New_Nodes_OK := S_New_Nodes_OK;
1317 Outer_Generic_Scope := S_Outer_Gen_Scope;
1319 Restore_Opt_Config_Switches (Save_Config_Switches);
1320 Expander_Mode_Restore;
1322 end Semantics;
1323 end Sem;