1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Casing
; use Casing
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Errout
; use Errout
;
31 with Elists
; use Elists
;
32 with Exp_Disp
; use Exp_Disp
;
33 with Exp_Tss
; use Exp_Tss
;
34 with Exp_Util
; use Exp_Util
;
35 with Fname
; use Fname
;
36 with Freeze
; use Freeze
;
38 with Lib
.Xref
; use Lib
.Xref
;
39 with Nlists
; use Nlists
;
40 with Output
; use Output
;
42 with Rtsfind
; use Rtsfind
;
43 with Scans
; use Scans
;
46 with Sem_Aux
; use Sem_Aux
;
47 with Sem_Attr
; use Sem_Attr
;
48 with Sem_Ch8
; use Sem_Ch8
;
49 with Sem_Eval
; use Sem_Eval
;
50 with Sem_Res
; use Sem_Res
;
51 with Sem_Type
; use Sem_Type
;
52 with Sinfo
; use Sinfo
;
53 with Sinput
; use Sinput
;
54 with Stand
; use Stand
;
56 with Stringt
; use Stringt
;
57 with Targparm
; use Targparm
;
58 with Tbuild
; use Tbuild
;
59 with Ttypes
; use Ttypes
;
60 with Uname
; use Uname
;
62 with GNAT
.HTable
; use GNAT
.HTable
;
63 package body Sem_Util
is
65 ----------------------------------------
66 -- Global_Variables for New_Copy_Tree --
67 ----------------------------------------
69 -- These global variables are used by New_Copy_Tree. See description
70 -- of the body of this subprogram for details. Global variables can be
71 -- safely used by New_Copy_Tree, since there is no case of a recursive
72 -- call from the processing inside New_Copy_Tree.
74 NCT_Hash_Threshhold
: constant := 20;
75 -- If there are more than this number of pairs of entries in the
76 -- map, then Hash_Tables_Used will be set, and the hash tables will
77 -- be initialized and used for the searches.
79 NCT_Hash_Tables_Used
: Boolean := False;
80 -- Set to True if hash tables are in use
82 NCT_Table_Entries
: Nat
;
83 -- Count entries in table to see if threshhold is reached
85 NCT_Hash_Table_Setup
: Boolean := False;
86 -- Set to True if hash table contains data. We set this True if we
87 -- setup the hash table with data, and leave it set permanently
88 -- from then on, this is a signal that second and subsequent users
89 -- of the hash table must clear the old entries before reuse.
91 subtype NCT_Header_Num
is Int
range 0 .. 511;
92 -- Defines range of headers in hash tables (512 headers)
94 -----------------------
95 -- Local Subprograms --
96 -----------------------
98 function Build_Component_Subtype
101 T
: Entity_Id
) return Node_Id
;
102 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
103 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
104 -- Loc is the source location, T is the original subtype.
106 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
107 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
108 -- with discriminants whose default values are static, examine only the
109 -- components in the selected variant to determine whether all of them
112 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
113 -- T is a derived tagged type. Check whether the type extension is null.
114 -- If the parent type is fully initialized, T can be treated as such.
116 ------------------------------
117 -- Abstract_Interface_List --
118 ------------------------------
120 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
124 if Is_Concurrent_Type
(Typ
) then
126 -- If we are dealing with a synchronized subtype, go to the base
127 -- type, whose declaration has the interface list.
129 -- Shouldn't this be Declaration_Node???
131 Nod
:= Parent
(Base_Type
(Typ
));
133 if Nkind
(Nod
) = N_Full_Type_Declaration
then
137 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
138 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
139 Nod
:= Type_Definition
(Parent
(Typ
));
141 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
142 if Present
(Full_View
(Typ
)) then
143 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
145 -- If the full-view is not available we cannot do anything else
146 -- here (the source has errors).
152 -- Support for generic formals with interfaces is still missing ???
154 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
159 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
163 elsif Ekind
(Typ
) = E_Record_Subtype
then
164 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
166 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
168 -- Recurse, because parent may still be a private extension. Also
169 -- note that the full view of the subtype or the full view of its
170 -- base type may (both) be unavailable.
172 return Abstract_Interface_List
(Etype
(Typ
));
174 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
175 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
176 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
178 Nod
:= Type_Definition
(Parent
(Typ
));
182 return Interface_List
(Nod
);
183 end Abstract_Interface_List
;
185 --------------------------------
186 -- Add_Access_Type_To_Process --
187 --------------------------------
189 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
193 Ensure_Freeze_Node
(E
);
194 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
198 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
202 end Add_Access_Type_To_Process
;
204 ----------------------------
205 -- Add_Global_Declaration --
206 ----------------------------
208 procedure Add_Global_Declaration
(N
: Node_Id
) is
209 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
212 if No
(Declarations
(Aux_Node
)) then
213 Set_Declarations
(Aux_Node
, New_List
);
216 Append_To
(Declarations
(Aux_Node
), N
);
218 end Add_Global_Declaration
;
220 -----------------------
221 -- Alignment_In_Bits --
222 -----------------------
224 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
226 return Alignment
(E
) * System_Storage_Unit
;
227 end Alignment_In_Bits
;
229 -----------------------------------------
230 -- Apply_Compile_Time_Constraint_Error --
231 -----------------------------------------
233 procedure Apply_Compile_Time_Constraint_Error
236 Reason
: RT_Exception_Code
;
237 Ent
: Entity_Id
:= Empty
;
238 Typ
: Entity_Id
:= Empty
;
239 Loc
: Source_Ptr
:= No_Location
;
240 Rep
: Boolean := True;
241 Warn
: Boolean := False)
243 Stat
: constant Boolean := Is_Static_Expression
(N
);
244 R_Stat
: constant Node_Id
:=
245 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
256 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
262 -- Now we replace the node by an N_Raise_Constraint_Error node
263 -- This does not need reanalyzing, so set it as analyzed now.
266 Set_Analyzed
(N
, True);
269 Set_Raises_Constraint_Error
(N
);
271 -- If the original expression was marked as static, the result is
272 -- still marked as static, but the Raises_Constraint_Error flag is
273 -- always set so that further static evaluation is not attempted.
276 Set_Is_Static_Expression
(N
);
278 end Apply_Compile_Time_Constraint_Error
;
280 --------------------------
281 -- Build_Actual_Subtype --
282 --------------------------
284 function Build_Actual_Subtype
286 N
: Node_Or_Entity_Id
) return Node_Id
289 -- Normally Sloc (N), but may point to corresponding body in some cases
291 Constraints
: List_Id
;
297 Disc_Type
: Entity_Id
;
303 if Nkind
(N
) = N_Defining_Identifier
then
304 Obj
:= New_Reference_To
(N
, Loc
);
306 -- If this is a formal parameter of a subprogram declaration, and
307 -- we are compiling the body, we want the declaration for the
308 -- actual subtype to carry the source position of the body, to
309 -- prevent anomalies in gdb when stepping through the code.
311 if Is_Formal
(N
) then
313 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
315 if Nkind
(Decl
) = N_Subprogram_Declaration
316 and then Present
(Corresponding_Body
(Decl
))
318 Loc
:= Sloc
(Corresponding_Body
(Decl
));
327 if Is_Array_Type
(T
) then
328 Constraints
:= New_List
;
329 for J
in 1 .. Number_Dimensions
(T
) loop
331 -- Build an array subtype declaration with the nominal subtype and
332 -- the bounds of the actual. Add the declaration in front of the
333 -- local declarations for the subprogram, for analysis before any
334 -- reference to the formal in the body.
337 Make_Attribute_Reference
(Loc
,
339 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
340 Attribute_Name
=> Name_First
,
341 Expressions
=> New_List
(
342 Make_Integer_Literal
(Loc
, J
)));
345 Make_Attribute_Reference
(Loc
,
347 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
348 Attribute_Name
=> Name_Last
,
349 Expressions
=> New_List
(
350 Make_Integer_Literal
(Loc
, J
)));
352 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
355 -- If the type has unknown discriminants there is no constrained
356 -- subtype to build. This is never called for a formal or for a
357 -- lhs, so returning the type is ok ???
359 elsif Has_Unknown_Discriminants
(T
) then
363 Constraints
:= New_List
;
365 -- Type T is a generic derived type, inherit the discriminants from
368 if Is_Private_Type
(T
)
369 and then No
(Full_View
(T
))
371 -- T was flagged as an error if it was declared as a formal
372 -- derived type with known discriminants. In this case there
373 -- is no need to look at the parent type since T already carries
374 -- its own discriminants.
376 and then not Error_Posted
(T
)
378 Disc_Type
:= Etype
(Base_Type
(T
));
383 Discr
:= First_Discriminant
(Disc_Type
);
384 while Present
(Discr
) loop
385 Append_To
(Constraints
,
386 Make_Selected_Component
(Loc
,
388 Duplicate_Subexpr_No_Checks
(Obj
),
389 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
390 Next_Discriminant
(Discr
);
395 Make_Defining_Identifier
(Loc
,
396 Chars
=> New_Internal_Name
('S'));
397 Set_Is_Internal
(Subt
);
400 Make_Subtype_Declaration
(Loc
,
401 Defining_Identifier
=> Subt
,
402 Subtype_Indication
=>
403 Make_Subtype_Indication
(Loc
,
404 Subtype_Mark
=> New_Reference_To
(T
, Loc
),
406 Make_Index_Or_Discriminant_Constraint
(Loc
,
407 Constraints
=> Constraints
)));
409 Mark_Rewrite_Insertion
(Decl
);
411 end Build_Actual_Subtype
;
413 ---------------------------------------
414 -- Build_Actual_Subtype_Of_Component --
415 ---------------------------------------
417 function Build_Actual_Subtype_Of_Component
419 N
: Node_Id
) return Node_Id
421 Loc
: constant Source_Ptr
:= Sloc
(N
);
422 P
: constant Node_Id
:= Prefix
(N
);
425 Indx_Type
: Entity_Id
;
427 Deaccessed_T
: Entity_Id
;
428 -- This is either a copy of T, or if T is an access type, then it is
429 -- the directly designated type of this access type.
431 function Build_Actual_Array_Constraint
return List_Id
;
432 -- If one or more of the bounds of the component depends on
433 -- discriminants, build actual constraint using the discriminants
436 function Build_Actual_Record_Constraint
return List_Id
;
437 -- Similar to previous one, for discriminated components constrained
438 -- by the discriminant of the enclosing object.
440 -----------------------------------
441 -- Build_Actual_Array_Constraint --
442 -----------------------------------
444 function Build_Actual_Array_Constraint
return List_Id
is
445 Constraints
: constant List_Id
:= New_List
;
453 Indx
:= First_Index
(Deaccessed_T
);
454 while Present
(Indx
) loop
455 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
456 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
458 if Denotes_Discriminant
(Old_Lo
) then
460 Make_Selected_Component
(Loc
,
461 Prefix
=> New_Copy_Tree
(P
),
462 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
465 Lo
:= New_Copy_Tree
(Old_Lo
);
467 -- The new bound will be reanalyzed in the enclosing
468 -- declaration. For literal bounds that come from a type
469 -- declaration, the type of the context must be imposed, so
470 -- insure that analysis will take place. For non-universal
471 -- types this is not strictly necessary.
473 Set_Analyzed
(Lo
, False);
476 if Denotes_Discriminant
(Old_Hi
) then
478 Make_Selected_Component
(Loc
,
479 Prefix
=> New_Copy_Tree
(P
),
480 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
483 Hi
:= New_Copy_Tree
(Old_Hi
);
484 Set_Analyzed
(Hi
, False);
487 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
492 end Build_Actual_Array_Constraint
;
494 ------------------------------------
495 -- Build_Actual_Record_Constraint --
496 ------------------------------------
498 function Build_Actual_Record_Constraint
return List_Id
is
499 Constraints
: constant List_Id
:= New_List
;
504 D
:= First_Elmt
(Discriminant_Constraint
(Deaccessed_T
));
505 while Present
(D
) loop
506 if Denotes_Discriminant
(Node
(D
)) then
507 D_Val
:= Make_Selected_Component
(Loc
,
508 Prefix
=> New_Copy_Tree
(P
),
509 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
512 D_Val
:= New_Copy_Tree
(Node
(D
));
515 Append
(D_Val
, Constraints
);
520 end Build_Actual_Record_Constraint
;
522 -- Start of processing for Build_Actual_Subtype_Of_Component
525 -- Why the test for Spec_Expression mode here???
527 if In_Spec_Expression
then
530 -- More comments for the rest of this body would be good ???
532 elsif Nkind
(N
) = N_Explicit_Dereference
then
533 if Is_Composite_Type
(T
)
534 and then not Is_Constrained
(T
)
535 and then not (Is_Class_Wide_Type
(T
)
536 and then Is_Constrained
(Root_Type
(T
)))
537 and then not Has_Unknown_Discriminants
(T
)
539 -- If the type of the dereference is already constrained, it
540 -- is an actual subtype.
542 if Is_Array_Type
(Etype
(N
))
543 and then Is_Constrained
(Etype
(N
))
547 Remove_Side_Effects
(P
);
548 return Build_Actual_Subtype
(T
, N
);
555 if Ekind
(T
) = E_Access_Subtype
then
556 Deaccessed_T
:= Designated_Type
(T
);
561 if Ekind
(Deaccessed_T
) = E_Array_Subtype
then
562 Id
:= First_Index
(Deaccessed_T
);
563 while Present
(Id
) loop
564 Indx_Type
:= Underlying_Type
(Etype
(Id
));
566 if Denotes_Discriminant
(Type_Low_Bound
(Indx_Type
))
568 Denotes_Discriminant
(Type_High_Bound
(Indx_Type
))
570 Remove_Side_Effects
(P
);
572 Build_Component_Subtype
573 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
579 elsif Is_Composite_Type
(Deaccessed_T
)
580 and then Has_Discriminants
(Deaccessed_T
)
581 and then not Has_Unknown_Discriminants
(Deaccessed_T
)
583 D
:= First_Elmt
(Discriminant_Constraint
(Deaccessed_T
));
584 while Present
(D
) loop
585 if Denotes_Discriminant
(Node
(D
)) then
586 Remove_Side_Effects
(P
);
588 Build_Component_Subtype
(
589 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
596 -- If none of the above, the actual and nominal subtypes are the same
599 end Build_Actual_Subtype_Of_Component
;
601 -----------------------------
602 -- Build_Component_Subtype --
603 -----------------------------
605 function Build_Component_Subtype
608 T
: Entity_Id
) return Node_Id
614 -- Unchecked_Union components do not require component subtypes
616 if Is_Unchecked_Union
(T
) then
621 Make_Defining_Identifier
(Loc
,
622 Chars
=> New_Internal_Name
('S'));
623 Set_Is_Internal
(Subt
);
626 Make_Subtype_Declaration
(Loc
,
627 Defining_Identifier
=> Subt
,
628 Subtype_Indication
=>
629 Make_Subtype_Indication
(Loc
,
630 Subtype_Mark
=> New_Reference_To
(Base_Type
(T
), Loc
),
632 Make_Index_Or_Discriminant_Constraint
(Loc
,
635 Mark_Rewrite_Insertion
(Decl
);
637 end Build_Component_Subtype
;
639 ---------------------------
640 -- Build_Default_Subtype --
641 ---------------------------
643 function Build_Default_Subtype
645 N
: Node_Id
) return Entity_Id
647 Loc
: constant Source_Ptr
:= Sloc
(N
);
651 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
655 Disc
:= First_Discriminant
(T
);
657 if No
(Discriminant_Default_Value
(Disc
)) then
662 Act
: constant Entity_Id
:=
663 Make_Defining_Identifier
(Loc
,
664 Chars
=> New_Internal_Name
('S'));
666 Constraints
: constant List_Id
:= New_List
;
670 while Present
(Disc
) loop
671 Append_To
(Constraints
,
672 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
673 Next_Discriminant
(Disc
);
677 Make_Subtype_Declaration
(Loc
,
678 Defining_Identifier
=> Act
,
679 Subtype_Indication
=>
680 Make_Subtype_Indication
(Loc
,
681 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
683 Make_Index_Or_Discriminant_Constraint
(Loc
,
684 Constraints
=> Constraints
)));
686 Insert_Action
(N
, Decl
);
690 end Build_Default_Subtype
;
692 --------------------------------------------
693 -- Build_Discriminal_Subtype_Of_Component --
694 --------------------------------------------
696 function Build_Discriminal_Subtype_Of_Component
697 (T
: Entity_Id
) return Node_Id
699 Loc
: constant Source_Ptr
:= Sloc
(T
);
703 function Build_Discriminal_Array_Constraint
return List_Id
;
704 -- If one or more of the bounds of the component depends on
705 -- discriminants, build actual constraint using the discriminants
708 function Build_Discriminal_Record_Constraint
return List_Id
;
709 -- Similar to previous one, for discriminated components constrained
710 -- by the discriminant of the enclosing object.
712 ----------------------------------------
713 -- Build_Discriminal_Array_Constraint --
714 ----------------------------------------
716 function Build_Discriminal_Array_Constraint
return List_Id
is
717 Constraints
: constant List_Id
:= New_List
;
725 Indx
:= First_Index
(T
);
726 while Present
(Indx
) loop
727 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
728 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
730 if Denotes_Discriminant
(Old_Lo
) then
731 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
734 Lo
:= New_Copy_Tree
(Old_Lo
);
737 if Denotes_Discriminant
(Old_Hi
) then
738 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
741 Hi
:= New_Copy_Tree
(Old_Hi
);
744 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
749 end Build_Discriminal_Array_Constraint
;
751 -----------------------------------------
752 -- Build_Discriminal_Record_Constraint --
753 -----------------------------------------
755 function Build_Discriminal_Record_Constraint
return List_Id
is
756 Constraints
: constant List_Id
:= New_List
;
761 D
:= First_Elmt
(Discriminant_Constraint
(T
));
762 while Present
(D
) loop
763 if Denotes_Discriminant
(Node
(D
)) then
765 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
768 D_Val
:= New_Copy_Tree
(Node
(D
));
771 Append
(D_Val
, Constraints
);
776 end Build_Discriminal_Record_Constraint
;
778 -- Start of processing for Build_Discriminal_Subtype_Of_Component
781 if Ekind
(T
) = E_Array_Subtype
then
782 Id
:= First_Index
(T
);
783 while Present
(Id
) loop
784 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
))) or else
785 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
787 return Build_Component_Subtype
788 (Build_Discriminal_Array_Constraint
, Loc
, T
);
794 elsif Ekind
(T
) = E_Record_Subtype
795 and then Has_Discriminants
(T
)
796 and then not Has_Unknown_Discriminants
(T
)
798 D
:= First_Elmt
(Discriminant_Constraint
(T
));
799 while Present
(D
) loop
800 if Denotes_Discriminant
(Node
(D
)) then
801 return Build_Component_Subtype
802 (Build_Discriminal_Record_Constraint
, Loc
, T
);
809 -- If none of the above, the actual and nominal subtypes are the same
812 end Build_Discriminal_Subtype_Of_Component
;
814 ------------------------------
815 -- Build_Elaboration_Entity --
816 ------------------------------
818 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
819 Loc
: constant Source_Ptr
:= Sloc
(N
);
821 Elab_Ent
: Entity_Id
;
823 procedure Set_Package_Name
(Ent
: Entity_Id
);
824 -- Given an entity, sets the fully qualified name of the entity in
825 -- Name_Buffer, with components separated by double underscores. This
826 -- is a recursive routine that climbs the scope chain to Standard.
828 ----------------------
829 -- Set_Package_Name --
830 ----------------------
832 procedure Set_Package_Name
(Ent
: Entity_Id
) is
834 if Scope
(Ent
) /= Standard_Standard
then
835 Set_Package_Name
(Scope
(Ent
));
838 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
840 Name_Buffer
(Name_Len
+ 1) := '_';
841 Name_Buffer
(Name_Len
+ 2) := '_';
842 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
843 Name_Len
:= Name_Len
+ Nam
'Length + 2;
847 Get_Name_String
(Chars
(Ent
));
849 end Set_Package_Name
;
851 -- Start of processing for Build_Elaboration_Entity
854 -- Ignore if already constructed
856 if Present
(Elaboration_Entity
(Spec_Id
)) then
860 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
861 -- name with dots replaced by double underscore. We have to manually
862 -- construct this name, since it will be elaborated in the outer scope,
863 -- and thus will not have the unit name automatically prepended.
865 Set_Package_Name
(Spec_Id
);
869 Name_Buffer
(Name_Len
+ 1) := '_';
870 Name_Buffer
(Name_Len
+ 2) := 'E';
871 Name_Len
:= Name_Len
+ 2;
873 -- Create elaboration flag
876 Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
877 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
880 Make_Object_Declaration
(Loc
,
881 Defining_Identifier
=> Elab_Ent
,
883 New_Occurrence_Of
(Standard_Boolean
, Loc
),
885 New_Occurrence_Of
(Standard_False
, Loc
));
887 Push_Scope
(Standard_Standard
);
888 Add_Global_Declaration
(Decl
);
891 -- Reset True_Constant indication, since we will indeed assign a value
892 -- to the variable in the binder main. We also kill the Current_Value
893 -- and Last_Assignment fields for the same reason.
895 Set_Is_True_Constant
(Elab_Ent
, False);
896 Set_Current_Value
(Elab_Ent
, Empty
);
897 Set_Last_Assignment
(Elab_Ent
, Empty
);
899 -- We do not want any further qualification of the name (if we did
900 -- not do this, we would pick up the name of the generic package
901 -- in the case of a library level generic instantiation).
903 Set_Has_Qualified_Name
(Elab_Ent
);
904 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
905 end Build_Elaboration_Entity
;
907 -----------------------------------
908 -- Cannot_Raise_Constraint_Error --
909 -----------------------------------
911 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
913 if Compile_Time_Known_Value
(Expr
) then
916 elsif Do_Range_Check
(Expr
) then
919 elsif Raises_Constraint_Error
(Expr
) then
927 when N_Expanded_Name
=>
930 when N_Selected_Component
=>
931 return not Do_Discriminant_Check
(Expr
);
933 when N_Attribute_Reference
=>
934 if Do_Overflow_Check
(Expr
) then
937 elsif No
(Expressions
(Expr
)) then
945 N
:= First
(Expressions
(Expr
));
946 while Present
(N
) loop
947 if Cannot_Raise_Constraint_Error
(N
) then
958 when N_Type_Conversion
=>
959 if Do_Overflow_Check
(Expr
)
960 or else Do_Length_Check
(Expr
)
961 or else Do_Tag_Check
(Expr
)
966 Cannot_Raise_Constraint_Error
(Expression
(Expr
));
969 when N_Unchecked_Type_Conversion
=>
970 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
973 if Do_Overflow_Check
(Expr
) then
977 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
984 if Do_Division_Check
(Expr
)
985 or else Do_Overflow_Check
(Expr
)
990 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
992 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1011 N_Op_Shift_Right_Arithmetic |
1015 if Do_Overflow_Check
(Expr
) then
1019 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1021 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1028 end Cannot_Raise_Constraint_Error
;
1030 --------------------------
1031 -- Check_Fully_Declared --
1032 --------------------------
1034 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
1036 if Ekind
(T
) = E_Incomplete_Type
then
1038 -- Ada 2005 (AI-50217): If the type is available through a limited
1039 -- with_clause, verify that its full view has been analyzed.
1041 if From_With_Type
(T
)
1042 and then Present
(Non_Limited_View
(T
))
1043 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
1045 -- The non-limited view is fully declared
1050 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1053 -- Need comments for these tests ???
1055 elsif Has_Private_Component
(T
)
1056 and then not Is_Generic_Type
(Root_Type
(T
))
1057 and then not In_Spec_Expression
1059 -- Special case: if T is the anonymous type created for a single
1060 -- task or protected object, use the name of the source object.
1062 if Is_Concurrent_Type
(T
)
1063 and then not Comes_From_Source
(T
)
1064 and then Nkind
(N
) = N_Object_Declaration
1066 Error_Msg_NE
("type of& has incomplete component", N
,
1067 Defining_Identifier
(N
));
1071 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1074 end Check_Fully_Declared
;
1076 -------------------------
1077 -- Check_Nested_Access --
1078 -------------------------
1080 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
1081 Scop
: constant Entity_Id
:= Current_Scope
;
1082 Current_Subp
: Entity_Id
;
1083 Enclosing
: Entity_Id
;
1086 -- Currently only enabled for VM back-ends for efficiency, should we
1087 -- enable it more systematically ???
1089 -- Check for Is_Imported needs commenting below ???
1091 if VM_Target
/= No_VM
1092 and then (Ekind
(Ent
) = E_Variable
1094 Ekind
(Ent
) = E_Constant
1096 Ekind
(Ent
) = E_Loop_Parameter
)
1097 and then Scope
(Ent
) /= Empty
1098 and then not Is_Library_Level_Entity
(Ent
)
1099 and then not Is_Imported
(Ent
)
1101 if Is_Subprogram
(Scop
)
1102 or else Is_Generic_Subprogram
(Scop
)
1103 or else Is_Entry
(Scop
)
1105 Current_Subp
:= Scop
;
1107 Current_Subp
:= Current_Subprogram
;
1110 Enclosing
:= Enclosing_Subprogram
(Ent
);
1112 if Enclosing
/= Empty
1113 and then Enclosing
/= Current_Subp
1115 Set_Has_Up_Level_Access
(Ent
, True);
1118 end Check_Nested_Access
;
1120 ------------------------------------------
1121 -- Check_Potentially_Blocking_Operation --
1122 ------------------------------------------
1124 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
1127 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1128 -- When pragma Detect_Blocking is active, the run time will raise
1129 -- Program_Error. Here we only issue a warning, since we generally
1130 -- support the use of potentially blocking operations in the absence
1133 -- Indirect blocking through a subprogram call cannot be diagnosed
1134 -- statically without interprocedural analysis, so we do not attempt
1137 S
:= Scope
(Current_Scope
);
1138 while Present
(S
) and then S
/= Standard_Standard
loop
1139 if Is_Protected_Type
(S
) then
1141 ("potentially blocking operation in protected operation?", N
);
1148 end Check_Potentially_Blocking_Operation
;
1150 ------------------------------
1151 -- Check_Unprotected_Access --
1152 ------------------------------
1154 procedure Check_Unprotected_Access
1158 Cont_Encl_Typ
: Entity_Id
;
1159 Pref_Encl_Typ
: Entity_Id
;
1161 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
1162 -- Check whether Obj is a private component of a protected object.
1163 -- Return the protected type where the component resides, Empty
1166 function Is_Public_Operation
return Boolean;
1167 -- Verify that the enclosing operation is callable from outside the
1168 -- protected object, to minimize false positives.
1170 ------------------------------
1171 -- Enclosing_Protected_Type --
1172 ------------------------------
1174 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
1176 if Is_Entity_Name
(Obj
) then
1178 Ent
: Entity_Id
:= Entity
(Obj
);
1181 -- The object can be a renaming of a private component, use
1182 -- the original record component.
1184 if Is_Prival
(Ent
) then
1185 Ent
:= Prival_Link
(Ent
);
1188 if Is_Protected_Type
(Scope
(Ent
)) then
1194 -- For indexed and selected components, recursively check the prefix
1196 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
1197 return Enclosing_Protected_Type
(Prefix
(Obj
));
1199 -- The object does not denote a protected component
1204 end Enclosing_Protected_Type
;
1206 -------------------------
1207 -- Is_Public_Operation --
1208 -------------------------
1210 function Is_Public_Operation
return Boolean is
1217 and then S
/= Pref_Encl_Typ
1219 if Scope
(S
) = Pref_Encl_Typ
then
1220 E
:= First_Entity
(Pref_Encl_Typ
);
1222 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
1235 end Is_Public_Operation
;
1237 -- Start of processing for Check_Unprotected_Access
1240 if Nkind
(Expr
) = N_Attribute_Reference
1241 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
1243 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
1244 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
1246 -- Check whether we are trying to export a protected component to a
1247 -- context with an equal or lower access level.
1249 if Present
(Pref_Encl_Typ
)
1250 and then No
(Cont_Encl_Typ
)
1251 and then Is_Public_Operation
1252 and then Scope_Depth
(Pref_Encl_Typ
) >=
1253 Object_Access_Level
(Context
)
1256 ("?possible unprotected access to protected data", Expr
);
1259 end Check_Unprotected_Access
;
1265 procedure Check_VMS
(Construct
: Node_Id
) is
1267 if not OpenVMS_On_Target
then
1269 ("this construct is allowed only in Open'V'M'S", Construct
);
1273 ------------------------
1274 -- Collect_Interfaces --
1275 ------------------------
1277 procedure Collect_Interfaces
1279 Ifaces_List
: out Elist_Id
;
1280 Exclude_Parents
: Boolean := False;
1281 Use_Full_View
: Boolean := True)
1283 procedure Collect
(Typ
: Entity_Id
);
1284 -- Subsidiary subprogram used to traverse the whole list
1285 -- of directly and indirectly implemented interfaces
1291 procedure Collect
(Typ
: Entity_Id
) is
1292 Ancestor
: Entity_Id
;
1300 -- Handle private types
1303 and then Is_Private_Type
(Typ
)
1304 and then Present
(Full_View
(Typ
))
1306 Full_T
:= Full_View
(Typ
);
1309 -- Include the ancestor if we are generating the whole list of
1310 -- abstract interfaces.
1312 if Etype
(Full_T
) /= Typ
1314 -- Protect the frontend against wrong sources. For example:
1317 -- type A is tagged null record;
1318 -- type B is new A with private;
1319 -- type C is new A with private;
1321 -- type B is new C with null record;
1322 -- type C is new B with null record;
1325 and then Etype
(Full_T
) /= T
1327 Ancestor
:= Etype
(Full_T
);
1330 if Is_Interface
(Ancestor
)
1331 and then not Exclude_Parents
1333 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
1337 -- Traverse the graph of ancestor interfaces
1339 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
1340 Id
:= First
(Abstract_Interface_List
(Full_T
));
1341 while Present
(Id
) loop
1342 Iface
:= Etype
(Id
);
1344 -- Protect against wrong uses. For example:
1345 -- type I is interface;
1346 -- type O is tagged null record;
1347 -- type Wrong is new I and O with null record; -- ERROR
1349 if Is_Interface
(Iface
) then
1351 and then Etype
(T
) /= T
1352 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
1357 Append_Unique_Elmt
(Iface
, Ifaces_List
);
1366 -- Start of processing for Collect_Interfaces
1369 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
1370 Ifaces_List
:= New_Elmt_List
;
1372 end Collect_Interfaces
;
1374 ----------------------------------
1375 -- Collect_Interface_Components --
1376 ----------------------------------
1378 procedure Collect_Interface_Components
1379 (Tagged_Type
: Entity_Id
;
1380 Components_List
: out Elist_Id
)
1382 procedure Collect
(Typ
: Entity_Id
);
1383 -- Subsidiary subprogram used to climb to the parents
1389 procedure Collect
(Typ
: Entity_Id
) is
1390 Tag_Comp
: Entity_Id
;
1391 Parent_Typ
: Entity_Id
;
1394 -- Handle private types
1396 if Present
(Full_View
(Etype
(Typ
))) then
1397 Parent_Typ
:= Full_View
(Etype
(Typ
));
1399 Parent_Typ
:= Etype
(Typ
);
1402 if Parent_Typ
/= Typ
1404 -- Protect the frontend against wrong sources. For example:
1407 -- type A is tagged null record;
1408 -- type B is new A with private;
1409 -- type C is new A with private;
1411 -- type B is new C with null record;
1412 -- type C is new B with null record;
1415 and then Parent_Typ
/= Tagged_Type
1417 Collect
(Parent_Typ
);
1420 -- Collect the components containing tags of secondary dispatch
1423 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
1424 while Present
(Tag_Comp
) loop
1425 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
1426 Append_Elmt
(Tag_Comp
, Components_List
);
1428 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
1432 -- Start of processing for Collect_Interface_Components
1435 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
1436 and then Is_Tagged_Type
(Tagged_Type
));
1438 Components_List
:= New_Elmt_List
;
1439 Collect
(Tagged_Type
);
1440 end Collect_Interface_Components
;
1442 -----------------------------
1443 -- Collect_Interfaces_Info --
1444 -----------------------------
1446 procedure Collect_Interfaces_Info
1448 Ifaces_List
: out Elist_Id
;
1449 Components_List
: out Elist_Id
;
1450 Tags_List
: out Elist_Id
)
1452 Comps_List
: Elist_Id
;
1453 Comp_Elmt
: Elmt_Id
;
1454 Comp_Iface
: Entity_Id
;
1455 Iface_Elmt
: Elmt_Id
;
1458 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
1459 -- Search for the secondary tag associated with the interface type
1460 -- Iface that is implemented by T.
1466 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
1470 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
1472 and then Ekind
(Node
(ADT
)) = E_Constant
1473 and then Related_Type
(Node
(ADT
)) /= Iface
1475 -- Skip the secondary dispatch tables of Iface
1483 pragma Assert
(Ekind
(Node
(ADT
)) = E_Constant
);
1487 -- Start of processing for Collect_Interfaces_Info
1490 Collect_Interfaces
(T
, Ifaces_List
);
1491 Collect_Interface_Components
(T
, Comps_List
);
1493 -- Search for the record component and tag associated with each
1494 -- interface type of T.
1496 Components_List
:= New_Elmt_List
;
1497 Tags_List
:= New_Elmt_List
;
1499 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1500 while Present
(Iface_Elmt
) loop
1501 Iface
:= Node
(Iface_Elmt
);
1503 -- Associate the primary tag component and the primary dispatch table
1504 -- with all the interfaces that are parents of T
1506 if Is_Ancestor
(Iface
, T
) then
1507 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
1508 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
1510 -- Otherwise search for the tag component and secondary dispatch
1514 Comp_Elmt
:= First_Elmt
(Comps_List
);
1515 while Present
(Comp_Elmt
) loop
1516 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
1518 if Comp_Iface
= Iface
1519 or else Is_Ancestor
(Iface
, Comp_Iface
)
1521 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
1522 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
1526 Next_Elmt
(Comp_Elmt
);
1528 pragma Assert
(Present
(Comp_Elmt
));
1531 Next_Elmt
(Iface_Elmt
);
1533 end Collect_Interfaces_Info
;
1535 ----------------------------------
1536 -- Collect_Primitive_Operations --
1537 ----------------------------------
1539 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
1540 B_Type
: constant Entity_Id
:= Base_Type
(T
);
1541 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
1542 B_Scope
: Entity_Id
:= Scope
(B_Type
);
1546 Formal_Derived
: Boolean := False;
1550 -- For tagged types, the primitive operations are collected as they
1551 -- are declared, and held in an explicit list which is simply returned.
1553 if Is_Tagged_Type
(B_Type
) then
1554 return Primitive_Operations
(B_Type
);
1556 -- An untagged generic type that is a derived type inherits the
1557 -- primitive operations of its parent type. Other formal types only
1558 -- have predefined operators, which are not explicitly represented.
1560 elsif Is_Generic_Type
(B_Type
) then
1561 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
1562 and then Nkind
(Formal_Type_Definition
(B_Decl
))
1563 = N_Formal_Derived_Type_Definition
1565 Formal_Derived
:= True;
1567 return New_Elmt_List
;
1571 Op_List
:= New_Elmt_List
;
1573 if B_Scope
= Standard_Standard
then
1574 if B_Type
= Standard_String
then
1575 Append_Elmt
(Standard_Op_Concat
, Op_List
);
1577 elsif B_Type
= Standard_Wide_String
then
1578 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
1584 elsif (Is_Package_Or_Generic_Package
(B_Scope
)
1586 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
1588 or else Is_Derived_Type
(B_Type
)
1590 -- The primitive operations appear after the base type, except
1591 -- if the derivation happens within the private part of B_Scope
1592 -- and the type is a private type, in which case both the type
1593 -- and some primitive operations may appear before the base
1594 -- type, and the list of candidates starts after the type.
1596 if In_Open_Scopes
(B_Scope
)
1597 and then Scope
(T
) = B_Scope
1598 and then In_Private_Part
(B_Scope
)
1600 Id
:= Next_Entity
(T
);
1602 Id
:= Next_Entity
(B_Type
);
1605 while Present
(Id
) loop
1607 -- Note that generic formal subprograms are not
1608 -- considered to be primitive operations and thus
1609 -- are never inherited.
1611 if Is_Overloadable
(Id
)
1612 and then Nkind
(Parent
(Parent
(Id
)))
1613 not in N_Formal_Subprogram_Declaration
1617 if Base_Type
(Etype
(Id
)) = B_Type
then
1620 Formal
:= First_Formal
(Id
);
1621 while Present
(Formal
) loop
1622 if Base_Type
(Etype
(Formal
)) = B_Type
then
1626 elsif Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
1628 (Designated_Type
(Etype
(Formal
))) = B_Type
1634 Next_Formal
(Formal
);
1638 -- For a formal derived type, the only primitives are the
1639 -- ones inherited from the parent type. Operations appearing
1640 -- in the package declaration are not primitive for it.
1643 and then (not Formal_Derived
1644 or else Present
(Alias
(Id
)))
1646 Append_Elmt
(Id
, Op_List
);
1652 -- For a type declared in System, some of its operations
1653 -- may appear in the target-specific extension to System.
1656 and then Chars
(B_Scope
) = Name_System
1657 and then Scope
(B_Scope
) = Standard_Standard
1658 and then Present_System_Aux
1660 B_Scope
:= System_Aux_Id
;
1661 Id
:= First_Entity
(System_Aux_Id
);
1667 end Collect_Primitive_Operations
;
1669 -----------------------------------
1670 -- Compile_Time_Constraint_Error --
1671 -----------------------------------
1673 function Compile_Time_Constraint_Error
1676 Ent
: Entity_Id
:= Empty
;
1677 Loc
: Source_Ptr
:= No_Location
;
1678 Warn
: Boolean := False) return Node_Id
1680 Msgc
: String (1 .. Msg
'Length + 2);
1681 -- Copy of message, with room for possible ? and ! at end
1691 -- A static constraint error in an instance body is not a fatal error.
1692 -- we choose to inhibit the message altogether, because there is no
1693 -- obvious node (for now) on which to post it. On the other hand the
1694 -- offending node must be replaced with a constraint_error in any case.
1696 -- No messages are generated if we already posted an error on this node
1698 if not Error_Posted
(N
) then
1699 if Loc
/= No_Location
then
1705 Msgc
(1 .. Msg
'Length) := Msg
;
1708 -- Message is a warning, even in Ada 95 case
1710 if Msg
(Msg
'Last) = '?' then
1713 -- In Ada 83, all messages are warnings. In the private part and
1714 -- the body of an instance, constraint_checks are only warnings.
1715 -- We also make this a warning if the Warn parameter is set.
1718 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
1724 elsif In_Instance_Not_Visible
then
1729 -- Otherwise we have a real error message (Ada 95 static case)
1730 -- and we make this an unconditional message. Note that in the
1731 -- warning case we do not make the message unconditional, it seems
1732 -- quite reasonable to delete messages like this (about exceptions
1733 -- that will be raised) in dead code.
1741 -- Should we generate a warning? The answer is not quite yes. The
1742 -- very annoying exception occurs in the case of a short circuit
1743 -- operator where the left operand is static and decisive. Climb
1744 -- parents to see if that is the case we have here. Conditional
1745 -- expressions with decisive conditions are a similar situation.
1753 -- And then with False as left operand
1755 if Nkind
(P
) = N_And_Then
1756 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
1757 and then Is_False
(Expr_Value
(Left_Opnd
(P
)))
1762 -- OR ELSE with True as left operand
1764 elsif Nkind
(P
) = N_Or_Else
1765 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
1766 and then Is_True
(Expr_Value
(Left_Opnd
(P
)))
1771 -- Conditional expression
1773 elsif Nkind
(P
) = N_Conditional_Expression
then
1775 Cond
: constant Node_Id
:= First
(Expressions
(P
));
1776 Texp
: constant Node_Id
:= Next
(Cond
);
1777 Fexp
: constant Node_Id
:= Next
(Texp
);
1780 if Compile_Time_Known_Value
(Cond
) then
1782 -- Condition is True and we are in the right operand
1784 if Is_True
(Expr_Value
(Cond
))
1785 and then OldP
= Fexp
1790 -- Condition is False and we are in the left operand
1792 elsif Is_False
(Expr_Value
(Cond
))
1793 and then OldP
= Texp
1801 -- Special case for component association in aggregates, where
1802 -- we want to keep climbing up to the parent aggregate.
1804 elsif Nkind
(P
) = N_Component_Association
1805 and then Nkind
(Parent
(P
)) = N_Aggregate
1809 -- Keep going if within subexpression
1812 exit when Nkind
(P
) not in N_Subexpr
;
1817 if Present
(Ent
) then
1818 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
1820 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
1824 if Inside_Init_Proc
then
1826 ("\?& will be raised for objects of this type",
1827 N
, Standard_Constraint_Error
, Eloc
);
1830 ("\?& will be raised at run time",
1831 N
, Standard_Constraint_Error
, Eloc
);
1836 ("\static expression fails Constraint_Check", Eloc
);
1837 Set_Error_Posted
(N
);
1843 end Compile_Time_Constraint_Error
;
1845 -----------------------
1846 -- Conditional_Delay --
1847 -----------------------
1849 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
1851 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
1852 Set_Has_Delayed_Freeze
(New_Ent
);
1854 end Conditional_Delay
;
1856 -------------------------
1857 -- Copy_Parameter_List --
1858 -------------------------
1860 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
1861 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
1866 if No
(First_Formal
(Subp_Id
)) then
1870 Formal
:= First_Formal
(Subp_Id
);
1871 while Present
(Formal
) loop
1873 (Make_Parameter_Specification
(Loc
,
1874 Defining_Identifier
=>
1875 Make_Defining_Identifier
(Sloc
(Formal
),
1876 Chars
=> Chars
(Formal
)),
1877 In_Present
=> In_Present
(Parent
(Formal
)),
1878 Out_Present
=> Out_Present
(Parent
(Formal
)),
1880 New_Reference_To
(Etype
(Formal
), Loc
),
1882 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
1885 Next_Formal
(Formal
);
1890 end Copy_Parameter_List
;
1892 --------------------
1893 -- Current_Entity --
1894 --------------------
1896 -- The currently visible definition for a given identifier is the
1897 -- one most chained at the start of the visibility chain, i.e. the
1898 -- one that is referenced by the Node_Id value of the name of the
1899 -- given identifier.
1901 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
1903 return Get_Name_Entity_Id
(Chars
(N
));
1906 -----------------------------
1907 -- Current_Entity_In_Scope --
1908 -----------------------------
1910 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
1912 CS
: constant Entity_Id
:= Current_Scope
;
1914 Transient_Case
: constant Boolean := Scope_Is_Transient
;
1917 E
:= Get_Name_Entity_Id
(Chars
(N
));
1919 and then Scope
(E
) /= CS
1920 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
1926 end Current_Entity_In_Scope
;
1932 function Current_Scope
return Entity_Id
is
1934 if Scope_Stack
.Last
= -1 then
1935 return Standard_Standard
;
1938 C
: constant Entity_Id
:=
1939 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
1944 return Standard_Standard
;
1950 ------------------------
1951 -- Current_Subprogram --
1952 ------------------------
1954 function Current_Subprogram
return Entity_Id
is
1955 Scop
: constant Entity_Id
:= Current_Scope
;
1957 if Is_Subprogram
(Scop
) or else Is_Generic_Subprogram
(Scop
) then
1960 return Enclosing_Subprogram
(Scop
);
1962 end Current_Subprogram
;
1964 ---------------------
1965 -- Defining_Entity --
1966 ---------------------
1968 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
1969 K
: constant Node_Kind
:= Nkind
(N
);
1970 Err
: Entity_Id
:= Empty
;
1975 N_Subprogram_Declaration |
1976 N_Abstract_Subprogram_Declaration |
1978 N_Package_Declaration |
1979 N_Subprogram_Renaming_Declaration |
1980 N_Subprogram_Body_Stub |
1981 N_Generic_Subprogram_Declaration |
1982 N_Generic_Package_Declaration |
1983 N_Formal_Subprogram_Declaration
1985 return Defining_Entity
(Specification
(N
));
1988 N_Component_Declaration |
1989 N_Defining_Program_Unit_Name |
1990 N_Discriminant_Specification |
1992 N_Entry_Declaration |
1993 N_Entry_Index_Specification |
1994 N_Exception_Declaration |
1995 N_Exception_Renaming_Declaration |
1996 N_Formal_Object_Declaration |
1997 N_Formal_Package_Declaration |
1998 N_Formal_Type_Declaration |
1999 N_Full_Type_Declaration |
2000 N_Implicit_Label_Declaration |
2001 N_Incomplete_Type_Declaration |
2002 N_Loop_Parameter_Specification |
2003 N_Number_Declaration |
2004 N_Object_Declaration |
2005 N_Object_Renaming_Declaration |
2006 N_Package_Body_Stub |
2007 N_Parameter_Specification |
2008 N_Private_Extension_Declaration |
2009 N_Private_Type_Declaration |
2011 N_Protected_Body_Stub |
2012 N_Protected_Type_Declaration |
2013 N_Single_Protected_Declaration |
2014 N_Single_Task_Declaration |
2015 N_Subtype_Declaration |
2018 N_Task_Type_Declaration
2020 return Defining_Identifier
(N
);
2023 return Defining_Entity
(Proper_Body
(N
));
2026 N_Function_Instantiation |
2027 N_Function_Specification |
2028 N_Generic_Function_Renaming_Declaration |
2029 N_Generic_Package_Renaming_Declaration |
2030 N_Generic_Procedure_Renaming_Declaration |
2032 N_Package_Instantiation |
2033 N_Package_Renaming_Declaration |
2034 N_Package_Specification |
2035 N_Procedure_Instantiation |
2036 N_Procedure_Specification
2039 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
2042 if Nkind
(Nam
) in N_Entity
then
2045 -- For Error, make up a name and attach to declaration
2046 -- so we can continue semantic analysis
2048 elsif Nam
= Error
then
2050 Make_Defining_Identifier
(Sloc
(N
),
2051 Chars
=> New_Internal_Name
('T'));
2052 Set_Defining_Unit_Name
(N
, Err
);
2055 -- If not an entity, get defining identifier
2058 return Defining_Identifier
(Nam
);
2062 when N_Block_Statement
=>
2063 return Entity
(Identifier
(N
));
2066 raise Program_Error
;
2069 end Defining_Entity
;
2071 --------------------------
2072 -- Denotes_Discriminant --
2073 --------------------------
2075 function Denotes_Discriminant
2077 Check_Concurrent
: Boolean := False) return Boolean
2081 if not Is_Entity_Name
(N
)
2082 or else No
(Entity
(N
))
2089 -- If we are checking for a protected type, the discriminant may have
2090 -- been rewritten as the corresponding discriminal of the original type
2091 -- or of the corresponding concurrent record, depending on whether we
2092 -- are in the spec or body of the protected type.
2094 return Ekind
(E
) = E_Discriminant
2097 and then Ekind
(E
) = E_In_Parameter
2098 and then Present
(Discriminal_Link
(E
))
2100 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
2102 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
2104 end Denotes_Discriminant
;
2106 ----------------------
2107 -- Denotes_Variable --
2108 ----------------------
2110 function Denotes_Variable
(N
: Node_Id
) return Boolean is
2112 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
2113 end Denotes_Variable
;
2115 -----------------------------
2116 -- Depends_On_Discriminant --
2117 -----------------------------
2119 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
2124 Get_Index_Bounds
(N
, L
, H
);
2125 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
2126 end Depends_On_Discriminant
;
2128 -------------------------
2129 -- Designate_Same_Unit --
2130 -------------------------
2132 function Designate_Same_Unit
2134 Name2
: Node_Id
) return Boolean
2136 K1
: constant Node_Kind
:= Nkind
(Name1
);
2137 K2
: constant Node_Kind
:= Nkind
(Name2
);
2139 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
2140 -- Returns the parent unit name node of a defining program unit name
2141 -- or the prefix if N is a selected component or an expanded name.
2143 function Select_Node
(N
: Node_Id
) return Node_Id
;
2144 -- Returns the defining identifier node of a defining program unit
2145 -- name or the selector node if N is a selected component or an
2152 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
2154 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
2166 function Select_Node
(N
: Node_Id
) return Node_Id
is
2168 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
2169 return Defining_Identifier
(N
);
2172 return Selector_Name
(N
);
2176 -- Start of processing for Designate_Next_Unit
2179 if (K1
= N_Identifier
or else
2180 K1
= N_Defining_Identifier
)
2182 (K2
= N_Identifier
or else
2183 K2
= N_Defining_Identifier
)
2185 return Chars
(Name1
) = Chars
(Name2
);
2188 (K1
= N_Expanded_Name
or else
2189 K1
= N_Selected_Component
or else
2190 K1
= N_Defining_Program_Unit_Name
)
2192 (K2
= N_Expanded_Name
or else
2193 K2
= N_Selected_Component
or else
2194 K2
= N_Defining_Program_Unit_Name
)
2197 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
2199 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
2204 end Designate_Same_Unit
;
2206 ----------------------------
2207 -- Enclosing_Generic_Body --
2208 ----------------------------
2210 function Enclosing_Generic_Body
2211 (N
: Node_Id
) return Node_Id
2219 while Present
(P
) loop
2220 if Nkind
(P
) = N_Package_Body
2221 or else Nkind
(P
) = N_Subprogram_Body
2223 Spec
:= Corresponding_Spec
(P
);
2225 if Present
(Spec
) then
2226 Decl
:= Unit_Declaration_Node
(Spec
);
2228 if Nkind
(Decl
) = N_Generic_Package_Declaration
2229 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
2240 end Enclosing_Generic_Body
;
2242 ----------------------------
2243 -- Enclosing_Generic_Unit --
2244 ----------------------------
2246 function Enclosing_Generic_Unit
2247 (N
: Node_Id
) return Node_Id
2255 while Present
(P
) loop
2256 if Nkind
(P
) = N_Generic_Package_Declaration
2257 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
2261 elsif Nkind
(P
) = N_Package_Body
2262 or else Nkind
(P
) = N_Subprogram_Body
2264 Spec
:= Corresponding_Spec
(P
);
2266 if Present
(Spec
) then
2267 Decl
:= Unit_Declaration_Node
(Spec
);
2269 if Nkind
(Decl
) = N_Generic_Package_Declaration
2270 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
2281 end Enclosing_Generic_Unit
;
2283 -------------------------------
2284 -- Enclosing_Lib_Unit_Entity --
2285 -------------------------------
2287 function Enclosing_Lib_Unit_Entity
return Entity_Id
is
2288 Unit_Entity
: Entity_Id
;
2291 -- Look for enclosing library unit entity by following scope links.
2292 -- Equivalent to, but faster than indexing through the scope stack.
2294 Unit_Entity
:= Current_Scope
;
2295 while (Present
(Scope
(Unit_Entity
))
2296 and then Scope
(Unit_Entity
) /= Standard_Standard
)
2297 and not Is_Child_Unit
(Unit_Entity
)
2299 Unit_Entity
:= Scope
(Unit_Entity
);
2303 end Enclosing_Lib_Unit_Entity
;
2305 -----------------------------
2306 -- Enclosing_Lib_Unit_Node --
2307 -----------------------------
2309 function Enclosing_Lib_Unit_Node
(N
: Node_Id
) return Node_Id
is
2310 Current_Node
: Node_Id
;
2314 while Present
(Current_Node
)
2315 and then Nkind
(Current_Node
) /= N_Compilation_Unit
2317 Current_Node
:= Parent
(Current_Node
);
2320 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
2324 return Current_Node
;
2325 end Enclosing_Lib_Unit_Node
;
2327 --------------------------
2328 -- Enclosing_Subprogram --
2329 --------------------------
2331 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
2332 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
2335 if Dynamic_Scope
= Standard_Standard
then
2338 elsif Dynamic_Scope
= Empty
then
2341 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
2342 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
2344 elsif Ekind
(Dynamic_Scope
) = E_Block
2345 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
2347 return Enclosing_Subprogram
(Dynamic_Scope
);
2349 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
2350 return Get_Task_Body_Procedure
(Dynamic_Scope
);
2352 elsif Convention
(Dynamic_Scope
) = Convention_Protected
then
2353 return Protected_Body_Subprogram
(Dynamic_Scope
);
2356 return Dynamic_Scope
;
2358 end Enclosing_Subprogram
;
2360 ------------------------
2361 -- Ensure_Freeze_Node --
2362 ------------------------
2364 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
2368 if No
(Freeze_Node
(E
)) then
2369 FN
:= Make_Freeze_Entity
(Sloc
(E
));
2370 Set_Has_Delayed_Freeze
(E
);
2371 Set_Freeze_Node
(E
, FN
);
2372 Set_Access_Types_To_Process
(FN
, No_Elist
);
2373 Set_TSS_Elist
(FN
, No_Elist
);
2376 end Ensure_Freeze_Node
;
2382 procedure Enter_Name
(Def_Id
: Entity_Id
) is
2383 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
2384 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
2385 S
: constant Entity_Id
:= Current_Scope
;
2388 Generate_Definition
(Def_Id
);
2390 -- Add new name to current scope declarations. Check for duplicate
2391 -- declaration, which may or may not be a genuine error.
2395 -- Case of previous entity entered because of a missing declaration
2396 -- or else a bad subtype indication. Best is to use the new entity,
2397 -- and make the previous one invisible.
2399 if Etype
(E
) = Any_Type
then
2400 Set_Is_Immediately_Visible
(E
, False);
2402 -- Case of renaming declaration constructed for package instances.
2403 -- if there is an explicit declaration with the same identifier,
2404 -- the renaming is not immediately visible any longer, but remains
2405 -- visible through selected component notation.
2407 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
2408 and then not Comes_From_Source
(E
)
2410 Set_Is_Immediately_Visible
(E
, False);
2412 -- The new entity may be the package renaming, which has the same
2413 -- same name as a generic formal which has been seen already.
2415 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
2416 and then not Comes_From_Source
(Def_Id
)
2418 Set_Is_Immediately_Visible
(E
, False);
2420 -- For a fat pointer corresponding to a remote access to subprogram,
2421 -- we use the same identifier as the RAS type, so that the proper
2422 -- name appears in the stub. This type is only retrieved through
2423 -- the RAS type and never by visibility, and is not added to the
2424 -- visibility list (see below).
2426 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
2427 and then Present
(Corresponding_Remote_Type
(Def_Id
))
2431 -- A controller component for a type extension overrides the
2432 -- inherited component.
2434 elsif Chars
(E
) = Name_uController
then
2437 -- Case of an implicit operation or derived literal. The new entity
2438 -- hides the implicit one, which is removed from all visibility,
2439 -- i.e. the entity list of its scope, and homonym chain of its name.
2441 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
2442 or else Is_Internal
(E
)
2446 Prev_Vis
: Entity_Id
;
2447 Decl
: constant Node_Id
:= Parent
(E
);
2450 -- If E is an implicit declaration, it cannot be the first
2451 -- entity in the scope.
2453 Prev
:= First_Entity
(Current_Scope
);
2454 while Present
(Prev
)
2455 and then Next_Entity
(Prev
) /= E
2462 -- If E is not on the entity chain of the current scope,
2463 -- it is an implicit declaration in the generic formal
2464 -- part of a generic subprogram. When analyzing the body,
2465 -- the generic formals are visible but not on the entity
2466 -- chain of the subprogram. The new entity will become
2467 -- the visible one in the body.
2470 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
2474 Set_Next_Entity
(Prev
, Next_Entity
(E
));
2476 if No
(Next_Entity
(Prev
)) then
2477 Set_Last_Entity
(Current_Scope
, Prev
);
2480 if E
= Current_Entity
(E
) then
2484 Prev_Vis
:= Current_Entity
(E
);
2485 while Homonym
(Prev_Vis
) /= E
loop
2486 Prev_Vis
:= Homonym
(Prev_Vis
);
2490 if Present
(Prev_Vis
) then
2492 -- Skip E in the visibility chain
2494 Set_Homonym
(Prev_Vis
, Homonym
(E
));
2497 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
2502 -- This section of code could use a comment ???
2504 elsif Present
(Etype
(E
))
2505 and then Is_Concurrent_Type
(Etype
(E
))
2510 -- If the homograph is a protected component renaming, it should not
2511 -- be hiding the current entity. Such renamings are treated as weak
2514 elsif Is_Prival
(E
) then
2515 Set_Is_Immediately_Visible
(E
, False);
2517 -- In this case the current entity is a protected component renaming.
2518 -- Perform minimal decoration by setting the scope and return since
2519 -- the prival should not be hiding other visible entities.
2521 elsif Is_Prival
(Def_Id
) then
2522 Set_Scope
(Def_Id
, Current_Scope
);
2525 -- Analogous to privals, the discriminal generated for an entry
2526 -- index parameter acts as a weak declaration. Perform minimal
2527 -- decoration to avoid bogus errors.
2529 elsif Is_Discriminal
(Def_Id
)
2530 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
2532 Set_Scope
(Def_Id
, Current_Scope
);
2535 -- In the body or private part of an instance, a type extension
2536 -- may introduce a component with the same name as that of an
2537 -- actual. The legality rule is not enforced, but the semantics
2538 -- of the full type with two components of the same name are not
2539 -- clear at this point ???
2541 elsif In_Instance_Not_Visible
then
2544 -- When compiling a package body, some child units may have become
2545 -- visible. They cannot conflict with local entities that hide them.
2547 elsif Is_Child_Unit
(E
)
2548 and then In_Open_Scopes
(Scope
(E
))
2549 and then not Is_Immediately_Visible
(E
)
2553 -- Conversely, with front-end inlining we may compile the parent
2554 -- body first, and a child unit subsequently. The context is now
2555 -- the parent spec, and body entities are not visible.
2557 elsif Is_Child_Unit
(Def_Id
)
2558 and then Is_Package_Body_Entity
(E
)
2559 and then not In_Package_Body
(Current_Scope
)
2563 -- Case of genuine duplicate declaration
2566 Error_Msg_Sloc
:= Sloc
(E
);
2568 -- If the previous declaration is an incomplete type declaration
2569 -- this may be an attempt to complete it with a private type.
2570 -- The following avoids confusing cascaded errors.
2572 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
2573 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
2576 ("incomplete type cannot be completed with a private " &
2577 "declaration", Parent
(Def_Id
));
2578 Set_Is_Immediately_Visible
(E
, False);
2579 Set_Full_View
(E
, Def_Id
);
2581 -- An inherited component of a record conflicts with a new
2582 -- discriminant. The discriminant is inserted first in the scope,
2583 -- but the error should be posted on it, not on the component.
2585 elsif Ekind
(E
) = E_Discriminant
2586 and then Present
(Scope
(Def_Id
))
2587 and then Scope
(Def_Id
) /= Current_Scope
2589 Error_Msg_Sloc
:= Sloc
(Def_Id
);
2590 Error_Msg_N
("& conflicts with declaration#", E
);
2593 -- If the name of the unit appears in its own context clause,
2594 -- a dummy package with the name has already been created, and
2595 -- the error emitted. Try to continue quietly.
2597 elsif Error_Posted
(E
)
2598 and then Sloc
(E
) = No_Location
2599 and then Nkind
(Parent
(E
)) = N_Package_Specification
2600 and then Current_Scope
= Standard_Standard
2602 Set_Scope
(Def_Id
, Current_Scope
);
2606 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
2608 -- Avoid cascaded messages with duplicate components in
2611 if Ekind
(E
) = E_Component
2612 or else Ekind
(E
) = E_Discriminant
2618 if Nkind
(Parent
(Parent
(Def_Id
))) =
2619 N_Generic_Subprogram_Declaration
2621 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
2623 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
2626 -- If entity is in standard, then we are in trouble, because
2627 -- it means that we have a library package with a duplicated
2628 -- name. That's hard to recover from, so abort!
2630 if S
= Standard_Standard
then
2631 raise Unrecoverable_Error
;
2633 -- Otherwise we continue with the declaration. Having two
2634 -- identical declarations should not cause us too much trouble!
2642 -- If we fall through, declaration is OK , or OK enough to continue
2644 -- If Def_Id is a discriminant or a record component we are in the
2645 -- midst of inheriting components in a derived record definition.
2646 -- Preserve their Ekind and Etype.
2648 if Ekind
(Def_Id
) = E_Discriminant
2649 or else Ekind
(Def_Id
) = E_Component
2653 -- If a type is already set, leave it alone (happens whey a type
2654 -- declaration is reanalyzed following a call to the optimizer)
2656 elsif Present
(Etype
(Def_Id
)) then
2659 -- Otherwise, the kind E_Void insures that premature uses of the entity
2660 -- will be detected. Any_Type insures that no cascaded errors will occur
2663 Set_Ekind
(Def_Id
, E_Void
);
2664 Set_Etype
(Def_Id
, Any_Type
);
2667 -- Inherited discriminants and components in derived record types are
2668 -- immediately visible. Itypes are not.
2670 if Ekind
(Def_Id
) = E_Discriminant
2671 or else Ekind
(Def_Id
) = E_Component
2672 or else (No
(Corresponding_Remote_Type
(Def_Id
))
2673 and then not Is_Itype
(Def_Id
))
2675 Set_Is_Immediately_Visible
(Def_Id
);
2676 Set_Current_Entity
(Def_Id
);
2679 Set_Homonym
(Def_Id
, C
);
2680 Append_Entity
(Def_Id
, S
);
2681 Set_Public_Status
(Def_Id
);
2683 -- Warn if new entity hides an old one
2685 if Warn_On_Hiding
and then Present
(C
)
2687 -- Don't warn for record components since they always have a well
2688 -- defined scope which does not confuse other uses. Note that in
2689 -- some cases, Ekind has not been set yet.
2691 and then Ekind
(C
) /= E_Component
2692 and then Ekind
(C
) /= E_Discriminant
2693 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
2694 and then Ekind
(Def_Id
) /= E_Component
2695 and then Ekind
(Def_Id
) /= E_Discriminant
2696 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
2698 -- Don't warn for one character variables. It is too common to use
2699 -- such variables as locals and will just cause too many false hits.
2701 and then Length_Of_Name
(Chars
(C
)) /= 1
2703 -- Don't warn for non-source entities
2705 and then Comes_From_Source
(C
)
2706 and then Comes_From_Source
(Def_Id
)
2708 -- Don't warn unless entity in question is in extended main source
2710 and then In_Extended_Main_Source_Unit
(Def_Id
)
2712 -- Finally, the hidden entity must be either immediately visible
2713 -- or use visible (from a used package)
2716 (Is_Immediately_Visible
(C
)
2718 Is_Potentially_Use_Visible
(C
))
2720 Error_Msg_Sloc
:= Sloc
(C
);
2721 Error_Msg_N
("declaration hides &#?", Def_Id
);
2725 --------------------------
2726 -- Explain_Limited_Type --
2727 --------------------------
2729 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
2733 -- For array, component type must be limited
2735 if Is_Array_Type
(T
) then
2736 Error_Msg_Node_2
:= T
;
2738 ("\component type& of type& is limited", N
, Component_Type
(T
));
2739 Explain_Limited_Type
(Component_Type
(T
), N
);
2741 elsif Is_Record_Type
(T
) then
2743 -- No need for extra messages if explicit limited record
2745 if Is_Limited_Record
(Base_Type
(T
)) then
2749 -- Otherwise find a limited component. Check only components that
2750 -- come from source, or inherited components that appear in the
2751 -- source of the ancestor.
2753 C
:= First_Component
(T
);
2754 while Present
(C
) loop
2755 if Is_Limited_Type
(Etype
(C
))
2757 (Comes_From_Source
(C
)
2759 (Present
(Original_Record_Component
(C
))
2761 Comes_From_Source
(Original_Record_Component
(C
))))
2763 Error_Msg_Node_2
:= T
;
2764 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
2765 Explain_Limited_Type
(Etype
(C
), N
);
2772 -- The type may be declared explicitly limited, even if no component
2773 -- of it is limited, in which case we fall out of the loop.
2776 end Explain_Limited_Type
;
2782 procedure Find_Actual
2784 Formal
: out Entity_Id
;
2787 Parnt
: constant Node_Id
:= Parent
(N
);
2791 if (Nkind
(Parnt
) = N_Indexed_Component
2793 Nkind
(Parnt
) = N_Selected_Component
)
2794 and then N
= Prefix
(Parnt
)
2796 Find_Actual
(Parnt
, Formal
, Call
);
2799 elsif Nkind
(Parnt
) = N_Parameter_Association
2800 and then N
= Explicit_Actual_Parameter
(Parnt
)
2802 Call
:= Parent
(Parnt
);
2804 elsif Nkind
(Parnt
) = N_Procedure_Call_Statement
then
2813 -- If we have a call to a subprogram look for the parameter. Note that
2814 -- we exclude overloaded calls, since we don't know enough to be sure
2815 -- of giving the right answer in this case.
2817 if Is_Entity_Name
(Name
(Call
))
2818 and then Present
(Entity
(Name
(Call
)))
2819 and then Is_Overloadable
(Entity
(Name
(Call
)))
2820 and then not Is_Overloaded
(Name
(Call
))
2822 -- Fall here if we are definitely a parameter
2824 Actual
:= First_Actual
(Call
);
2825 Formal
:= First_Formal
(Entity
(Name
(Call
)));
2826 while Present
(Formal
) and then Present
(Actual
) loop
2830 Actual
:= Next_Actual
(Actual
);
2831 Formal
:= Next_Formal
(Formal
);
2836 -- Fall through here if we did not find matching actual
2842 -------------------------------------
2843 -- Find_Corresponding_Discriminant --
2844 -------------------------------------
2846 function Find_Corresponding_Discriminant
2848 Typ
: Entity_Id
) return Entity_Id
2850 Par_Disc
: Entity_Id
;
2851 Old_Disc
: Entity_Id
;
2852 New_Disc
: Entity_Id
;
2855 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
2857 -- The original type may currently be private, and the discriminant
2858 -- only appear on its full view.
2860 if Is_Private_Type
(Scope
(Par_Disc
))
2861 and then not Has_Discriminants
(Scope
(Par_Disc
))
2862 and then Present
(Full_View
(Scope
(Par_Disc
)))
2864 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
2866 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
2869 if Is_Class_Wide_Type
(Typ
) then
2870 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
2872 New_Disc
:= First_Discriminant
(Typ
);
2875 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
2876 if Old_Disc
= Par_Disc
then
2879 Next_Discriminant
(Old_Disc
);
2880 Next_Discriminant
(New_Disc
);
2884 -- Should always find it
2886 raise Program_Error
;
2887 end Find_Corresponding_Discriminant
;
2889 --------------------------
2890 -- Find_Overlaid_Object --
2891 --------------------------
2893 function Find_Overlaid_Object
(N
: Node_Id
) return Entity_Id
is
2897 -- We are looking for one of the two following forms:
2899 -- for X'Address use Y'Address
2903 -- Const : constant Address := expr;
2905 -- for X'Address use Const;
2907 -- In the second case, the expr is either Y'Address, or recursively a
2908 -- constant that eventually references Y'Address.
2910 if Nkind
(N
) = N_Attribute_Definition_Clause
2911 and then Chars
(N
) = Name_Address
2913 -- This loop checks the form of the expression for Y'Address where Y
2914 -- is an object entity name. The first loop checks the original
2915 -- expression in the attribute definition clause. Subsequent loops
2916 -- check referenced constants.
2918 Expr
:= Expression
(N
);
2920 -- Check for Y'Address where Y is an object entity
2922 if Nkind
(Expr
) = N_Attribute_Reference
2923 and then Attribute_Name
(Expr
) = Name_Address
2924 and then Is_Entity_Name
(Prefix
(Expr
))
2925 and then Is_Object
(Entity
(Prefix
(Expr
)))
2927 return Entity
(Prefix
(Expr
));
2929 -- Check for Const where Const is a constant entity
2931 elsif Is_Entity_Name
(Expr
)
2932 and then Ekind
(Entity
(Expr
)) = E_Constant
2934 Expr
:= Constant_Value
(Entity
(Expr
));
2936 -- Anything else does not need checking
2945 end Find_Overlaid_Object
;
2947 -------------------------
2948 -- Find_Parameter_Type --
2949 -------------------------
2951 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
2953 if Nkind
(Param
) /= N_Parameter_Specification
then
2956 -- For an access parameter, obtain the type from the formal entity
2957 -- itself, because access to subprogram nodes do not carry a type.
2958 -- Shouldn't we always use the formal entity ???
2960 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
2961 return Etype
(Defining_Identifier
(Param
));
2964 return Etype
(Parameter_Type
(Param
));
2966 end Find_Parameter_Type
;
2968 -----------------------------
2969 -- Find_Static_Alternative --
2970 -----------------------------
2972 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
2973 Expr
: constant Node_Id
:= Expression
(N
);
2974 Val
: constant Uint
:= Expr_Value
(Expr
);
2979 Alt
:= First
(Alternatives
(N
));
2982 if Nkind
(Alt
) /= N_Pragma
then
2983 Choice
:= First
(Discrete_Choices
(Alt
));
2984 while Present
(Choice
) loop
2986 -- Others choice, always matches
2988 if Nkind
(Choice
) = N_Others_Choice
then
2991 -- Range, check if value is in the range
2993 elsif Nkind
(Choice
) = N_Range
then
2995 Val
>= Expr_Value
(Low_Bound
(Choice
))
2997 Val
<= Expr_Value
(High_Bound
(Choice
));
2999 -- Choice is a subtype name. Note that we know it must
3000 -- be a static subtype, since otherwise it would have
3001 -- been diagnosed as illegal.
3003 elsif Is_Entity_Name
(Choice
)
3004 and then Is_Type
(Entity
(Choice
))
3006 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
3007 Assume_Valid
=> False);
3009 -- Choice is a subtype indication
3011 elsif Nkind
(Choice
) = N_Subtype_Indication
then
3013 C
: constant Node_Id
:= Constraint
(Choice
);
3014 R
: constant Node_Id
:= Range_Expression
(C
);
3018 Val
>= Expr_Value
(Low_Bound
(R
))
3020 Val
<= Expr_Value
(High_Bound
(R
));
3023 -- Choice is a simple expression
3026 exit Search
when Val
= Expr_Value
(Choice
);
3034 pragma Assert
(Present
(Alt
));
3037 -- The above loop *must* terminate by finding a match, since
3038 -- we know the case statement is valid, and the value of the
3039 -- expression is known at compile time. When we fall out of
3040 -- the loop, Alt points to the alternative that we know will
3041 -- be selected at run time.
3044 end Find_Static_Alternative
;
3050 function First_Actual
(Node
: Node_Id
) return Node_Id
is
3054 if No
(Parameter_Associations
(Node
)) then
3058 N
:= First
(Parameter_Associations
(Node
));
3060 if Nkind
(N
) = N_Parameter_Association
then
3061 return First_Named_Actual
(Node
);
3067 -------------------------
3068 -- Full_Qualified_Name --
3069 -------------------------
3071 function Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
3073 pragma Warnings
(Off
, Res
);
3075 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
;
3076 -- Compute recursively the qualified name without NUL at the end
3078 ----------------------------------
3079 -- Internal_Full_Qualified_Name --
3080 ----------------------------------
3082 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
3083 Ent
: Entity_Id
:= E
;
3084 Parent_Name
: String_Id
:= No_String
;
3087 -- Deals properly with child units
3089 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
3090 Ent
:= Defining_Identifier
(Ent
);
3093 -- Compute qualification recursively (only "Standard" has no scope)
3095 if Present
(Scope
(Scope
(Ent
))) then
3096 Parent_Name
:= Internal_Full_Qualified_Name
(Scope
(Ent
));
3099 -- Every entity should have a name except some expanded blocks
3100 -- don't bother about those.
3102 if Chars
(Ent
) = No_Name
then
3106 -- Add a period between Name and qualification
3108 if Parent_Name
/= No_String
then
3109 Start_String
(Parent_Name
);
3110 Store_String_Char
(Get_Char_Code
('.'));
3116 -- Generates the entity name in upper case
3118 Get_Decoded_Name_String
(Chars
(Ent
));
3120 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
3122 end Internal_Full_Qualified_Name
;
3124 -- Start of processing for Full_Qualified_Name
3127 Res
:= Internal_Full_Qualified_Name
(E
);
3128 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
3130 end Full_Qualified_Name
;
3132 -----------------------
3133 -- Gather_Components --
3134 -----------------------
3136 procedure Gather_Components
3138 Comp_List
: Node_Id
;
3139 Governed_By
: List_Id
;
3141 Report_Errors
: out Boolean)
3145 Discrete_Choice
: Node_Id
;
3146 Comp_Item
: Node_Id
;
3148 Discrim
: Entity_Id
;
3149 Discrim_Name
: Node_Id
;
3150 Discrim_Value
: Node_Id
;
3153 Report_Errors
:= False;
3155 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
3158 elsif Present
(Component_Items
(Comp_List
)) then
3159 Comp_Item
:= First
(Component_Items
(Comp_List
));
3165 while Present
(Comp_Item
) loop
3167 -- Skip the tag of a tagged record, the interface tags, as well
3168 -- as all items that are not user components (anonymous types,
3169 -- rep clauses, Parent field, controller field).
3171 if Nkind
(Comp_Item
) = N_Component_Declaration
then
3173 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
3175 if not Is_Tag
(Comp
)
3176 and then Chars
(Comp
) /= Name_uParent
3177 and then Chars
(Comp
) /= Name_uController
3179 Append_Elmt
(Comp
, Into
);
3187 if No
(Variant_Part
(Comp_List
)) then
3190 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
3191 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3194 -- Look for the discriminant that governs this variant part.
3195 -- The discriminant *must* be in the Governed_By List
3197 Assoc
:= First
(Governed_By
);
3198 Find_Constraint
: loop
3199 Discrim
:= First
(Choices
(Assoc
));
3200 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
3201 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
3203 Chars
(Corresponding_Discriminant
(Entity
(Discrim
)))
3204 = Chars
(Discrim_Name
))
3205 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
3206 = Chars
(Discrim_Name
);
3208 if No
(Next
(Assoc
)) then
3209 if not Is_Constrained
(Typ
)
3210 and then Is_Derived_Type
(Typ
)
3211 and then Present
(Stored_Constraint
(Typ
))
3213 -- If the type is a tagged type with inherited discriminants,
3214 -- use the stored constraint on the parent in order to find
3215 -- the values of discriminants that are otherwise hidden by an
3216 -- explicit constraint. Renamed discriminants are handled in
3219 -- If several parent discriminants are renamed by a single
3220 -- discriminant of the derived type, the call to obtain the
3221 -- Corresponding_Discriminant field only retrieves the last
3222 -- of them. We recover the constraint on the others from the
3223 -- Stored_Constraint as well.
3230 D
:= First_Discriminant
(Etype
(Typ
));
3231 C
:= First_Elmt
(Stored_Constraint
(Typ
));
3232 while Present
(D
) and then Present
(C
) loop
3233 if Chars
(Discrim_Name
) = Chars
(D
) then
3234 if Is_Entity_Name
(Node
(C
))
3235 and then Entity
(Node
(C
)) = Entity
(Discrim
)
3237 -- D is renamed by Discrim, whose value is given in
3244 Make_Component_Association
(Sloc
(Typ
),
3246 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
3247 Duplicate_Subexpr_No_Checks
(Node
(C
)));
3249 exit Find_Constraint
;
3252 Next_Discriminant
(D
);
3259 if No
(Next
(Assoc
)) then
3260 Error_Msg_NE
(" missing value for discriminant&",
3261 First
(Governed_By
), Discrim_Name
);
3262 Report_Errors
:= True;
3267 end loop Find_Constraint
;
3269 Discrim_Value
:= Expression
(Assoc
);
3271 if not Is_OK_Static_Expression
(Discrim_Value
) then
3273 ("value for discriminant & must be static!",
3274 Discrim_Value
, Discrim
);
3275 Why_Not_Static
(Discrim_Value
);
3276 Report_Errors
:= True;
3280 Search_For_Discriminant_Value
: declare
3286 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
3289 Find_Discrete_Value
: while Present
(Variant
) loop
3290 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
3291 while Present
(Discrete_Choice
) loop
3293 exit Find_Discrete_Value
when
3294 Nkind
(Discrete_Choice
) = N_Others_Choice
;
3296 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
3298 UI_Low
:= Expr_Value
(Low
);
3299 UI_High
:= Expr_Value
(High
);
3301 exit Find_Discrete_Value
when
3302 UI_Low
<= UI_Discrim_Value
3304 UI_High
>= UI_Discrim_Value
;
3306 Next
(Discrete_Choice
);
3309 Next_Non_Pragma
(Variant
);
3310 end loop Find_Discrete_Value
;
3311 end Search_For_Discriminant_Value
;
3313 if No
(Variant
) then
3315 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
3316 Report_Errors
:= True;
3320 -- If we have found the corresponding choice, recursively add its
3321 -- components to the Into list.
3323 Gather_Components
(Empty
,
3324 Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
3325 end Gather_Components
;
3327 ------------------------
3328 -- Get_Actual_Subtype --
3329 ------------------------
3331 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
3332 Typ
: constant Entity_Id
:= Etype
(N
);
3333 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
3342 -- If what we have is an identifier that references a subprogram
3343 -- formal, or a variable or constant object, then we get the actual
3344 -- subtype from the referenced entity if one has been built.
3346 if Nkind
(N
) = N_Identifier
3348 (Is_Formal
(Entity
(N
))
3349 or else Ekind
(Entity
(N
)) = E_Constant
3350 or else Ekind
(Entity
(N
)) = E_Variable
)
3351 and then Present
(Actual_Subtype
(Entity
(N
)))
3353 return Actual_Subtype
(Entity
(N
));
3355 -- Actual subtype of unchecked union is always itself. We never need
3356 -- the "real" actual subtype. If we did, we couldn't get it anyway
3357 -- because the discriminant is not available. The restrictions on
3358 -- Unchecked_Union are designed to make sure that this is OK.
3360 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
3363 -- Here for the unconstrained case, we must find actual subtype
3364 -- No actual subtype is available, so we must build it on the fly.
3366 -- Checking the type, not the underlying type, for constrainedness
3367 -- seems to be necessary. Maybe all the tests should be on the type???
3369 elsif (not Is_Constrained
(Typ
))
3370 and then (Is_Array_Type
(Utyp
)
3371 or else (Is_Record_Type
(Utyp
)
3372 and then Has_Discriminants
(Utyp
)))
3373 and then not Has_Unknown_Discriminants
(Utyp
)
3374 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
3376 -- Nothing to do if in spec expression (why not???)
3378 if In_Spec_Expression
then
3381 elsif Is_Private_Type
(Typ
)
3382 and then not Has_Discriminants
(Typ
)
3384 -- If the type has no discriminants, there is no subtype to
3385 -- build, even if the underlying type is discriminated.
3389 -- Else build the actual subtype
3392 Decl
:= Build_Actual_Subtype
(Typ
, N
);
3393 Atyp
:= Defining_Identifier
(Decl
);
3395 -- If Build_Actual_Subtype generated a new declaration then use it
3399 -- The actual subtype is an Itype, so analyze the declaration,
3400 -- but do not attach it to the tree, to get the type defined.
3402 Set_Parent
(Decl
, N
);
3403 Set_Is_Itype
(Atyp
);
3404 Analyze
(Decl
, Suppress
=> All_Checks
);
3405 Set_Associated_Node_For_Itype
(Atyp
, N
);
3406 Set_Has_Delayed_Freeze
(Atyp
, False);
3408 -- We need to freeze the actual subtype immediately. This is
3409 -- needed, because otherwise this Itype will not get frozen
3410 -- at all, and it is always safe to freeze on creation because
3411 -- any associated types must be frozen at this point.
3413 Freeze_Itype
(Atyp
, N
);
3416 -- Otherwise we did not build a declaration, so return original
3423 -- For all remaining cases, the actual subtype is the same as
3424 -- the nominal type.
3429 end Get_Actual_Subtype
;
3431 -------------------------------------
3432 -- Get_Actual_Subtype_If_Available --
3433 -------------------------------------
3435 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
3436 Typ
: constant Entity_Id
:= Etype
(N
);
3439 -- If what we have is an identifier that references a subprogram
3440 -- formal, or a variable or constant object, then we get the actual
3441 -- subtype from the referenced entity if one has been built.
3443 if Nkind
(N
) = N_Identifier
3445 (Is_Formal
(Entity
(N
))
3446 or else Ekind
(Entity
(N
)) = E_Constant
3447 or else Ekind
(Entity
(N
)) = E_Variable
)
3448 and then Present
(Actual_Subtype
(Entity
(N
)))
3450 return Actual_Subtype
(Entity
(N
));
3452 -- Otherwise the Etype of N is returned unchanged
3457 end Get_Actual_Subtype_If_Available
;
3459 -------------------------------
3460 -- Get_Default_External_Name --
3461 -------------------------------
3463 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
3465 Get_Decoded_Name_String
(Chars
(E
));
3467 if Opt
.External_Name_Imp_Casing
= Uppercase
then
3468 Set_Casing
(All_Upper_Case
);
3470 Set_Casing
(All_Lower_Case
);
3474 Make_String_Literal
(Sloc
(E
),
3475 Strval
=> String_From_Name_Buffer
);
3476 end Get_Default_External_Name
;
3478 ---------------------------
3479 -- Get_Enum_Lit_From_Pos --
3480 ---------------------------
3482 function Get_Enum_Lit_From_Pos
3485 Loc
: Source_Ptr
) return Node_Id
3490 -- In the case where the literal is of type Character, Wide_Character
3491 -- or Wide_Wide_Character or of a type derived from them, there needs
3492 -- to be some special handling since there is no explicit chain of
3493 -- literals to search. Instead, an N_Character_Literal node is created
3494 -- with the appropriate Char_Code and Chars fields.
3496 if Is_Standard_Character_Type
(T
) then
3497 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
3499 Make_Character_Literal
(Loc
,
3501 Char_Literal_Value
=> Pos
);
3503 -- For all other cases, we have a complete table of literals, and
3504 -- we simply iterate through the chain of literal until the one
3505 -- with the desired position value is found.
3509 Lit
:= First_Literal
(Base_Type
(T
));
3510 for J
in 1 .. UI_To_Int
(Pos
) loop
3514 return New_Occurrence_Of
(Lit
, Loc
);
3516 end Get_Enum_Lit_From_Pos
;
3518 ------------------------
3519 -- Get_Generic_Entity --
3520 ------------------------
3522 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
3523 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
3525 if Present
(Renamed_Object
(Ent
)) then
3526 return Renamed_Object
(Ent
);
3530 end Get_Generic_Entity
;
3532 ----------------------
3533 -- Get_Index_Bounds --
3534 ----------------------
3536 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
3537 Kind
: constant Node_Kind
:= Nkind
(N
);
3541 if Kind
= N_Range
then
3543 H
:= High_Bound
(N
);
3545 elsif Kind
= N_Subtype_Indication
then
3546 R
:= Range_Expression
(Constraint
(N
));
3554 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
3555 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
3558 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
3559 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
3563 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
3564 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
3567 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
3568 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
3572 -- N is an expression, indicating a range with one value
3577 end Get_Index_Bounds
;
3579 ----------------------------------
3580 -- Get_Library_Unit_Name_string --
3581 ----------------------------------
3583 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
3584 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
3587 Get_Unit_Name_String
(Unit_Name_Id
);
3589 -- Remove seven last character (" (spec)" or " (body)")
3591 Name_Len
:= Name_Len
- 7;
3592 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
3593 end Get_Library_Unit_Name_String
;
3595 ------------------------
3596 -- Get_Name_Entity_Id --
3597 ------------------------
3599 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
3601 return Entity_Id
(Get_Name_Table_Info
(Id
));
3602 end Get_Name_Entity_Id
;
3608 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
3610 return Get_Pragma_Id
(Pragma_Name
(N
));
3613 ---------------------------
3614 -- Get_Referenced_Object --
3615 ---------------------------
3617 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
3622 while Is_Entity_Name
(R
)
3623 and then Present
(Renamed_Object
(Entity
(R
)))
3625 R
:= Renamed_Object
(Entity
(R
));
3629 end Get_Referenced_Object
;
3631 ------------------------
3632 -- Get_Renamed_Entity --
3633 ------------------------
3635 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
3640 while Present
(Renamed_Entity
(R
)) loop
3641 R
:= Renamed_Entity
(R
);
3645 end Get_Renamed_Entity
;
3647 -------------------------
3648 -- Get_Subprogram_Body --
3649 -------------------------
3651 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
3655 Decl
:= Unit_Declaration_Node
(E
);
3657 if Nkind
(Decl
) = N_Subprogram_Body
then
3660 -- The below comment is bad, because it is possible for
3661 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3663 else -- Nkind (Decl) = N_Subprogram_Declaration
3665 if Present
(Corresponding_Body
(Decl
)) then
3666 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
3668 -- Imported subprogram case
3674 end Get_Subprogram_Body
;
3676 ---------------------------
3677 -- Get_Subprogram_Entity --
3678 ---------------------------
3680 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
3685 if Nkind
(Nod
) = N_Accept_Statement
then
3686 Nam
:= Entry_Direct_Name
(Nod
);
3688 -- For an entry call, the prefix of the call is a selected component.
3689 -- Need additional code for internal calls ???
3691 elsif Nkind
(Nod
) = N_Entry_Call_Statement
then
3692 if Nkind
(Name
(Nod
)) = N_Selected_Component
then
3693 Nam
:= Entity
(Selector_Name
(Name
(Nod
)));
3702 if Nkind
(Nam
) = N_Explicit_Dereference
then
3703 Proc
:= Etype
(Prefix
(Nam
));
3704 elsif Is_Entity_Name
(Nam
) then
3705 Proc
:= Entity
(Nam
);
3710 if Is_Object
(Proc
) then
3711 Proc
:= Etype
(Proc
);
3714 if Ekind
(Proc
) = E_Access_Subprogram_Type
then
3715 Proc
:= Directly_Designated_Type
(Proc
);
3718 if not Is_Subprogram
(Proc
)
3719 and then Ekind
(Proc
) /= E_Subprogram_Type
3725 end Get_Subprogram_Entity
;
3727 -----------------------------
3728 -- Get_Task_Body_Procedure --
3729 -----------------------------
3731 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
3733 -- Note: A task type may be the completion of a private type with
3734 -- discriminants. When performing elaboration checks on a task
3735 -- declaration, the current view of the type may be the private one,
3736 -- and the procedure that holds the body of the task is held in its
3739 -- This is an odd function, why not have Task_Body_Procedure do
3740 -- the following digging???
3742 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
3743 end Get_Task_Body_Procedure
;
3745 -----------------------
3746 -- Has_Access_Values --
3747 -----------------------
3749 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
3750 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
3753 -- Case of a private type which is not completed yet. This can only
3754 -- happen in the case of a generic format type appearing directly, or
3755 -- as a component of the type to which this function is being applied
3756 -- at the top level. Return False in this case, since we certainly do
3757 -- not know that the type contains access types.
3762 elsif Is_Access_Type
(Typ
) then
3765 elsif Is_Array_Type
(Typ
) then
3766 return Has_Access_Values
(Component_Type
(Typ
));
3768 elsif Is_Record_Type
(Typ
) then
3773 -- Loop to Check components
3775 Comp
:= First_Component_Or_Discriminant
(Typ
);
3776 while Present
(Comp
) loop
3778 -- Check for access component, tag field does not count, even
3779 -- though it is implemented internally using an access type.
3781 if Has_Access_Values
(Etype
(Comp
))
3782 and then Chars
(Comp
) /= Name_uTag
3787 Next_Component_Or_Discriminant
(Comp
);
3796 end Has_Access_Values
;
3798 ------------------------------
3799 -- Has_Compatible_Alignment --
3800 ------------------------------
3802 function Has_Compatible_Alignment
3804 Expr
: Node_Id
) return Alignment_Result
3806 function Has_Compatible_Alignment_Internal
3809 Default
: Alignment_Result
) return Alignment_Result
;
3810 -- This is the internal recursive function that actually does the work.
3811 -- There is one additional parameter, which says what the result should
3812 -- be if no alignment information is found, and there is no definite
3813 -- indication of compatible alignments. At the outer level, this is set
3814 -- to Unknown, but for internal recursive calls in the case where types
3815 -- are known to be correct, it is set to Known_Compatible.
3817 ---------------------------------------
3818 -- Has_Compatible_Alignment_Internal --
3819 ---------------------------------------
3821 function Has_Compatible_Alignment_Internal
3824 Default
: Alignment_Result
) return Alignment_Result
3826 Result
: Alignment_Result
:= Known_Compatible
;
3827 -- Set to result if Problem_Prefix or Problem_Offset returns True.
3828 -- Note that once a value of Known_Incompatible is set, it is sticky
3829 -- and does not get changed to Unknown (the value in Result only gets
3830 -- worse as we go along, never better).
3832 procedure Check_Offset
(Offs
: Uint
);
3833 -- Called when Expr is a selected or indexed component with Offs set
3834 -- to resp Component_First_Bit or Component_Size. Checks that if the
3835 -- offset is specified it is compatible with the object alignment
3836 -- requirements. The value in Result is modified accordingly.
3838 procedure Check_Prefix
;
3839 -- Checks the prefix recursively in the case where the expression
3840 -- is an indexed or selected component.
3842 procedure Set_Result
(R
: Alignment_Result
);
3843 -- If R represents a worse outcome (unknown instead of known
3844 -- compatible, or known incompatible), then set Result to R.
3850 procedure Check_Offset
(Offs
: Uint
) is
3852 -- Unspecified or zero offset is always OK
3854 if Offs
= No_Uint
or else Offs
= Uint_0
then
3857 -- If we do not know required alignment, any non-zero offset is
3858 -- a potential problem (but certainly may be OK, so result is
3861 elsif Unknown_Alignment
(Obj
) then
3862 Set_Result
(Unknown
);
3864 -- If we know the required alignment, see if offset is compatible
3867 if Offs
mod (System_Storage_Unit
* Alignment
(Obj
)) /= 0 then
3868 Set_Result
(Known_Incompatible
);
3877 procedure Check_Prefix
is
3879 -- The subtlety here is that in doing a recursive call to check
3880 -- the prefix, we have to decide what to do in the case where we
3881 -- don't find any specific indication of an alignment problem.
3883 -- At the outer level, we normally set Unknown as the result in
3884 -- this case, since we can only set Known_Compatible if we really
3885 -- know that the alignment value is OK, but for the recursive
3886 -- call, in the case where the types match, and we have not
3887 -- specified a peculiar alignment for the object, we are only
3888 -- concerned about suspicious rep clauses, the default case does
3889 -- not affect us, since the compiler will, in the absence of such
3890 -- rep clauses, ensure that the alignment is correct.
3892 if Default
= Known_Compatible
3894 (Etype
(Obj
) = Etype
(Expr
)
3895 and then (Unknown_Alignment
(Obj
)
3897 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
3900 (Has_Compatible_Alignment_Internal
3901 (Obj
, Prefix
(Expr
), Known_Compatible
));
3903 -- In all other cases, we need a full check on the prefix
3907 (Has_Compatible_Alignment_Internal
3908 (Obj
, Prefix
(Expr
), Unknown
));
3916 procedure Set_Result
(R
: Alignment_Result
) is
3923 -- Start of processing for Has_Compatible_Alignment_Internal
3926 -- If Expr is a selected component, we must make sure there is no
3927 -- potentially troublesome component clause, and that the record is
3930 if Nkind
(Expr
) = N_Selected_Component
then
3932 -- Packed record always generate unknown alignment
3934 if Is_Packed
(Etype
(Prefix
(Expr
))) then
3935 Set_Result
(Unknown
);
3938 -- Check possible bad component offset and check prefix
3941 (Component_Bit_Offset
(Entity
(Selector_Name
(Expr
))));
3944 -- If Expr is an indexed component, we must make sure there is no
3945 -- potentially troublesome Component_Size clause and that the array
3946 -- is not bit-packed.
3948 elsif Nkind
(Expr
) = N_Indexed_Component
then
3950 -- Bit packed array always generates unknown alignment
3952 if Is_Bit_Packed_Array
(Etype
(Prefix
(Expr
))) then
3953 Set_Result
(Unknown
);
3956 -- Check possible bad component size and check prefix
3958 Check_Offset
(Component_Size
(Etype
(Prefix
(Expr
))));
3962 -- Case where we know the alignment of the object
3964 if Known_Alignment
(Obj
) then
3966 ObjA
: constant Uint
:= Alignment
(Obj
);
3967 ExpA
: Uint
:= No_Uint
;
3968 SizA
: Uint
:= No_Uint
;
3971 -- If alignment of Obj is 1, then we are always OK
3974 Set_Result
(Known_Compatible
);
3976 -- Alignment of Obj is greater than 1, so we need to check
3979 -- See if Expr is an object with known alignment
3981 if Is_Entity_Name
(Expr
)
3982 and then Known_Alignment
(Entity
(Expr
))
3984 ExpA
:= Alignment
(Entity
(Expr
));
3986 -- Otherwise, we can use the alignment of the type of
3987 -- Expr given that we already checked for
3988 -- discombobulating rep clauses for the cases of indexed
3989 -- and selected components above.
3991 elsif Known_Alignment
(Etype
(Expr
)) then
3992 ExpA
:= Alignment
(Etype
(Expr
));
3995 -- If we got an alignment, see if it is acceptable
3997 if ExpA
/= No_Uint
then
3999 Set_Result
(Known_Incompatible
);
4002 -- Case of Expr alignment unknown
4005 Set_Result
(Default
);
4008 -- See if size is given. If so, check that it is not too
4009 -- small for the required alignment.
4010 -- See if Expr is an object with known alignment
4012 if Is_Entity_Name
(Expr
)
4013 and then Known_Static_Esize
(Entity
(Expr
))
4015 SizA
:= Esize
(Entity
(Expr
));
4017 -- Otherwise, we check the object size of the Expr type
4019 elsif Known_Static_Esize
(Etype
(Expr
)) then
4020 SizA
:= Esize
(Etype
(Expr
));
4023 -- If we got a size, see if it is a multiple of the Obj
4024 -- alignment, if not, then the alignment cannot be
4025 -- acceptable, since the size is always a multiple of the
4028 if SizA
/= No_Uint
then
4029 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
4030 Set_Result
(Known_Incompatible
);
4036 -- If we can't find the result by direct comparison of alignment
4037 -- values, then there is still one case that we can determine known
4038 -- result, and that is when we can determine that the types are the
4039 -- same, and no alignments are specified. Then we known that the
4040 -- alignments are compatible, even if we don't know the alignment
4041 -- value in the front end.
4043 elsif Etype
(Obj
) = Etype
(Expr
) then
4045 -- Types are the same, but we have to check for possible size
4046 -- and alignments on the Expr object that may make the alignment
4047 -- different, even though the types are the same.
4049 if Is_Entity_Name
(Expr
) then
4051 -- First check alignment of the Expr object. Any alignment less
4052 -- than Maximum_Alignment is worrisome since this is the case
4053 -- where we do not know the alignment of Obj.
4055 if Known_Alignment
(Entity
(Expr
))
4057 UI_To_Int
(Alignment
(Entity
(Expr
)))
4058 < Ttypes
.Maximum_Alignment
4060 Set_Result
(Unknown
);
4062 -- Now check size of Expr object. Any size that is not an
4063 -- even multiple of Maximum_Alignment is also worrisome
4064 -- since it may cause the alignment of the object to be less
4065 -- than the alignment of the type.
4067 elsif Known_Static_Esize
(Entity
(Expr
))
4069 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
4070 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
4073 Set_Result
(Unknown
);
4075 -- Otherwise same type is decisive
4078 Set_Result
(Known_Compatible
);
4082 -- Another case to deal with is when there is an explicit size or
4083 -- alignment clause when the types are not the same. If so, then the
4084 -- result is Unknown. We don't need to do this test if the Default is
4085 -- Unknown, since that result will be set in any case.
4087 elsif Default
/= Unknown
4088 and then (Has_Size_Clause
(Etype
(Expr
))
4090 Has_Alignment_Clause
(Etype
(Expr
)))
4092 Set_Result
(Unknown
);
4094 -- If no indication found, set default
4097 Set_Result
(Default
);
4100 -- Return worst result found
4103 end Has_Compatible_Alignment_Internal
;
4105 -- Start of processing for Has_Compatible_Alignment
4108 -- If Obj has no specified alignment, then set alignment from the type
4109 -- alignment. Perhaps we should always do this, but for sure we should
4110 -- do it when there is an address clause since we can do more if the
4111 -- alignment is known.
4113 if Unknown_Alignment
(Obj
) then
4114 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
4117 -- Now do the internal call that does all the work
4119 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
4120 end Has_Compatible_Alignment
;
4122 ----------------------
4123 -- Has_Declarations --
4124 ----------------------
4126 function Has_Declarations
(N
: Node_Id
) return Boolean is
4127 K
: constant Node_Kind
:= Nkind
(N
);
4129 return K
= N_Accept_Statement
4130 or else K
= N_Block_Statement
4131 or else K
= N_Compilation_Unit_Aux
4132 or else K
= N_Entry_Body
4133 or else K
= N_Package_Body
4134 or else K
= N_Protected_Body
4135 or else K
= N_Subprogram_Body
4136 or else K
= N_Task_Body
4137 or else K
= N_Package_Specification
;
4138 end Has_Declarations
;
4140 -------------------------------------------
4141 -- Has_Discriminant_Dependent_Constraint --
4142 -------------------------------------------
4144 function Has_Discriminant_Dependent_Constraint
4145 (Comp
: Entity_Id
) return Boolean
4147 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
4148 Subt_Indic
: constant Node_Id
:=
4149 Subtype_Indication
(Component_Definition
(Comp_Decl
));
4154 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
4155 Constr
:= Constraint
(Subt_Indic
);
4157 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
4158 Assn
:= First
(Constraints
(Constr
));
4159 while Present
(Assn
) loop
4160 case Nkind
(Assn
) is
4161 when N_Subtype_Indication |
4165 if Depends_On_Discriminant
(Assn
) then
4169 when N_Discriminant_Association
=>
4170 if Depends_On_Discriminant
(Expression
(Assn
)) then
4185 end Has_Discriminant_Dependent_Constraint
;
4187 --------------------
4188 -- Has_Infinities --
4189 --------------------
4191 function Has_Infinities
(E
: Entity_Id
) return Boolean is
4194 Is_Floating_Point_Type
(E
)
4195 and then Nkind
(Scalar_Range
(E
)) = N_Range
4196 and then Includes_Infinities
(Scalar_Range
(E
));
4199 --------------------
4200 -- Has_Interfaces --
4201 --------------------
4203 function Has_Interfaces
4205 Use_Full_View
: Boolean := True) return Boolean
4210 -- Handle concurrent types
4212 if Is_Concurrent_Type
(T
) then
4213 Typ
:= Corresponding_Record_Type
(T
);
4218 if not Present
(Typ
)
4219 or else not Is_Record_Type
(Typ
)
4220 or else not Is_Tagged_Type
(Typ
)
4225 -- Handle private types
4228 and then Present
(Full_View
(Typ
))
4230 Typ
:= Full_View
(Typ
);
4233 -- Handle concurrent record types
4235 if Is_Concurrent_Record_Type
(Typ
)
4236 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
4242 if Is_Interface
(Typ
)
4244 (Is_Record_Type
(Typ
)
4245 and then Present
(Interfaces
(Typ
))
4246 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
4251 exit when Etype
(Typ
) = Typ
4253 -- Handle private types
4255 or else (Present
(Full_View
(Etype
(Typ
)))
4256 and then Full_View
(Etype
(Typ
)) = Typ
)
4258 -- Protect the frontend against wrong source with cyclic
4261 or else Etype
(Typ
) = T
;
4263 -- Climb to the ancestor type handling private types
4265 if Present
(Full_View
(Etype
(Typ
))) then
4266 Typ
:= Full_View
(Etype
(Typ
));
4275 ------------------------
4276 -- Has_Null_Exclusion --
4277 ------------------------
4279 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
4282 when N_Access_Definition |
4283 N_Access_Function_Definition |
4284 N_Access_Procedure_Definition |
4285 N_Access_To_Object_Definition |
4287 N_Derived_Type_Definition |
4288 N_Function_Specification |
4289 N_Subtype_Declaration
=>
4290 return Null_Exclusion_Present
(N
);
4292 when N_Component_Definition |
4293 N_Formal_Object_Declaration |
4294 N_Object_Renaming_Declaration
=>
4295 if Present
(Subtype_Mark
(N
)) then
4296 return Null_Exclusion_Present
(N
);
4297 else pragma Assert
(Present
(Access_Definition
(N
)));
4298 return Null_Exclusion_Present
(Access_Definition
(N
));
4301 when N_Discriminant_Specification
=>
4302 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
4303 return Null_Exclusion_Present
(Discriminant_Type
(N
));
4305 return Null_Exclusion_Present
(N
);
4308 when N_Object_Declaration
=>
4309 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
4310 return Null_Exclusion_Present
(Object_Definition
(N
));
4312 return Null_Exclusion_Present
(N
);
4315 when N_Parameter_Specification
=>
4316 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
4317 return Null_Exclusion_Present
(Parameter_Type
(N
));
4319 return Null_Exclusion_Present
(N
);
4326 end Has_Null_Exclusion
;
4328 ------------------------
4329 -- Has_Null_Extension --
4330 ------------------------
4332 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
4333 B
: constant Entity_Id
:= Base_Type
(T
);
4338 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
4339 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
4341 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
4343 if Present
(Ext
) then
4344 if Null_Present
(Ext
) then
4347 Comps
:= Component_List
(Ext
);
4349 -- The null component list is rewritten during analysis to
4350 -- include the parent component. Any other component indicates
4351 -- that the extension was not originally null.
4353 return Null_Present
(Comps
)
4354 or else No
(Next
(First
(Component_Items
(Comps
))));
4363 end Has_Null_Extension
;
4365 -------------------------------
4366 -- Has_Overriding_Initialize --
4367 -------------------------------
4369 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
4370 BT
: constant Entity_Id
:= Base_Type
(T
);
4375 if Is_Controlled
(BT
) then
4377 -- For derived types, check immediate ancestor, excluding
4378 -- Controlled itself.
4380 if Is_Derived_Type
(BT
)
4381 and then not In_Predefined_Unit
(Etype
(BT
))
4382 and then Has_Overriding_Initialize
(Etype
(BT
))
4386 elsif Present
(Primitive_Operations
(BT
)) then
4387 P
:= First_Elmt
(Primitive_Operations
(BT
));
4388 while Present
(P
) loop
4389 if Chars
(Node
(P
)) = Name_Initialize
4390 and then Comes_From_Source
(Node
(P
))
4401 elsif Has_Controlled_Component
(BT
) then
4402 Comp
:= First_Component
(BT
);
4403 while Present
(Comp
) loop
4404 if Has_Overriding_Initialize
(Etype
(Comp
)) then
4408 Next_Component
(Comp
);
4416 end Has_Overriding_Initialize
;
4418 --------------------------------------
4419 -- Has_Preelaborable_Initialization --
4420 --------------------------------------
4422 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
4425 procedure Check_Components
(E
: Entity_Id
);
4426 -- Check component/discriminant chain, sets Has_PE False if a component
4427 -- or discriminant does not meet the preelaborable initialization rules.
4429 ----------------------
4430 -- Check_Components --
4431 ----------------------
4433 procedure Check_Components
(E
: Entity_Id
) is
4437 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
4438 -- Returns True if and only if the expression denoted by N does not
4439 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4441 ---------------------------------
4442 -- Is_Preelaborable_Expression --
4443 ---------------------------------
4445 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
4449 Comp_Type
: Entity_Id
;
4450 Is_Array_Aggr
: Boolean;
4453 if Is_Static_Expression
(N
) then
4456 elsif Nkind
(N
) = N_Null
then
4459 -- Attributes are allowed in general, even if their prefix is a
4460 -- formal type. (It seems that certain attributes known not to be
4461 -- static might not be allowed, but there are no rules to prevent
4464 elsif Nkind
(N
) = N_Attribute_Reference
then
4467 -- The name of a discriminant evaluated within its parent type is
4468 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4469 -- names that denote discriminals as well as discriminants to
4470 -- catch references occurring within init procs.
4472 elsif Is_Entity_Name
(N
)
4474 (Ekind
(Entity
(N
)) = E_Discriminant
4476 ((Ekind
(Entity
(N
)) = E_Constant
4477 or else Ekind
(Entity
(N
)) = E_In_Parameter
)
4478 and then Present
(Discriminal_Link
(Entity
(N
)))))
4482 elsif Nkind
(N
) = N_Qualified_Expression
then
4483 return Is_Preelaborable_Expression
(Expression
(N
));
4485 -- For aggregates we have to check that each of the associations
4486 -- is preelaborable.
4488 elsif Nkind
(N
) = N_Aggregate
4489 or else Nkind
(N
) = N_Extension_Aggregate
4491 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
4493 if Is_Array_Aggr
then
4494 Comp_Type
:= Component_Type
(Etype
(N
));
4497 -- Check the ancestor part of extension aggregates, which must
4498 -- be either the name of a type that has preelaborable init or
4499 -- an expression that is preelaborable.
4501 if Nkind
(N
) = N_Extension_Aggregate
then
4503 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
4506 if Is_Entity_Name
(Anc_Part
)
4507 and then Is_Type
(Entity
(Anc_Part
))
4509 if not Has_Preelaborable_Initialization
4515 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
4521 -- Check positional associations
4523 Exp
:= First
(Expressions
(N
));
4524 while Present
(Exp
) loop
4525 if not Is_Preelaborable_Expression
(Exp
) then
4532 -- Check named associations
4534 Assn
:= First
(Component_Associations
(N
));
4535 while Present
(Assn
) loop
4536 Choice
:= First
(Choices
(Assn
));
4537 while Present
(Choice
) loop
4538 if Is_Array_Aggr
then
4539 if Nkind
(Choice
) = N_Others_Choice
then
4542 elsif Nkind
(Choice
) = N_Range
then
4543 if not Is_Static_Range
(Choice
) then
4547 elsif not Is_Static_Expression
(Choice
) then
4552 Comp_Type
:= Etype
(Choice
);
4558 -- If the association has a <> at this point, then we have
4559 -- to check whether the component's type has preelaborable
4560 -- initialization. Note that this only occurs when the
4561 -- association's corresponding component does not have a
4562 -- default expression, the latter case having already been
4563 -- expanded as an expression for the association.
4565 if Box_Present
(Assn
) then
4566 if not Has_Preelaborable_Initialization
(Comp_Type
) then
4570 -- In the expression case we check whether the expression
4571 -- is preelaborable.
4574 not Is_Preelaborable_Expression
(Expression
(Assn
))
4582 -- If we get here then aggregate as a whole is preelaborable
4586 -- All other cases are not preelaborable
4591 end Is_Preelaborable_Expression
;
4593 -- Start of processing for Check_Components
4596 -- Loop through entities of record or protected type
4599 while Present
(Ent
) loop
4601 -- We are interested only in components and discriminants
4603 if Ekind
(Ent
) = E_Component
4605 Ekind
(Ent
) = E_Discriminant
4607 -- Get default expression if any. If there is no declaration
4608 -- node, it means we have an internal entity. The parent and
4609 -- tag fields are examples of such entities. For these cases,
4610 -- we just test the type of the entity.
4612 if Present
(Declaration_Node
(Ent
)) then
4613 Exp
:= Expression
(Declaration_Node
(Ent
));
4618 -- A component has PI if it has no default expression and the
4619 -- component type has PI.
4622 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
4627 -- Require the default expression to be preelaborable
4629 elsif not Is_Preelaborable_Expression
(Exp
) then
4637 end Check_Components
;
4639 -- Start of processing for Has_Preelaborable_Initialization
4642 -- Immediate return if already marked as known preelaborable init. This
4643 -- covers types for which this function has already been called once
4644 -- and returned True (in which case the result is cached), and also
4645 -- types to which a pragma Preelaborable_Initialization applies.
4647 if Known_To_Have_Preelab_Init
(E
) then
4651 -- If the type is a subtype representing a generic actual type, then
4652 -- test whether its base type has preelaborable initialization since
4653 -- the subtype representing the actual does not inherit this attribute
4654 -- from the actual or formal. (but maybe it should???)
4656 if Is_Generic_Actual_Type
(E
) then
4657 return Has_Preelaborable_Initialization
(Base_Type
(E
));
4660 -- All elementary types have preelaborable initialization
4662 if Is_Elementary_Type
(E
) then
4665 -- Array types have PI if the component type has PI
4667 elsif Is_Array_Type
(E
) then
4668 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
4670 -- A derived type has preelaborable initialization if its parent type
4671 -- has preelaborable initialization and (in the case of a derived record
4672 -- extension) if the non-inherited components all have preelaborable
4673 -- initialization. However, a user-defined controlled type with an
4674 -- overriding Initialize procedure does not have preelaborable
4677 elsif Is_Derived_Type
(E
) then
4679 -- If the derived type is a private extension then it doesn't have
4680 -- preelaborable initialization.
4682 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
4686 -- First check whether ancestor type has preelaborable initialization
4688 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
4690 -- If OK, check extension components (if any)
4692 if Has_PE
and then Is_Record_Type
(E
) then
4693 Check_Components
(First_Entity
(E
));
4696 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4697 -- with a user defined Initialize procedure does not have PI.
4700 and then Is_Controlled
(E
)
4701 and then Has_Overriding_Initialize
(E
)
4706 -- Private types not derived from a type having preelaborable init and
4707 -- that are not marked with pragma Preelaborable_Initialization do not
4708 -- have preelaborable initialization.
4710 elsif Is_Private_Type
(E
) then
4713 -- Record type has PI if it is non private and all components have PI
4715 elsif Is_Record_Type
(E
) then
4717 Check_Components
(First_Entity
(E
));
4719 -- Protected types must not have entries, and components must meet
4720 -- same set of rules as for record components.
4722 elsif Is_Protected_Type
(E
) then
4723 if Has_Entries
(E
) then
4727 Check_Components
(First_Entity
(E
));
4728 Check_Components
(First_Private_Entity
(E
));
4731 -- Type System.Address always has preelaborable initialization
4733 elsif Is_RTE
(E
, RE_Address
) then
4736 -- In all other cases, type does not have preelaborable initialization
4742 -- If type has preelaborable initialization, cache result
4745 Set_Known_To_Have_Preelab_Init
(E
);
4749 end Has_Preelaborable_Initialization
;
4751 ---------------------------
4752 -- Has_Private_Component --
4753 ---------------------------
4755 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
4756 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
4757 Component
: Entity_Id
;
4760 if Error_Posted
(Type_Id
)
4761 or else Error_Posted
(Btype
)
4766 if Is_Class_Wide_Type
(Btype
) then
4767 Btype
:= Root_Type
(Btype
);
4770 if Is_Private_Type
(Btype
) then
4772 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
4775 if No
(Full_View
(Btype
)) then
4776 return not Is_Generic_Type
(Btype
)
4777 and then not Is_Generic_Type
(Root_Type
(Btype
));
4779 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
4782 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
4786 elsif Is_Array_Type
(Btype
) then
4787 return Has_Private_Component
(Component_Type
(Btype
));
4789 elsif Is_Record_Type
(Btype
) then
4790 Component
:= First_Component
(Btype
);
4791 while Present
(Component
) loop
4792 if Has_Private_Component
(Etype
(Component
)) then
4796 Next_Component
(Component
);
4801 elsif Is_Protected_Type
(Btype
)
4802 and then Present
(Corresponding_Record_Type
(Btype
))
4804 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
4809 end Has_Private_Component
;
4815 function Has_Stream
(T
: Entity_Id
) return Boolean is
4822 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
4825 elsif Is_Array_Type
(T
) then
4826 return Has_Stream
(Component_Type
(T
));
4828 elsif Is_Record_Type
(T
) then
4829 E
:= First_Component
(T
);
4830 while Present
(E
) loop
4831 if Has_Stream
(Etype
(E
)) then
4840 elsif Is_Private_Type
(T
) then
4841 return Has_Stream
(Underlying_Type
(T
));
4848 --------------------------
4849 -- Has_Tagged_Component --
4850 --------------------------
4852 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
4856 if Is_Private_Type
(Typ
)
4857 and then Present
(Underlying_Type
(Typ
))
4859 return Has_Tagged_Component
(Underlying_Type
(Typ
));
4861 elsif Is_Array_Type
(Typ
) then
4862 return Has_Tagged_Component
(Component_Type
(Typ
));
4864 elsif Is_Tagged_Type
(Typ
) then
4867 elsif Is_Record_Type
(Typ
) then
4868 Comp
:= First_Component
(Typ
);
4869 while Present
(Comp
) loop
4870 if Has_Tagged_Component
(Etype
(Comp
)) then
4874 Next_Component
(Comp
);
4882 end Has_Tagged_Component
;
4884 --------------------------
4885 -- Implements_Interface --
4886 --------------------------
4888 function Implements_Interface
4889 (Typ_Ent
: Entity_Id
;
4890 Iface_Ent
: Entity_Id
;
4891 Exclude_Parents
: Boolean := False) return Boolean
4893 Ifaces_List
: Elist_Id
;
4899 if Is_Class_Wide_Type
(Typ_Ent
) then
4900 Typ
:= Etype
(Typ_Ent
);
4905 if Is_Class_Wide_Type
(Iface_Ent
) then
4906 Iface
:= Etype
(Iface_Ent
);
4911 if not Has_Interfaces
(Typ
) then
4915 Collect_Interfaces
(Typ
, Ifaces_List
);
4917 Elmt
:= First_Elmt
(Ifaces_List
);
4918 while Present
(Elmt
) loop
4919 if Is_Ancestor
(Node
(Elmt
), Typ
)
4920 and then Exclude_Parents
4924 elsif Node
(Elmt
) = Iface
then
4932 end Implements_Interface
;
4938 function In_Instance
return Boolean is
4939 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
4945 and then S
/= Standard_Standard
4947 if (Ekind
(S
) = E_Function
4948 or else Ekind
(S
) = E_Package
4949 or else Ekind
(S
) = E_Procedure
)
4950 and then Is_Generic_Instance
(S
)
4952 -- A child instance is always compiled in the context of a parent
4953 -- instance. Nevertheless, the actuals are not analyzed in an
4954 -- instance context. We detect this case by examining the current
4955 -- compilation unit, which must be a child instance, and checking
4956 -- that it is not currently on the scope stack.
4958 if Is_Child_Unit
(Curr_Unit
)
4960 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)))
4961 = N_Package_Instantiation
4962 and then not In_Open_Scopes
(Curr_Unit
)
4976 ----------------------
4977 -- In_Instance_Body --
4978 ----------------------
4980 function In_Instance_Body
return Boolean is
4986 and then S
/= Standard_Standard
4988 if (Ekind
(S
) = E_Function
4989 or else Ekind
(S
) = E_Procedure
)
4990 and then Is_Generic_Instance
(S
)
4994 elsif Ekind
(S
) = E_Package
4995 and then In_Package_Body
(S
)
4996 and then Is_Generic_Instance
(S
)
5005 end In_Instance_Body
;
5007 -----------------------------
5008 -- In_Instance_Not_Visible --
5009 -----------------------------
5011 function In_Instance_Not_Visible
return Boolean is
5017 and then S
/= Standard_Standard
5019 if (Ekind
(S
) = E_Function
5020 or else Ekind
(S
) = E_Procedure
)
5021 and then Is_Generic_Instance
(S
)
5025 elsif Ekind
(S
) = E_Package
5026 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
5027 and then Is_Generic_Instance
(S
)
5036 end In_Instance_Not_Visible
;
5038 ------------------------------
5039 -- In_Instance_Visible_Part --
5040 ------------------------------
5042 function In_Instance_Visible_Part
return Boolean is
5048 and then S
/= Standard_Standard
5050 if Ekind
(S
) = E_Package
5051 and then Is_Generic_Instance
(S
)
5052 and then not In_Package_Body
(S
)
5053 and then not In_Private_Part
(S
)
5062 end In_Instance_Visible_Part
;
5064 ---------------------
5065 -- In_Package_Body --
5066 ---------------------
5068 function In_Package_Body
return Boolean is
5074 and then S
/= Standard_Standard
5076 if Ekind
(S
) = E_Package
5077 and then In_Package_Body
(S
)
5086 end In_Package_Body
;
5088 --------------------------------
5089 -- In_Parameter_Specification --
5090 --------------------------------
5092 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
5097 while Present
(PN
) loop
5098 if Nkind
(PN
) = N_Parameter_Specification
then
5106 end In_Parameter_Specification
;
5108 --------------------------------------
5109 -- In_Subprogram_Or_Concurrent_Unit --
5110 --------------------------------------
5112 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
5117 -- Use scope chain to check successively outer scopes
5123 if K
in Subprogram_Kind
5124 or else K
in Concurrent_Kind
5125 or else K
in Generic_Subprogram_Kind
5129 elsif E
= Standard_Standard
then
5135 end In_Subprogram_Or_Concurrent_Unit
;
5137 ---------------------
5138 -- In_Visible_Part --
5139 ---------------------
5141 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
5144 Is_Package_Or_Generic_Package
(Scope_Id
)
5145 and then In_Open_Scopes
(Scope_Id
)
5146 and then not In_Package_Body
(Scope_Id
)
5147 and then not In_Private_Part
(Scope_Id
);
5148 end In_Visible_Part
;
5150 ---------------------------------
5151 -- Insert_Explicit_Dereference --
5152 ---------------------------------
5154 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
5155 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
5156 Ent
: Entity_Id
:= Empty
;
5163 Save_Interps
(N
, New_Prefix
);
5165 Make_Explicit_Dereference
(Sloc
(N
),
5166 Prefix
=> New_Prefix
));
5168 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
5170 if Is_Overloaded
(New_Prefix
) then
5172 -- The deference is also overloaded, and its interpretations are the
5173 -- designated types of the interpretations of the original node.
5175 Set_Etype
(N
, Any_Type
);
5177 Get_First_Interp
(New_Prefix
, I
, It
);
5178 while Present
(It
.Nam
) loop
5181 if Is_Access_Type
(T
) then
5182 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
5185 Get_Next_Interp
(I
, It
);
5191 -- Prefix is unambiguous: mark the original prefix (which might
5192 -- Come_From_Source) as a reference, since the new (relocated) one
5193 -- won't be taken into account.
5195 if Is_Entity_Name
(New_Prefix
) then
5196 Ent
:= Entity
(New_Prefix
);
5198 -- For a retrieval of a subcomponent of some composite object,
5199 -- retrieve the ultimate entity if there is one.
5201 elsif Nkind
(New_Prefix
) = N_Selected_Component
5202 or else Nkind
(New_Prefix
) = N_Indexed_Component
5204 Pref
:= Prefix
(New_Prefix
);
5205 while Present
(Pref
)
5207 (Nkind
(Pref
) = N_Selected_Component
5208 or else Nkind
(Pref
) = N_Indexed_Component
)
5210 Pref
:= Prefix
(Pref
);
5213 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
5214 Ent
:= Entity
(Pref
);
5218 if Present
(Ent
) then
5219 Generate_Reference
(Ent
, New_Prefix
);
5222 end Insert_Explicit_Dereference
;
5224 ------------------------------------------
5225 -- Inspect_Deferred_Constant_Completion --
5226 ------------------------------------------
5228 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
5232 Decl
:= First
(Decls
);
5233 while Present
(Decl
) loop
5235 -- Deferred constant signature
5237 if Nkind
(Decl
) = N_Object_Declaration
5238 and then Constant_Present
(Decl
)
5239 and then No
(Expression
(Decl
))
5241 -- No need to check internally generated constants
5243 and then Comes_From_Source
(Decl
)
5245 -- The constant is not completed. A full object declaration
5246 -- or a pragma Import complete a deferred constant.
5248 and then not Has_Completion
(Defining_Identifier
(Decl
))
5251 ("constant declaration requires initialization expression",
5252 Defining_Identifier
(Decl
));
5255 Decl
:= Next
(Decl
);
5257 end Inspect_Deferred_Constant_Completion
;
5263 function Is_AAMP_Float
(E
: Entity_Id
) return Boolean is
5264 pragma Assert
(Is_Type
(E
));
5266 return AAMP_On_Target
5267 and then Is_Floating_Point_Type
(E
)
5268 and then E
= Base_Type
(E
);
5271 -------------------------
5272 -- Is_Actual_Parameter --
5273 -------------------------
5275 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
5276 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
5280 when N_Parameter_Association
=>
5281 return N
= Explicit_Actual_Parameter
(Parent
(N
));
5283 when N_Function_Call | N_Procedure_Call_Statement
=>
5284 return Is_List_Member
(N
)
5286 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
5291 end Is_Actual_Parameter
;
5293 ---------------------
5294 -- Is_Aliased_View --
5295 ---------------------
5297 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
5301 if Is_Entity_Name
(Obj
) then
5309 or else (Present
(Renamed_Object
(E
))
5310 and then Is_Aliased_View
(Renamed_Object
(E
)))))
5312 or else ((Is_Formal
(E
)
5313 or else Ekind
(E
) = E_Generic_In_Out_Parameter
5314 or else Ekind
(E
) = E_Generic_In_Parameter
)
5315 and then Is_Tagged_Type
(Etype
(E
)))
5317 or else (Is_Concurrent_Type
(E
)
5318 and then In_Open_Scopes
(E
))
5320 -- Current instance of type, either directly or as rewritten
5321 -- reference to the current object.
5323 or else (Is_Entity_Name
(Original_Node
(Obj
))
5324 and then Present
(Entity
(Original_Node
(Obj
)))
5325 and then Is_Type
(Entity
(Original_Node
(Obj
))))
5327 or else (Is_Type
(E
) and then E
= Current_Scope
)
5329 or else (Is_Incomplete_Or_Private_Type
(E
)
5330 and then Full_View
(E
) = Current_Scope
);
5332 elsif Nkind
(Obj
) = N_Selected_Component
then
5333 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
5335 elsif Nkind
(Obj
) = N_Indexed_Component
then
5336 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
5338 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
5340 Has_Aliased_Components
5341 (Designated_Type
(Etype
(Prefix
(Obj
)))));
5343 elsif Nkind
(Obj
) = N_Unchecked_Type_Conversion
5344 or else Nkind
(Obj
) = N_Type_Conversion
5346 return Is_Tagged_Type
(Etype
(Obj
))
5347 and then Is_Aliased_View
(Expression
(Obj
));
5349 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
5350 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
5355 end Is_Aliased_View
;
5357 -------------------------
5358 -- Is_Ancestor_Package --
5359 -------------------------
5361 function Is_Ancestor_Package
5363 E2
: Entity_Id
) return Boolean
5370 and then Par
/= Standard_Standard
5380 end Is_Ancestor_Package
;
5382 ----------------------
5383 -- Is_Atomic_Object --
5384 ----------------------
5386 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
5388 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
5389 -- Determines if given object has atomic components
5391 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
5392 -- If prefix is an implicit dereference, examine designated type
5394 ----------------------
5395 -- Is_Atomic_Prefix --
5396 ----------------------
5398 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
5400 if Is_Access_Type
(Etype
(N
)) then
5402 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
5404 return Object_Has_Atomic_Components
(N
);
5406 end Is_Atomic_Prefix
;
5408 ----------------------------------
5409 -- Object_Has_Atomic_Components --
5410 ----------------------------------
5412 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
5414 if Has_Atomic_Components
(Etype
(N
))
5415 or else Is_Atomic
(Etype
(N
))
5419 elsif Is_Entity_Name
(N
)
5420 and then (Has_Atomic_Components
(Entity
(N
))
5421 or else Is_Atomic
(Entity
(N
)))
5425 elsif Nkind
(N
) = N_Indexed_Component
5426 or else Nkind
(N
) = N_Selected_Component
5428 return Is_Atomic_Prefix
(Prefix
(N
));
5433 end Object_Has_Atomic_Components
;
5435 -- Start of processing for Is_Atomic_Object
5438 if Is_Atomic
(Etype
(N
))
5439 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
5443 elsif Nkind
(N
) = N_Indexed_Component
5444 or else Nkind
(N
) = N_Selected_Component
5446 return Is_Atomic_Prefix
(Prefix
(N
));
5451 end Is_Atomic_Object
;
5453 -------------------------
5454 -- Is_Coextension_Root --
5455 -------------------------
5457 function Is_Coextension_Root
(N
: Node_Id
) return Boolean is
5460 Nkind
(N
) = N_Allocator
5461 and then Present
(Coextensions
(N
))
5463 -- Anonymous access discriminants carry a list of all nested
5464 -- controlled coextensions.
5466 and then not Is_Dynamic_Coextension
(N
)
5467 and then not Is_Static_Coextension
(N
);
5468 end Is_Coextension_Root
;
5470 -----------------------------
5471 -- Is_Concurrent_Interface --
5472 -----------------------------
5474 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
5479 (Is_Protected_Interface
(T
)
5480 or else Is_Synchronized_Interface
(T
)
5481 or else Is_Task_Interface
(T
));
5482 end Is_Concurrent_Interface
;
5484 --------------------------------------
5485 -- Is_Controlling_Limited_Procedure --
5486 --------------------------------------
5488 function Is_Controlling_Limited_Procedure
5489 (Proc_Nam
: Entity_Id
) return Boolean
5491 Param_Typ
: Entity_Id
:= Empty
;
5494 if Ekind
(Proc_Nam
) = E_Procedure
5495 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
5497 Param_Typ
:= Etype
(Parameter_Type
(First
(
5498 Parameter_Specifications
(Parent
(Proc_Nam
)))));
5500 -- In this case where an Itype was created, the procedure call has been
5503 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
5504 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
5506 Present
(Parameter_Associations
5507 (Associated_Node_For_Itype
(Proc_Nam
)))
5510 Etype
(First
(Parameter_Associations
5511 (Associated_Node_For_Itype
(Proc_Nam
))));
5514 if Present
(Param_Typ
) then
5516 Is_Interface
(Param_Typ
)
5517 and then Is_Limited_Record
(Param_Typ
);
5521 end Is_Controlling_Limited_Procedure
;
5523 ----------------------------------------------
5524 -- Is_Dependent_Component_Of_Mutable_Object --
5525 ----------------------------------------------
5527 function Is_Dependent_Component_Of_Mutable_Object
5528 (Object
: Node_Id
) return Boolean
5531 Prefix_Type
: Entity_Id
;
5532 P_Aliased
: Boolean := False;
5535 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
5536 -- Returns True if and only if Comp is declared within a variant part
5538 --------------------------------
5539 -- Is_Declared_Within_Variant --
5540 --------------------------------
5542 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
5543 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
5544 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
5546 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
5547 end Is_Declared_Within_Variant
;
5549 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5552 if Is_Variable
(Object
) then
5554 if Nkind
(Object
) = N_Selected_Component
then
5555 P
:= Prefix
(Object
);
5556 Prefix_Type
:= Etype
(P
);
5558 if Is_Entity_Name
(P
) then
5560 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
5561 Prefix_Type
:= Base_Type
(Prefix_Type
);
5564 if Is_Aliased
(Entity
(P
)) then
5568 -- A discriminant check on a selected component may be
5569 -- expanded into a dereference when removing side-effects.
5570 -- Recover the original node and its type, which may be
5573 elsif Nkind
(P
) = N_Explicit_Dereference
5574 and then not (Comes_From_Source
(P
))
5576 P
:= Original_Node
(P
);
5577 Prefix_Type
:= Etype
(P
);
5580 -- Check for prefix being an aliased component ???
5585 -- A heap object is constrained by its initial value
5587 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5588 -- the dereferenced case, since the access value might denote an
5589 -- unconstrained aliased object, whereas in Ada 95 the designated
5590 -- object is guaranteed to be constrained. A worst-case assumption
5591 -- has to apply in Ada 2005 because we can't tell at compile time
5592 -- whether the object is "constrained by its initial value"
5593 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5594 -- semantic rules -- these rules are acknowledged to need fixing).
5596 if Ada_Version
< Ada_05
then
5597 if Is_Access_Type
(Prefix_Type
)
5598 or else Nkind
(P
) = N_Explicit_Dereference
5603 elsif Ada_Version
>= Ada_05
then
5604 if Is_Access_Type
(Prefix_Type
) then
5606 -- If the access type is pool-specific, and there is no
5607 -- constrained partial view of the designated type, then the
5608 -- designated object is known to be constrained.
5610 if Ekind
(Prefix_Type
) = E_Access_Type
5611 and then not Has_Constrained_Partial_View
5612 (Designated_Type
(Prefix_Type
))
5616 -- Otherwise (general access type, or there is a constrained
5617 -- partial view of the designated type), we need to check
5618 -- based on the designated type.
5621 Prefix_Type
:= Designated_Type
(Prefix_Type
);
5627 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
5629 -- As per AI-0017, the renaming is illegal in a generic body,
5630 -- even if the subtype is indefinite.
5632 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5634 if not Is_Constrained
(Prefix_Type
)
5635 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
5637 (Is_Generic_Type
(Prefix_Type
)
5638 and then Ekind
(Current_Scope
) = E_Generic_Package
5639 and then In_Package_Body
(Current_Scope
)))
5641 and then (Is_Declared_Within_Variant
(Comp
)
5642 or else Has_Discriminant_Dependent_Constraint
(Comp
))
5643 and then (not P_Aliased
or else Ada_Version
>= Ada_05
)
5649 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
5653 elsif Nkind
(Object
) = N_Indexed_Component
5654 or else Nkind
(Object
) = N_Slice
5656 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
5658 -- A type conversion that Is_Variable is a view conversion:
5659 -- go back to the denoted object.
5661 elsif Nkind
(Object
) = N_Type_Conversion
then
5663 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
5668 end Is_Dependent_Component_Of_Mutable_Object
;
5670 ---------------------
5671 -- Is_Dereferenced --
5672 ---------------------
5674 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
5675 P
: constant Node_Id
:= Parent
(N
);
5678 (Nkind
(P
) = N_Selected_Component
5680 Nkind
(P
) = N_Explicit_Dereference
5682 Nkind
(P
) = N_Indexed_Component
5684 Nkind
(P
) = N_Slice
)
5685 and then Prefix
(P
) = N
;
5686 end Is_Dereferenced
;
5688 ----------------------
5689 -- Is_Descendent_Of --
5690 ----------------------
5692 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
5697 pragma Assert
(Nkind
(T1
) in N_Entity
);
5698 pragma Assert
(Nkind
(T2
) in N_Entity
);
5700 T
:= Base_Type
(T1
);
5702 -- Immediate return if the types match
5707 -- Comment needed here ???
5709 elsif Ekind
(T
) = E_Class_Wide_Type
then
5710 return Etype
(T
) = T2
;
5718 -- Done if we found the type we are looking for
5723 -- Done if no more derivations to check
5730 -- Following test catches error cases resulting from prev errors
5732 elsif No
(Etyp
) then
5735 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
5738 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
5742 T
:= Base_Type
(Etyp
);
5745 end Is_Descendent_Of
;
5751 function Is_False
(U
: Uint
) return Boolean is
5756 ---------------------------
5757 -- Is_Fixed_Model_Number --
5758 ---------------------------
5760 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
5761 S
: constant Ureal
:= Small_Value
(T
);
5762 M
: Urealp
.Save_Mark
;
5766 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
5769 end Is_Fixed_Model_Number
;
5771 -------------------------------
5772 -- Is_Fully_Initialized_Type --
5773 -------------------------------
5775 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
5777 if Is_Scalar_Type
(Typ
) then
5780 elsif Is_Access_Type
(Typ
) then
5783 elsif Is_Array_Type
(Typ
) then
5784 if Is_Fully_Initialized_Type
(Component_Type
(Typ
)) then
5788 -- An interesting case, if we have a constrained type one of whose
5789 -- bounds is known to be null, then there are no elements to be
5790 -- initialized, so all the elements are initialized!
5792 if Is_Constrained
(Typ
) then
5795 Indx_Typ
: Entity_Id
;
5799 Indx
:= First_Index
(Typ
);
5800 while Present
(Indx
) loop
5801 if Etype
(Indx
) = Any_Type
then
5804 -- If index is a range, use directly
5806 elsif Nkind
(Indx
) = N_Range
then
5807 Lbd
:= Low_Bound
(Indx
);
5808 Hbd
:= High_Bound
(Indx
);
5811 Indx_Typ
:= Etype
(Indx
);
5813 if Is_Private_Type
(Indx_Typ
) then
5814 Indx_Typ
:= Full_View
(Indx_Typ
);
5817 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
5820 Lbd
:= Type_Low_Bound
(Indx_Typ
);
5821 Hbd
:= Type_High_Bound
(Indx_Typ
);
5825 if Compile_Time_Known_Value
(Lbd
)
5826 and then Compile_Time_Known_Value
(Hbd
)
5828 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
5838 -- If no null indexes, then type is not fully initialized
5844 elsif Is_Record_Type
(Typ
) then
5845 if Has_Discriminants
(Typ
)
5847 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
5848 and then Is_Fully_Initialized_Variant
(Typ
)
5853 -- Controlled records are considered to be fully initialized if
5854 -- there is a user defined Initialize routine. This may not be
5855 -- entirely correct, but as the spec notes, we are guessing here
5856 -- what is best from the point of view of issuing warnings.
5858 if Is_Controlled
(Typ
) then
5860 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
5863 if Present
(Utyp
) then
5865 Init
: constant Entity_Id
:=
5867 (Underlying_Type
(Typ
), Name_Initialize
));
5871 and then Comes_From_Source
(Init
)
5873 Is_Predefined_File_Name
5874 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
5878 elsif Has_Null_Extension
(Typ
)
5880 Is_Fully_Initialized_Type
5881 (Etype
(Base_Type
(Typ
)))
5890 -- Otherwise see if all record components are initialized
5896 Ent
:= First_Entity
(Typ
);
5897 while Present
(Ent
) loop
5898 if Chars
(Ent
) = Name_uController
then
5901 elsif Ekind
(Ent
) = E_Component
5902 and then (No
(Parent
(Ent
))
5903 or else No
(Expression
(Parent
(Ent
))))
5904 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
5906 -- Special VM case for tag components, which need to be
5907 -- defined in this case, but are never initialized as VMs
5908 -- are using other dispatching mechanisms. Ignore this
5909 -- uninitialized case. Note that this applies both to the
5910 -- uTag entry and the main vtable pointer (CPP_Class case).
5912 and then (VM_Target
= No_VM
or else not Is_Tag
(Ent
))
5921 -- No uninitialized components, so type is fully initialized.
5922 -- Note that this catches the case of no components as well.
5926 elsif Is_Concurrent_Type
(Typ
) then
5929 elsif Is_Private_Type
(Typ
) then
5931 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
5937 return Is_Fully_Initialized_Type
(U
);
5944 end Is_Fully_Initialized_Type
;
5946 ----------------------------------
5947 -- Is_Fully_Initialized_Variant --
5948 ----------------------------------
5950 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
5951 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5952 Constraints
: constant List_Id
:= New_List
;
5953 Components
: constant Elist_Id
:= New_Elmt_List
;
5954 Comp_Elmt
: Elmt_Id
;
5956 Comp_List
: Node_Id
;
5958 Discr_Val
: Node_Id
;
5960 Report_Errors
: Boolean;
5961 pragma Warnings
(Off
, Report_Errors
);
5964 if Serious_Errors_Detected
> 0 then
5968 if Is_Record_Type
(Typ
)
5969 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
5970 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
5972 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
5974 Discr
:= First_Discriminant
(Typ
);
5975 while Present
(Discr
) loop
5976 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
5977 Discr_Val
:= Expression
(Parent
(Discr
));
5979 if Present
(Discr_Val
)
5980 and then Is_OK_Static_Expression
(Discr_Val
)
5982 Append_To
(Constraints
,
5983 Make_Component_Association
(Loc
,
5984 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
5985 Expression
=> New_Copy
(Discr_Val
)));
5993 Next_Discriminant
(Discr
);
5998 Comp_List
=> Comp_List
,
5999 Governed_By
=> Constraints
,
6001 Report_Errors
=> Report_Errors
);
6003 -- Check that each component present is fully initialized
6005 Comp_Elmt
:= First_Elmt
(Components
);
6006 while Present
(Comp_Elmt
) loop
6007 Comp_Id
:= Node
(Comp_Elmt
);
6009 if Ekind
(Comp_Id
) = E_Component
6010 and then (No
(Parent
(Comp_Id
))
6011 or else No
(Expression
(Parent
(Comp_Id
))))
6012 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
6017 Next_Elmt
(Comp_Elmt
);
6022 elsif Is_Private_Type
(Typ
) then
6024 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
6030 return Is_Fully_Initialized_Variant
(U
);
6036 end Is_Fully_Initialized_Variant
;
6038 ----------------------------
6039 -- Is_Inherited_Operation --
6040 ----------------------------
6042 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
6043 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
6045 pragma Assert
(Is_Overloadable
(E
));
6046 return Kind
= N_Full_Type_Declaration
6047 or else Kind
= N_Private_Extension_Declaration
6048 or else Kind
= N_Subtype_Declaration
6049 or else (Ekind
(E
) = E_Enumeration_Literal
6050 and then Is_Derived_Type
(Etype
(E
)));
6051 end Is_Inherited_Operation
;
6053 -----------------------------
6054 -- Is_Library_Level_Entity --
6055 -----------------------------
6057 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
6059 -- The following is a small optimization, and it also properly handles
6060 -- discriminals, which in task bodies might appear in expressions before
6061 -- the corresponding procedure has been created, and which therefore do
6062 -- not have an assigned scope.
6064 if Ekind
(E
) in Formal_Kind
then
6068 -- Normal test is simply that the enclosing dynamic scope is Standard
6070 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
6071 end Is_Library_Level_Entity
;
6073 ---------------------------------
6074 -- Is_Local_Variable_Reference --
6075 ---------------------------------
6077 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
6079 if not Is_Entity_Name
(Expr
) then
6084 Ent
: constant Entity_Id
:= Entity
(Expr
);
6085 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
6087 if Ekind
(Ent
) /= E_Variable
6089 Ekind
(Ent
) /= E_In_Out_Parameter
6093 return Present
(Sub
) and then Sub
= Current_Subprogram
;
6097 end Is_Local_Variable_Reference
;
6099 -------------------------
6100 -- Is_Object_Reference --
6101 -------------------------
6103 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
6105 if Is_Entity_Name
(N
) then
6106 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
6110 when N_Indexed_Component | N_Slice
=>
6112 Is_Object_Reference
(Prefix
(N
))
6113 or else Is_Access_Type
(Etype
(Prefix
(N
)));
6115 -- In Ada95, a function call is a constant object; a procedure
6118 when N_Function_Call
=>
6119 return Etype
(N
) /= Standard_Void_Type
;
6121 -- A reference to the stream attribute Input is a function call
6123 when N_Attribute_Reference
=>
6124 return Attribute_Name
(N
) = Name_Input
;
6126 when N_Selected_Component
=>
6128 Is_Object_Reference
(Selector_Name
(N
))
6130 (Is_Object_Reference
(Prefix
(N
))
6131 or else Is_Access_Type
(Etype
(Prefix
(N
))));
6133 when N_Explicit_Dereference
=>
6136 -- A view conversion of a tagged object is an object reference
6138 when N_Type_Conversion
=>
6139 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
6140 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
6141 and then Is_Object_Reference
(Expression
(N
));
6143 -- An unchecked type conversion is considered to be an object if
6144 -- the operand is an object (this construction arises only as a
6145 -- result of expansion activities).
6147 when N_Unchecked_Type_Conversion
=>
6154 end Is_Object_Reference
;
6156 -----------------------------------
6157 -- Is_OK_Variable_For_Out_Formal --
6158 -----------------------------------
6160 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
6162 Note_Possible_Modification
(AV
, Sure
=> True);
6164 -- We must reject parenthesized variable names. The check for
6165 -- Comes_From_Source is present because there are currently
6166 -- cases where the compiler violates this rule (e.g. passing
6167 -- a task object to its controlled Initialize routine).
6169 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
6172 -- A variable is always allowed
6174 elsif Is_Variable
(AV
) then
6177 -- Unchecked conversions are allowed only if they come from the
6178 -- generated code, which sometimes uses unchecked conversions for out
6179 -- parameters in cases where code generation is unaffected. We tell
6180 -- source unchecked conversions by seeing if they are rewrites of an
6181 -- original Unchecked_Conversion function call, or of an explicit
6182 -- conversion of a function call.
6184 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
6185 if Nkind
(Original_Node
(AV
)) = N_Function_Call
then
6188 elsif Comes_From_Source
(AV
)
6189 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
6193 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
6194 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
6200 -- Normal type conversions are allowed if argument is a variable
6202 elsif Nkind
(AV
) = N_Type_Conversion
then
6203 if Is_Variable
(Expression
(AV
))
6204 and then Paren_Count
(Expression
(AV
)) = 0
6206 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
6209 -- We also allow a non-parenthesized expression that raises
6210 -- constraint error if it rewrites what used to be a variable
6212 elsif Raises_Constraint_Error
(Expression
(AV
))
6213 and then Paren_Count
(Expression
(AV
)) = 0
6214 and then Is_Variable
(Original_Node
(Expression
(AV
)))
6218 -- Type conversion of something other than a variable
6224 -- If this node is rewritten, then test the original form, if that is
6225 -- OK, then we consider the rewritten node OK (for example, if the
6226 -- original node is a conversion, then Is_Variable will not be true
6227 -- but we still want to allow the conversion if it converts a variable).
6229 elsif Original_Node
(AV
) /= AV
then
6230 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
6232 -- All other non-variables are rejected
6237 end Is_OK_Variable_For_Out_Formal
;
6239 -----------------------------------
6240 -- Is_Partially_Initialized_Type --
6241 -----------------------------------
6243 function Is_Partially_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
6245 if Is_Scalar_Type
(Typ
) then
6248 elsif Is_Access_Type
(Typ
) then
6251 elsif Is_Array_Type
(Typ
) then
6253 -- If component type is partially initialized, so is array type
6255 if Is_Partially_Initialized_Type
(Component_Type
(Typ
)) then
6258 -- Otherwise we are only partially initialized if we are fully
6259 -- initialized (this is the empty array case, no point in us
6260 -- duplicating that code here).
6263 return Is_Fully_Initialized_Type
(Typ
);
6266 elsif Is_Record_Type
(Typ
) then
6268 -- A discriminated type is always partially initialized
6270 if Has_Discriminants
(Typ
) then
6273 -- A tagged type is always partially initialized
6275 elsif Is_Tagged_Type
(Typ
) then
6278 -- Case of non-discriminated record
6284 Component_Present
: Boolean := False;
6285 -- Set True if at least one component is present. If no
6286 -- components are present, then record type is fully
6287 -- initialized (another odd case, like the null array).
6290 -- Loop through components
6292 Ent
:= First_Entity
(Typ
);
6293 while Present
(Ent
) loop
6294 if Ekind
(Ent
) = E_Component
then
6295 Component_Present
:= True;
6297 -- If a component has an initialization expression then
6298 -- the enclosing record type is partially initialized
6300 if Present
(Parent
(Ent
))
6301 and then Present
(Expression
(Parent
(Ent
)))
6305 -- If a component is of a type which is itself partially
6306 -- initialized, then the enclosing record type is also.
6308 elsif Is_Partially_Initialized_Type
(Etype
(Ent
)) then
6316 -- No initialized components found. If we found any components
6317 -- they were all uninitialized so the result is false.
6319 if Component_Present
then
6322 -- But if we found no components, then all the components are
6323 -- initialized so we consider the type to be initialized.
6331 -- Concurrent types are always fully initialized
6333 elsif Is_Concurrent_Type
(Typ
) then
6336 -- For a private type, go to underlying type. If there is no underlying
6337 -- type then just assume this partially initialized. Not clear if this
6338 -- can happen in a non-error case, but no harm in testing for this.
6340 elsif Is_Private_Type
(Typ
) then
6342 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
6347 return Is_Partially_Initialized_Type
(U
);
6351 -- For any other type (are there any?) assume partially initialized
6356 end Is_Partially_Initialized_Type
;
6358 ------------------------------------
6359 -- Is_Potentially_Persistent_Type --
6360 ------------------------------------
6362 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
6367 -- For private type, test corresponding full type
6369 if Is_Private_Type
(T
) then
6370 return Is_Potentially_Persistent_Type
(Full_View
(T
));
6372 -- Scalar types are potentially persistent
6374 elsif Is_Scalar_Type
(T
) then
6377 -- Record type is potentially persistent if not tagged and the types of
6378 -- all it components are potentially persistent, and no component has
6379 -- an initialization expression.
6381 elsif Is_Record_Type
(T
)
6382 and then not Is_Tagged_Type
(T
)
6383 and then not Is_Partially_Initialized_Type
(T
)
6385 Comp
:= First_Component
(T
);
6386 while Present
(Comp
) loop
6387 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
6396 -- Array type is potentially persistent if its component type is
6397 -- potentially persistent and if all its constraints are static.
6399 elsif Is_Array_Type
(T
) then
6400 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
6404 Indx
:= First_Index
(T
);
6405 while Present
(Indx
) loop
6406 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
6415 -- All other types are not potentially persistent
6420 end Is_Potentially_Persistent_Type
;
6422 ---------------------------------
6423 -- Is_Protected_Self_Reference --
6424 ---------------------------------
6426 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
6428 function In_Access_Definition
(N
: Node_Id
) return Boolean;
6429 -- Returns true if N belongs to an access definition
6431 --------------------------
6432 -- In_Access_Definition --
6433 --------------------------
6435 function In_Access_Definition
(N
: Node_Id
) return Boolean is
6440 while Present
(P
) loop
6441 if Nkind
(P
) = N_Access_Definition
then
6449 end In_Access_Definition
;
6451 -- Start of processing for Is_Protected_Self_Reference
6454 -- Verify that prefix is analyzed and has the proper form. Note that
6455 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
6456 -- produce the address of an entity, do not analyze their prefix
6457 -- because they denote entities that are not necessarily visible.
6458 -- Neither of them can apply to a protected type.
6460 return Ada_Version
>= Ada_05
6461 and then Is_Entity_Name
(N
)
6462 and then Present
(Entity
(N
))
6463 and then Is_Protected_Type
(Entity
(N
))
6464 and then In_Open_Scopes
(Entity
(N
))
6465 and then not In_Access_Definition
(N
);
6466 end Is_Protected_Self_Reference
;
6468 -----------------------------
6469 -- Is_RCI_Pkg_Spec_Or_Body --
6470 -----------------------------
6472 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
6474 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
6475 -- Return True if the unit of Cunit is an RCI package declaration
6477 ---------------------------
6478 -- Is_RCI_Pkg_Decl_Cunit --
6479 ---------------------------
6481 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
6482 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
6485 if Nkind
(The_Unit
) /= N_Package_Declaration
then
6489 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
6490 end Is_RCI_Pkg_Decl_Cunit
;
6492 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6495 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
6497 (Nkind
(Unit
(Cunit
)) = N_Package_Body
6498 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
6499 end Is_RCI_Pkg_Spec_Or_Body
;
6501 -----------------------------------------
6502 -- Is_Remote_Access_To_Class_Wide_Type --
6503 -----------------------------------------
6505 function Is_Remote_Access_To_Class_Wide_Type
6506 (E
: Entity_Id
) return Boolean
6509 -- A remote access to class-wide type is a general access to object type
6510 -- declared in the visible part of a Remote_Types or Remote_Call_
6513 return Ekind
(E
) = E_General_Access_Type
6514 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
6515 end Is_Remote_Access_To_Class_Wide_Type
;
6517 -----------------------------------------
6518 -- Is_Remote_Access_To_Subprogram_Type --
6519 -----------------------------------------
6521 function Is_Remote_Access_To_Subprogram_Type
6522 (E
: Entity_Id
) return Boolean
6525 return (Ekind
(E
) = E_Access_Subprogram_Type
6526 or else (Ekind
(E
) = E_Record_Type
6527 and then Present
(Corresponding_Remote_Type
(E
))))
6528 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
6529 end Is_Remote_Access_To_Subprogram_Type
;
6531 --------------------
6532 -- Is_Remote_Call --
6533 --------------------
6535 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
6537 if Nkind
(N
) /= N_Procedure_Call_Statement
6538 and then Nkind
(N
) /= N_Function_Call
6540 -- An entry call cannot be remote
6544 elsif Nkind
(Name
(N
)) in N_Has_Entity
6545 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
6547 -- A subprogram declared in the spec of a RCI package is remote
6551 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
6552 and then Is_Remote_Access_To_Subprogram_Type
6553 (Etype
(Prefix
(Name
(N
))))
6555 -- The dereference of a RAS is a remote call
6559 elsif Present
(Controlling_Argument
(N
))
6560 and then Is_Remote_Access_To_Class_Wide_Type
6561 (Etype
(Controlling_Argument
(N
)))
6563 -- Any primitive operation call with a controlling argument of
6564 -- a RACW type is a remote call.
6569 -- All other calls are local calls
6574 ----------------------
6575 -- Is_Renamed_Entry --
6576 ----------------------
6578 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
6579 Orig_Node
: Node_Id
:= Empty
;
6580 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
6582 function Is_Entry
(Nam
: Node_Id
) return Boolean;
6583 -- Determine whether Nam is an entry. Traverse selectors if there are
6584 -- nested selected components.
6590 function Is_Entry
(Nam
: Node_Id
) return Boolean is
6592 if Nkind
(Nam
) = N_Selected_Component
then
6593 return Is_Entry
(Selector_Name
(Nam
));
6596 return Ekind
(Entity
(Nam
)) = E_Entry
;
6599 -- Start of processing for Is_Renamed_Entry
6602 if Present
(Alias
(Proc_Nam
)) then
6603 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
6606 -- Look for a rewritten subprogram renaming declaration
6608 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
6609 and then Present
(Original_Node
(Subp_Decl
))
6611 Orig_Node
:= Original_Node
(Subp_Decl
);
6614 -- The rewritten subprogram is actually an entry
6616 if Present
(Orig_Node
)
6617 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
6618 and then Is_Entry
(Name
(Orig_Node
))
6624 end Is_Renamed_Entry
;
6626 ----------------------
6627 -- Is_Selector_Name --
6628 ----------------------
6630 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
6632 if not Is_List_Member
(N
) then
6634 P
: constant Node_Id
:= Parent
(N
);
6635 K
: constant Node_Kind
:= Nkind
(P
);
6638 (K
= N_Expanded_Name
or else
6639 K
= N_Generic_Association
or else
6640 K
= N_Parameter_Association
or else
6641 K
= N_Selected_Component
)
6642 and then Selector_Name
(P
) = N
;
6647 L
: constant List_Id
:= List_Containing
(N
);
6648 P
: constant Node_Id
:= Parent
(L
);
6650 return (Nkind
(P
) = N_Discriminant_Association
6651 and then Selector_Names
(P
) = L
)
6653 (Nkind
(P
) = N_Component_Association
6654 and then Choices
(P
) = L
);
6657 end Is_Selector_Name
;
6663 function Is_Statement
(N
: Node_Id
) return Boolean is
6666 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
6667 or else Nkind
(N
) = N_Procedure_Call_Statement
;
6670 ---------------------------------
6671 -- Is_Synchronized_Tagged_Type --
6672 ---------------------------------
6674 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
6675 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
6678 -- A task or protected type derived from an interface is a tagged type.
6679 -- Such a tagged type is called a synchronized tagged type, as are
6680 -- synchronized interfaces and private extensions whose declaration
6681 -- includes the reserved word synchronized.
6683 return (Is_Tagged_Type
(E
)
6684 and then (Kind
= E_Task_Type
6685 or else Kind
= E_Protected_Type
))
6688 and then Is_Synchronized_Interface
(E
))
6690 (Ekind
(E
) = E_Record_Type_With_Private
6691 and then (Synchronized_Present
(Parent
(E
))
6692 or else Is_Synchronized_Interface
(Etype
(E
))));
6693 end Is_Synchronized_Tagged_Type
;
6699 function Is_Transfer
(N
: Node_Id
) return Boolean is
6700 Kind
: constant Node_Kind
:= Nkind
(N
);
6703 if Kind
= N_Simple_Return_Statement
6705 Kind
= N_Extended_Return_Statement
6707 Kind
= N_Goto_Statement
6709 Kind
= N_Raise_Statement
6711 Kind
= N_Requeue_Statement
6715 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
6716 and then No
(Condition
(N
))
6720 elsif Kind
= N_Procedure_Call_Statement
6721 and then Is_Entity_Name
(Name
(N
))
6722 and then Present
(Entity
(Name
(N
)))
6723 and then No_Return
(Entity
(Name
(N
)))
6727 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
6739 function Is_True
(U
: Uint
) return Boolean is
6748 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
6750 return VM_Target
= CLI_Target
6751 and then Chars
(T
) /= No_Name
6752 and then Get_Name_String
(Chars
(T
)) = "valuetype";
6759 function Is_Variable
(N
: Node_Id
) return Boolean is
6761 Orig_Node
: constant Node_Id
:= Original_Node
(N
);
6762 -- We do the test on the original node, since this is basically a
6763 -- test of syntactic categories, so it must not be disturbed by
6764 -- whatever rewriting might have occurred. For example, an aggregate,
6765 -- which is certainly NOT a variable, could be turned into a variable
6768 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
6769 -- Within a protected function, the private components of the
6770 -- enclosing protected type are constants. A function nested within
6771 -- a (protected) procedure is not itself protected.
6773 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
6774 -- Prefixes can involve implicit dereferences, in which case we
6775 -- must test for the case of a reference of a constant access
6776 -- type, which can never be a variable.
6778 ---------------------------
6779 -- In_Protected_Function --
6780 ---------------------------
6782 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
6783 Prot
: constant Entity_Id
:= Scope
(E
);
6787 if not Is_Protected_Type
(Prot
) then
6791 while Present
(S
) and then S
/= Prot
loop
6792 if Ekind
(S
) = E_Function
6793 and then Scope
(S
) = Prot
6803 end In_Protected_Function
;
6805 ------------------------
6806 -- Is_Variable_Prefix --
6807 ------------------------
6809 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
6811 if Is_Access_Type
(Etype
(P
)) then
6812 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
6814 -- For the case of an indexed component whose prefix has a packed
6815 -- array type, the prefix has been rewritten into a type conversion.
6816 -- Determine variable-ness from the converted expression.
6818 elsif Nkind
(P
) = N_Type_Conversion
6819 and then not Comes_From_Source
(P
)
6820 and then Is_Array_Type
(Etype
(P
))
6821 and then Is_Packed
(Etype
(P
))
6823 return Is_Variable
(Expression
(P
));
6826 return Is_Variable
(P
);
6828 end Is_Variable_Prefix
;
6830 -- Start of processing for Is_Variable
6833 -- Definitely OK if Assignment_OK is set. Since this is something that
6834 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6836 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
6839 -- Normally we go to the original node, but there is one exception
6840 -- where we use the rewritten node, namely when it is an explicit
6841 -- dereference. The generated code may rewrite a prefix which is an
6842 -- access type with an explicit dereference. The dereference is a
6843 -- variable, even though the original node may not be (since it could
6844 -- be a constant of the access type).
6846 -- In Ada 2005 we have a further case to consider: the prefix may be
6847 -- a function call given in prefix notation. The original node appears
6848 -- to be a selected component, but we need to examine the call.
6850 elsif Nkind
(N
) = N_Explicit_Dereference
6851 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
6852 and then Present
(Etype
(Orig_Node
))
6853 and then Is_Access_Type
(Etype
(Orig_Node
))
6855 -- Note that if the prefix is an explicit dereference that does not
6856 -- come from source, we must check for a rewritten function call in
6857 -- prefixed notation before other forms of rewriting, to prevent a
6861 (Nkind
(Orig_Node
) = N_Function_Call
6862 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
6864 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
6866 -- A function call is never a variable
6868 elsif Nkind
(N
) = N_Function_Call
then
6871 -- All remaining checks use the original node
6873 elsif Is_Entity_Name
(Orig_Node
)
6874 and then Present
(Entity
(Orig_Node
))
6877 E
: constant Entity_Id
:= Entity
(Orig_Node
);
6878 K
: constant Entity_Kind
:= Ekind
(E
);
6881 return (K
= E_Variable
6882 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
6883 or else (K
= E_Component
6884 and then not In_Protected_Function
(E
))
6885 or else K
= E_Out_Parameter
6886 or else K
= E_In_Out_Parameter
6887 or else K
= E_Generic_In_Out_Parameter
6889 -- Current instance of type:
6891 or else (Is_Type
(E
) and then In_Open_Scopes
(E
))
6892 or else (Is_Incomplete_Or_Private_Type
(E
)
6893 and then In_Open_Scopes
(Full_View
(E
)));
6897 case Nkind
(Orig_Node
) is
6898 when N_Indexed_Component | N_Slice
=>
6899 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
6901 when N_Selected_Component
=>
6902 return Is_Variable_Prefix
(Prefix
(Orig_Node
))
6903 and then Is_Variable
(Selector_Name
(Orig_Node
));
6905 -- For an explicit dereference, the type of the prefix cannot
6906 -- be an access to constant or an access to subprogram.
6908 when N_Explicit_Dereference
=>
6910 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
6912 return Is_Access_Type
(Typ
)
6913 and then not Is_Access_Constant
(Root_Type
(Typ
))
6914 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
6917 -- The type conversion is the case where we do not deal with the
6918 -- context dependent special case of an actual parameter. Thus
6919 -- the type conversion is only considered a variable for the
6920 -- purposes of this routine if the target type is tagged. However,
6921 -- a type conversion is considered to be a variable if it does not
6922 -- come from source (this deals for example with the conversions
6923 -- of expressions to their actual subtypes).
6925 when N_Type_Conversion
=>
6926 return Is_Variable
(Expression
(Orig_Node
))
6928 (not Comes_From_Source
(Orig_Node
)
6930 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
6932 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
6934 -- GNAT allows an unchecked type conversion as a variable. This
6935 -- only affects the generation of internal expanded code, since
6936 -- calls to instantiations of Unchecked_Conversion are never
6937 -- considered variables (since they are function calls).
6938 -- This is also true for expression actions.
6940 when N_Unchecked_Type_Conversion
=>
6941 return Is_Variable
(Expression
(Orig_Node
));
6949 ------------------------
6950 -- Is_Volatile_Object --
6951 ------------------------
6953 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
6955 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
6956 -- Determines if given object has volatile components
6958 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
6959 -- If prefix is an implicit dereference, examine designated type
6961 ------------------------
6962 -- Is_Volatile_Prefix --
6963 ------------------------
6965 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
6966 Typ
: constant Entity_Id
:= Etype
(N
);
6969 if Is_Access_Type
(Typ
) then
6971 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
6974 return Is_Volatile
(Dtyp
)
6975 or else Has_Volatile_Components
(Dtyp
);
6979 return Object_Has_Volatile_Components
(N
);
6981 end Is_Volatile_Prefix
;
6983 ------------------------------------
6984 -- Object_Has_Volatile_Components --
6985 ------------------------------------
6987 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
6988 Typ
: constant Entity_Id
:= Etype
(N
);
6991 if Is_Volatile
(Typ
)
6992 or else Has_Volatile_Components
(Typ
)
6996 elsif Is_Entity_Name
(N
)
6997 and then (Has_Volatile_Components
(Entity
(N
))
6998 or else Is_Volatile
(Entity
(N
)))
7002 elsif Nkind
(N
) = N_Indexed_Component
7003 or else Nkind
(N
) = N_Selected_Component
7005 return Is_Volatile_Prefix
(Prefix
(N
));
7010 end Object_Has_Volatile_Components
;
7012 -- Start of processing for Is_Volatile_Object
7015 if Is_Volatile
(Etype
(N
))
7016 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
7020 elsif Nkind
(N
) = N_Indexed_Component
7021 or else Nkind
(N
) = N_Selected_Component
7023 return Is_Volatile_Prefix
(Prefix
(N
));
7028 end Is_Volatile_Object
;
7030 -------------------------
7031 -- Kill_Current_Values --
7032 -------------------------
7034 procedure Kill_Current_Values
7036 Last_Assignment_Only
: Boolean := False)
7039 if Is_Assignable
(Ent
) then
7040 Set_Last_Assignment
(Ent
, Empty
);
7043 if not Last_Assignment_Only
and then Is_Object
(Ent
) then
7045 Set_Current_Value
(Ent
, Empty
);
7047 if not Can_Never_Be_Null
(Ent
) then
7048 Set_Is_Known_Non_Null
(Ent
, False);
7051 Set_Is_Known_Null
(Ent
, False);
7053 end Kill_Current_Values
;
7055 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
7058 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
7059 -- Clear current value for entity E and all entities chained to E
7061 ------------------------------------------
7062 -- Kill_Current_Values_For_Entity_Chain --
7063 ------------------------------------------
7065 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
7069 while Present
(Ent
) loop
7070 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
7073 end Kill_Current_Values_For_Entity_Chain
;
7075 -- Start of processing for Kill_Current_Values
7078 -- Kill all saved checks, a special case of killing saved values
7080 if not Last_Assignment_Only
then
7084 -- Loop through relevant scopes, which includes the current scope and
7085 -- any parent scopes if the current scope is a block or a package.
7090 -- Clear current values of all entities in current scope
7092 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
7094 -- If scope is a package, also clear current values of all
7095 -- private entities in the scope.
7097 if Is_Package_Or_Generic_Package
(S
)
7098 or else Is_Concurrent_Type
(S
)
7100 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
7103 -- If this is a not a subprogram, deal with parents
7105 if not Is_Subprogram
(S
) then
7107 exit Scope_Loop
when S
= Standard_Standard
;
7111 end loop Scope_Loop
;
7112 end Kill_Current_Values
;
7114 --------------------------
7115 -- Kill_Size_Check_Code --
7116 --------------------------
7118 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
7120 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
7121 and then Present
(Size_Check_Code
(E
))
7123 Remove
(Size_Check_Code
(E
));
7124 Set_Size_Check_Code
(E
, Empty
);
7126 end Kill_Size_Check_Code
;
7128 --------------------------
7129 -- Known_To_Be_Assigned --
7130 --------------------------
7132 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
7133 P
: constant Node_Id
:= Parent
(N
);
7138 -- Test left side of assignment
7140 when N_Assignment_Statement
=>
7141 return N
= Name
(P
);
7143 -- Function call arguments are never lvalues
7145 when N_Function_Call
=>
7148 -- Positional parameter for procedure or accept call
7150 when N_Procedure_Call_Statement |
7159 Proc
:= Get_Subprogram_Entity
(P
);
7165 -- If we are not a list member, something is strange, so
7166 -- be conservative and return False.
7168 if not Is_List_Member
(N
) then
7172 -- We are going to find the right formal by stepping forward
7173 -- through the formals, as we step backwards in the actuals.
7175 Form
:= First_Formal
(Proc
);
7178 -- If no formal, something is weird, so be conservative
7179 -- and return False.
7190 return Ekind
(Form
) /= E_In_Parameter
;
7193 -- Named parameter for procedure or accept call
7195 when N_Parameter_Association
=>
7201 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
7207 -- Loop through formals to find the one that matches
7209 Form
:= First_Formal
(Proc
);
7211 -- If no matching formal, that's peculiar, some kind of
7212 -- previous error, so return False to be conservative.
7218 -- Else test for match
7220 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
7221 return Ekind
(Form
) /= E_In_Parameter
;
7228 -- Test for appearing in a conversion that itself appears
7229 -- in an lvalue context, since this should be an lvalue.
7231 when N_Type_Conversion
=>
7232 return Known_To_Be_Assigned
(P
);
7234 -- All other references are definitely not known to be modifications
7240 end Known_To_Be_Assigned
;
7246 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
7247 P
: constant Node_Id
:= Parent
(N
);
7252 -- Test left side of assignment
7254 when N_Assignment_Statement
=>
7255 return N
= Name
(P
);
7257 -- Test prefix of component or attribute. Note that the prefix of an
7258 -- explicit or implicit dereference cannot be an l-value.
7260 when N_Attribute_Reference
=>
7261 return N
= Prefix
(P
)
7262 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
7264 when N_Expanded_Name |
7265 N_Indexed_Component |
7266 N_Selected_Component |
7268 if Is_Access_Type
(Etype
(N
)) then
7269 return False; -- P is an implicit dereference
7271 return N
= Prefix
(P
);
7275 return N
= Prefix
(P
);
7277 when N_Explicit_Dereference
=>
7280 -- Function call arguments are never lvalues
7282 when N_Function_Call
=>
7285 -- Positional parameter for procedure, entry, or accept call
7287 when N_Procedure_Call_Statement |
7288 N_Entry_Call_Statement |
7297 Proc
:= Get_Subprogram_Entity
(P
);
7303 -- If we are not a list member, something is strange, so
7304 -- be conservative and return True.
7306 if not Is_List_Member
(N
) then
7310 -- We are going to find the right formal by stepping forward
7311 -- through the formals, as we step backwards in the actuals.
7313 Form
:= First_Formal
(Proc
);
7316 -- If no formal, something is weird, so be conservative
7328 return Ekind
(Form
) /= E_In_Parameter
;
7331 -- Named parameter for procedure or accept call
7333 when N_Parameter_Association
=>
7339 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
7345 -- Loop through formals to find the one that matches
7347 Form
:= First_Formal
(Proc
);
7349 -- If no matching formal, that's peculiar, some kind of
7350 -- previous error, so return True to be conservative.
7356 -- Else test for match
7358 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
7359 return Ekind
(Form
) /= E_In_Parameter
;
7366 -- Test for appearing in a conversion that itself appears in an
7367 -- lvalue context, since this should be an lvalue.
7369 when N_Type_Conversion
=>
7370 return May_Be_Lvalue
(P
);
7372 -- Test for appearance in object renaming declaration
7374 when N_Object_Renaming_Declaration
=>
7377 -- All other references are definitely not Lvalues
7385 -----------------------
7386 -- Mark_Coextensions --
7387 -----------------------
7389 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
7390 Is_Dynamic
: Boolean;
7391 -- Indicates whether the context causes nested coextensions to be
7392 -- dynamic or static
7394 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
7395 -- Recognize an allocator node and label it as a dynamic coextension
7397 --------------------
7398 -- Mark_Allocator --
7399 --------------------
7401 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
7403 if Nkind
(N
) = N_Allocator
then
7405 Set_Is_Dynamic_Coextension
(N
);
7407 Set_Is_Static_Coextension
(N
);
7414 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
7416 -- Start of processing Mark_Coextensions
7419 case Nkind
(Context_Nod
) is
7420 when N_Assignment_Statement |
7421 N_Simple_Return_Statement
=>
7422 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
7424 when N_Object_Declaration
=>
7425 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
;
7427 -- This routine should not be called for constructs which may not
7428 -- contain coextensions.
7431 raise Program_Error
;
7434 Mark_Allocators
(Root_Nod
);
7435 end Mark_Coextensions
;
7437 ----------------------
7438 -- Needs_One_Actual --
7439 ----------------------
7441 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
7445 if Ada_Version
>= Ada_05
7446 and then Present
(First_Formal
(E
))
7448 Formal
:= Next_Formal
(First_Formal
(E
));
7449 while Present
(Formal
) loop
7450 if No
(Default_Value
(Formal
)) then
7454 Next_Formal
(Formal
);
7462 end Needs_One_Actual
;
7464 ------------------------
7465 -- New_Copy_List_Tree --
7466 ------------------------
7468 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
7473 if List
= No_List
then
7480 while Present
(E
) loop
7481 Append
(New_Copy_Tree
(E
), NL
);
7487 end New_Copy_List_Tree
;
7493 use Atree
.Unchecked_Access
;
7494 use Atree_Private_Part
;
7496 -- Our approach here requires a two pass traversal of the tree. The
7497 -- first pass visits all nodes that eventually will be copied looking
7498 -- for defining Itypes. If any defining Itypes are found, then they are
7499 -- copied, and an entry is added to the replacement map. In the second
7500 -- phase, the tree is copied, using the replacement map to replace any
7501 -- Itype references within the copied tree.
7503 -- The following hash tables are used if the Map supplied has more
7504 -- than hash threshhold entries to speed up access to the map. If
7505 -- there are fewer entries, then the map is searched sequentially
7506 -- (because setting up a hash table for only a few entries takes
7507 -- more time than it saves.
7509 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
;
7510 -- Hash function used for hash operations
7516 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
is
7518 return Nat
(E
) mod (NCT_Header_Num
'Last + 1);
7525 -- The hash table NCT_Assoc associates old entities in the table
7526 -- with their corresponding new entities (i.e. the pairs of entries
7527 -- presented in the original Map argument are Key-Element pairs).
7529 package NCT_Assoc
is new Simple_HTable
(
7530 Header_Num
=> NCT_Header_Num
,
7531 Element
=> Entity_Id
,
7532 No_Element
=> Empty
,
7534 Hash
=> New_Copy_Hash
,
7535 Equal
=> Types
."=");
7537 ---------------------
7538 -- NCT_Itype_Assoc --
7539 ---------------------
7541 -- The hash table NCT_Itype_Assoc contains entries only for those
7542 -- old nodes which have a non-empty Associated_Node_For_Itype set.
7543 -- The key is the associated node, and the element is the new node
7544 -- itself (NOT the associated node for the new node).
7546 package NCT_Itype_Assoc
is new Simple_HTable
(
7547 Header_Num
=> NCT_Header_Num
,
7548 Element
=> Entity_Id
,
7549 No_Element
=> Empty
,
7551 Hash
=> New_Copy_Hash
,
7552 Equal
=> Types
."=");
7554 -- Start of processing for New_Copy_Tree function
7556 function New_Copy_Tree
7558 Map
: Elist_Id
:= No_Elist
;
7559 New_Sloc
: Source_Ptr
:= No_Location
;
7560 New_Scope
: Entity_Id
:= Empty
) return Node_Id
7562 Actual_Map
: Elist_Id
:= Map
;
7563 -- This is the actual map for the copy. It is initialized with the
7564 -- given elements, and then enlarged as required for Itypes that are
7565 -- copied during the first phase of the copy operation. The visit
7566 -- procedures add elements to this map as Itypes are encountered.
7567 -- The reason we cannot use Map directly, is that it may well be
7568 -- (and normally is) initialized to No_Elist, and if we have mapped
7569 -- entities, we have to reset it to point to a real Elist.
7571 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
;
7572 -- Called during second phase to map entities into their corresponding
7573 -- copies using Actual_Map. If the argument is not an entity, or is not
7574 -- in Actual_Map, then it is returned unchanged.
7576 procedure Build_NCT_Hash_Tables
;
7577 -- Builds hash tables (number of elements >= threshold value)
7579 function Copy_Elist_With_Replacement
7580 (Old_Elist
: Elist_Id
) return Elist_Id
;
7581 -- Called during second phase to copy element list doing replacements
7583 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
);
7584 -- Called during the second phase to process a copied Itype. The actual
7585 -- copy happened during the first phase (so that we could make the entry
7586 -- in the mapping), but we still have to deal with the descendents of
7587 -- the copied Itype and copy them where necessary.
7589 function Copy_List_With_Replacement
(Old_List
: List_Id
) return List_Id
;
7590 -- Called during second phase to copy list doing replacements
7592 function Copy_Node_With_Replacement
(Old_Node
: Node_Id
) return Node_Id
;
7593 -- Called during second phase to copy node doing replacements
7595 procedure Visit_Elist
(E
: Elist_Id
);
7596 -- Called during first phase to visit all elements of an Elist
7598 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
);
7599 -- Visit a single field, recursing to call Visit_Node or Visit_List
7600 -- if the field is a syntactic descendent of the current node (i.e.
7601 -- its parent is Node N).
7603 procedure Visit_Itype
(Old_Itype
: Entity_Id
);
7604 -- Called during first phase to visit subsidiary fields of a defining
7605 -- Itype, and also create a copy and make an entry in the replacement
7606 -- map for the new copy.
7608 procedure Visit_List
(L
: List_Id
);
7609 -- Called during first phase to visit all elements of a List
7611 procedure Visit_Node
(N
: Node_Or_Entity_Id
);
7612 -- Called during first phase to visit a node and all its subtrees
7618 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
is
7623 if not Has_Extension
(N
) or else No
(Actual_Map
) then
7626 elsif NCT_Hash_Tables_Used
then
7627 Ent
:= NCT_Assoc
.Get
(Entity_Id
(N
));
7629 if Present
(Ent
) then
7635 -- No hash table used, do serial search
7638 E
:= First_Elmt
(Actual_Map
);
7639 while Present
(E
) loop
7640 if Node
(E
) = N
then
7641 return Node
(Next_Elmt
(E
));
7643 E
:= Next_Elmt
(Next_Elmt
(E
));
7651 ---------------------------
7652 -- Build_NCT_Hash_Tables --
7653 ---------------------------
7655 procedure Build_NCT_Hash_Tables
is
7659 if NCT_Hash_Table_Setup
then
7661 NCT_Itype_Assoc
.Reset
;
7664 Elmt
:= First_Elmt
(Actual_Map
);
7665 while Present
(Elmt
) loop
7668 -- Get new entity, and associate old and new
7671 NCT_Assoc
.Set
(Ent
, Node
(Elmt
));
7673 if Is_Type
(Ent
) then
7675 Anode
: constant Entity_Id
:=
7676 Associated_Node_For_Itype
(Ent
);
7679 if Present
(Anode
) then
7681 -- Enter a link between the associated node of the
7682 -- old Itype and the new Itype, for updating later
7683 -- when node is copied.
7685 NCT_Itype_Assoc
.Set
(Anode
, Node
(Elmt
));
7693 NCT_Hash_Tables_Used
:= True;
7694 NCT_Hash_Table_Setup
:= True;
7695 end Build_NCT_Hash_Tables
;
7697 ---------------------------------
7698 -- Copy_Elist_With_Replacement --
7699 ---------------------------------
7701 function Copy_Elist_With_Replacement
7702 (Old_Elist
: Elist_Id
) return Elist_Id
7705 New_Elist
: Elist_Id
;
7708 if No
(Old_Elist
) then
7712 New_Elist
:= New_Elmt_List
;
7714 M
:= First_Elmt
(Old_Elist
);
7715 while Present
(M
) loop
7716 Append_Elmt
(Copy_Node_With_Replacement
(Node
(M
)), New_Elist
);
7722 end Copy_Elist_With_Replacement
;
7724 ---------------------------------
7725 -- Copy_Itype_With_Replacement --
7726 ---------------------------------
7728 -- This routine exactly parallels its phase one analog Visit_Itype,
7730 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
) is
7732 -- Translate Next_Entity, Scope and Etype fields, in case they
7733 -- reference entities that have been mapped into copies.
7735 Set_Next_Entity
(New_Itype
, Assoc
(Next_Entity
(New_Itype
)));
7736 Set_Etype
(New_Itype
, Assoc
(Etype
(New_Itype
)));
7738 if Present
(New_Scope
) then
7739 Set_Scope
(New_Itype
, New_Scope
);
7741 Set_Scope
(New_Itype
, Assoc
(Scope
(New_Itype
)));
7744 -- Copy referenced fields
7746 if Is_Discrete_Type
(New_Itype
) then
7747 Set_Scalar_Range
(New_Itype
,
7748 Copy_Node_With_Replacement
(Scalar_Range
(New_Itype
)));
7750 elsif Has_Discriminants
(Base_Type
(New_Itype
)) then
7751 Set_Discriminant_Constraint
(New_Itype
,
7752 Copy_Elist_With_Replacement
7753 (Discriminant_Constraint
(New_Itype
)));
7755 elsif Is_Array_Type
(New_Itype
) then
7756 if Present
(First_Index
(New_Itype
)) then
7757 Set_First_Index
(New_Itype
,
7758 First
(Copy_List_With_Replacement
7759 (List_Containing
(First_Index
(New_Itype
)))));
7762 if Is_Packed
(New_Itype
) then
7763 Set_Packed_Array_Type
(New_Itype
,
7764 Copy_Node_With_Replacement
7765 (Packed_Array_Type
(New_Itype
)));
7768 end Copy_Itype_With_Replacement
;
7770 --------------------------------
7771 -- Copy_List_With_Replacement --
7772 --------------------------------
7774 function Copy_List_With_Replacement
7775 (Old_List
: List_Id
) return List_Id
7781 if Old_List
= No_List
then
7785 New_List
:= Empty_List
;
7787 E
:= First
(Old_List
);
7788 while Present
(E
) loop
7789 Append
(Copy_Node_With_Replacement
(E
), New_List
);
7795 end Copy_List_With_Replacement
;
7797 --------------------------------
7798 -- Copy_Node_With_Replacement --
7799 --------------------------------
7801 function Copy_Node_With_Replacement
7802 (Old_Node
: Node_Id
) return Node_Id
7806 procedure Adjust_Named_Associations
7807 (Old_Node
: Node_Id
;
7808 New_Node
: Node_Id
);
7809 -- If a call node has named associations, these are chained through
7810 -- the First_Named_Actual, Next_Named_Actual links. These must be
7811 -- propagated separately to the new parameter list, because these
7812 -- are not syntactic fields.
7814 function Copy_Field_With_Replacement
7815 (Field
: Union_Id
) return Union_Id
;
7816 -- Given Field, which is a field of Old_Node, return a copy of it
7817 -- if it is a syntactic field (i.e. its parent is Node), setting
7818 -- the parent of the copy to poit to New_Node. Otherwise returns
7819 -- the field (possibly mapped if it is an entity).
7821 -------------------------------
7822 -- Adjust_Named_Associations --
7823 -------------------------------
7825 procedure Adjust_Named_Associations
7826 (Old_Node
: Node_Id
;
7836 Old_E
:= First
(Parameter_Associations
(Old_Node
));
7837 New_E
:= First
(Parameter_Associations
(New_Node
));
7838 while Present
(Old_E
) loop
7839 if Nkind
(Old_E
) = N_Parameter_Association
7840 and then Present
(Next_Named_Actual
(Old_E
))
7842 if First_Named_Actual
(Old_Node
)
7843 = Explicit_Actual_Parameter
(Old_E
)
7845 Set_First_Named_Actual
7846 (New_Node
, Explicit_Actual_Parameter
(New_E
));
7849 -- Now scan parameter list from the beginning,to locate
7850 -- next named actual, which can be out of order.
7852 Old_Next
:= First
(Parameter_Associations
(Old_Node
));
7853 New_Next
:= First
(Parameter_Associations
(New_Node
));
7855 while Nkind
(Old_Next
) /= N_Parameter_Association
7856 or else Explicit_Actual_Parameter
(Old_Next
)
7857 /= Next_Named_Actual
(Old_E
)
7863 Set_Next_Named_Actual
7864 (New_E
, Explicit_Actual_Parameter
(New_Next
));
7870 end Adjust_Named_Associations
;
7872 ---------------------------------
7873 -- Copy_Field_With_Replacement --
7874 ---------------------------------
7876 function Copy_Field_With_Replacement
7877 (Field
: Union_Id
) return Union_Id
7880 if Field
= Union_Id
(Empty
) then
7883 elsif Field
in Node_Range
then
7885 Old_N
: constant Node_Id
:= Node_Id
(Field
);
7889 -- If syntactic field, as indicated by the parent pointer
7890 -- being set, then copy the referenced node recursively.
7892 if Parent
(Old_N
) = Old_Node
then
7893 New_N
:= Copy_Node_With_Replacement
(Old_N
);
7895 if New_N
/= Old_N
then
7896 Set_Parent
(New_N
, New_Node
);
7899 -- For semantic fields, update possible entity reference
7900 -- from the replacement map.
7903 New_N
:= Assoc
(Old_N
);
7906 return Union_Id
(New_N
);
7909 elsif Field
in List_Range
then
7911 Old_L
: constant List_Id
:= List_Id
(Field
);
7915 -- If syntactic field, as indicated by the parent pointer,
7916 -- then recursively copy the entire referenced list.
7918 if Parent
(Old_L
) = Old_Node
then
7919 New_L
:= Copy_List_With_Replacement
(Old_L
);
7920 Set_Parent
(New_L
, New_Node
);
7922 -- For semantic list, just returned unchanged
7928 return Union_Id
(New_L
);
7931 -- Anything other than a list or a node is returned unchanged
7936 end Copy_Field_With_Replacement
;
7938 -- Start of processing for Copy_Node_With_Replacement
7941 if Old_Node
<= Empty_Or_Error
then
7944 elsif Has_Extension
(Old_Node
) then
7945 return Assoc
(Old_Node
);
7948 New_Node
:= New_Copy
(Old_Node
);
7950 -- If the node we are copying is the associated node of a
7951 -- previously copied Itype, then adjust the associated node
7952 -- of the copy of that Itype accordingly.
7954 if Present
(Actual_Map
) then
7960 -- Case of hash table used
7962 if NCT_Hash_Tables_Used
then
7963 Ent
:= NCT_Itype_Assoc
.Get
(Old_Node
);
7965 if Present
(Ent
) then
7966 Set_Associated_Node_For_Itype
(Ent
, New_Node
);
7969 -- Case of no hash table used
7972 E
:= First_Elmt
(Actual_Map
);
7973 while Present
(E
) loop
7974 if Is_Itype
(Node
(E
))
7976 Old_Node
= Associated_Node_For_Itype
(Node
(E
))
7978 Set_Associated_Node_For_Itype
7979 (Node
(Next_Elmt
(E
)), New_Node
);
7982 E
:= Next_Elmt
(Next_Elmt
(E
));
7988 -- Recursively copy descendents
7991 (New_Node
, Copy_Field_With_Replacement
(Field1
(New_Node
)));
7993 (New_Node
, Copy_Field_With_Replacement
(Field2
(New_Node
)));
7995 (New_Node
, Copy_Field_With_Replacement
(Field3
(New_Node
)));
7997 (New_Node
, Copy_Field_With_Replacement
(Field4
(New_Node
)));
7999 (New_Node
, Copy_Field_With_Replacement
(Field5
(New_Node
)));
8001 -- Adjust Sloc of new node if necessary
8003 if New_Sloc
/= No_Location
then
8004 Set_Sloc
(New_Node
, New_Sloc
);
8006 -- If we adjust the Sloc, then we are essentially making
8007 -- a completely new node, so the Comes_From_Source flag
8008 -- should be reset to the proper default value.
8010 Nodes
.Table
(New_Node
).Comes_From_Source
:=
8011 Default_Node
.Comes_From_Source
;
8014 -- If the node is call and has named associations,
8015 -- set the corresponding links in the copy.
8017 if (Nkind
(Old_Node
) = N_Function_Call
8018 or else Nkind
(Old_Node
) = N_Entry_Call_Statement
8020 Nkind
(Old_Node
) = N_Procedure_Call_Statement
)
8021 and then Present
(First_Named_Actual
(Old_Node
))
8023 Adjust_Named_Associations
(Old_Node
, New_Node
);
8026 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8027 -- The replacement mechanism applies to entities, and is not used
8028 -- here. Eventually we may need a more general graph-copying
8029 -- routine. For now, do a sequential search to find desired node.
8031 if Nkind
(Old_Node
) = N_Handled_Sequence_Of_Statements
8032 and then Present
(First_Real_Statement
(Old_Node
))
8035 Old_F
: constant Node_Id
:= First_Real_Statement
(Old_Node
);
8039 N1
:= First
(Statements
(Old_Node
));
8040 N2
:= First
(Statements
(New_Node
));
8042 while N1
/= Old_F
loop
8047 Set_First_Real_Statement
(New_Node
, N2
);
8052 -- All done, return copied node
8055 end Copy_Node_With_Replacement
;
8061 procedure Visit_Elist
(E
: Elist_Id
) is
8065 Elmt
:= First_Elmt
(E
);
8067 while Elmt
/= No_Elmt
loop
8068 Visit_Node
(Node
(Elmt
));
8078 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
) is
8080 if F
= Union_Id
(Empty
) then
8083 elsif F
in Node_Range
then
8085 -- Copy node if it is syntactic, i.e. its parent pointer is
8086 -- set to point to the field that referenced it (certain
8087 -- Itypes will also meet this criterion, which is fine, since
8088 -- these are clearly Itypes that do need to be copied, since
8089 -- we are copying their parent.)
8091 if Parent
(Node_Id
(F
)) = N
then
8092 Visit_Node
(Node_Id
(F
));
8095 -- Another case, if we are pointing to an Itype, then we want
8096 -- to copy it if its associated node is somewhere in the tree
8099 -- Note: the exclusion of self-referential copies is just an
8100 -- optimization, since the search of the already copied list
8101 -- would catch it, but it is a common case (Etype pointing
8102 -- to itself for an Itype that is a base type).
8104 elsif Has_Extension
(Node_Id
(F
))
8105 and then Is_Itype
(Entity_Id
(F
))
8106 and then Node_Id
(F
) /= N
8112 P
:= Associated_Node_For_Itype
(Node_Id
(F
));
8113 while Present
(P
) loop
8115 Visit_Node
(Node_Id
(F
));
8122 -- An Itype whose parent is not being copied definitely
8123 -- should NOT be copied, since it does not belong in any
8124 -- sense to the copied subtree.
8130 elsif F
in List_Range
8131 and then Parent
(List_Id
(F
)) = N
8133 Visit_List
(List_Id
(F
));
8142 procedure Visit_Itype
(Old_Itype
: Entity_Id
) is
8143 New_Itype
: Entity_Id
;
8148 -- Itypes that describe the designated type of access to subprograms
8149 -- have the structure of subprogram declarations, with signatures,
8150 -- etc. Either we duplicate the signatures completely, or choose to
8151 -- share such itypes, which is fine because their elaboration will
8152 -- have no side effects.
8154 if Ekind
(Old_Itype
) = E_Subprogram_Type
then
8158 New_Itype
:= New_Copy
(Old_Itype
);
8160 -- The new Itype has all the attributes of the old one, and
8161 -- we just copy the contents of the entity. However, the back-end
8162 -- needs different names for debugging purposes, so we create a
8163 -- new internal name for it in all cases.
8165 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
8167 -- If our associated node is an entity that has already been copied,
8168 -- then set the associated node of the copy to point to the right
8169 -- copy. If we have copied an Itype that is itself the associated
8170 -- node of some previously copied Itype, then we set the right
8171 -- pointer in the other direction.
8173 if Present
(Actual_Map
) then
8175 -- Case of hash tables used
8177 if NCT_Hash_Tables_Used
then
8179 Ent
:= NCT_Assoc
.Get
(Associated_Node_For_Itype
(Old_Itype
));
8181 if Present
(Ent
) then
8182 Set_Associated_Node_For_Itype
(New_Itype
, Ent
);
8185 Ent
:= NCT_Itype_Assoc
.Get
(Old_Itype
);
8186 if Present
(Ent
) then
8187 Set_Associated_Node_For_Itype
(Ent
, New_Itype
);
8189 -- If the hash table has no association for this Itype and
8190 -- its associated node, enter one now.
8194 (Associated_Node_For_Itype
(Old_Itype
), New_Itype
);
8197 -- Case of hash tables not used
8200 E
:= First_Elmt
(Actual_Map
);
8201 while Present
(E
) loop
8202 if Associated_Node_For_Itype
(Old_Itype
) = Node
(E
) then
8203 Set_Associated_Node_For_Itype
8204 (New_Itype
, Node
(Next_Elmt
(E
)));
8207 if Is_Type
(Node
(E
))
8209 Old_Itype
= Associated_Node_For_Itype
(Node
(E
))
8211 Set_Associated_Node_For_Itype
8212 (Node
(Next_Elmt
(E
)), New_Itype
);
8215 E
:= Next_Elmt
(Next_Elmt
(E
));
8220 if Present
(Freeze_Node
(New_Itype
)) then
8221 Set_Is_Frozen
(New_Itype
, False);
8222 Set_Freeze_Node
(New_Itype
, Empty
);
8225 -- Add new association to map
8227 if No
(Actual_Map
) then
8228 Actual_Map
:= New_Elmt_List
;
8231 Append_Elmt
(Old_Itype
, Actual_Map
);
8232 Append_Elmt
(New_Itype
, Actual_Map
);
8234 if NCT_Hash_Tables_Used
then
8235 NCT_Assoc
.Set
(Old_Itype
, New_Itype
);
8238 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
8240 if NCT_Table_Entries
> NCT_Hash_Threshhold
then
8241 Build_NCT_Hash_Tables
;
8245 -- If a record subtype is simply copied, the entity list will be
8246 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
8248 if Ekind
(Old_Itype
) = E_Record_Subtype
8249 or else Ekind
(Old_Itype
) = E_Class_Wide_Subtype
8251 Set_Cloned_Subtype
(New_Itype
, Old_Itype
);
8254 -- Visit descendents that eventually get copied
8256 Visit_Field
(Union_Id
(Etype
(Old_Itype
)), Old_Itype
);
8258 if Is_Discrete_Type
(Old_Itype
) then
8259 Visit_Field
(Union_Id
(Scalar_Range
(Old_Itype
)), Old_Itype
);
8261 elsif Has_Discriminants
(Base_Type
(Old_Itype
)) then
8262 -- ??? This should involve call to Visit_Field
8263 Visit_Elist
(Discriminant_Constraint
(Old_Itype
));
8265 elsif Is_Array_Type
(Old_Itype
) then
8266 if Present
(First_Index
(Old_Itype
)) then
8267 Visit_Field
(Union_Id
(List_Containing
8268 (First_Index
(Old_Itype
))),
8272 if Is_Packed
(Old_Itype
) then
8273 Visit_Field
(Union_Id
(Packed_Array_Type
(Old_Itype
)),
8283 procedure Visit_List
(L
: List_Id
) is
8286 if L
/= No_List
then
8289 while Present
(N
) loop
8300 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
8302 -- Start of processing for Visit_Node
8305 -- Handle case of an Itype, which must be copied
8307 if Has_Extension
(N
)
8308 and then Is_Itype
(N
)
8310 -- Nothing to do if already in the list. This can happen with an
8311 -- Itype entity that appears more than once in the tree.
8312 -- Note that we do not want to visit descendents in this case.
8314 -- Test for already in list when hash table is used
8316 if NCT_Hash_Tables_Used
then
8317 if Present
(NCT_Assoc
.Get
(Entity_Id
(N
))) then
8321 -- Test for already in list when hash table not used
8327 if Present
(Actual_Map
) then
8328 E
:= First_Elmt
(Actual_Map
);
8329 while Present
(E
) loop
8330 if Node
(E
) = N
then
8333 E
:= Next_Elmt
(Next_Elmt
(E
));
8343 -- Visit descendents
8345 Visit_Field
(Field1
(N
), N
);
8346 Visit_Field
(Field2
(N
), N
);
8347 Visit_Field
(Field3
(N
), N
);
8348 Visit_Field
(Field4
(N
), N
);
8349 Visit_Field
(Field5
(N
), N
);
8352 -- Start of processing for New_Copy_Tree
8357 -- See if we should use hash table
8359 if No
(Actual_Map
) then
8360 NCT_Hash_Tables_Used
:= False;
8367 NCT_Table_Entries
:= 0;
8369 Elmt
:= First_Elmt
(Actual_Map
);
8370 while Present
(Elmt
) loop
8371 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
8376 if NCT_Table_Entries
> NCT_Hash_Threshhold
then
8377 Build_NCT_Hash_Tables
;
8379 NCT_Hash_Tables_Used
:= False;
8384 -- Hash table set up if required, now start phase one by visiting
8385 -- top node (we will recursively visit the descendents).
8387 Visit_Node
(Source
);
8389 -- Now the second phase of the copy can start. First we process
8390 -- all the mapped entities, copying their descendents.
8392 if Present
(Actual_Map
) then
8395 New_Itype
: Entity_Id
;
8397 Elmt
:= First_Elmt
(Actual_Map
);
8398 while Present
(Elmt
) loop
8400 New_Itype
:= Node
(Elmt
);
8401 Copy_Itype_With_Replacement
(New_Itype
);
8407 -- Now we can copy the actual tree
8409 return Copy_Node_With_Replacement
(Source
);
8412 -------------------------
8413 -- New_External_Entity --
8414 -------------------------
8416 function New_External_Entity
8417 (Kind
: Entity_Kind
;
8418 Scope_Id
: Entity_Id
;
8419 Sloc_Value
: Source_Ptr
;
8420 Related_Id
: Entity_Id
;
8422 Suffix_Index
: Nat
:= 0;
8423 Prefix
: Character := ' ') return Entity_Id
8425 N
: constant Entity_Id
:=
8426 Make_Defining_Identifier
(Sloc_Value
,
8428 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
8431 Set_Ekind
(N
, Kind
);
8432 Set_Is_Internal
(N
, True);
8433 Append_Entity
(N
, Scope_Id
);
8434 Set_Public_Status
(N
);
8436 if Kind
in Type_Kind
then
8437 Init_Size_Align
(N
);
8441 end New_External_Entity
;
8443 -------------------------
8444 -- New_Internal_Entity --
8445 -------------------------
8447 function New_Internal_Entity
8448 (Kind
: Entity_Kind
;
8449 Scope_Id
: Entity_Id
;
8450 Sloc_Value
: Source_Ptr
;
8451 Id_Char
: Character) return Entity_Id
8453 N
: constant Entity_Id
:=
8454 Make_Defining_Identifier
(Sloc_Value
, New_Internal_Name
(Id_Char
));
8457 Set_Ekind
(N
, Kind
);
8458 Set_Is_Internal
(N
, True);
8459 Append_Entity
(N
, Scope_Id
);
8461 if Kind
in Type_Kind
then
8462 Init_Size_Align
(N
);
8466 end New_Internal_Entity
;
8472 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
8476 -- If we are pointing at a positional parameter, it is a member of a
8477 -- node list (the list of parameters), and the next parameter is the
8478 -- next node on the list, unless we hit a parameter association, then
8479 -- we shift to using the chain whose head is the First_Named_Actual in
8480 -- the parent, and then is threaded using the Next_Named_Actual of the
8481 -- Parameter_Association. All this fiddling is because the original node
8482 -- list is in the textual call order, and what we need is the
8483 -- declaration order.
8485 if Is_List_Member
(Actual_Id
) then
8486 N
:= Next
(Actual_Id
);
8488 if Nkind
(N
) = N_Parameter_Association
then
8489 return First_Named_Actual
(Parent
(Actual_Id
));
8495 return Next_Named_Actual
(Parent
(Actual_Id
));
8499 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
8501 Actual_Id
:= Next_Actual
(Actual_Id
);
8504 -----------------------
8505 -- Normalize_Actuals --
8506 -----------------------
8508 -- Chain actuals according to formals of subprogram. If there are no named
8509 -- associations, the chain is simply the list of Parameter Associations,
8510 -- since the order is the same as the declaration order. If there are named
8511 -- associations, then the First_Named_Actual field in the N_Function_Call
8512 -- or N_Procedure_Call_Statement node points to the Parameter_Association
8513 -- node for the parameter that comes first in declaration order. The
8514 -- remaining named parameters are then chained in declaration order using
8515 -- Next_Named_Actual.
8517 -- This routine also verifies that the number of actuals is compatible with
8518 -- the number and default values of formals, but performs no type checking
8519 -- (type checking is done by the caller).
8521 -- If the matching succeeds, Success is set to True and the caller proceeds
8522 -- with type-checking. If the match is unsuccessful, then Success is set to
8523 -- False, and the caller attempts a different interpretation, if there is
8526 -- If the flag Report is on, the call is not overloaded, and a failure to
8527 -- match can be reported here, rather than in the caller.
8529 procedure Normalize_Actuals
8533 Success
: out Boolean)
8535 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
8536 Actual
: Node_Id
:= Empty
;
8538 Last
: Node_Id
:= Empty
;
8539 First_Named
: Node_Id
:= Empty
;
8542 Formals_To_Match
: Integer := 0;
8543 Actuals_To_Match
: Integer := 0;
8545 procedure Chain
(A
: Node_Id
);
8546 -- Add named actual at the proper place in the list, using the
8547 -- Next_Named_Actual link.
8549 function Reporting
return Boolean;
8550 -- Determines if an error is to be reported. To report an error, we
8551 -- need Report to be True, and also we do not report errors caused
8552 -- by calls to init procs that occur within other init procs. Such
8553 -- errors must always be cascaded errors, since if all the types are
8554 -- declared correctly, the compiler will certainly build decent calls!
8560 procedure Chain
(A
: Node_Id
) is
8564 -- Call node points to first actual in list
8566 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
8569 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
8573 Set_Next_Named_Actual
(Last
, Empty
);
8580 function Reporting
return Boolean is
8585 elsif not Within_Init_Proc
then
8588 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
8596 -- Start of processing for Normalize_Actuals
8599 if Is_Access_Type
(S
) then
8601 -- The name in the call is a function call that returns an access
8602 -- to subprogram. The designated type has the list of formals.
8604 Formal
:= First_Formal
(Designated_Type
(S
));
8606 Formal
:= First_Formal
(S
);
8609 while Present
(Formal
) loop
8610 Formals_To_Match
:= Formals_To_Match
+ 1;
8611 Next_Formal
(Formal
);
8614 -- Find if there is a named association, and verify that no positional
8615 -- associations appear after named ones.
8617 if Present
(Actuals
) then
8618 Actual
:= First
(Actuals
);
8621 while Present
(Actual
)
8622 and then Nkind
(Actual
) /= N_Parameter_Association
8624 Actuals_To_Match
:= Actuals_To_Match
+ 1;
8628 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
8630 -- Most common case: positional notation, no defaults
8635 elsif Actuals_To_Match
> Formals_To_Match
then
8637 -- Too many actuals: will not work
8640 if Is_Entity_Name
(Name
(N
)) then
8641 Error_Msg_N
("too many arguments in call to&", Name
(N
));
8643 Error_Msg_N
("too many arguments in call", N
);
8651 First_Named
:= Actual
;
8653 while Present
(Actual
) loop
8654 if Nkind
(Actual
) /= N_Parameter_Association
then
8656 ("positional parameters not allowed after named ones", Actual
);
8661 Actuals_To_Match
:= Actuals_To_Match
+ 1;
8667 if Present
(Actuals
) then
8668 Actual
:= First
(Actuals
);
8671 Formal
:= First_Formal
(S
);
8672 while Present
(Formal
) loop
8674 -- Match the formals in order. If the corresponding actual is
8675 -- positional, nothing to do. Else scan the list of named actuals
8676 -- to find the one with the right name.
8679 and then Nkind
(Actual
) /= N_Parameter_Association
8682 Actuals_To_Match
:= Actuals_To_Match
- 1;
8683 Formals_To_Match
:= Formals_To_Match
- 1;
8686 -- For named parameters, search the list of actuals to find
8687 -- one that matches the next formal name.
8689 Actual
:= First_Named
;
8691 while Present
(Actual
) loop
8692 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
8695 Actuals_To_Match
:= Actuals_To_Match
- 1;
8696 Formals_To_Match
:= Formals_To_Match
- 1;
8704 if Ekind
(Formal
) /= E_In_Parameter
8705 or else No
(Default_Value
(Formal
))
8708 if (Comes_From_Source
(S
)
8709 or else Sloc
(S
) = Standard_Location
)
8710 and then Is_Overloadable
(S
)
8714 (Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
8716 (Nkind
(Parent
(N
)) = N_Function_Call
8718 Nkind
(Parent
(N
)) = N_Parameter_Association
))
8719 and then Ekind
(S
) /= E_Function
8721 Set_Etype
(N
, Etype
(S
));
8723 Error_Msg_Name_1
:= Chars
(S
);
8724 Error_Msg_Sloc
:= Sloc
(S
);
8726 ("missing argument for parameter & " &
8727 "in call to % declared #", N
, Formal
);
8730 elsif Is_Overloadable
(S
) then
8731 Error_Msg_Name_1
:= Chars
(S
);
8733 -- Point to type derivation that generated the
8736 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
8739 ("missing argument for parameter & " &
8740 "in call to % (inherited) #", N
, Formal
);
8744 ("missing argument for parameter &", N
, Formal
);
8752 Formals_To_Match
:= Formals_To_Match
- 1;
8757 Next_Formal
(Formal
);
8760 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
8767 -- Find some superfluous named actual that did not get
8768 -- attached to the list of associations.
8770 Actual
:= First
(Actuals
);
8771 while Present
(Actual
) loop
8772 if Nkind
(Actual
) = N_Parameter_Association
8773 and then Actual
/= Last
8774 and then No
(Next_Named_Actual
(Actual
))
8776 Error_Msg_N
("unmatched actual & in call",
8777 Selector_Name
(Actual
));
8788 end Normalize_Actuals
;
8790 --------------------------------
8791 -- Note_Possible_Modification --
8792 --------------------------------
8794 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
8795 Modification_Comes_From_Source
: constant Boolean :=
8796 Comes_From_Source
(Parent
(N
));
8802 -- Loop to find referenced entity, if there is one
8809 if Is_Entity_Name
(Exp
) then
8810 Ent
:= Entity
(Exp
);
8812 -- If the entity is missing, it is an undeclared identifier,
8813 -- and there is nothing to annotate.
8819 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
8821 P
: constant Node_Id
:= Prefix
(Exp
);
8824 if Nkind
(P
) = N_Selected_Component
8826 Entry_Formal
(Entity
(Selector_Name
(P
))))
8828 -- Case of a reference to an entry formal
8830 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
8832 elsif Nkind
(P
) = N_Identifier
8833 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
8834 and then Present
(Expression
(Parent
(Entity
(P
))))
8835 and then Nkind
(Expression
(Parent
(Entity
(P
))))
8838 -- Case of a reference to a value on which side effects have
8841 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
8850 elsif Nkind
(Exp
) = N_Type_Conversion
8851 or else Nkind
(Exp
) = N_Unchecked_Type_Conversion
8853 Exp
:= Expression
(Exp
);
8856 elsif Nkind
(Exp
) = N_Slice
8857 or else Nkind
(Exp
) = N_Indexed_Component
8858 or else Nkind
(Exp
) = N_Selected_Component
8860 Exp
:= Prefix
(Exp
);
8867 -- Now look for entity being referenced
8869 if Present
(Ent
) then
8870 if Is_Object
(Ent
) then
8871 if Comes_From_Source
(Exp
)
8872 or else Modification_Comes_From_Source
8874 if Has_Pragma_Unmodified
(Ent
) then
8875 Error_Msg_NE
("?pragma Unmodified given for &!", N
, Ent
);
8878 Set_Never_Set_In_Source
(Ent
, False);
8881 Set_Is_True_Constant
(Ent
, False);
8882 Set_Current_Value
(Ent
, Empty
);
8883 Set_Is_Known_Null
(Ent
, False);
8885 if not Can_Never_Be_Null
(Ent
) then
8886 Set_Is_Known_Non_Null
(Ent
, False);
8889 -- Follow renaming chain
8891 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
8892 and then Present
(Renamed_Object
(Ent
))
8894 Exp
:= Renamed_Object
(Ent
);
8898 -- Generate a reference only if the assignment comes from
8899 -- source. This excludes, for example, calls to a dispatching
8900 -- assignment operation when the left-hand side is tagged.
8902 if Modification_Comes_From_Source
then
8903 Generate_Reference
(Ent
, Exp
, 'm');
8906 Check_Nested_Access
(Ent
);
8911 -- If we are sure this is a modification from source, and we know
8912 -- this modifies a constant, then give an appropriate warning.
8914 if Overlays_Constant
(Ent
)
8915 and then Modification_Comes_From_Source
8919 A
: constant Node_Id
:= Address_Clause
(Ent
);
8923 Exp
: constant Node_Id
:= Expression
(A
);
8925 if Nkind
(Exp
) = N_Attribute_Reference
8926 and then Attribute_Name
(Exp
) = Name_Address
8927 and then Is_Entity_Name
(Prefix
(Exp
))
8929 Error_Msg_Sloc
:= Sloc
(A
);
8931 ("constant& may be modified via address clause#?",
8932 N
, Entity
(Prefix
(Exp
)));
8942 end Note_Possible_Modification
;
8944 -------------------------
8945 -- Object_Access_Level --
8946 -------------------------
8948 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
8951 -- Returns the static accessibility level of the view denoted by Obj. Note
8952 -- that the value returned is the result of a call to Scope_Depth. Only
8953 -- scope depths associated with dynamic scopes can actually be returned.
8954 -- Since only relative levels matter for accessibility checking, the fact
8955 -- that the distance between successive levels of accessibility is not
8956 -- always one is immaterial (invariant: if level(E2) is deeper than
8957 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
8959 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
8960 -- An explicit dereference is created when removing side-effects from
8961 -- expressions for constraint checking purposes. In this case a local
8962 -- access type is created for it. The correct access level is that of
8963 -- the original source node. We detect this case by noting that the
8964 -- prefix of the dereference is created by an object declaration whose
8965 -- initial expression is a reference.
8971 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
8972 Pref
: constant Node_Id
:= Prefix
(Obj
);
8974 if Is_Entity_Name
(Pref
)
8975 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
8976 and then Present
(Expression
(Parent
(Entity
(Pref
))))
8977 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
8979 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
8985 -- Start of processing for Object_Access_Level
8988 if Is_Entity_Name
(Obj
) then
8991 if Is_Prival
(E
) then
8992 E
:= Prival_Link
(E
);
8995 -- If E is a type then it denotes a current instance. For this case
8996 -- we add one to the normal accessibility level of the type to ensure
8997 -- that current instances are treated as always being deeper than
8998 -- than the level of any visible named access type (see 3.10.2(21)).
9001 return Type_Access_Level
(E
) + 1;
9003 elsif Present
(Renamed_Object
(E
)) then
9004 return Object_Access_Level
(Renamed_Object
(E
));
9006 -- Similarly, if E is a component of the current instance of a
9007 -- protected type, any instance of it is assumed to be at a deeper
9008 -- level than the type. For a protected object (whose type is an
9009 -- anonymous protected type) its components are at the same level
9010 -- as the type itself.
9012 elsif not Is_Overloadable
(E
)
9013 and then Ekind
(Scope
(E
)) = E_Protected_Type
9014 and then Comes_From_Source
(Scope
(E
))
9016 return Type_Access_Level
(Scope
(E
)) + 1;
9019 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
9022 elsif Nkind
(Obj
) = N_Selected_Component
then
9023 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
9024 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
9026 return Object_Access_Level
(Prefix
(Obj
));
9029 elsif Nkind
(Obj
) = N_Indexed_Component
then
9030 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
9031 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
9033 return Object_Access_Level
(Prefix
(Obj
));
9036 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
9038 -- If the prefix is a selected access discriminant then we make a
9039 -- recursive call on the prefix, which will in turn check the level
9040 -- of the prefix object of the selected discriminant.
9042 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
9043 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
9045 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
9047 return Object_Access_Level
(Prefix
(Obj
));
9049 elsif not (Comes_From_Source
(Obj
)) then
9051 Ref
: constant Node_Id
:= Reference_To
(Obj
);
9053 if Present
(Ref
) then
9054 return Object_Access_Level
(Ref
);
9056 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
9061 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
9064 elsif Nkind
(Obj
) = N_Type_Conversion
9065 or else Nkind
(Obj
) = N_Unchecked_Type_Conversion
9067 return Object_Access_Level
(Expression
(Obj
));
9069 -- Function results are objects, so we get either the access level of
9070 -- the function or, in the case of an indirect call, the level of the
9071 -- access-to-subprogram type.
9073 elsif Nkind
(Obj
) = N_Function_Call
then
9074 if Is_Entity_Name
(Name
(Obj
)) then
9075 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
9077 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
9080 -- For convenience we handle qualified expressions, even though
9081 -- they aren't technically object names.
9083 elsif Nkind
(Obj
) = N_Qualified_Expression
then
9084 return Object_Access_Level
(Expression
(Obj
));
9086 -- Otherwise return the scope level of Standard.
9087 -- (If there are cases that fall through
9088 -- to this point they will be treated as
9089 -- having global accessibility for now. ???)
9092 return Scope_Depth
(Standard_Standard
);
9094 end Object_Access_Level
;
9096 -----------------------
9097 -- Private_Component --
9098 -----------------------
9100 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
9101 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
9103 function Trace_Components
9105 Check
: Boolean) return Entity_Id
;
9106 -- Recursive function that does the work, and checks against circular
9107 -- definition for each subcomponent type.
9109 ----------------------
9110 -- Trace_Components --
9111 ----------------------
9113 function Trace_Components
9115 Check
: Boolean) return Entity_Id
9117 Btype
: constant Entity_Id
:= Base_Type
(T
);
9118 Component
: Entity_Id
;
9120 Candidate
: Entity_Id
:= Empty
;
9123 if Check
and then Btype
= Ancestor
then
9124 Error_Msg_N
("circular type definition", Type_Id
);
9128 if Is_Private_Type
(Btype
)
9129 and then not Is_Generic_Type
(Btype
)
9131 if Present
(Full_View
(Btype
))
9132 and then Is_Record_Type
(Full_View
(Btype
))
9133 and then not Is_Frozen
(Btype
)
9135 -- To indicate that the ancestor depends on a private type, the
9136 -- current Btype is sufficient. However, to check for circular
9137 -- definition we must recurse on the full view.
9139 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
9141 if Candidate
= Any_Type
then
9151 elsif Is_Array_Type
(Btype
) then
9152 return Trace_Components
(Component_Type
(Btype
), True);
9154 elsif Is_Record_Type
(Btype
) then
9155 Component
:= First_Entity
(Btype
);
9156 while Present
(Component
) loop
9158 -- Skip anonymous types generated by constrained components
9160 if not Is_Type
(Component
) then
9161 P
:= Trace_Components
(Etype
(Component
), True);
9164 if P
= Any_Type
then
9172 Next_Entity
(Component
);
9180 end Trace_Components
;
9182 -- Start of processing for Private_Component
9185 return Trace_Components
(Type_Id
, False);
9186 end Private_Component
;
9188 ---------------------------
9189 -- Primitive_Names_Match --
9190 ---------------------------
9192 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
9194 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
9195 -- Given an internal name, returns the corresponding non-internal name
9197 ------------------------
9198 -- Non_Internal_Name --
9199 ------------------------
9201 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
9203 Get_Name_String
(Chars
(E
));
9204 Name_Len
:= Name_Len
- 1;
9206 end Non_Internal_Name
;
9208 -- Start of processing for Primitive_Names_Match
9211 pragma Assert
(Present
(E1
) and then Present
(E2
));
9213 return Chars
(E1
) = Chars
(E2
)
9215 (not Is_Internal_Name
(Chars
(E1
))
9216 and then Is_Internal_Name
(Chars
(E2
))
9217 and then Non_Internal_Name
(E2
) = Chars
(E1
))
9219 (not Is_Internal_Name
(Chars
(E2
))
9220 and then Is_Internal_Name
(Chars
(E1
))
9221 and then Non_Internal_Name
(E1
) = Chars
(E2
))
9223 (Is_Predefined_Dispatching_Operation
(E1
)
9224 and then Is_Predefined_Dispatching_Operation
(E2
)
9225 and then Same_TSS
(E1
, E2
))
9227 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
9228 end Primitive_Names_Match
;
9230 -----------------------
9231 -- Process_End_Label --
9232 -----------------------
9234 procedure Process_End_Label
9243 Label_Ref
: Boolean;
9244 -- Set True if reference to end label itself is required
9247 -- Gets set to the operator symbol or identifier that references the
9248 -- entity Ent. For the child unit case, this is the identifier from the
9249 -- designator. For other cases, this is simply Endl.
9251 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
9252 -- N is an identifier node that appears as a parent unit reference in
9253 -- the case where Ent is a child unit. This procedure generates an
9254 -- appropriate cross-reference entry. E is the corresponding entity.
9256 -------------------------
9257 -- Generate_Parent_Ref --
9258 -------------------------
9260 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
9262 -- If names do not match, something weird, skip reference
9264 if Chars
(E
) = Chars
(N
) then
9266 -- Generate the reference. We do NOT consider this as a reference
9267 -- for unreferenced symbol purposes.
9269 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
9272 Style
.Check_Identifier
(N
, E
);
9275 end Generate_Parent_Ref
;
9277 -- Start of processing for Process_End_Label
9280 -- If no node, ignore. This happens in some error situations, and
9281 -- also for some internally generated structures where no end label
9282 -- references are required in any case.
9288 -- Nothing to do if no End_Label, happens for internally generated
9289 -- constructs where we don't want an end label reference anyway. Also
9290 -- nothing to do if Endl is a string literal, which means there was
9291 -- some prior error (bad operator symbol)
9293 Endl
:= End_Label
(N
);
9295 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
9299 -- Reference node is not in extended main source unit
9301 if not In_Extended_Main_Source_Unit
(N
) then
9303 -- Generally we do not collect references except for the extended
9304 -- main source unit. The one exception is the 'e' entry for a
9305 -- package spec, where it is useful for a client to have the
9306 -- ending information to define scopes.
9314 -- For this case, we can ignore any parent references, but we
9315 -- need the package name itself for the 'e' entry.
9317 if Nkind
(Endl
) = N_Designator
then
9318 Endl
:= Identifier
(Endl
);
9322 -- Reference is in extended main source unit
9327 -- For designator, generate references for the parent entries
9329 if Nkind
(Endl
) = N_Designator
then
9331 -- Generate references for the prefix if the END line comes from
9332 -- source (otherwise we do not need these references) We climb the
9333 -- scope stack to find the expected entities.
9335 if Comes_From_Source
(Endl
) then
9337 Scop
:= Current_Scope
;
9338 while Nkind
(Nam
) = N_Selected_Component
loop
9339 Scop
:= Scope
(Scop
);
9340 exit when No
(Scop
);
9341 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
9342 Nam
:= Prefix
(Nam
);
9345 if Present
(Scop
) then
9346 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
9350 Endl
:= Identifier
(Endl
);
9354 -- If the end label is not for the given entity, then either we have
9355 -- some previous error, or this is a generic instantiation for which
9356 -- we do not need to make a cross-reference in this case anyway. In
9357 -- either case we simply ignore the call.
9359 if Chars
(Ent
) /= Chars
(Endl
) then
9363 -- If label was really there, then generate a normal reference and then
9364 -- adjust the location in the end label to point past the name (which
9365 -- should almost always be the semicolon).
9369 if Comes_From_Source
(Endl
) then
9371 -- If a label reference is required, then do the style check and
9372 -- generate an l-type cross-reference entry for the label
9376 Style
.Check_Identifier
(Endl
, Ent
);
9379 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
9382 -- Set the location to point past the label (normally this will
9383 -- mean the semicolon immediately following the label). This is
9384 -- done for the sake of the 'e' or 't' entry generated below.
9386 Get_Decoded_Name_String
(Chars
(Endl
));
9387 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
9390 -- Now generate the e/t reference
9392 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
9394 -- Restore Sloc, in case modified above, since we have an identifier
9395 -- and the normal Sloc should be left set in the tree.
9397 Set_Sloc
(Endl
, Loc
);
9398 end Process_End_Label
;
9404 -- We do the conversion to get the value of the real string by using
9405 -- the scanner, see Sinput for details on use of the internal source
9406 -- buffer for scanning internal strings.
9408 function Real_Convert
(S
: String) return Node_Id
is
9409 Save_Src
: constant Source_Buffer_Ptr
:= Source
;
9413 Source
:= Internal_Source_Ptr
;
9416 for J
in S
'Range loop
9417 Source
(Source_Ptr
(J
)) := S
(J
);
9420 Source
(S
'Length + 1) := EOF
;
9422 if Source
(Scan_Ptr
) = '-' then
9424 Scan_Ptr
:= Scan_Ptr
+ 1;
9432 Set_Realval
(Token_Node
, UR_Negate
(Realval
(Token_Node
)));
9439 --------------------
9440 -- Remove_Homonym --
9441 --------------------
9443 procedure Remove_Homonym
(E
: Entity_Id
) is
9444 Prev
: Entity_Id
:= Empty
;
9448 if E
= Current_Entity
(E
) then
9449 if Present
(Homonym
(E
)) then
9450 Set_Current_Entity
(Homonym
(E
));
9452 Set_Name_Entity_Id
(Chars
(E
), Empty
);
9455 H
:= Current_Entity
(E
);
9456 while Present
(H
) and then H
/= E
loop
9461 Set_Homonym
(Prev
, Homonym
(E
));
9465 ---------------------
9466 -- Rep_To_Pos_Flag --
9467 ---------------------
9469 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
9471 return New_Occurrence_Of
9472 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
9473 end Rep_To_Pos_Flag
;
9475 --------------------
9476 -- Require_Entity --
9477 --------------------
9479 procedure Require_Entity
(N
: Node_Id
) is
9481 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
9482 if Total_Errors_Detected
/= 0 then
9483 Set_Entity
(N
, Any_Id
);
9485 raise Program_Error
;
9490 ------------------------------
9491 -- Requires_Transient_Scope --
9492 ------------------------------
9494 -- A transient scope is required when variable-sized temporaries are
9495 -- allocated in the primary or secondary stack, or when finalization
9496 -- actions must be generated before the next instruction.
9498 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
9499 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
9501 -- Start of processing for Requires_Transient_Scope
9504 -- This is a private type which is not completed yet. This can only
9505 -- happen in a default expression (of a formal parameter or of a
9506 -- record component). Do not expand transient scope in this case
9511 -- Do not expand transient scope for non-existent procedure return
9513 elsif Typ
= Standard_Void_Type
then
9516 -- Elementary types do not require a transient scope
9518 elsif Is_Elementary_Type
(Typ
) then
9521 -- Generally, indefinite subtypes require a transient scope, since the
9522 -- back end cannot generate temporaries, since this is not a valid type
9523 -- for declaring an object. It might be possible to relax this in the
9524 -- future, e.g. by declaring the maximum possible space for the type.
9526 elsif Is_Indefinite_Subtype
(Typ
) then
9529 -- Functions returning tagged types may dispatch on result so their
9530 -- returned value is allocated on the secondary stack. Controlled
9531 -- type temporaries need finalization.
9533 elsif Is_Tagged_Type
(Typ
)
9534 or else Has_Controlled_Component
(Typ
)
9536 return not Is_Value_Type
(Typ
);
9540 elsif Is_Record_Type
(Typ
) then
9544 Comp
:= First_Entity
(Typ
);
9545 while Present
(Comp
) loop
9546 if Ekind
(Comp
) = E_Component
9547 and then Requires_Transient_Scope
(Etype
(Comp
))
9558 -- String literal types never require transient scope
9560 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
9563 -- Array type. Note that we already know that this is a constrained
9564 -- array, since unconstrained arrays will fail the indefinite test.
9566 elsif Is_Array_Type
(Typ
) then
9568 -- If component type requires a transient scope, the array does too
9570 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
9573 -- Otherwise, we only need a transient scope if the size is not
9574 -- known at compile time.
9577 return not Size_Known_At_Compile_Time
(Typ
);
9580 -- All other cases do not require a transient scope
9585 end Requires_Transient_Scope
;
9587 --------------------------
9588 -- Reset_Analyzed_Flags --
9589 --------------------------
9591 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
9593 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
9594 -- Function used to reset Analyzed flags in tree. Note that we do
9595 -- not reset Analyzed flags in entities, since there is no need to
9596 -- reanalyze entities, and indeed, it is wrong to do so, since it
9597 -- can result in generating auxiliary stuff more than once.
9599 --------------------
9600 -- Clear_Analyzed --
9601 --------------------
9603 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
9605 if not Has_Extension
(N
) then
9606 Set_Analyzed
(N
, False);
9612 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
9614 -- Start of processing for Reset_Analyzed_Flags
9618 end Reset_Analyzed_Flags
;
9620 ---------------------------
9621 -- Safe_To_Capture_Value --
9622 ---------------------------
9624 function Safe_To_Capture_Value
9627 Cond
: Boolean := False) return Boolean
9630 -- The only entities for which we track constant values are variables
9631 -- which are not renamings, constants, out parameters, and in out
9632 -- parameters, so check if we have this case.
9634 -- Note: it may seem odd to track constant values for constants, but in
9635 -- fact this routine is used for other purposes than simply capturing
9636 -- the value. In particular, the setting of Known[_Non]_Null.
9638 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
9640 Ekind
(Ent
) = E_Constant
9642 Ekind
(Ent
) = E_Out_Parameter
9644 Ekind
(Ent
) = E_In_Out_Parameter
9648 -- For conditionals, we also allow loop parameters and all formals,
9649 -- including in parameters.
9653 (Ekind
(Ent
) = E_Loop_Parameter
9655 Ekind
(Ent
) = E_In_Parameter
)
9659 -- For all other cases, not just unsafe, but impossible to capture
9660 -- Current_Value, since the above are the only entities which have
9661 -- Current_Value fields.
9667 -- Skip if volatile or aliased, since funny things might be going on in
9668 -- these cases which we cannot necessarily track. Also skip any variable
9669 -- for which an address clause is given, or whose address is taken. Also
9670 -- never capture value of library level variables (an attempt to do so
9671 -- can occur in the case of package elaboration code).
9673 if Treat_As_Volatile
(Ent
)
9674 or else Is_Aliased
(Ent
)
9675 or else Present
(Address_Clause
(Ent
))
9676 or else Address_Taken
(Ent
)
9677 or else (Is_Library_Level_Entity
(Ent
)
9678 and then Ekind
(Ent
) = E_Variable
)
9683 -- OK, all above conditions are met. We also require that the scope of
9684 -- the reference be the same as the scope of the entity, not counting
9685 -- packages and blocks and loops.
9688 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
9689 R_Scope
: Entity_Id
;
9692 R_Scope
:= Current_Scope
;
9693 while R_Scope
/= Standard_Standard
loop
9694 exit when R_Scope
= E_Scope
;
9696 if Ekind
(R_Scope
) /= E_Package
9698 Ekind
(R_Scope
) /= E_Block
9700 Ekind
(R_Scope
) /= E_Loop
9704 R_Scope
:= Scope
(R_Scope
);
9709 -- We also require that the reference does not appear in a context
9710 -- where it is not sure to be executed (i.e. a conditional context
9711 -- or an exception handler). We skip this if Cond is True, since the
9712 -- capturing of values from conditional tests handles this ok.
9726 while Present
(P
) loop
9727 if Nkind
(P
) = N_If_Statement
9728 or else Nkind
(P
) = N_Case_Statement
9729 or else (Nkind
(P
) = N_And_Then
and then Desc
= Right_Opnd
(P
))
9730 or else (Nkind
(P
) = N_Or_Else
and then Desc
= Right_Opnd
(P
))
9731 or else Nkind
(P
) = N_Exception_Handler
9732 or else Nkind
(P
) = N_Selective_Accept
9733 or else Nkind
(P
) = N_Conditional_Entry_Call
9734 or else Nkind
(P
) = N_Timed_Entry_Call
9735 or else Nkind
(P
) = N_Asynchronous_Select
9745 -- OK, looks safe to set value
9748 end Safe_To_Capture_Value
;
9754 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
9755 K1
: constant Node_Kind
:= Nkind
(N1
);
9756 K2
: constant Node_Kind
:= Nkind
(N2
);
9759 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
9760 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
9762 return Chars
(N1
) = Chars
(N2
);
9764 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
9765 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
9767 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
9768 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
9779 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
9780 N1
: constant Node_Id
:= Original_Node
(Node1
);
9781 N2
: constant Node_Id
:= Original_Node
(Node2
);
9782 -- We do the tests on original nodes, since we are most interested
9783 -- in the original source, not any expansion that got in the way.
9785 K1
: constant Node_Kind
:= Nkind
(N1
);
9786 K2
: constant Node_Kind
:= Nkind
(N2
);
9789 -- First case, both are entities with same entity
9791 if K1
in N_Has_Entity
9792 and then K2
in N_Has_Entity
9793 and then Present
(Entity
(N1
))
9794 and then Present
(Entity
(N2
))
9795 and then (Ekind
(Entity
(N1
)) = E_Variable
9797 Ekind
(Entity
(N1
)) = E_Constant
)
9798 and then Entity
(N1
) = Entity
(N2
)
9802 -- Second case, selected component with same selector, same record
9804 elsif K1
= N_Selected_Component
9805 and then K2
= N_Selected_Component
9806 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
9808 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
9810 -- Third case, indexed component with same subscripts, same array
9812 elsif K1
= N_Indexed_Component
9813 and then K2
= N_Indexed_Component
9814 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
9819 E1
:= First
(Expressions
(N1
));
9820 E2
:= First
(Expressions
(N2
));
9821 while Present
(E1
) loop
9822 if not Same_Value
(E1
, E2
) then
9833 -- Fourth case, slice of same array with same bounds
9836 and then K2
= N_Slice
9837 and then Nkind
(Discrete_Range
(N1
)) = N_Range
9838 and then Nkind
(Discrete_Range
(N2
)) = N_Range
9839 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
9840 Low_Bound
(Discrete_Range
(N2
)))
9841 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
9842 High_Bound
(Discrete_Range
(N2
)))
9844 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
9846 -- All other cases, not clearly the same object
9857 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
9862 elsif not Is_Constrained
(T1
)
9863 and then not Is_Constrained
(T2
)
9864 and then Base_Type
(T1
) = Base_Type
(T2
)
9868 -- For now don't bother with case of identical constraints, to be
9869 -- fiddled with later on perhaps (this is only used for optimization
9870 -- purposes, so it is not critical to do a best possible job)
9881 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
9883 if Compile_Time_Known_Value
(Node1
)
9884 and then Compile_Time_Known_Value
(Node2
)
9885 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
9888 elsif Same_Object
(Node1
, Node2
) then
9895 ------------------------
9896 -- Scope_Is_Transient --
9897 ------------------------
9899 function Scope_Is_Transient
return Boolean is
9901 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
9902 end Scope_Is_Transient
;
9908 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
9913 while Scop
/= Standard_Standard
loop
9914 Scop
:= Scope
(Scop
);
9916 if Scop
= Scope2
then
9924 --------------------------
9925 -- Scope_Within_Or_Same --
9926 --------------------------
9928 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
9933 while Scop
/= Standard_Standard
loop
9934 if Scop
= Scope2
then
9937 Scop
:= Scope
(Scop
);
9942 end Scope_Within_Or_Same
;
9944 --------------------
9945 -- Set_Convention --
9946 --------------------
9948 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
9950 Basic_Set_Convention
(E
, Val
);
9953 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
9954 and then Has_Foreign_Convention
(E
)
9956 Set_Can_Use_Internal_Rep
(E
, False);
9960 ------------------------
9961 -- Set_Current_Entity --
9962 ------------------------
9964 -- The given entity is to be set as the currently visible definition
9965 -- of its associated name (i.e. the Node_Id associated with its name).
9966 -- All we have to do is to get the name from the identifier, and
9967 -- then set the associated Node_Id to point to the given entity.
9969 procedure Set_Current_Entity
(E
: Entity_Id
) is
9971 Set_Name_Entity_Id
(Chars
(E
), E
);
9972 end Set_Current_Entity
;
9974 ---------------------------
9975 -- Set_Debug_Info_Needed --
9976 ---------------------------
9978 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
9980 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
9981 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
9982 -- Used to set debug info in a related node if not set already
9984 --------------------------------------
9985 -- Set_Debug_Info_Needed_If_Not_Set --
9986 --------------------------------------
9988 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
9991 and then not Needs_Debug_Info
(E
)
9993 Set_Debug_Info_Needed
(E
);
9995 -- For a private type, indicate that the full view also needs
9996 -- debug information.
9999 and then Is_Private_Type
(E
)
10000 and then Present
(Full_View
(E
))
10002 Set_Debug_Info_Needed
(Full_View
(E
));
10005 end Set_Debug_Info_Needed_If_Not_Set
;
10007 -- Start of processing for Set_Debug_Info_Needed
10010 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
10011 -- indicates that Debug_Info_Needed is never required for the entity.
10014 or else Debug_Info_Off
(T
)
10019 -- Set flag in entity itself. Note that we will go through the following
10020 -- circuitry even if the flag is already set on T. That's intentional,
10021 -- it makes sure that the flag will be set in subsidiary entities.
10023 Set_Needs_Debug_Info
(T
);
10025 -- Set flag on subsidiary entities if not set already
10027 if Is_Object
(T
) then
10028 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
10030 elsif Is_Type
(T
) then
10031 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
10033 if Is_Record_Type
(T
) then
10035 Ent
: Entity_Id
:= First_Entity
(T
);
10037 while Present
(Ent
) loop
10038 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
10043 elsif Is_Array_Type
(T
) then
10044 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
10047 Indx
: Node_Id
:= First_Index
(T
);
10049 while Present
(Indx
) loop
10050 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
10051 Indx
:= Next_Index
(Indx
);
10055 if Is_Packed
(T
) then
10056 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Type
(T
));
10059 elsif Is_Access_Type
(T
) then
10060 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
10062 elsif Is_Private_Type
(T
) then
10063 Set_Debug_Info_Needed_If_Not_Set
(Full_View
(T
));
10065 elsif Is_Protected_Type
(T
) then
10066 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
10069 end Set_Debug_Info_Needed
;
10071 ---------------------------------
10072 -- Set_Entity_With_Style_Check --
10073 ---------------------------------
10075 procedure Set_Entity_With_Style_Check
(N
: Node_Id
; Val
: Entity_Id
) is
10076 Val_Actual
: Entity_Id
;
10080 Set_Entity
(N
, Val
);
10083 and then not Suppress_Style_Checks
(Val
)
10084 and then not In_Instance
10086 if Nkind
(N
) = N_Identifier
then
10088 elsif Nkind
(N
) = N_Expanded_Name
then
10089 Nod
:= Selector_Name
(N
);
10094 -- A special situation arises for derived operations, where we want
10095 -- to do the check against the parent (since the Sloc of the derived
10096 -- operation points to the derived type declaration itself).
10099 while not Comes_From_Source
(Val_Actual
)
10100 and then Nkind
(Val_Actual
) in N_Entity
10101 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
10102 or else Is_Subprogram
(Val_Actual
)
10103 or else Is_Generic_Subprogram
(Val_Actual
))
10104 and then Present
(Alias
(Val_Actual
))
10106 Val_Actual
:= Alias
(Val_Actual
);
10109 -- Renaming declarations for generic actuals do not come from source,
10110 -- and have a different name from that of the entity they rename, so
10111 -- there is no style check to perform here.
10113 if Chars
(Nod
) = Chars
(Val_Actual
) then
10114 Style
.Check_Identifier
(Nod
, Val_Actual
);
10118 Set_Entity
(N
, Val
);
10119 end Set_Entity_With_Style_Check
;
10121 ------------------------
10122 -- Set_Name_Entity_Id --
10123 ------------------------
10125 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
10127 Set_Name_Table_Info
(Id
, Int
(Val
));
10128 end Set_Name_Entity_Id
;
10130 ---------------------
10131 -- Set_Next_Actual --
10132 ---------------------
10134 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
10136 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
10137 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
10139 end Set_Next_Actual
;
10141 ----------------------------------
10142 -- Set_Optimize_Alignment_Flags --
10143 ----------------------------------
10145 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
10147 if Optimize_Alignment
= 'S' then
10148 Set_Optimize_Alignment_Space
(E
);
10149 elsif Optimize_Alignment
= 'T' then
10150 Set_Optimize_Alignment_Time
(E
);
10152 end Set_Optimize_Alignment_Flags
;
10154 -----------------------
10155 -- Set_Public_Status --
10156 -----------------------
10158 procedure Set_Public_Status
(Id
: Entity_Id
) is
10159 S
: constant Entity_Id
:= Current_Scope
;
10161 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
10162 -- Determines if E is defined within handled statement sequence or
10163 -- an if statement, returns True if so, False otherwise.
10165 ----------------------
10166 -- Within_HSS_Or_If --
10167 ----------------------
10169 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
10172 N
:= Declaration_Node
(E
);
10179 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
10185 end Within_HSS_Or_If
;
10187 -- Start of processing for Set_Public_Status
10190 -- Everything in the scope of Standard is public
10192 if S
= Standard_Standard
then
10193 Set_Is_Public
(Id
);
10195 -- Entity is definitely not public if enclosing scope is not public
10197 elsif not Is_Public
(S
) then
10200 -- An object or function declaration that occurs in a handled sequence
10201 -- of statements or within an if statement is the declaration for a
10202 -- temporary object or local subprogram generated by the expander. It
10203 -- never needs to be made public and furthermore, making it public can
10204 -- cause back end problems.
10206 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
10207 N_Function_Specification
)
10208 and then Within_HSS_Or_If
(Id
)
10212 -- Entities in public packages or records are public
10214 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
10215 Set_Is_Public
(Id
);
10217 -- The bounds of an entry family declaration can generate object
10218 -- declarations that are visible to the back-end, e.g. in the
10219 -- the declaration of a composite type that contains tasks.
10221 elsif Is_Concurrent_Type
(S
)
10222 and then not Has_Completion
(S
)
10223 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
10225 Set_Is_Public
(Id
);
10227 end Set_Public_Status
;
10229 -----------------------------
10230 -- Set_Referenced_Modified --
10231 -----------------------------
10233 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
10237 -- Deal with indexed or selected component where prefix is modified
10239 if Nkind
(N
) = N_Indexed_Component
10241 Nkind
(N
) = N_Selected_Component
10243 Pref
:= Prefix
(N
);
10245 -- If prefix is access type, then it is the designated object that is
10246 -- being modified, which means we have no entity to set the flag on.
10248 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
10251 -- Otherwise chase the prefix
10254 Set_Referenced_Modified
(Pref
, Out_Param
);
10257 -- Otherwise see if we have an entity name (only other case to process)
10259 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
10260 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
10261 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
10263 end Set_Referenced_Modified
;
10265 ----------------------------
10266 -- Set_Scope_Is_Transient --
10267 ----------------------------
10269 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
10271 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
10272 end Set_Scope_Is_Transient
;
10274 -------------------
10275 -- Set_Size_Info --
10276 -------------------
10278 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
10280 -- We copy Esize, but not RM_Size, since in general RM_Size is
10281 -- subtype specific and does not get inherited by all subtypes.
10283 Set_Esize
(T1
, Esize
(T2
));
10284 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
10286 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
10288 Is_Discrete_Or_Fixed_Point_Type
(T2
)
10290 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
10293 Set_Alignment
(T1
, Alignment
(T2
));
10296 --------------------
10297 -- Static_Integer --
10298 --------------------
10300 function Static_Integer
(N
: Node_Id
) return Uint
is
10302 Analyze_And_Resolve
(N
, Any_Integer
);
10305 or else Error_Posted
(N
)
10306 or else Etype
(N
) = Any_Type
10311 if Is_Static_Expression
(N
) then
10312 if not Raises_Constraint_Error
(N
) then
10313 return Expr_Value
(N
);
10318 elsif Etype
(N
) = Any_Type
then
10322 Flag_Non_Static_Expr
10323 ("static integer expression required here", N
);
10326 end Static_Integer
;
10328 --------------------------
10329 -- Statically_Different --
10330 --------------------------
10332 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
10333 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
10334 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
10336 return Is_Entity_Name
(R1
)
10337 and then Is_Entity_Name
(R2
)
10338 and then Entity
(R1
) /= Entity
(R2
)
10339 and then not Is_Formal
(Entity
(R1
))
10340 and then not Is_Formal
(Entity
(R2
));
10341 end Statically_Different
;
10343 -----------------------------
10344 -- Subprogram_Access_Level --
10345 -----------------------------
10347 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
10349 if Present
(Alias
(Subp
)) then
10350 return Subprogram_Access_Level
(Alias
(Subp
));
10352 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
10354 end Subprogram_Access_Level
;
10360 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
10362 if Debug_Flag_W
then
10363 for J
in 0 .. Scope_Stack
.Last
loop
10368 Write_Name
(Chars
(E
));
10369 Write_Str
(" from ");
10370 Write_Location
(Sloc
(N
));
10375 -----------------------
10376 -- Transfer_Entities --
10377 -----------------------
10379 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
10380 Ent
: Entity_Id
:= First_Entity
(From
);
10387 if (Last_Entity
(To
)) = Empty
then
10388 Set_First_Entity
(To
, Ent
);
10390 Set_Next_Entity
(Last_Entity
(To
), Ent
);
10393 Set_Last_Entity
(To
, Last_Entity
(From
));
10395 while Present
(Ent
) loop
10396 Set_Scope
(Ent
, To
);
10398 if not Is_Public
(Ent
) then
10399 Set_Public_Status
(Ent
);
10402 and then Ekind
(Ent
) = E_Record_Subtype
10405 -- The components of the propagated Itype must be public
10411 Comp
:= First_Entity
(Ent
);
10412 while Present
(Comp
) loop
10413 Set_Is_Public
(Comp
);
10414 Next_Entity
(Comp
);
10423 Set_First_Entity
(From
, Empty
);
10424 Set_Last_Entity
(From
, Empty
);
10425 end Transfer_Entities
;
10427 -----------------------
10428 -- Type_Access_Level --
10429 -----------------------
10431 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
10435 Btyp
:= Base_Type
(Typ
);
10437 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
10438 -- simply use the level where the type is declared. This is true for
10439 -- stand-alone object declarations, and for anonymous access types
10440 -- associated with components the level is the same as that of the
10441 -- enclosing composite type. However, special treatment is needed for
10442 -- the cases of access parameters, return objects of an anonymous access
10443 -- type, and, in Ada 95, access discriminants of limited types.
10445 if Ekind
(Btyp
) in Access_Kind
then
10446 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
10448 -- If the type is a nonlocal anonymous access type (such as for
10449 -- an access parameter) we treat it as being declared at the
10450 -- library level to ensure that names such as X.all'access don't
10451 -- fail static accessibility checks.
10453 if not Is_Local_Anonymous_Access
(Typ
) then
10454 return Scope_Depth
(Standard_Standard
);
10456 -- If this is a return object, the accessibility level is that of
10457 -- the result subtype of the enclosing function. The test here is
10458 -- little complicated, because we have to account for extended
10459 -- return statements that have been rewritten as blocks, in which
10460 -- case we have to find and the Is_Return_Object attribute of the
10461 -- itype's associated object. It would be nice to find a way to
10462 -- simplify this test, but it doesn't seem worthwhile to add a new
10463 -- flag just for purposes of this test. ???
10465 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
10468 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
10469 N_Object_Declaration
10470 and then Is_Return_Object
10471 (Defining_Identifier
10472 (Associated_Node_For_Itype
(Btyp
))))
10478 Scop
:= Scope
(Scope
(Btyp
));
10479 while Present
(Scop
) loop
10480 exit when Ekind
(Scop
) = E_Function
;
10481 Scop
:= Scope
(Scop
);
10484 -- Treat the return object's type as having the level of the
10485 -- function's result subtype (as per RM05-6.5(5.3/2)).
10487 return Type_Access_Level
(Etype
(Scop
));
10492 Btyp
:= Root_Type
(Btyp
);
10494 -- The accessibility level of anonymous access types associated with
10495 -- discriminants is that of the current instance of the type, and
10496 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
10498 -- AI-402: access discriminants have accessibility based on the
10499 -- object rather than the type in Ada 2005, so the above paragraph
10502 -- ??? Needs completion with rules from AI-416
10504 if Ada_Version
<= Ada_95
10505 and then Ekind
(Typ
) = E_Anonymous_Access_Type
10506 and then Present
(Associated_Node_For_Itype
(Typ
))
10507 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
10508 N_Discriminant_Specification
10510 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
10514 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
10515 end Type_Access_Level
;
10517 --------------------
10518 -- Ultimate_Alias --
10519 --------------------
10520 -- To do: add occurrences calling this new subprogram
10522 function Ultimate_Alias
(Prim
: Entity_Id
) return Entity_Id
is
10523 E
: Entity_Id
:= Prim
;
10526 while Present
(Alias
(E
)) loop
10531 end Ultimate_Alias
;
10533 --------------------------
10534 -- Unit_Declaration_Node --
10535 --------------------------
10537 function Unit_Declaration_Node
(Unit_Id
: Entity_Id
) return Node_Id
is
10538 N
: Node_Id
:= Parent
(Unit_Id
);
10541 -- Predefined operators do not have a full function declaration
10543 if Ekind
(Unit_Id
) = E_Operator
then
10547 -- Isn't there some better way to express the following ???
10549 while Nkind
(N
) /= N_Abstract_Subprogram_Declaration
10550 and then Nkind
(N
) /= N_Formal_Package_Declaration
10551 and then Nkind
(N
) /= N_Function_Instantiation
10552 and then Nkind
(N
) /= N_Generic_Package_Declaration
10553 and then Nkind
(N
) /= N_Generic_Subprogram_Declaration
10554 and then Nkind
(N
) /= N_Package_Declaration
10555 and then Nkind
(N
) /= N_Package_Body
10556 and then Nkind
(N
) /= N_Package_Instantiation
10557 and then Nkind
(N
) /= N_Package_Renaming_Declaration
10558 and then Nkind
(N
) /= N_Procedure_Instantiation
10559 and then Nkind
(N
) /= N_Protected_Body
10560 and then Nkind
(N
) /= N_Subprogram_Declaration
10561 and then Nkind
(N
) /= N_Subprogram_Body
10562 and then Nkind
(N
) /= N_Subprogram_Body_Stub
10563 and then Nkind
(N
) /= N_Subprogram_Renaming_Declaration
10564 and then Nkind
(N
) /= N_Task_Body
10565 and then Nkind
(N
) /= N_Task_Type_Declaration
10566 and then Nkind
(N
) not in N_Formal_Subprogram_Declaration
10567 and then Nkind
(N
) not in N_Generic_Renaming_Declaration
10570 pragma Assert
(Present
(N
));
10574 end Unit_Declaration_Node
;
10576 ------------------------------
10577 -- Universal_Interpretation --
10578 ------------------------------
10580 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
10581 Index
: Interp_Index
;
10585 -- The argument may be a formal parameter of an operator or subprogram
10586 -- with multiple interpretations, or else an expression for an actual.
10588 if Nkind
(Opnd
) = N_Defining_Identifier
10589 or else not Is_Overloaded
(Opnd
)
10591 if Etype
(Opnd
) = Universal_Integer
10592 or else Etype
(Opnd
) = Universal_Real
10594 return Etype
(Opnd
);
10600 Get_First_Interp
(Opnd
, Index
, It
);
10601 while Present
(It
.Typ
) loop
10602 if It
.Typ
= Universal_Integer
10603 or else It
.Typ
= Universal_Real
10608 Get_Next_Interp
(Index
, It
);
10613 end Universal_Interpretation
;
10619 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
10621 -- Recurse to handle unlikely case of multiple levels of qualification
10623 if Nkind
(Expr
) = N_Qualified_Expression
then
10624 return Unqualify
(Expression
(Expr
));
10626 -- Normal case, not a qualified expression
10633 ----------------------
10634 -- Within_Init_Proc --
10635 ----------------------
10637 function Within_Init_Proc
return Boolean is
10641 S
:= Current_Scope
;
10642 while not Is_Overloadable
(S
) loop
10643 if S
= Standard_Standard
then
10650 return Is_Init_Proc
(S
);
10651 end Within_Init_Proc
;
10657 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
10658 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
10659 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
10661 function Has_One_Matching_Field
return Boolean;
10662 -- Determines if Expec_Type is a record type with a single component or
10663 -- discriminant whose type matches the found type or is one dimensional
10664 -- array whose component type matches the found type.
10666 ----------------------------
10667 -- Has_One_Matching_Field --
10668 ----------------------------
10670 function Has_One_Matching_Field
return Boolean is
10674 if Is_Array_Type
(Expec_Type
)
10675 and then Number_Dimensions
(Expec_Type
) = 1
10677 Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
10681 elsif not Is_Record_Type
(Expec_Type
) then
10685 E
:= First_Entity
(Expec_Type
);
10690 elsif (Ekind
(E
) /= E_Discriminant
10691 and then Ekind
(E
) /= E_Component
)
10692 or else (Chars
(E
) = Name_uTag
10693 or else Chars
(E
) = Name_uParent
)
10702 if not Covers
(Etype
(E
), Found_Type
) then
10705 elsif Present
(Next_Entity
(E
)) then
10712 end Has_One_Matching_Field
;
10714 -- Start of processing for Wrong_Type
10717 -- Don't output message if either type is Any_Type, or if a message
10718 -- has already been posted for this node. We need to do the latter
10719 -- check explicitly (it is ordinarily done in Errout), because we
10720 -- are using ! to force the output of the error messages.
10722 if Expec_Type
= Any_Type
10723 or else Found_Type
= Any_Type
10724 or else Error_Posted
(Expr
)
10728 -- In an instance, there is an ongoing problem with completion of
10729 -- type derived from private types. Their structure is what Gigi
10730 -- expects, but the Etype is the parent type rather than the
10731 -- derived private type itself. Do not flag error in this case. The
10732 -- private completion is an entity without a parent, like an Itype.
10733 -- Similarly, full and partial views may be incorrect in the instance.
10734 -- There is no simple way to insure that it is consistent ???
10736 elsif In_Instance
then
10737 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
10739 (Has_Private_Declaration
(Expected_Type
)
10740 or else Has_Private_Declaration
(Etype
(Expr
)))
10741 and then No
(Parent
(Expected_Type
))
10747 -- An interesting special check. If the expression is parenthesized
10748 -- and its type corresponds to the type of the sole component of the
10749 -- expected record type, or to the component type of the expected one
10750 -- dimensional array type, then assume we have a bad aggregate attempt.
10752 if Nkind
(Expr
) in N_Subexpr
10753 and then Paren_Count
(Expr
) /= 0
10754 and then Has_One_Matching_Field
10756 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
10758 -- Another special check, if we are looking for a pool-specific access
10759 -- type and we found an E_Access_Attribute_Type, then we have the case
10760 -- of an Access attribute being used in a context which needs a pool-
10761 -- specific type, which is never allowed. The one extra check we make
10762 -- is that the expected designated type covers the Found_Type.
10764 elsif Is_Access_Type
(Expec_Type
)
10765 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
10766 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
10767 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
10769 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
10771 Error_Msg_N
("result must be general access type!", Expr
);
10772 Error_Msg_NE
("add ALL to }!", Expr
, Expec_Type
);
10774 -- Another special check, if the expected type is an integer type,
10775 -- but the expression is of type System.Address, and the parent is
10776 -- an addition or subtraction operation whose left operand is the
10777 -- expression in question and whose right operand is of an integral
10778 -- type, then this is an attempt at address arithmetic, so give
10779 -- appropriate message.
10781 elsif Is_Integer_Type
(Expec_Type
)
10782 and then Is_RTE
(Found_Type
, RE_Address
)
10783 and then (Nkind
(Parent
(Expr
)) = N_Op_Add
10785 Nkind
(Parent
(Expr
)) = N_Op_Subtract
)
10786 and then Expr
= Left_Opnd
(Parent
(Expr
))
10787 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
10790 ("address arithmetic not predefined in package System",
10793 ("\possible missing with/use of System.Storage_Elements",
10797 -- If the expected type is an anonymous access type, as for access
10798 -- parameters and discriminants, the error is on the designated types.
10800 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
10801 if Comes_From_Source
(Expec_Type
) then
10802 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
10805 ("expected an access type with designated}",
10806 Expr
, Designated_Type
(Expec_Type
));
10809 if Is_Access_Type
(Found_Type
)
10810 and then not Comes_From_Source
(Found_Type
)
10813 ("\\found an access type with designated}!",
10814 Expr
, Designated_Type
(Found_Type
));
10816 if From_With_Type
(Found_Type
) then
10817 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
10818 Error_Msg_Qual_Level
:= 99;
10819 Error_Msg_NE
("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
10820 Error_Msg_Qual_Level
:= 0;
10822 Error_Msg_NE
("found}!", Expr
, Found_Type
);
10826 -- Normal case of one type found, some other type expected
10829 -- If the names of the two types are the same, see if some number
10830 -- of levels of qualification will help. Don't try more than three
10831 -- levels, and if we get to standard, it's no use (and probably
10832 -- represents an error in the compiler) Also do not bother with
10833 -- internal scope names.
10836 Expec_Scope
: Entity_Id
;
10837 Found_Scope
: Entity_Id
;
10840 Expec_Scope
:= Expec_Type
;
10841 Found_Scope
:= Found_Type
;
10843 for Levels
in Int
range 0 .. 3 loop
10844 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
10845 Error_Msg_Qual_Level
:= Levels
;
10849 Expec_Scope
:= Scope
(Expec_Scope
);
10850 Found_Scope
:= Scope
(Found_Scope
);
10852 exit when Expec_Scope
= Standard_Standard
10853 or else Found_Scope
= Standard_Standard
10854 or else not Comes_From_Source
(Expec_Scope
)
10855 or else not Comes_From_Source
(Found_Scope
);
10859 if Is_Record_Type
(Expec_Type
)
10860 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
10862 Error_Msg_NE
("expected}!", Expr
,
10863 Corresponding_Remote_Type
(Expec_Type
));
10865 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
10868 if Is_Entity_Name
(Expr
)
10869 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
10871 Error_Msg_N
("\\found package name!", Expr
);
10873 elsif Is_Entity_Name
(Expr
)
10875 (Ekind
(Entity
(Expr
)) = E_Procedure
10877 Ekind
(Entity
(Expr
)) = E_Generic_Procedure
)
10879 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
10881 ("found procedure name, possibly missing Access attribute!",
10885 ("\\found procedure name instead of function!", Expr
);
10888 elsif Nkind
(Expr
) = N_Function_Call
10889 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
10890 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
10891 and then No
(Parameter_Associations
(Expr
))
10894 ("found function name, possibly missing Access attribute!",
10897 -- Catch common error: a prefix or infix operator which is not
10898 -- directly visible because the type isn't.
10900 elsif Nkind
(Expr
) in N_Op
10901 and then Is_Overloaded
(Expr
)
10902 and then not Is_Immediately_Visible
(Expec_Type
)
10903 and then not Is_Potentially_Use_Visible
(Expec_Type
)
10904 and then not In_Use
(Expec_Type
)
10905 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
10908 ("operator of the type is not directly visible!", Expr
);
10910 elsif Ekind
(Found_Type
) = E_Void
10911 and then Present
(Parent
(Found_Type
))
10912 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
10914 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
10917 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
10920 Error_Msg_Qual_Level
:= 0;