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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 Debug
; use Debug
;
29 with Debug_A
; use Debug_A
;
30 with Errout
; use Errout
;
31 with Expander
; use Expander
;
32 with Fname
; use Fname
;
35 with Lib
.Load
; use Lib
.Load
;
36 with Nlists
; use Nlists
;
37 with Sem_Attr
; use Sem_Attr
;
38 with Sem_Ch2
; use Sem_Ch2
;
39 with Sem_Ch3
; use Sem_Ch3
;
40 with Sem_Ch4
; use Sem_Ch4
;
41 with Sem_Ch5
; use Sem_Ch5
;
42 with Sem_Ch6
; use Sem_Ch6
;
43 with Sem_Ch7
; use Sem_Ch7
;
44 with Sem_Ch8
; use Sem_Ch8
;
45 with Sem_Ch9
; use Sem_Ch9
;
46 with Sem_Ch10
; use Sem_Ch10
;
47 with Sem_Ch11
; use Sem_Ch11
;
48 with Sem_Ch12
; use Sem_Ch12
;
49 with Sem_Ch13
; use Sem_Ch13
;
50 with Sem_Prag
; use Sem_Prag
;
51 with Sem_Util
; use Sem_Util
;
52 with Sinfo
; use Sinfo
;
53 with Stand
; use Stand
;
54 with Uintp
; use Uintp
;
56 pragma Warnings
(Off
, Sem_Util
);
57 -- Suppress warnings of unused with for Sem_Util (used only in asserts)
61 Outer_Generic_Scope
: Entity_Id
:= Empty
;
62 -- Global reference to the outer scope that is generic. In a non
63 -- generic context, it is empty. At the moment, it is only used
64 -- for avoiding freezing of external references in generics.
70 procedure Analyze
(N
: Node_Id
) is
72 Debug_A_Entry
("analyzing ", N
);
74 -- Immediate return if already analyzed
77 Debug_A_Exit
("analyzing ", N
, " (done, analyzed already)");
81 -- Otherwise processing depends on the node kind
85 when N_Abort_Statement
=>
86 Analyze_Abort_Statement
(N
);
88 when N_Abstract_Subprogram_Declaration
=>
89 Analyze_Abstract_Subprogram_Declaration
(N
);
91 when N_Accept_Alternative
=>
92 Analyze_Accept_Alternative
(N
);
94 when N_Accept_Statement
=>
95 Analyze_Accept_Statement
(N
);
98 Analyze_Aggregate
(N
);
101 Analyze_Allocator
(N
);
104 Analyze_Short_Circuit
(N
);
106 when N_Assignment_Statement
=>
107 Analyze_Assignment
(N
);
109 when N_Asynchronous_Select
=>
110 Analyze_Asynchronous_Select
(N
);
113 Analyze_At_Clause
(N
);
115 when N_Attribute_Reference
=>
116 Analyze_Attribute
(N
);
118 when N_Attribute_Definition_Clause
=>
119 Analyze_Attribute_Definition_Clause
(N
);
121 when N_Block_Statement
=>
122 Analyze_Block_Statement
(N
);
124 when N_Case_Statement
=>
125 Analyze_Case_Statement
(N
);
127 when N_Character_Literal
=>
128 Analyze_Character_Literal
(N
);
130 when N_Code_Statement
=>
131 Analyze_Code_Statement
(N
);
133 when N_Compilation_Unit
=>
134 Analyze_Compilation_Unit
(N
);
136 when N_Component_Declaration
=>
137 Analyze_Component_Declaration
(N
);
139 when N_Conditional_Expression
=>
140 Analyze_Conditional_Expression
(N
);
142 when N_Conditional_Entry_Call
=>
143 Analyze_Conditional_Entry_Call
(N
);
145 when N_Delay_Alternative
=>
146 Analyze_Delay_Alternative
(N
);
148 when N_Delay_Relative_Statement
=>
149 Analyze_Delay_Relative
(N
);
151 when N_Delay_Until_Statement
=>
152 Analyze_Delay_Until
(N
);
155 Analyze_Entry_Body
(N
);
157 when N_Entry_Body_Formal_Part
=>
158 Analyze_Entry_Body_Formal_Part
(N
);
160 when N_Entry_Call_Alternative
=>
161 Analyze_Entry_Call_Alternative
(N
);
163 when N_Entry_Declaration
=>
164 Analyze_Entry_Declaration
(N
);
166 when N_Entry_Index_Specification
=>
167 Analyze_Entry_Index_Specification
(N
);
169 when N_Enumeration_Representation_Clause
=>
170 Analyze_Enumeration_Representation_Clause
(N
);
172 when N_Exception_Declaration
=>
173 Analyze_Exception_Declaration
(N
);
175 when N_Exception_Renaming_Declaration
=>
176 Analyze_Exception_Renaming
(N
);
178 when N_Exit_Statement
=>
179 Analyze_Exit_Statement
(N
);
181 when N_Expanded_Name
=>
182 Analyze_Expanded_Name
(N
);
184 when N_Explicit_Dereference
=>
185 Analyze_Explicit_Dereference
(N
);
187 when N_Extension_Aggregate
=>
188 Analyze_Aggregate
(N
);
190 when N_Formal_Object_Declaration
=>
191 Analyze_Formal_Object_Declaration
(N
);
193 when N_Formal_Package_Declaration
=>
194 Analyze_Formal_Package
(N
);
196 when N_Formal_Subprogram_Declaration
=>
197 Analyze_Formal_Subprogram
(N
);
199 when N_Formal_Type_Declaration
=>
200 Analyze_Formal_Type_Declaration
(N
);
202 when N_Free_Statement
=>
203 Analyze_Free_Statement
(N
);
205 when N_Freeze_Entity
=>
206 null; -- no semantic processing required
208 when N_Full_Type_Declaration
=>
209 Analyze_Type_Declaration
(N
);
211 when N_Function_Call
=>
212 Analyze_Function_Call
(N
);
214 when N_Function_Instantiation
=>
215 Analyze_Function_Instantiation
(N
);
217 when N_Generic_Function_Renaming_Declaration
=>
218 Analyze_Generic_Function_Renaming
(N
);
220 when N_Generic_Package_Declaration
=>
221 Analyze_Generic_Package_Declaration
(N
);
223 when N_Generic_Package_Renaming_Declaration
=>
224 Analyze_Generic_Package_Renaming
(N
);
226 when N_Generic_Procedure_Renaming_Declaration
=>
227 Analyze_Generic_Procedure_Renaming
(N
);
229 when N_Generic_Subprogram_Declaration
=>
230 Analyze_Generic_Subprogram_Declaration
(N
);
232 when N_Goto_Statement
=>
233 Analyze_Goto_Statement
(N
);
235 when N_Handled_Sequence_Of_Statements
=>
236 Analyze_Handled_Statements
(N
);
239 Analyze_Identifier
(N
);
241 when N_If_Statement
=>
242 Analyze_If_Statement
(N
);
244 when N_Implicit_Label_Declaration
=>
245 Analyze_Implicit_Label_Declaration
(N
);
248 Analyze_Membership_Op
(N
);
250 when N_Incomplete_Type_Declaration
=>
251 Analyze_Incomplete_Type_Decl
(N
);
253 when N_Indexed_Component
=>
254 Analyze_Indexed_Component_Form
(N
);
256 when N_Integer_Literal
=>
257 Analyze_Integer_Literal
(N
);
259 when N_Itype_Reference
=>
260 Analyze_Itype_Reference
(N
);
265 when N_Loop_Statement
=>
266 Analyze_Loop_Statement
(N
);
269 Analyze_Membership_Op
(N
);
274 when N_Null_Statement
=>
275 Analyze_Null_Statement
(N
);
277 when N_Number_Declaration
=>
278 Analyze_Number_Declaration
(N
);
280 when N_Object_Declaration
=>
281 Analyze_Object_Declaration
(N
);
283 when N_Object_Renaming_Declaration
=>
284 Analyze_Object_Renaming
(N
);
286 when N_Operator_Symbol
=>
287 Analyze_Operator_Symbol
(N
);
290 Analyze_Unary_Op
(N
);
293 Analyze_Arithmetic_Op
(N
);
296 Analyze_Logical_Op
(N
);
299 Analyze_Concatenation
(N
);
302 Analyze_Arithmetic_Op
(N
);
305 Analyze_Equality_Op
(N
);
308 Analyze_Arithmetic_Op
(N
);
311 Analyze_Comparison_Op
(N
);
314 Analyze_Comparison_Op
(N
);
317 Analyze_Comparison_Op
(N
);
320 Analyze_Comparison_Op
(N
);
323 Analyze_Unary_Op
(N
);
326 Analyze_Arithmetic_Op
(N
);
328 when N_Op_Multiply
=>
329 Analyze_Arithmetic_Op
(N
);
332 Analyze_Equality_Op
(N
);
335 Analyze_Negation
(N
);
338 Analyze_Logical_Op
(N
);
341 Analyze_Unary_Op
(N
);
344 Analyze_Arithmetic_Op
(N
);
346 when N_Op_Rotate_Left
=>
347 Analyze_Arithmetic_Op
(N
);
349 when N_Op_Rotate_Right
=>
350 Analyze_Arithmetic_Op
(N
);
352 when N_Op_Shift_Left
=>
353 Analyze_Arithmetic_Op
(N
);
355 when N_Op_Shift_Right
=>
356 Analyze_Arithmetic_Op
(N
);
358 when N_Op_Shift_Right_Arithmetic
=>
359 Analyze_Arithmetic_Op
(N
);
361 when N_Op_Subtract
=>
362 Analyze_Arithmetic_Op
(N
);
365 Analyze_Logical_Op
(N
);
368 Analyze_Short_Circuit
(N
);
370 when N_Others_Choice
=>
371 Analyze_Others_Choice
(N
);
373 when N_Package_Body
=>
374 Analyze_Package_Body
(N
);
376 when N_Package_Body_Stub
=>
377 Analyze_Package_Body_Stub
(N
);
379 when N_Package_Declaration
=>
380 Analyze_Package_Declaration
(N
);
382 when N_Package_Instantiation
=>
383 Analyze_Package_Instantiation
(N
);
385 when N_Package_Renaming_Declaration
=>
386 Analyze_Package_Renaming
(N
);
388 when N_Package_Specification
=>
389 Analyze_Package_Specification
(N
);
391 when N_Parameter_Association
=>
392 Analyze_Parameter_Association
(N
);
397 when N_Private_Extension_Declaration
=>
398 Analyze_Private_Extension_Declaration
(N
);
400 when N_Private_Type_Declaration
=>
401 Analyze_Private_Type_Declaration
(N
);
403 when N_Procedure_Call_Statement
=>
404 Analyze_Procedure_Call
(N
);
406 when N_Procedure_Instantiation
=>
407 Analyze_Procedure_Instantiation
(N
);
409 when N_Protected_Body
=>
410 Analyze_Protected_Body
(N
);
412 when N_Protected_Body_Stub
=>
413 Analyze_Protected_Body_Stub
(N
);
415 when N_Protected_Definition
=>
416 Analyze_Protected_Definition
(N
);
418 when N_Protected_Type_Declaration
=>
419 Analyze_Protected_Type
(N
);
421 when N_Qualified_Expression
=>
422 Analyze_Qualified_Expression
(N
);
424 when N_Raise_Statement
=>
425 Analyze_Raise_Statement
(N
);
427 when N_Raise_xxx_Error
=>
428 Analyze_Raise_xxx_Error
(N
);
433 when N_Range_Constraint
=>
434 Analyze_Range
(Range_Expression
(N
));
436 when N_Real_Literal
=>
437 Analyze_Real_Literal
(N
);
439 when N_Record_Representation_Clause
=>
440 Analyze_Record_Representation_Clause
(N
);
443 Analyze_Reference
(N
);
445 when N_Requeue_Statement
=>
448 when N_Return_Statement
=>
449 Analyze_Return_Statement
(N
);
451 when N_Selected_Component
=>
452 Find_Selected_Component
(N
);
453 -- ??? why not Analyze_Selected_Component, needs comments
455 when N_Selective_Accept
=>
456 Analyze_Selective_Accept
(N
);
458 when N_Single_Protected_Declaration
=>
459 Analyze_Single_Protected
(N
);
461 when N_Single_Task_Declaration
=>
462 Analyze_Single_Task
(N
);
467 when N_String_Literal
=>
468 Analyze_String_Literal
(N
);
470 when N_Subprogram_Body
=>
471 Analyze_Subprogram_Body
(N
);
473 when N_Subprogram_Body_Stub
=>
474 Analyze_Subprogram_Body_Stub
(N
);
476 when N_Subprogram_Declaration
=>
477 Analyze_Subprogram_Declaration
(N
);
479 when N_Subprogram_Info
=>
480 Analyze_Subprogram_Info
(N
);
482 when N_Subprogram_Renaming_Declaration
=>
483 Analyze_Subprogram_Renaming
(N
);
485 when N_Subtype_Declaration
=>
486 Analyze_Subtype_Declaration
(N
);
488 when N_Subtype_Indication
=>
489 Analyze_Subtype_Indication
(N
);
495 Analyze_Task_Body
(N
);
497 when N_Task_Body_Stub
=>
498 Analyze_Task_Body_Stub
(N
);
500 when N_Task_Definition
=>
501 Analyze_Task_Definition
(N
);
503 when N_Task_Type_Declaration
=>
504 Analyze_Task_Type
(N
);
506 when N_Terminate_Alternative
=>
507 Analyze_Terminate_Alternative
(N
);
509 when N_Timed_Entry_Call
=>
510 Analyze_Timed_Entry_Call
(N
);
512 when N_Triggering_Alternative
=>
513 Analyze_Triggering_Alternative
(N
);
515 when N_Type_Conversion
=>
516 Analyze_Type_Conversion
(N
);
518 when N_Unchecked_Expression
=>
519 Analyze_Unchecked_Expression
(N
);
521 when N_Unchecked_Type_Conversion
=>
522 Analyze_Unchecked_Type_Conversion
(N
);
524 when N_Use_Package_Clause
=>
525 Analyze_Use_Package
(N
);
527 when N_Use_Type_Clause
=>
528 Analyze_Use_Type
(N
);
530 when N_Validate_Unchecked_Conversion
=>
533 when N_Variant_Part
=>
534 Analyze_Variant_Part
(N
);
536 when N_With_Clause
=>
537 Analyze_With_Clause
(N
);
539 when N_With_Type_Clause
=>
540 Analyze_With_Type_Clause
(N
);
542 -- A call to analyze the Empty node is an error, but most likely
543 -- it is an error caused by an attempt to analyze a malformed
544 -- piece of tree caused by some other error, so if there have
545 -- been any other errors, we just ignore it, otherwise it is
546 -- a real internal error which we complain about.
549 pragma Assert
(Serious_Errors_Detected
/= 0);
552 -- A call to analyze the error node is simply ignored, to avoid
553 -- causing cascaded errors (happens of course only in error cases)
558 -- For the remaining node types, we generate compiler abort, because
559 -- these nodes are always analyzed within the Sem_Chn routines and
560 -- there should never be a case of making a call to the main Analyze
561 -- routine for these node kinds. For example, an N_Access_Definition
562 -- node appears only in the context of a type declaration, and is
563 -- processed by the analyze routine for type declarations.
567 N_Access_Definition |
568 N_Access_Function_Definition |
569 N_Access_Procedure_Definition |
570 N_Access_To_Object_Definition |
571 N_Case_Statement_Alternative |
572 N_Compilation_Unit_Aux |
573 N_Component_Association |
575 N_Component_Definition |
577 N_Constrained_Array_Definition |
578 N_Decimal_Fixed_Point_Definition |
579 N_Defining_Character_Literal |
580 N_Defining_Identifier |
581 N_Defining_Operator_Symbol |
582 N_Defining_Program_Unit_Name |
584 N_Derived_Type_Definition |
586 N_Digits_Constraint |
587 N_Discriminant_Association |
588 N_Discriminant_Specification |
590 N_Entry_Call_Statement |
591 N_Enumeration_Type_Definition |
592 N_Exception_Handler |
593 N_Floating_Point_Definition |
594 N_Formal_Decimal_Fixed_Point_Definition |
595 N_Formal_Derived_Type_Definition |
596 N_Formal_Discrete_Type_Definition |
597 N_Formal_Floating_Point_Definition |
598 N_Formal_Modular_Type_Definition |
599 N_Formal_Ordinary_Fixed_Point_Definition |
600 N_Formal_Private_Type_Definition |
601 N_Formal_Signed_Integer_Type_Definition |
602 N_Function_Specification |
603 N_Generic_Association |
604 N_Index_Or_Discriminant_Constraint |
606 N_Loop_Parameter_Specification |
608 N_Modular_Type_Definition |
609 N_Ordinary_Fixed_Point_Definition |
610 N_Parameter_Specification |
611 N_Pragma_Argument_Association |
612 N_Procedure_Specification |
613 N_Real_Range_Specification |
614 N_Record_Definition |
615 N_Signed_Integer_Type_Definition |
616 N_Unconstrained_Array_Definition |
624 Debug_A_Exit
("analyzing ", N
, " (done)");
626 -- Now that we have analyzed the node, we call the expander to
627 -- perform possible expansion. This is done only for nodes that
628 -- are not subexpressions, because in the case of subexpressions,
629 -- we don't have the type yet, and the expander will need to know
630 -- the type before it can do its job. For subexpression nodes, the
631 -- call to the expander happens in the Sem_Res.Resolve.
633 -- The Analyzed flag is also set at this point for non-subexpression
634 -- nodes (in the case of subexpression nodes, we can't set the flag
635 -- yet, since resolution and expansion have not yet been completed)
637 if Nkind
(N
) not in N_Subexpr
then
642 -- Version with check(s) suppressed
644 procedure Analyze
(N
: Node_Id
; Suppress
: Check_Id
) is
646 if Suppress
= All_Checks
then
648 Svg
: constant Suppress_Array
:= Scope_Suppress
;
650 Scope_Suppress
:= (others => True);
652 Scope_Suppress
:= Svg
;
657 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
659 Scope_Suppress
(Suppress
) := True;
661 Scope_Suppress
(Suppress
) := Svg
;
670 procedure Analyze_List
(L
: List_Id
) is
675 while Present
(Node
) loop
681 -- Version with check(s) suppressed
683 procedure Analyze_List
(L
: List_Id
; Suppress
: Check_Id
) is
685 if Suppress
= All_Checks
then
687 Svg
: constant Suppress_Array
:= Scope_Suppress
;
689 Scope_Suppress
:= (others => True);
691 Scope_Suppress
:= Svg
;
696 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
698 Scope_Suppress
(Suppress
) := True;
700 Scope_Suppress
(Suppress
) := Svg
;
705 --------------------------
706 -- Copy_Suppress_Status --
707 --------------------------
709 procedure Copy_Suppress_Status
715 if not Checks_May_Be_Suppressed
(From
) then
719 -- First search the local entity suppress table, we search this in
720 -- reverse order so that we get the innermost entry that applies to
721 -- this case if there are nested entries. Note that for the purpose
722 -- of this procedure we are ONLY looking for entries corresponding
723 -- to a two-argument Suppress, where the second argument matches From.
726 reverse Local_Entity_Suppress
.First
.. Local_Entity_Suppress
.Last
729 R
: Entity_Check_Suppress_Record
730 renames Local_Entity_Suppress
.Table
(J
);
734 and then (R
.Check
= All_Checks
or else R
.Check
= C
)
737 Set_Checks_May_Be_Suppressed
(To
, True);
738 Local_Entity_Suppress
.Append
748 -- Now search the global entity suppress table for a matching entry
749 -- We also search this in reverse order so that if there are multiple
750 -- pragmas for the same entity, the last one applies.
753 reverse Global_Entity_Suppress
.First
.. Global_Entity_Suppress
.Last
756 R
: Entity_Check_Suppress_Record
757 renames Global_Entity_Suppress
.Table
(J
);
761 and then (R
.Check
= All_Checks
or else R
.Check
= C
)
764 Set_Checks_May_Be_Suppressed
(To
, True);
765 Local_Entity_Suppress
.Append
773 end Copy_Suppress_Status
;
775 -------------------------
776 -- Enter_Generic_Scope --
777 -------------------------
779 procedure Enter_Generic_Scope
(S
: Entity_Id
) is
781 if No
(Outer_Generic_Scope
) then
782 Outer_Generic_Scope
:= S
;
784 end Enter_Generic_Scope
;
786 ------------------------
787 -- Exit_Generic_Scope --
788 ------------------------
790 procedure Exit_Generic_Scope
(S
: Entity_Id
) is
792 if S
= Outer_Generic_Scope
then
793 Outer_Generic_Scope
:= Empty
;
795 end Exit_Generic_Scope
;
797 -----------------------
798 -- Explicit_Suppress --
799 -----------------------
801 function Explicit_Suppress
(E
: Entity_Id
; C
: Check_Id
) return Boolean is
803 if not Checks_May_Be_Suppressed
(E
) then
808 reverse Global_Entity_Suppress
.First
.. Global_Entity_Suppress
.Last
811 R
: Entity_Check_Suppress_Record
812 renames Global_Entity_Suppress
.Table
(J
);
816 and then (R
.Check
= All_Checks
or else R
.Check
= C
)
825 end Explicit_Suppress
;
827 -----------------------------
828 -- External_Ref_In_Generic --
829 -----------------------------
831 function External_Ref_In_Generic
(E
: Entity_Id
) return Boolean is
835 -- Entity is global if defined outside of current outer_generic_scope:
836 -- Either the entity has a smaller depth that the outer generic, or it
837 -- is in a different compilation unit, or it is defined within a unit
838 -- in the same compilation, that is not within the outer_generic.
840 if No
(Outer_Generic_Scope
) then
843 elsif Scope_Depth
(Scope
(E
)) < Scope_Depth
(Outer_Generic_Scope
)
844 or else not In_Same_Source_Unit
(E
, Outer_Generic_Scope
)
851 while Present
(Scop
) loop
852 if Scop
= Outer_Generic_Scope
then
854 elsif Scope_Depth
(Scop
) < Scope_Depth
(Outer_Generic_Scope
) then
857 Scop
:= Scope
(Scop
);
863 end External_Ref_In_Generic
;
869 procedure Initialize
is
871 Local_Entity_Suppress
.Init
;
872 Global_Entity_Suppress
.Init
;
874 Unloaded_Subunits
:= False;
877 ------------------------------
878 -- Insert_After_And_Analyze --
879 ------------------------------
881 procedure Insert_After_And_Analyze
(N
: Node_Id
; M
: Node_Id
) is
887 -- If we are not at the end of the list, then the easiest
888 -- coding is simply to insert before our successor
890 if Present
(Next
(N
)) then
891 Insert_Before_And_Analyze
(Next
(N
), M
);
893 -- Case of inserting at the end of the list
896 -- Capture the Node_Id of the node to be inserted. This Node_Id
897 -- will still be the same after the insert operation.
902 -- Now just analyze from the inserted node to the end of
903 -- the new list (note that this properly handles the case
904 -- where any of the analyze calls result in the insertion of
905 -- nodes after the analyzed node, expecting analysis).
907 while Present
(Node
) loop
909 Mark_Rewrite_Insertion
(Node
);
914 end Insert_After_And_Analyze
;
916 -- Version with check(s) suppressed
918 procedure Insert_After_And_Analyze
924 if Suppress
= All_Checks
then
926 Svg
: constant Suppress_Array
:= Scope_Suppress
;
928 Scope_Suppress
:= (others => True);
929 Insert_After_And_Analyze
(N
, M
);
930 Scope_Suppress
:= Svg
;
935 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
937 Scope_Suppress
(Suppress
) := True;
938 Insert_After_And_Analyze
(N
, M
);
939 Scope_Suppress
(Suppress
) := Svg
;
942 end Insert_After_And_Analyze
;
944 -------------------------------
945 -- Insert_Before_And_Analyze --
946 -------------------------------
948 procedure Insert_Before_And_Analyze
(N
: Node_Id
; M
: Node_Id
) is
954 -- Capture the Node_Id of the first list node to be inserted.
955 -- This will still be the first node after the insert operation,
956 -- since Insert_List_After does not modify the Node_Id values.
959 Insert_Before
(N
, M
);
961 -- The insertion does not change the Id's of any of the nodes in
962 -- the list, and they are still linked, so we can simply loop from
963 -- the original first node until we meet the node before which the
964 -- insertion is occurring. Note that this properly handles the case
965 -- where any of the analyzed nodes insert nodes after themselves,
966 -- expecting them to get analyzed.
970 Mark_Rewrite_Insertion
(Node
);
974 end Insert_Before_And_Analyze
;
976 -- Version with check(s) suppressed
978 procedure Insert_Before_And_Analyze
984 if Suppress
= All_Checks
then
986 Svg
: constant Suppress_Array
:= Scope_Suppress
;
988 Scope_Suppress
:= (others => True);
989 Insert_Before_And_Analyze
(N
, M
);
990 Scope_Suppress
:= Svg
;
995 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
997 Scope_Suppress
(Suppress
) := True;
998 Insert_Before_And_Analyze
(N
, M
);
999 Scope_Suppress
(Suppress
) := Svg
;
1002 end Insert_Before_And_Analyze
;
1004 -----------------------------------
1005 -- Insert_List_After_And_Analyze --
1006 -----------------------------------
1008 procedure Insert_List_After_And_Analyze
(N
: Node_Id
; L
: List_Id
) is
1009 After
: constant Node_Id
:= Next
(N
);
1013 if Is_Non_Empty_List
(L
) then
1015 -- Capture the Node_Id of the first list node to be inserted.
1016 -- This will still be the first node after the insert operation,
1017 -- since Insert_List_After does not modify the Node_Id values.
1020 Insert_List_After
(N
, L
);
1022 -- Now just analyze from the original first node until we get to
1023 -- the successor of the original insertion point (which may be
1024 -- Empty if the insertion point was at the end of the list). Note
1025 -- that this properly handles the case where any of the analyze
1026 -- calls result in the insertion of nodes after the analyzed
1027 -- node (possibly calling this routine recursively).
1029 while Node
/= After
loop
1031 Mark_Rewrite_Insertion
(Node
);
1035 end Insert_List_After_And_Analyze
;
1037 -- Version with check(s) suppressed
1039 procedure Insert_List_After_And_Analyze
1040 (N
: Node_Id
; L
: List_Id
; Suppress
: Check_Id
)
1043 if Suppress
= All_Checks
then
1045 Svg
: constant Suppress_Array
:= Scope_Suppress
;
1047 Scope_Suppress
:= (others => True);
1048 Insert_List_After_And_Analyze
(N
, L
);
1049 Scope_Suppress
:= Svg
;
1054 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
1056 Scope_Suppress
(Suppress
) := True;
1057 Insert_List_After_And_Analyze
(N
, L
);
1058 Scope_Suppress
(Suppress
) := Svg
;
1061 end Insert_List_After_And_Analyze
;
1063 ------------------------------------
1064 -- Insert_List_Before_And_Analyze --
1065 ------------------------------------
1067 procedure Insert_List_Before_And_Analyze
(N
: Node_Id
; L
: List_Id
) is
1071 if Is_Non_Empty_List
(L
) then
1073 -- Capture the Node_Id of the first list node to be inserted.
1074 -- This will still be the first node after the insert operation,
1075 -- since Insert_List_After does not modify the Node_Id values.
1078 Insert_List_Before
(N
, L
);
1080 -- The insertion does not change the Id's of any of the nodes in
1081 -- the list, and they are still linked, so we can simply loop from
1082 -- the original first node until we meet the node before which the
1083 -- insertion is occurring. Note that this properly handles the case
1084 -- where any of the analyzed nodes insert nodes after themselves,
1085 -- expecting them to get analyzed.
1087 while Node
/= N
loop
1089 Mark_Rewrite_Insertion
(Node
);
1093 end Insert_List_Before_And_Analyze
;
1095 -- Version with check(s) suppressed
1097 procedure Insert_List_Before_And_Analyze
1098 (N
: Node_Id
; L
: List_Id
; Suppress
: Check_Id
)
1101 if Suppress
= All_Checks
then
1103 Svg
: constant Suppress_Array
:= Scope_Suppress
;
1105 Scope_Suppress
:= (others => True);
1106 Insert_List_Before_And_Analyze
(N
, L
);
1107 Scope_Suppress
:= Svg
;
1112 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
1114 Scope_Suppress
(Suppress
) := True;
1115 Insert_List_Before_And_Analyze
(N
, L
);
1116 Scope_Suppress
(Suppress
) := Svg
;
1119 end Insert_List_Before_And_Analyze
;
1121 -------------------------
1122 -- Is_Check_Suppressed --
1123 -------------------------
1125 function Is_Check_Suppressed
(E
: Entity_Id
; C
: Check_Id
) return Boolean is
1127 -- First search the local entity suppress table, we search this in
1128 -- reverse order so that we get the innermost entry that applies to
1129 -- this case if there are nested entries.
1132 reverse Local_Entity_Suppress
.First
.. Local_Entity_Suppress
.Last
1135 R
: Entity_Check_Suppress_Record
1136 renames Local_Entity_Suppress
.Table
(J
);
1139 if (R
.Entity
= Empty
or else R
.Entity
= E
)
1140 and then (R
.Check
= All_Checks
or else R
.Check
= C
)
1147 -- Now search the global entity suppress table for a matching entry
1148 -- We also search this in reverse order so that if there are multiple
1149 -- pragmas for the same entity, the last one applies (not clear what
1150 -- or whether the RM specifies this handling, but it seems reasonable).
1153 reverse Global_Entity_Suppress
.First
.. Global_Entity_Suppress
.Last
1156 R
: Entity_Check_Suppress_Record
1157 renames Global_Entity_Suppress
.Table
(J
);
1161 and then (R
.Check
= All_Checks
or else R
.Check
= C
)
1168 -- If we did not find a matching entry, then use the normal scope
1169 -- suppress value after all (actually this will be the global setting
1170 -- since it clearly was not overridden at any point)
1172 return Scope_Suppress
(C
);
1173 end Is_Check_Suppressed
;
1181 Local_Entity_Suppress
.Locked
:= True;
1182 Global_Entity_Suppress
.Locked
:= True;
1183 Scope_Stack
.Locked
:= True;
1184 Local_Entity_Suppress
.Release
;
1185 Global_Entity_Suppress
.Release
;
1186 Scope_Stack
.Release
;
1193 procedure Semantics
(Comp_Unit
: Node_Id
) is
1195 -- The following locations save the corresponding global flags and
1196 -- variables so that they can be restored on completion. This is
1197 -- needed so that calls to Rtsfind start with the proper default
1198 -- values for these variables, and also that such calls do not
1199 -- disturb the settings for units being analyzed at a higher level.
1201 S_Full_Analysis
: constant Boolean := Full_Analysis
;
1202 S_In_Default_Expr
: constant Boolean := In_Default_Expression
;
1203 S_Inside_A_Generic
: constant Boolean := Inside_A_Generic
;
1204 S_New_Nodes_OK
: constant Int
:= New_Nodes_OK
;
1205 S_Outer_Gen_Scope
: constant Entity_Id
:= Outer_Generic_Scope
;
1206 S_Sem_Unit
: constant Unit_Number_Type
:= Current_Sem_Unit
;
1207 S_GNAT_Mode
: constant Boolean := GNAT_Mode
;
1208 Generic_Main
: constant Boolean :=
1209 Nkind
(Unit
(Cunit
(Main_Unit
)))
1210 in N_Generic_Declaration
;
1212 -- If the main unit is generic, every compiled unit, including its
1213 -- context, is compiled with expansion disabled.
1215 Save_Config_Switches
: Config_Switches_Type
;
1216 -- Variable used to save values of config switches while we analyze
1217 -- the new unit, to be restored on exit for proper recursive behavior.
1219 procedure Do_Analyze
;
1220 -- Procedure to analyze the compilation unit. This is called more
1221 -- than once when the high level optimizer is activated.
1227 procedure Do_Analyze
is
1230 New_Scope
(Standard_Standard
);
1231 Scope_Suppress
:= Suppress_Options
;
1233 (Scope_Stack
.Last
).Component_Alignment_Default
:= Calign_Default
;
1235 (Scope_Stack
.Last
).Is_Active_Stack_Base
:= True;
1236 Outer_Generic_Scope
:= Empty
;
1238 -- Now analyze the top level compilation unit node
1240 Analyze
(Comp_Unit
);
1242 -- Check for scope mismatch on exit from compilation
1244 pragma Assert
(Current_Scope
= Standard_Standard
1245 or else Comp_Unit
= Cunit
(Main_Unit
));
1247 -- Then pop entry for Standard, and pop implicit types
1250 Restore_Scope_Stack
;
1253 -- Start of processing for Semantics
1256 Compiler_State
:= Analyzing
;
1257 Current_Sem_Unit
:= Get_Cunit_Unit_Number
(Comp_Unit
);
1259 -- Compile predefined units with GNAT_Mode set to True, to properly
1260 -- process the categorization stuff. However, do not set set GNAT_Mode
1261 -- to True for the renamings units (Text_IO, IO_Exceptions, Direct_IO,
1262 -- Sequential_IO) as this would prevent pragma System_Extend to be
1263 -- taken into account, for example when Text_IO is renaming DEC.Text_IO.
1265 -- Cleaner might be to do the kludge at the point of excluding the
1266 -- pragma (do not exclude for renamings ???)
1270 or else Is_Predefined_File_Name
1271 (Unit_File_Name
(Current_Sem_Unit
),
1272 Renamings_Included
=> False);
1274 if Generic_Main
then
1275 Expander_Mode_Save_And_Set
(False);
1277 Expander_Mode_Save_And_Set
1278 (Operating_Mode
= Generate_Code
or Debug_Flag_X
);
1281 Full_Analysis
:= True;
1282 Inside_A_Generic
:= False;
1283 In_Default_Expression
:= False;
1285 Set_Comes_From_Source_Default
(False);
1286 Save_Opt_Config_Switches
(Save_Config_Switches
);
1287 Set_Opt_Config_Switches
1288 (Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
)),
1289 Current_Sem_Unit
= Main_Unit
);
1291 -- Only do analysis of unit that has not already been analyzed
1293 if not Analyzed
(Comp_Unit
) then
1294 Initialize_Version
(Current_Sem_Unit
);
1296 Expander_Mode_Save_And_Set
(False);
1299 Reset_Analyzed_Flags
(Comp_Unit
);
1300 Expander_Mode_Restore
;
1301 High_Level_Optimize
(Comp_Unit
);
1308 -- Save indication of dynamic elaboration checks for ALI file
1310 Set_Dynamic_Elab
(Current_Sem_Unit
, Dynamic_Elaboration_Checks
);
1312 -- Restore settings of saved switches to entry values
1314 Current_Sem_Unit
:= S_Sem_Unit
;
1315 Full_Analysis
:= S_Full_Analysis
;
1316 In_Default_Expression
:= S_In_Default_Expr
;
1317 Inside_A_Generic
:= S_Inside_A_Generic
;
1318 New_Nodes_OK
:= S_New_Nodes_OK
;
1319 Outer_Generic_Scope
:= S_Outer_Gen_Scope
;
1320 GNAT_Mode
:= S_GNAT_Mode
;
1322 Restore_Opt_Config_Switches
(Save_Config_Switches
);
1323 Expander_Mode_Restore
;